Regular API function

simExportMesh / sim.exportMesh

Description Exports a mesh to a file. See also sim.importMesh and sim.getShapeMesh
C/C++
synopsis
int simExportMesh(int fileformat,const char* pathAndFilename,int options,double scalingFactor,int elementCount,double** vertices,const int* verticesSizes,int** indices,const int* indicesSizes,double** reserved,char** 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
elementCount: the number of meshes
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 int shapeCount=0; while (simGetObjects(shapeCount++,sim.object_shape_type)!=-1); shapeCount--; double** vertices=new double*[shapeCount]; int* verticesSizes=new int[shapeCount]; int** indices=new int*[shapeCount]; int* indicesSizes=new int[shapeCount]; int index=0; while (true) { int shapeHandle=simGetObjects(index++,sim.object_shape_type); if (shapeHandle<0) break; double* vert; int vertS; int* ind; int indS; simGetShapeMesh(shapeHandle,&vert,&vertS,&ind,&indS,nullptr); vertices[index-1]=vert; verticesSizes[index-1]=vertS; indices[index-1]=ind; indicesSizes[index-1]=indS; double m[12]; simGetObjectMatrix(shapeHandle,-1,m); for (int i=0;i<vertS/3;i++) { double 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 (int i=0;i<shapeCount;i++) { simReleaseBuffer((char*)vertices[i]); simReleaseBuffer((char*)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)