Page 1 of 1

how to set y vector up when importing mesh from a script

Posted: 13 Feb 2018, 12:28
by Virloria
Hi,
When importing a mesh from the File menu, the dialog box offers me to set the mesh orientation by choosing if y or z vector should be up. How can I specify the mesh orientation when I import a mesh from a script using the simImportMesh function?
Virloria

Re: how to set y vector up when importing mesh from a script

Posted: 15 Feb 2018, 09:06
by coppelia
Hello,

you can't specify this when importing a mesh. But you can then simply rotate the mesh as required.
Have a look at sim.multiplyVector

Cheers

Re: how to set y vector up when importing mesh from a script

Posted: 16 Feb 2018, 16:21
by Virloria
Hello,

Thanks, but I didn't manage to rotate my mesh with multiplyVector.
Instead I used setObjectOrientation :

FloatWA eulerAngles = new FloatWA(3);
eulerAngles.getArray()[0] = (float)Math.PI/2;
eulerAngles.getArray()[1] = 0f;
eulerAngles.getArray()[2] = -1*(float)Math.PI/2;
vrep.simxSetObjectOrientation(clientID, groupHandle, -1, eulerAngles, remoteApi.simx_opmode_blocking);

But it still looks different from the result I obtain when importing the mesh from the File menu: I still need to translate the "bottom/base" of my imported shape down along z-axis to align it with the default resizableFloor. But the question is: how much do I need to translate it of? Is there a way to get the distance between the origin of a group (my group represents buildings along a flat road) and "its base" (the road)?

Virloria

Re: how to set y vector up when importing mesh from a script

Posted: 17 Feb 2018, 06:23
by coppelia
You can iterate through your imported shape vertices and detect the lowest z-coordinate. Then iterate through your road shape and detect the highest z-coordinate. Then you know how much you need to shift the imported shape.

You will have to use sim.getShapeMesh. Remember that the read vertices are relative to the shape's position. i.e. to obtain the absolute position of a vertex do something like:

Code: Select all

local shapeMatrix=sim.getObjectMatrix(shapeHandle,-1)
local absoluteVertex=sim.multiplyVector(shapeMatrix,relativeVertex)
Cheers

Re: how to set y vector up when importing mesh from a script

Posted: 19 Feb 2018, 16:07
by Virloria
Hi,

Thanks for your help.
In case it might be useful from someone else, here is how I did it:

Code: Select all

FloatW objbbox_min_x = new FloatW(0f);
vrep.simxGetObjectFloatParameter(clientID, groupHandle, remoteApi.sim_objfloatparam_objbbox_min_x, objbbox_min_x, remoteApi.simx_opmode_blocking);

FloatWA position = new FloatWA(3);
position.getArray()[0] = 0;
position.getArray()[1] = 0;
position.getArray()[2] = -1*objbbox_min_x.getValue();
vrep.simxSetObjectPosition(clientID, groupHandle, -1, position, remoteApi.simx_opmode_blocking);
Virloria