Get size of imported model with API

Typically: "How do I... ", "How can I... " questions
Post Reply
RL_Niryo
Posts: 14
Joined: 03 Oct 2019, 17:05

Get size of imported model with API

Post by RL_Niryo »

Hi Everyone,

I do not know if I catch a bug or I am just badly using one API's function

I'm progressing in my sorting chain project, and now, I aim to generate multiple type of cans from models that I created.

These cans do not have the same size and I do not want to hard code each of them.

So, to get cans' size, I thought about using sim.getObjectSizeValues, nevertheless I do not get result I expected.

The code used is:

Code: Select all

h=sim.createPureShape(partType,19+4,{0.08,0.08,0.085},1,nil)
--h = sim.loadModel("models/mine/can_texture.ttm")

sim.setObjectParent(h,model,true)

--can_shape={0.08,0.08,0.085}
can_shape = sim.getObjectSizeValues(h)
a = sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_min_x)
b = sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_max_x)

print(can_shape)
print(a,b,(b-a))
I firstly tried to import my model (which is a customized Cylinder of size 8x8x8.5 cm) then I tested to create a Cylinder with PureShape, but I both cases sim.getObjectSizeValues gave me {1,1,1} and the variables a & b (which should give boudingboxes min/max on x axis) give also 1.

Do you have an idea why I'm not getting expected results ?

Cheers

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

Re: Get size of imported model with API

Post by coppelia »

Hello,

sim.getObjectSizeValues returns 3 variables that are correctly scales during scaling operations. If those variables are not correctly initialized with the size of the object, then you won't be able to use them.
Retrieving the bounding box of the object is the better way of doing, as you mention it. You should however use the API functions in following way:

Code: Select all

function getObjectBoundingBoxSize(h)
    local r,xmin=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_min_x)
    local r,xmax=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_max_x)
    local r,ymin=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_min_y)
    local r,ymax=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_max_y)
    local r,zmin=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_min_z)
    local r,zmax=sim.getObjectFloatParameter(h,sim.objfloatparam_objbbox_max_z)
    return xmax-xmin,ymax-ymin,zmax-zmin
end
Cheers

RL_Niryo
Posts: 14
Joined: 03 Oct 2019, 17:05

Re: Get size of imported model with API

Post by RL_Niryo »

Hi coppella,

Thx a lot ! I have been tricked by Lua :p
Nevertheless, it is now working.

Cheers from Niryo and have a good day ;)

Post Reply