Trying to create a mesh from each face of another mesh
Posted: Sat Mar 11, 2023 8:06 pm
I am trying to create a mesh from each face of another existing mesh, but don't know if there is a bug or is me who am making the things bad done.
The issue is i GetMeshData() form an Ico sphere and iterate each one of its faces to build a triangle mesh form each one, but it does not work because compiler seems unable to create the meshes.
The tip code should display at the left side the icosphere normally created, and at the right side, one of its triangle faces created as a new mesh and a new entity.
In the tip code are the comments about issue:
The issue is i GetMeshData() form an Ico sphere and iterate each one of its faces to build a triangle mesh form each one, but it does not work because compiler seems unable to create the meshes.
The tip code should display at the left side the icosphere normally created, and at the right side, one of its triangle faces created as a new mesh and a new entity.
In the tip code are the comments about issue:
Code: Select all
ExamineDesktops()
RX=1280:RY=720
InitEngine3D()
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,RX,RY,"Title",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,RX,RY,1,0,0,#PB_Screen_WaitSynchronization)
Enumeration; Camaras
#Camara
EndEnumeration
Enumeration; Luces
#Luz
EndEnumeration
Enumeration; Texturas
#Textura
EndEnumeration
Enumeration; Materiales
#Material
EndEnumeration
Enumeration; Mallas
#Object0malla
#Object1malla=100
EndEnumeration
Enumeration; Entidades
#Object0
#Object1=100
EndEnumeration
Enumeration; Nodos
#Pivotcamara
EndEnumeration
CreateLight(#luz,$EEEEEE,4,4,2,#PB_Light_Point)
CreateCamera(#Camara,0,0,100,100):CameraRange(#Camara,0.1,10000):CameraBackColor(#Camara,$181911)
MoveCamera(#Camara,0,0,6,#PB_Absolute)
;CameraRenderMode(#Camara,#PB_Camera_Wireframe)
CreateIcoSphere(#Object0malla,1,1)
CreateEntity(#Object0,MeshID(#Object0malla),#PB_Material_None,-2,0,0)
vertices.l=MeshIndexCount(#Object0malla,0)
caras.l=vertices/3
Dim vertice.MeshVertex(vertices)
Dim celda.i(caras)
GetMeshData(#Object0malla,0,vertice.MeshVertex(),#PB_Mesh_Vertex|#PB_Mesh_UVCoordinate|#PB_Mesh_Normal|#PB_Mesh_Color|#PB_Mesh_Tangent,0,vertices-1)
vertn.l=0
For t.l=1 To caras
celda.i(t)=CreateMesh(#Object1malla+t-1,#PB_Mesh_TriangleList)
debug celda.i(t); <- MeshID(#Object1malla+t-1) number is always the same. Why ?!?!?!?!
MeshVertex(vertice.MeshVertex(vertn)\x,vertice.MeshVertex(vertn)\y,vertice.MeshVertex(vertn)\z,0,0,$FFFFFF,vertice.MeshVertex(vertn)\NormalX,vertice.MeshVertex(vertn)\NormalY,vertice.MeshVertex(vertn)\NormalZ)
MeshVertex(vertice.MeshVertex(vertn+1)\x,vertice.MeshVertex(vertn+1)\y,vertice.MeshVertex(vertn+1)\z,0.5,0.5,$FFFFFF,vertice.MeshVertex(vertn+1)\NormalX,vertice.MeshVertex(vertn+1)\NormalY,vertice.MeshVertex(vertn+1)\NormalZ)
MeshVertex(vertice.MeshVertex(vertn+2)\x,vertice.MeshVertex(vertn+2)\y,vertice.MeshVertex(vertn+2)\z,1,1,$FFFFFF,vertice.MeshVertex(vertn+2)\NormalX,vertice.MeshVertex(vertn+2)\NormalY,vertice.MeshVertex(vertn+2)\NormalZ)
MeshFace(0,1,2)
vertn+3
FinishMesh(1)
Next
CreateEntity(#Object1+2,MeshID(#Object1malla+2),#PB_Material_None,2,0,0) ; <- try to create only the triangle entity number 2, but it does not create nothing!!
Repeat
ExamineMouse():ExamineKeyboard()
WaitWindowEvent(10)
RotateEntity(#Object0,-1,0.25,-0.5,#PB_Relative)
RotateEntity(#Object1+2,-1,0.25,-0.5,#PB_Relative)
TimeSinceLastFrame.i=RenderWorld(50)
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)