SetMeshData : create mesh from scratch ?

Everything related to 3D programming
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

SetMeshData : create mesh from scratch ?

Post by eddy »

Hi,

Is it possible to create mesh from scratch with SetMeshData(...) function ?

Code: Select all

mesh=CreateMesh(#PB_Any)
FinishMesh(1)
SetMeshData(mesh, ....) ; face
SetMeshData(mesh, ....)  ; vertex
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: SetMeshData : create mesh from scratch ?

Post by Comtois »

no you can't.
Please correct my english
http://purebasic.developpez.com/
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: SetMeshData : create mesh from scratch ?

Post by IdeasVacuum »

You can make a mesh from scratch, if you pre-calculate the vertex points.
In the code below, I have the points that describe a mesh saved as strings(x,y,z) in a linked list:

Code: Select all

D.s = Chr(44) ;comma

If CreateMesh(#MeshSTL, #PB_Mesh_TriangleList, #PB_Mesh_Static)

     SetMeshMaterial(#MeshSTL, MaterialID(#MatlSTL))

     FirstElement(sgListPts())

     Repeat

          MeshVertexPosition(ValD(StringField(sgListPts(),1,D)),ValD(StringField(sgListPts(),2,D)),ValD(StringField(sgListPts(),3,D)))
                 NextElement(sgListPts())

          MeshVertexPosition(ValD(StringField(sgListPts(),1,D)),ValD(StringField(sgListPts(),2,D)),ValD(StringField(sgListPts(),3,D)))
                 NextElement(sgListPts())

          MeshVertexPosition(ValD(StringField(sgListPts(),1,D)),ValD(StringField(sgListPts(),2,D)),ValD(StringField(sgListPts(),3,D)))
                 NextElement(sgListPts())

                    MeshFace(i, i + 1, i + 2)

                    i = i + 3

     Until i > ListSize(sgListPts())

    FinishMesh(#True)
EndIf
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: SetMeshData : create mesh from scratch ?

Post by eddy »

I found an old version of this function.
I thought it would be faster to create mesh with an array of vertices.
but, well, that's not possible.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: SetMeshData : create mesh from scratch ?

Post by IdeasVacuum »

...using code similar to mine in a Procedure, it is possible.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply