Page 1 of 1

Wrong transformation after convex hull

Posted: 19 Dec 2018, 11:25
by Boris
Hi,

When I try to compute the convex hull of an object in a child script, I notice that the original object and convex hull object do not align. I use the following code:

Code: Select all

h = sim.getObjectHandle('imported_part_0')
data = sim.getShapeViz(h, 0) 

newVertices, newFaces=sim.getQHull(data.vertices) -- get convex hull
newMeshh=sim.createMeshShape(0, 0, newVertices, newFaces)
sim.setObjectPosition(newMeshh, h, {0,0,0})
sim.setObjectOrientation(newMeshh, h, {0,0,0})
The scene with a minimal example: https://wetransfer.com/downloads/3026a9 ... 553/ce9487

Is this a bug, or am I doing something wrong?

Kind regards,
Boris

Re: Wrong transformation after convex hull

Posted: 20 Dec 2018, 09:52
by coppelia
Hello,

the API function sim.getShapeViz returns the vertices relative to the shape's reference frame. So following would give you correct results:

Code: Select all

function sysCall_init()
    h = sim.getObjectHandle('imported_part_0')
    data = sim.getShapeViz(h,0)
    local m=sim.getObjectMatrix(h,-1)
    for i=1,#data.vertices/3,1 do
        local v={data.vertices[3*(i-1)+1],data.vertices[3*(i-1)+2],data.vertices[3*(i-1)+3]}
        v=sim.multiplyVector(m,v)
        data.vertices[3*(i-1)+1]=v[1]
        data.vertices[3*(i-1)+2]=v[2]
        data.vertices[3*(i-1)+3]=v[3]
    end

    newVertices, newFaces=sim.getQHull(data.vertices) -- get convex hull
    newMeshh=sim.createMeshShape(0, 0, newVertices, newFaces)
	
--    sim.setObjectPosition(newMeshh, h, {0,0,0})
--	sim.setObjectOrientation(newMeshh, h, {0,0,0})
end
Cheers

Re: Wrong transformation after convex hull

Posted: 20 Dec 2018, 10:47
by Boris
Hi,

Thanks, this did indeed work.

Cheers,