Hi applePi! Yes, now I know.applePi wrote:Hi Lexicon
you write FinishMesh(#False), to create entity the FinishMesh should be true. FinishMesh(#True)
Terrain bugs
Re: Terrain bugs
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
Re: Terrain bugs
or create a sphere with 2 submeshapplePi wrote:seems to me the only way to texture a sphere room inside different than outside is to use two spheres
Code: Select all
IncludeFile "Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY, SpriteX, SpriteY
Global Dim MeshDataVertex.PB_MeshVertex(0)
Global Dim MeshDataIndex.PB_MeshFace(0)
Declare CreateSphere2(No, mRadius, mNumRings, mNumSegments)
If InitEngine3D()
Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Packs/Desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
;- Ground
;
CreateMaterial(0, LoadTexture(0, "Dirt.jpg"))
CreatePlane(0, 1500, 1500, 40, 40, 15, 15)
CreateEntity(0,MeshID(0),MaterialID(0))
EntityRenderMode(0, 0)
CreateCube(1, 50)
CreateEntity(1, MeshID(1), GetScriptMaterial(1, "Color/Blue"), 0, 50, 0)
;Sky
CreateMaterial(2, LoadTexture(2, "clouds.jpg"))
MaterialCullingMode(2, #PB_Material_AntiClockWiseCull)
ScaleMaterial(2, 0.05, 0.05)
CreateMaterial(3, LoadTexture(3, "RustySteel.jpg"))
MaterialCullingMode(3, #PB_Material_ClockWiseCull)
ScaleMaterial(3, 0.05, 0.05)
CreateSphere2(2, 1, 50, 50)
SetMeshMaterial(2,MaterialID(3), 0)
SetMeshMaterial(2,MaterialID(2), 1)
CreateEntity(2, MeshID(2), #PB_Material_None, 0, 200, 0)
ScaleEntity(2, 300, 300, 300)
;- Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 120, 50, #PB_Absolute)
CameraBackColor(0, $FF)
;- Light
;
CreateLight(0, RGB(255, 255, 255), -40, 100, 80)
AmbientColor(RGB(80, 80, 80))
Repeat
Screen3DEvents()
If ExamineMouse()
MouseX = -MouseDeltaX()/10
MouseY = -MouseDeltaY()/10
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 1
Else
KeyY = 0
EndIf
EndIf
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Procedure Build(Radius, NumRings, NumSegments)
DeltaRingAngle.f = #PI / NumRings
DeltaSegAngle.f = #PI*2 / NumSegments
offset = 0
For ring = 0 To NumRings
r0.f = Radius * Sin(ring * DeltaRingAngle)
y0.f = Radius * Cos(ring * DeltaRingAngle)
For seg = 0 To NumSegments;
x0.f = r0 * Sin(seg * DeltaSegAngle)
z0.f = r0 * Cos(seg * DeltaSegAngle)
MeshVertexPosition(x0, y0, z0)
MeshVertexNormal(x0, y0, z0); should be normalized if Radius <> 1
MeshVertexTextureCoordinate(seg / NumSegments, ring / NumRings)
If ring <> NumRings
If seg <> NumSegments
If ring <> NumRings-1
MeshFace(offset + NumSegments + 2, offset, offset + NumSegments + 1)
EndIf
If ring <> 0
MeshFace(offset + NumSegments + 2, offset + 1, offset)
EndIf
EndIf
offset + 1
EndIf
Next
Next
EndProcedure
Procedure CreateSphere2(No, Radius, NumRings, NumSegments)
CreateMesh(No)
Build(Radius, NumRings, NumSegments)
AddSubMesh()
Build(Radius, NumRings, NumSegments)
FinishMesh(#True)
UpdateMeshBoundingBox(0)
EndProcedurePlease correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Re: Terrain bugs
thanks Comtois for the solution, and especially the sphere generator code, i was just thinking yesterday how to manufacture a sphere manually but find some difficulty. i have made from it half sphere suitable for big rooms on the grounds with physics, also it is suitable for making umbrella (DeltaRingAngle.f = #PI / NumRings/3) , a telescope dish, also a concave and convex mirror to use with cube mapping. just small samples from that sphere.

