We’ve got an issue on trying to extrude a shape along a 2 points-path.
Here is an example with the issue (look at the red extrusion) : https://playground.babylonjs.com/#EJWES8#1
Here is another example without the issue : https://playground.babylonjs.com/#EJWES8#2
The issue happens when you try to make an angle with the extrusion (but only with an angle to the left)
To see exactly what happens, please make attention to the fact that all shapes are on the same Z-axis ( z = 75 ), but when you try to extrude them by making an angle to the left, it makes an abnormal rotation (?).
Don’t hesitate to ask for more information if needed
cc @Evgeni_Popov who is the king for this if he has any idea.
I don’t know how the extrude shape code works, but what I could find is that if you make sure the shape path is centered in the X dimension then it works as expected:
Thanks for the information
Thank you very much @Evgeni_Popov , you are the boss !
It should be added in the documentation that the extrusion is actually calculated in reference with the center of the shape. In consequence, the shape should be centered to the axis origin (not only on X-Axis, but also on Y-axis) or you’ll have some cases which could turn wrong.
See the example : https://playground.babylonjs.com/#EJWES8#4
The ExtrudeShapeXXX code creates a ribbon by placing the origin of shape, typically 0,0,0, at points along the extrusion path, optionally scaling and rotating the shape before creating the ribbon. The path points are used to generate a Path3d, from which tangets, normals, and binormals are used to determine the shape orientation. For this reason, 2 point or straightline extrusions can be badly affected when the extrusion is in the YZ plane, because the normal is undefined.
I’ve modified your playground to show both the problem (rotate around to look at extrusions in YZ plane):
and the fix, using the firstNormal option to ExtrudeShape:
I always use the firstNormal option because so I don’t need to keep track of what plane my extrusion is in