Hi,
I was wondering, if I simplify the shapes (e.g. generate the convex hull) of imported meshes, would this speed up the collision checking? If yes, would it be worth it (what would be the factor of speedup)? I guess it depends on the number and complexity of the shapes. Thanks.
Best,
Uli
Shape simplification to speed up collision checking recommended?
Re: Shape simplification to speed up collision checking recommended?
Hello,
yes, that often makes a difference. Typically, if your meshes are heavy, you would generate a largely simplified version of it (via mesh decimation and/or convex hull extraction), attach it to the original shape and make it invisible and collidable, while the visible shape is made non-collidable. This is also valid for distance calculations or other types of calculations (e.g. proximity sensor detection).
You might not always clearly notice speed differences when your objects are slowly moving, since V-REP uses cashing to speed-up calculations: the last colliding triangle-triangle pair on an object pair is memorized and first checked in a subsequent calculation.
Cheers
yes, that often makes a difference. Typically, if your meshes are heavy, you would generate a largely simplified version of it (via mesh decimation and/or convex hull extraction), attach it to the original shape and make it invisible and collidable, while the visible shape is made non-collidable. This is also valid for distance calculations or other types of calculations (e.g. proximity sensor detection).
You might not always clearly notice speed differences when your objects are slowly moving, since V-REP uses cashing to speed-up calculations: the last colliding triangle-triangle pair on an object pair is memorized and first checked in a subsequent calculation.
Cheers
Re: Shape simplification to speed up collision checking recommended?
Hi,
Thanks for the reply. Could you post a short LUA script example (or even a example scene) that would accomplish that for a single object/mesh? If I know the object handle of the mesh I want to simplify, then how to I use that with sim.getDecimatedMesh and sim.getQHull. It seems that these functions take list of vertices and return list of vertices. How do I get the simplified mesh/object from the table of vertices. I don't think I have to iterate myself over all the vertices and build the mesh myself.
Once I have the simplified mesh object, I should be able to set the visibility, collision attributes and its parent myself.
Best,
Uli
Thanks for the reply. Could you post a short LUA script example (or even a example scene) that would accomplish that for a single object/mesh? If I know the object handle of the mesh I want to simplify, then how to I use that with sim.getDecimatedMesh and sim.getQHull. It seems that these functions take list of vertices and return list of vertices. How do I get the simplified mesh/object from the table of vertices. I don't think I have to iterate myself over all the vertices and build the mesh myself.
Once I have the simplified mesh object, I should be able to set the visibility, collision attributes and its parent myself.
Best,
Uli
Re: Shape simplification to speed up collision checking recommended?
Maybe something like:
Cheers
Code: Select all
local shapeHandle=sim.getObjectHandle('shape#')
local shapeM=sim.getObjectMatrix(shapeHandle,-1)
local ind=0
local allVertices={}
local allIndices={}
local offset=0
while true do
local data=sim.getShapeViz(shapeHandle,ind)
ind=ind+1
if data then
for i=0,#data.vertices/3-1,1 do
local v={data.vertices[3*i+1],data.vertices[3*i+2],data.vertices[3*i+3]}
v=sim.multiplyVector(shapeM,v)
allVertices[#allVertices+1]=v[1]
allVertices[#allVertices+1]=v[2]
allVertices[#allVertices+1]=v[3]
end
for i=1,#data.indices,1 do
allIndices[#allIndices+1]=data.indices[i]+offset
end
offset=#allVertices/3
else
break
end
end
allVertices,allIndices=simQHull.compute(allVertices,true)
allVertices,allIndices=simOpenMesh.getDecimated(allVertices,allIndices,200,200)
allVertices,allIndices=simQHull.compute(allVertices,true)
sim.createMeshShape(0,0,allVertices,allIndices)
Re: Shape simplification to speed up collision checking recommended?
Hi,
Thanks, that was helpful. I am trying to export the simplified mesh, but I get an error when using;
Error message:
I checked and the tables are NOT empty. Is this a bug?
Thanks, that was helpful. I am trying to export the simplified mesh, but I get an error when using;
Code: Select all
formatId = simAssimp.getExportFormat(4)
simAssimp.exportMeshes(allVertices,allIndices,"simple.stl",formatId)
Code: Select all
argument 1&2: expected non-empty tables. (simAssimp.exportMeshes @ 'Assimp' plugin)
Re: Shape simplification to speed up collision checking recommended?
it should be:
since arg1 and arg2 should be tables of tables, i.e. to easily export several meshes.
Cheers
Code: Select all
formatDescription,formatExtension,formatId = simAssimp.getExportFormat(4)
simAssimp.exportMeshes({allVertices},{allIndices},"simple."..formatExtension,formatId)
Cheers
Re: Shape simplification to speed up collision checking recommended?
Thanks, that allows me to export the simplified shape.
When I try to import the shape with sim.importShape then it seems that the orientation is not as the original exported shape.
Do you have any idea how to fix this?
I noticed that in some cases the orientation is correct, but sometimes I have to rotate 180 degrees about z-axis (in world frame).
Best,
Uli
When I try to import the shape with sim.importShape then it seems that the orientation is not as the original exported shape.
Do you have any idea how to fix this?
I noticed that in some cases the orientation is correct, but sometimes I have to rotate 180 degrees about z-axis (in world frame).
Best,
Uli
Re: Shape simplification to speed up collision checking recommended?
Uhm... I have no idea. It could be something to do with the up-vector. But by default it is the Z vector, both for import and export without dlg.
Can you describe a reproducable scenario?
Cheers
Can you describe a reproducable scenario?
Cheers