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

Typically: "How do I... ", "How can I... " questions
Post Reply
Virloria
Posts: 5
Joined: 28 Nov 2017, 21:19

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

Post by Virloria » 13 Feb 2018, 12:28

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

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

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

Post by coppelia » 15 Feb 2018, 09:06

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

Virloria
Posts: 5
Joined: 28 Nov 2017, 21:19

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

Post by Virloria » 16 Feb 2018, 16:21

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

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

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

Post by coppelia » 17 Feb 2018, 06:23

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

Virloria
Posts: 5
Joined: 28 Nov 2017, 21:19

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

Post by Virloria » 19 Feb 2018, 16:07

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

Post Reply