haestflod Posted October 11, 2016 Share Posted October 11, 2016 Hi, in our app we have parent & child relations tree that could be for example have this structure: rootmesh mesh mesh mesh mesh Each mesh should have their own scale so if a parent is scaled it will remove that scale by dividing the parents scale. We recently added scaling and eventually found unintended behavior where rootmesh has a non-uniform scaling and if a mesh under has a rotation it skews that mesh. As reproduced in this playground: http://www.babylonjs-playground.com/#1CWAMX#2 So I was wondering if it was possible to solve somehow by math somehow. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 11, 2016 Share Posted October 11, 2016 Hello the problem here is that the child is rotated (and scaled around a different pivot due to the translation). You may need to first cancel completely parent scaling with the mesh.setPivotmatrix(parentScaling.inverse) (<-- pseudo code and not actual code as I'm on my phone) Quote Link to comment Share on other sites More sharing options...
haestflod Posted October 12, 2016 Author Share Posted October 12, 2016 Hey, I tried inverting some values with no luck. Could you clarify a bit of what I'd have to do? Sorry I don't have much experience with pivotMatrices. Quote Link to comment Share on other sites More sharing options...
adam Posted October 12, 2016 Share Posted October 12, 2016 This might help: Quote Link to comment Share on other sites More sharing options...
JohnK Posted October 13, 2016 Share Posted October 13, 2016 Instead of scaling set the values of the box to be those needed at the start. http://www.babylonjs-playground.com/#1CWAMX#7 Unless of course the parent needs to change scale over time. adam 1 Quote Link to comment Share on other sites More sharing options...
haestflod Posted October 13, 2016 Author Share Posted October 13, 2016 That's an interesting solution JohnK but is that applicable to a .babylon loaded mesh somehow? Like clone the geometry and alter all the vertice points? And no the parent will not change scale as long as it has a child attached. And thanks Adam for that piece of code if I can't find a way solve it without creating a helper mesh to act as parent. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted October 13, 2016 Share Posted October 13, 2016 Why parent it then? Why not just position them to the "parents" position and have them to rotate in relation to the "parents" center axis then they will have their own scaling. The other option is to just scale the child back after its parents resize, and all the sub children should come back to size. So if you scale down by 0.5 I think you would have to scale the child up by 2 if I'm not mistaken to get it back to size. Quote Link to comment Share on other sites More sharing options...
haestflod Posted October 13, 2016 Author Share Posted October 13, 2016 Because it made it simple to move & rotate them after adding as child mesh. All that is needed is to move & rotate the parent and children automatically does the same. Also the child & parent relations can be edited on the fly by either adding a mesh or remove a mesh and the children of that mesh by selecting with mouse. Edit: So in the end I solved it using adam's approach by adding an empty mesh. Here's a static version with 3 meshes:http://www.babylonjs-playground.com/#1CWAMX#15 Here's the same but with some rotation & scale being altered each frame:http://www.babylonjs-playground.com/#1CWAMX#18 I did try using some kind of matrix decomposition at first but it never worked so alas adam's approach it was! 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.