Page 1 of 1

Shape simplification to speed up collision checking recommended?

Posted: 12 Mar 2019, 21:24
by Uli_v
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

Re: Shape simplification to speed up collision checking recommended?

Posted: 13 Mar 2019, 14:09
by coppelia
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

Re: Shape simplification to speed up collision checking recommended?

Posted: 13 Mar 2019, 19:23
by Uli_v
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

Re: Shape simplification to speed up collision checking recommended?

Posted: 14 Mar 2019, 08:47
by coppelia
Maybe something like:

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)
Cheers

Re: Shape simplification to speed up collision checking recommended?

Posted: 15 Mar 2019, 20:12
by Uli_v
Hi,

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)
Error message:

Code: Select all

argument 1&2: expected non-empty tables. (simAssimp.exportMeshes @ 'Assimp' plugin)
I checked and the tables are NOT empty. Is this a bug?

Re: Shape simplification to speed up collision checking recommended?

Posted: 18 Mar 2019, 15:25
by coppelia
it should be:

Code: Select all

formatDescription,formatExtension,formatId = simAssimp.getExportFormat(4)
simAssimp.exportMeshes({allVertices},{allIndices},"simple."..formatExtension,formatId)
since arg1 and arg2 should be tables of tables, i.e. to easily export several meshes.

Cheers

Re: Shape simplification to speed up collision checking recommended?

Posted: 19 Mar 2019, 17:36
by Uli_v
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

Re: Shape simplification to speed up collision checking recommended?

Posted: 22 Mar 2019, 13:28
by coppelia
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