here 2000 cubes added together with a sphere trapped inside. with addMesh it is just addMesh(x,y) 2000 times.
just a show case for the benefits of addMesh.
Code: Select all
Enumeration
#LIGHT
#CAMERA
#mainwin
#Plane
#sphere
EndEnumeration
#cameraSpeed = 4
Define.f KeyX, KeyY, MouseX, MouseY
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
Define.f KeyX, KeyY
Declare CreateMatrix()
InitEngine3D()
InitMouse()
InitKeyboard()
InitSprite()
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "arrow keys+mouse: move/rotate camera.... X/Z rotate object", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
Add3DArchive(".",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures\",#PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\GUI",#PB_3DArchive_FileSystem)
Parse3DScripts()
CreateCamera(0,0,0,100,100)
CameraBackColor(0,RGB(0, 0, 0))
MoveCamera(0,10,100,160)
CreateLight(0,RGB(255, 255, 95),-50,50,100)
;;============================================
OpenWindow3D(0,0,0,300,120,"Engine Stats")
TextGadget3D(0,2,0,300,30,"")
TextGadget3D(1,2,0,300,60,"")
ShowGUI(255,0)
;=============================================
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
MaterialShadingMode(0, #PB_Material_Wireframe )
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 200, 250, #PB_Absolute)
CameraFOV(#camera, 70)
CameraBackColor(#camera, RGB(255,200,200))
CameraLookAt(#camera,0,0,0)
CreateLight(0, RGB(255,255,255), 0, 20, 30)
AmbientColor(RGB(200, 200, 200))
CreateMaterial(3, LoadTexture(3, "snow_1024.jpg"))
DisableMaterialLighting(3, #False)
SetMaterialColor(3, #PB_Material_AmbientColor, RGB(250, 255, 0))
SetMaterialColor(3, #PB_Material_SpecularColor, RGB(255, 255, 0))
CreateMaterial(1, LoadTexture(1, "ValetCoeur.jpg"))
MaterialCullingMode(1, #PB_Material_NoCulling)
DisableMaterialLighting(1, #False)
CreateMaterial(2, LoadTexture(2, "RustySteel.jpg"))
MaterialCullingMode(2, #PB_Material_NoCulling)
CreateMaterial(4, LoadTexture(4, "ground_diffuse.png"))
MaterialCullingMode(4, #PB_Material_NoCulling)
CreateMaterial(5, LoadTexture(5, "Geebee2.bmp"))
MaterialCullingMode(5, #PB_Material_NoCulling)
CreateMatrix()
For i=0 To 2000
SetEntityMaterial(0,MaterialID(Random(5)), i)
Next
WorldGravity(-20)
CreateSphere(#sphere, 10)
CreateEntity(#sphere, MeshID(#sphere), MaterialID(5))
EntityPhysicBody(#sphere, #PB_Entity_SphereBody, 0.5,0.5,0.2)
Repeat
Event = WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#cameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #cameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#cameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #cameraSpeed
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_Z)
DisableEntityBody(#sphere, #False)
ApplyEntityImpulse(#sphere, 0, 0, 0 )
RotateEntity(0,0,0,0.5, #PB_Relative)
ElseIf KeyboardPushed(#PB_Key_X)
DisableEntityBody(#sphere, #False)
ApplyEntityImpulse(#sphere, 0, 0, 0 )
RotateEntity(0,0,0,-0.5, #PB_Relative)
EndIf
If KeyboardPushed(#PB_Key_S)
SaveMesh(0, "Compound.mesh")
EndIf
EndIf
rot.f+0.6
RotateEntity(0, 0.0,0.5,0.0,#PB_Relative)
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
;;==============================================
SetGadgetText3D(0,"FPS: "+StrF(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
SetGadgetText3D(1,"Tris: "+StrF(Engine3DStatus(#PB_Engine3D_NbRenderedTriangles)))
;;================================================
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
End
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
CreateCube(30,5)
While count <=2000
AddSubMesh(#PB_Mesh_TriangleList)
CopyMesh(30,31)
TransformMesh(31,Random(200)-100,Random(200)-100,Random(200)-100, 1,1,1,0,0,0)
GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(31)-1)
GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
ArrSize = ArraySize(MeshData())
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
count+1
Wend
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(1))
CreateEntity(0, MeshID(0), MaterialID(1), 0,-10,0)
EntityPhysicBody(0, #PB_Entity_StaticBody, 1, 0.2, 1)
EndProcedure