Regular API function

simExportMesh / sim.exportMesh

Description Exports a mesh to a file. See also sim.importMesh and sim.getShapeMesh
C/C++
synopsis
simInt simExportMesh(simInt fileformat,const simChar* pathAndFilename,simInt options,simFloat scalingFactor,simInt elementCount,simFloat** vertices,const simInt* verticesSizes,simInt** indices,const simInt* indicesSizes,simFloat** reserved,simChar** names)
C/C++
parameters
fileformat: the fileformat to export to:
0: OBJ format
3: TEXT STL format
4: BINARY STL format
5: COLLADA format
6: TEXT PLY format
7: BINARY PLY format
pathAndFilename: the location of the file to create.
options: keep at 0
scalingFactor: the scaling factor to apply to the vertices to export
vertices: an array to vertice arrays. See the example below
verticesSizes: an array indicating the individual vertice array sizes. See the example below
indices: an array to indice arrays. See the example below
indicesSizes: an array indicating the individual indice array sizes. See the example below
reserved: reserved for future extensions. Keep at nullptr.
names: Keep at nullptr

USAGE EXAMPLE:
// Exports all shapes in the scene simInt shapeCount=0; while (simGetObjects(shapeCount++,sim.object_shape_type)!=-1); shapeCount--; simFloat** vertices=new simFloat*[shapeCount]; simInt* verticesSizes=new simInt[shapeCount]; simInt** indices=new simInt*[shapeCount]; simInt* indicesSizes=new simInt[shapeCount]; simInt index=0; while (true) { simInt shapeHandle=simGetObjects(index++,sim.object_shape_type); if (shapeHandle<0) break; simFloat* vert; simInt vertS; simInt* ind; simInt indS; simGetShapeMesh(shapeHandle,&vert,&vertS,&ind,&indS,nullptr); vertices[index-1]=vert; verticesSizes[index-1]=vertS; indices[index-1]=ind; indicesSizes[index-1]=indS; simFloat m[12]; simGetObjectMatrix(shapeHandle,-1,m); for (simInt i=0;i<vertS/3;i++) { simFloat v[3]={vert[3*i+0],vert[3*i+1],vert[3*i+2]}; simTransformVector(m,v); vert[3*i+0]=v[0]; vert[3*i+1]=v[1]; vert[3*i+2]=v[2]; } } simExportMesh(0,"d:\\example.obj",0,1,shapeCount,vertices, verticesSizes,indices,indicesSizes,nullptr,nullptr); for (simInt i=0;i<shapeCount;i++) { simReleaseBuffer((simChar*)vertices[i]); simReleaseBuffer((simChar*)indices[i]); } delete[] vertices; delete[] verticesSizes; delete[] indices; delete[] indicesSizes;
C/C++
return value
-1 if operation was not successful
Lua
synopsis
sim.exportMesh(int fileformat,string pathAndFilename,int options,float scalingFactor,float[] vertices,int[] indices)
Lua
parameters
fileformat: same as C function
pathAndFilename: same as C function
options: same as C function
scalingFactor: same as C function
vertices: a table of vertice tables. See the example below
indices: a table of indice tables. See the example below

USAGE EXAMPLE (e.g. in a customization script):
-- Exports all shapes in the scene if (exportButtonPressed) then allVertices={} allIndices={} shapeIndex=0 while (true) do h=sim.getObjects(shapeIndex,sim.object_shape_type) if (h<0) then break end shapeIndex=shapeIndex+1 vertices,indices=sim.getShapeMesh(h) m=sim.getObjectMatrix(h,-1) for i=1,#vertices/3,1 do v={vertices[3*(i-1)+1],vertices[3*(i-1)+2],vertices[3*(i-1)+3]} v=sim.multiplyVector(m,v) vertices[3*(i-1)+1]=v[1] vertices[3*(i-1)+2]=v[2] vertices[3*(i-1)+3]=v[3] end table.insert(allVertices,vertices) table.insert(allIndices,indices) end if (#allVertices>0) then sim.exportMesh(0,"d:\\example.obj",0,1,allVertices,allIndices) end end
Lua
return values
Python
synopsis
sim.exportMesh(int fileformat,string pathAndFilename,int options,float scalingFactor,list vertices,list indices)