JohnK Posted May 13, 2015 Share Posted May 13, 2015 I have been trying to use the extrudeShape method but have found that the original shape I created is rotated 90 degrees anti-clockwise around the Z axis when it is applied. My example is http://www.babylonjs-playground.com/#RF9W9#49 The shape to be extruded is shown in green. Is this an issue with extrudeShape or am I missing something? Quote Link to comment Share on other sites More sharing options...
jerome Posted May 13, 2015 Share Posted May 13, 2015 Hi, tl;dr : 3D geometry phobics, go away, now ! This is not really a bug, neither you are missing something The 2D model shape should be done in the xOy plane. You can set it off -1 on z-axis if you want, as you did, it will just report this offset on the extruded shape. This is just a note, nothing to do without your rotation problem. Well, if I revert your path, I get this : http://www.babylonjs-playground.com/#RF9W9#50 what is you expected I guess.But you are right, the extrusion in the other direction rotates the shape 90 degrees on the z-axis.... on this very axis only.If you had chosen another path, the initial rotation (may we talk about rotation here ?) would have been something else.Is there a rule about how to set the path or something for knowing initial rotation ?No. Because the extruder process doesn't know anything about your path and its direction in space. It's based on the path3D object.So the extruder process tries initially to set a plane orthogonal (*) to the first tangent of your path (right until here ? I'm know you are good at maths ) and then to set two arbitrary orthogonal vectors in this plane on the intersection first_tangent/plane.These two vectors will be the shape x and y axis reported in this plane. I could add an extra rule to force the initial computed vectors to be right the same as world Ox and Oy axis if the user wanted path is Oz.But I don't know if it's really worth it because it's really really a specific case.I understand it may be confusing because the doc says the extrusion will be along the z-axis.. but don't tell anything about initial rotation (quite complex to explain). When I designed path3D, I added an optional parameter called initialVector to force the initial rotation (actually the initial normal-to-the-path direction, please read the last path3D doc part).But if I decide to use this parameter with, say (0, 1, 0) to set it "vertical", it will prevent users who want a vertical path to build the underlying path3D (the tangent would be collinear to the normal).So as I can't predict the path I have to let the process to compute its own original vectors in the plane orthogonal to the path. Another solution would be to add an extra parameter so the user could choose his own initialVector value according to his own path.I don't know : yet many parameters in ExtrudeShape() method and difficult notion to understand... BJS is supposed to be simple and powerful.Maybe in the ExtrudeShapeCustom() then which is for advanced usages ? This explains the behavior so far but doesn't help you.Well, the right way to do could be :design your shape in the xOy planedesign your pathextrudeif the computed original rotation doesn't fit, then rotate the initial shape instead around the z-axis in the xOy plane Something like (not tested) :var angle = your_initial_angle;var matrix = BABYLON.Matrix.RotationAxis(BABYLON.Axis.Z, angle);for (var i = 0; i < shape.length; i++) { BABYLON.Vector3.TransformCoordinatesToRef(shape[i], matrix, shape[i]);}[EDIT](*) I could change the order the find an arbitrary vector in the plane in path3D also... I'm starting along x, but I could start along y as well ...Maybe would it be better as it doesn't impose an initial vector and it will surely give another initial normal, something more likely to a human expectation BTW, I'm about to implement a lathe method built onto extrusion Wingnut and JohnK 2 Quote Link to comment Share on other sites More sharing options...
jerome Posted May 13, 2015 Share Posted May 13, 2015 Waah... marked as answered ? I didn't think all that stuff would be understandable JohnK, extrusion is a part of BJS 2.1 as well as path3D. BJS 2.1 is not yet released. Maybe I could test/commit another path3D initial normal discovery order. So please don't consider it as fixed yet, it could change... so your initial shape would rotate alone (-/+ 90°) if you use a fresh BJS build Quote Link to comment Share on other sites More sharing options...
RaananW Posted May 13, 2015 Share Posted May 13, 2015 Waah... marked as answered ? I didn't think all that stuff would be understandable Next time explain in a more abstract way. It was understandable, apparently Wingnut and jerome 2 Quote Link to comment Share on other sites More sharing options...
jerome Posted May 18, 2015 Share Posted May 18, 2015 I just changed the path3D first normal discovery order : https://github.com/BabylonJS/Babylon.js/pull/517So if you now extrude along a path close to Z-axis, the shape initial rotation should be quite null. In other words, the shape model won't be initially rotated when extruded if your path is close to z world axis Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 19, 2015 Author Share Posted May 19, 2015 Jerome thank you for your continued work on this. I marked it as solved because you had solved the problem I had asked which was was it me or how the code worked. Since I knew it was how the code worked you had answered my question and thus solved my problem. What I had not expected, though very pleased that you are doing so, was to take the behaviour as a problem in its own right and set out to solve it. To show why I needed my mesh to behave as it should I have include a link to the part of the project I am now working on here. This also shows the reason for the offset. Each 'cubee' must fit to the boundaries of a 60 x 60 x 60 block with local origin at (0, 0, 0). I simply obtained the expected rotation using.rotation.z = Math.PI;However I am now having new rotation issues which as they are new I will start a new post. Quote Link to comment Share on other sites More sharing options...
jerome Posted May 19, 2015 Share Posted May 19, 2015 very smart project ! Quote Link to comment Share on other sites More sharing options...
Wingnut Posted May 19, 2015 Share Posted May 19, 2015 I'm really starting to like this JohnK guy. Jerome's things are brand new, and, well, I just love the hell out of the guy, because he is exploring a part of webGL... and teaching it to us... fantastically. And then, JohnK says... "What I had not expected, though very pleased that you are doing so, was to take the behaviour as a problem in its own right and set out to solve it." What a nice thing to say! And Jerome EXCELS at this. I've thrown quite a bucket of geometry challenges at Jerome, and he kicked butt on every single one of them, and then went on to write systems, with many playgrounds, and great documentation, so we all could learn all the things he knows. JohnK, thanks for being a cool forum participant and issue finder, and thanks for petting our heroes. I hope you can continue to hang around with us and tell us about your projects/hopes. That new post you did? Gorgeous! Wouldn't it be great if ALL forum users asked questions with THAT MUCH prep and great formatting? Phew. Excellent. Is that your axis code? Its pretty nice. I like big axes.... easy to see. I just saw a post from Jerome arrive. Hi Jerome! Great work, as always. Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 19, 2015 Author Share Posted May 19, 2015 Wingnut et al, thought I had better let everyone know that I am not responsible for the axis code - just followed the playground links given under Extensions on this BJS docs page and used the existing code. My hope is to produce a site that children can use to build up 3D models quickly and easy. Long way to go yet. Here are a couple of parts of the project still under development. Lathe Cubees (basic building blocks) Glad that there are people interested. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.