Hello

i have actually a problem with generating a path and make a shape (Wire in my case) from it via a child script.

I can use the Lua API functions to create a path and also insert control points and have a path easily. But i can't find a function to:

1. generate shape from this path and also

2. set Scaling factor (diameter of the wire generated by path)

This can be done manually with Path Shaping Parameters windows, but i can't generate shape and control the path shaping--> scaling factor via child script commands.

I would be so thankful for any suggestions.

Regards

## Generate shape from a path via script (Path Shaping parameters with code)

### Re: Generate shape from a path via script (Path Shaping parameters with code)

Hi,

You can create any (mesh) shape you want in Lua with sim.createMeshShape.

With a bit of 3D geometry and trigonometric functions, you can certainly create a mesh for a wire of arbitrary radius.

Beware that this mesh will be non-convex, thus it will slow down your simulation if you want it to be respondable. Consider approximating it with pure cylinder shapes if you need it to be respondable.

You can create any (mesh) shape you want in Lua with sim.createMeshShape.

With a bit of 3D geometry and trigonometric functions, you can certainly create a mesh for a wire of arbitrary radius.

Beware that this mesh will be non-convex, thus it will slow down your simulation if you want it to be respondable. Consider approximating it with pure cylinder shapes if you need it to be respondable.

### Re: Generate shape from a path via script (Path Shaping parameters with code)

Hellofferri wrote: ↑11 Jun 2019, 09:12Hi,

You can create any (mesh) shape you want in Lua with sim.createMeshShape.

With a bit of 3D geometry and trigonometric functions, you can certainly create a mesh for a wire of arbitrary radius.

Beware that this mesh will be non-convex, thus it will slow down your simulation if you want it to be respondable. Consider approximating it with pure cylinder shapes if you need it to be respondable.

Thank you so much. The reason that i want to generate shape from path is the Bezier control points. Actually i have a robot which is supposed to train with different type of wires. For that i need a function that takes in some points (ex. 10 bezier points) and a radius, then returns a shape (wire).

I assume with your idea i can only give the function vertices and indices as arrays.

I would be so thankful if you could help me understand the vertices and indices of sim.createMeshShape better. Actually i can make a single triangle with that, but how can i generate a mesh for something circular or a cylinder with triangles?

Code: Select all

```
sim.createMeshShape(0,0,{0,0,0,0,0.1,0,0,0.1,0.1},{0,1,2})
```

Thanks

Best

### Re: Generate shape from a path via script (Path Shaping parameters with code)

The vertices array contains x,y,z coordinates of vertices sequentially.

The indices array contains 0-based indices of points, which taken 3 by 3, defines triangles.

Simple example: to create a quad you would define vertices {x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4} and indices {0,1,2,0,2,3}.

To create an open cylinder from

Now you can expand this to create multiple open cylinders aligned along a path.

Use sim.getPositionOnPath to get the position in an arbitrary point on the path.

Collect all the vertices in

The indices array contains 0-based indices of points, which taken 3 by 3, defines triangles.

Simple example: to create a quad you would define vertices {x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4} and indices {0,1,2,0,2,3}.

To create an open cylinder from

**p**to**q**with caps aligned to unit vectors**s**and**t**, you can do the following:Code: Select all

```
local v={}
local idx={}
local p={0.0,0.0,0.0}
local q={0.0,0.0,0.5}
local s={1,0,0}
local t={0,1,0}
local radius=0.03
local res=10
for j=1,res do
local a=math.pi*2*(j-1)/res
table.insert(v,p[1]+s[1]*radius*math.cos(a)+t[1]*radius*math.sin(a))
table.insert(v,p[2]+s[2]*radius*math.cos(a)+t[2]*radius*math.sin(a))
table.insert(v,p[3]+s[3]*radius*math.cos(a)+t[3]*radius*math.sin(a))
table.insert(v,q[1]+s[1]*radius*math.cos(a)+t[1]*radius*math.sin(a))
table.insert(v,q[2]+s[2]*radius*math.cos(a)+t[2]*radius*math.sin(a))
table.insert(v,q[3]+s[3]*radius*math.cos(a)+t[3]*radius*math.sin(a))
table.insert(idx,math.mod(j-1,res)*2)
table.insert(idx,math.mod(j,res)*2+1)
table.insert(idx,math.mod(j-1,res)*2+1)
table.insert(idx,math.mod(j-1,res)*2)
table.insert(idx,math.mod(j,res)*2)
table.insert(idx,math.mod(j,res)*2+1)
end
sim.createMeshShape(0,0,v,idx)
```

Use sim.getPositionOnPath to get the position in an arbitrary point on the path.

Collect all the vertices in

**v**, and all the indices in**idx**, then use sim.createMeshShape(0,0,v,idx) at the very last.### Re: Generate shape from a path via script (Path Shaping parameters with code)

Thank you so much, i got the idea now.fferri wrote: ↑12 Jun 2019, 22:02The vertices array contains x,y,z coordinates of vertices sequentially.

The indices array contains 0-based indices of points, which taken 3 by 3, defines triangles.

Simple example: to create a quad you would define vertices {x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4} and indices {0,1,2,0,2,3}.

To create an open cylinder fromptoqwith caps aligned to unit vectorssandt, you can do the following:

Best,