Shape simplification to speed up collision checking recommended?

Typically: "How do I... ", "How can I... " questions
Post Reply
Uli_v
Posts: 23
Joined: 14 Dec 2018, 18:07

Shape simplification to speed up collision checking recommended?

Post by Uli_v » 12 Mar 2019, 21:24

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

coppelia
Site Admin
Posts: 7124
Joined: 14 Dec 2012, 00:25

Re: Shape simplification to speed up collision checking recommended?

Post by coppelia » 13 Mar 2019, 14:09

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

Uli_v
Posts: 23
Joined: 14 Dec 2018, 18:07

Re: Shape simplification to speed up collision checking recommended?

Post by Uli_v » 13 Mar 2019, 19:23

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

coppelia
Site Admin
Posts: 7124
Joined: 14 Dec 2012, 00:25

Re: Shape simplification to speed up collision checking recommended?

Post by coppelia » 14 Mar 2019, 08:47

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

Uli_v
Posts: 23
Joined: 14 Dec 2018, 18:07

Re: Shape simplification to speed up collision checking recommended?

Post by Uli_v » 15 Mar 2019, 20:12

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?

coppelia
Site Admin
Posts: 7124
Joined: 14 Dec 2012, 00:25

Re: Shape simplification to speed up collision checking recommended?

Post by coppelia » 18 Mar 2019, 15:25

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

Uli_v
Posts: 23
Joined: 14 Dec 2018, 18:07

Re: Shape simplification to speed up collision checking recommended?

Post by Uli_v » 19 Mar 2019, 17:36

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

coppelia
Site Admin
Posts: 7124
Joined: 14 Dec 2012, 00:25

Re: Shape simplification to speed up collision checking recommended?

Post by coppelia » 22 Mar 2019, 13:28

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

Post Reply