jerome Posted May 7, 2015 Share Posted May 7, 2015 After a long brainstorming with me, me and myself, I finally chose the name rebase() for the upcoming (I hope) function. Let's go :http://www.babylonjs-playground.com/#XSX1M#4 Line 39 = simple box creation as usual, ok ?Line 42 = I choose an arbitrary axis1following lines = I want my mesh oriented like this (my own arbitrary constraints) :- its current x axis should become the axis1- its current y axis should be in the world axis1Oy plane- it should be placed at (4, 4, -4) that's all.I don't know how to rotate it from its current orientation to the target one. And I don't want to learn about quaternion. Sorry, I'm lazzy. Let' go on.Axis1 will be my new x axis in the target orientation. Ok ?So in the following lines, from the axis1, I just created an orthogonal axis2 with the cross product axis1 ^ Axis.Y... which results in a temp vector orthogonal to axis1 and to Y world axis, re-crossed with axis1 and temp to be then in the axis1Oy plane as wanted by my own constraints. Ok ?I just create a last third orthogonal axis 3 = axis1 ^ axis2 And I draw them normalized, from (4, 4, -4) as asked, so you can understand better (line 48) : x = red, y = green, z = blue. A just created box, a target orientation/location defined by 3 orthogonal arbitrary vectors and no knowledge about rotations/quaternions. Right ? Let's uncomment lines 56-57 : http://www.babylonjs-playground.com/#XSX1M#5 Well, just a proto, there are yet many defaults :the normals don't seem correct,the mesh is created as updatableI guess I could solve the normal issue.No idea about how to avoid the updatable...Can we set a mesh updatable for a while, then re-freeze it (if it wasn't originally updatable) ? binyan 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted May 7, 2015 Author Share Posted May 7, 2015 seems the normals are well recomputed actually Quote Link to comment Share on other sites More sharing options...
jerome Posted May 7, 2015 Author Share Posted May 7, 2015 Want a plane instead ? (Alby's problem) Just change the mesh type : http://www.babylonjs-playground.com/#XSX1M#2 Prefer a torus ? http://www.babylonjs-playground.com/#XSX1M#3 Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Alby Posted May 7, 2015 Share Posted May 7, 2015 Waw, it seems you find the solution, even I don't understand exactely how. Thank you Jerome, DBawel will be glad too! Now the way to implement it in my case, surely, Wingy will help me to understand your "trick"! Quote Link to comment Share on other sites More sharing options...
jerome Posted May 8, 2015 Author Share Posted May 8, 2015 well, according to this post : http://www.html5gamedevs.com/topic/14352-setting-mesh-updatable-property/?p=81678I guess I will do two different things a localRebase(origin, axis1, axis2, axis3) method : this will need to set mesh as updatable and will allow to change the mesh position/orientation after building in its local space. The mesh is modified in its local space. This is quite the prototype function.If this function could be called within the mesh constructor, it wouldn't be necessary to set the mesh as updatable... but it would need an extra parameter to pass the target base.Hard choice. a worldRebase(origin, axis1, axis2, axis3) method (not yet even thought, too busy mind) : this will allow to keep a mesh non-updatable and will rebase the mesh in the world in the same way that the former method does. This will not modify the mesh in its local space. This should only modify the mesh.worldMatrix. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 8, 2015 Share Posted May 8, 2015 Warning: a mesh cannot be defined as updatable afterward. THis is only possible at construction time Can you explain me again what is the purpose of rebase? Quote Link to comment Share on other sites More sharing options...
jerome Posted May 9, 2015 Author Share Posted May 9, 2015 Ok. The original goal of worldRebase() is to give to the user, who has no good rotation competences (almost all of us ) the ability to set directly his mesh to a target location/orientation.Usually people know that they want their mesh, just after creation, then placed here and facing this other mesh, with its base parallel to this other axis or with this face in this place.In brief, they quite know in what cartesian system (3 orthogonal vectors + 1 origin) in the space to set their mesh, but they can't achieve to compute the rotations (translations are quite obvious) to orientate their mesh the right desired way. BJS provides tools about HOW rotate/move things. We've got an initial status and tools to transform it. Then we get a result. I just want a method for a new approach : the user knows the result he wants, but doesn't know how to set BJS tools to get it.So I want to give him the way to define the target orientation, without any notion about angles, rotations to apply, etc. Just a target cartesian system : 3 orthogonal vectors + 1 origin, defined in the world system.The worldRebase() method would do this : move/rotate the mesh to the target system. I know this kind of tool is really awaited by many users since the rotation/quaternion aren't that obvious to everyone. The localRebase() (almost done) does the same but modify the mesh (so upgradable = true) in its local system.Same paradigm : the user doesn't know HOW to do, but know WHAT (the target) he wants.Well maybe the localRebase() has not real interest actually. example : http://www.babylonjs-playground.com/#12ZRI0Here Alby creates text planes (grounds actually so they are created in the x0z plane).He wants each plane to be aligned with the box-sphere (bs) axis on this length, he wants the plane to be quite "vertical" on its width (so width in bsOy plane), he wants each plane to be located in the middle of the box-sphere segment...Well, he knows the target position/orientation for each plane but can't achieve how to rotate them the right way because it is quite complex.So he knows WHAT is the wanted result and not HOW to get it. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted May 9, 2015 Share Posted May 9, 2015 Well said, J! (I suspect. I didn't understand much.) These "standard orienting" tools are the basis for "snaps", too. (align/constraint, etc) And great snaps... are the basis of another tool I've dreamed about... an editor that lets you quickly assemble BJS basic shapes... into a single model. Or maybe takes a pile of basic shapes, and keeps trying to (re-) assemble them in different ways. (cooooool!) It's a bit related to another subject... making moving cameras and characters slide-along walls, and drop into slots in those walls - sideways tetris-like. Ok, maybe it's not like that at all. Back on topic... a guy could select a base mesh and an align-me mesh, and start whacking the TAB button. Smart-aligner code keeps aligning the object... to the target... in different ways. Find one you like, and then exit align-edit mode. HOW the user would get the CODE that DID that, so they could use it in their project... might not be easy. The SnapperBot! Yay! That SOB could assemble some serious BJS compound shapes. Place IT... and a pile of BJS shapes... into a scene. Come back in 5 seconds, and SnapperBot will have assembled all the shapes into SOMETHING. A Parent-a-thon! Full random-seeding, chaos, and fuzzy-logic allowed, of course. Wow! Later, we'll build CSG bot. He just enters a BJS scene with a bag of points, and a day later, he has built a mess! FUN! freebasing! Alright! Pardon? Oh, sorry... rebasing... cool! jerome 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 10, 2015 Share Posted May 10, 2015 I'm still convinced that lookAt + bake are enough but let's see where this study goes Wingnut 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted May 11, 2015 Author Share Posted May 11, 2015 mmmh... bake won't fit because it needs the mesh to be updatable as far as I understand : https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Mesh/babylon.mesh.ts#L899what I'm trying to avoid I'm off this pm, but my brain keeps working I have a lead inspired from the lookAt code. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 11, 2015 Share Posted May 11, 2015 No need to be updatable for bake. bake delete and recreate the vb Quote Link to comment Share on other sites More sharing options...
jerome Posted May 12, 2015 Author Share Posted May 12, 2015 @DK : https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Mesh/babylon.mesh.ts#L901 Does this mean we can even update a non-updatable mesh (updatable param set to false on creation) with :mesh.setVerticesData(kind, data, true);?seems weird if we can ... I can see the bake code that the passed updatable value is got from this.getVertexBuffer().isUpdatable().Isn't this property set on mesh creation with the mesh updatable parameter value ? Quote Link to comment Share on other sites More sharing options...
jerome Posted May 12, 2015 Author Share Posted May 12, 2015 mmh... after hours spent in grinding my lookAt() derivated home made method, I'm forgiving this way ... I just can't get the intermediate angles correctly. If a math expert wants to try to solve this problem :- Given 3 orthogonal normalized vectors (ie : world axis), the source (A, B, C), and knowing the world coordinates of their image after rotation (so 3 other orthogonal normalized vectors), the target (V1, V2, V3), find out either the 3 Euler angles, either raw, pitch, roll, either the quaternion, either the rotation matrix used for this transformation :A => V1B => V2C = > V3 You just know initial and target orientations (vectors).You've got an hour . I think bake() won't fit because it needs a transformation matrix and it's just what don't know here ... Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 12, 2015 Share Posted May 12, 2015 setVerticesData is not updateVerticesData and it ends up destroying the previous one instead of updating it:https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Mesh/babylon.geometry.ts#L64 Quote Link to comment Share on other sites More sharing options...
jerome Posted May 13, 2015 Author Share Posted May 13, 2015 sa race !Didn't notice it !!! Ok, so maybe I can go this lead : non-updatable mesh but using setVerticesDataie : my own bake without knowing any matrix but only the target resultWill give a PG try BTW : about the math problem (knowing source and target, find out the in between rotations), I just asked a math profs here.He sincerally has no idea how to do this Quote Link to comment Share on other sites More sharing options...
jerome Posted May 13, 2015 Author Share Posted May 13, 2015 Ok, let's go back into this rebase() method with the setVerticesData() approach. http://www.babylonjs-playground.com/#JVXM#1My box is now created explicitly as non-updatable (line 66) :var mesh = BABYLON.Mesh.CreateBox("box", 5, scene, false); And I still have my target system (x = red, y = green, z = blue) somewhere else in the space.I want my box to be set in this target system according to new x, y, z axis. line 69n, tadaaa : http://www.babylonjs-playground.com/#JVXM#2 Now it works as expected (maybe I need to really check the axis order, but it's not a big deal). However, I'm not satisfied if I scale the mesh (line 70-71) : http://www.babylonjs-playground.com/#JVXM#3scaling applies along the original x and y system axis here after the mesh has been rebased. Is this problem the same with the bake() method ? Probably not, because bake() works upon a transformation matrix, so the scaling should be embedded. Quote Link to comment Share on other sites More sharing options...
jerome Posted May 13, 2015 Author Share Posted May 13, 2015 Mmmh... last versionHere is a scaled box : http://www.babylonjs-playground.com/#JVXM#4 Rebasing it now : http://www.babylonjs-playground.com/#JVXM#5Quite the expected result, isn't it ? The only constraint is that we need to scale the mesh before rebasing it, else it doesn't work. So I would like to know if you satisfy with it (I wish I could deduct the transformation matrix from source-target status instead) ?Is it worth it a PR or rather a bjsx module (quite small for a real module) or simply an Alby's user custom centralized function ? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted May 13, 2015 Share Posted May 13, 2015 We don't need it in-framework in a hurry, do we? We all see the cool new functions in the playground editor. Consider them stolen. Let's take some time to do some more demos with plenty of visualization, and ponder the state of affairs. Jerome, don't be afraid to use matrices in these tools, because, they will be behind-the-scenes. You are writing helper functions, and you can let callers use Vec3 args to call your helper funcs. Underneath, you do whatever is necessary. Ok, WHO put the "quaternion" line in the originial cylinderBetweenPoints(), and WHY? It was probably deltaSquash... and he likely did it... for some kind of reason. Baking is weird. It is a "last thing"... because if you try standard rotating and scaling AFTER you did an offsetting bake... the axes will be weird. But, this, too, can be worked-with, under certain circumstances. I think Jerome is seeking sane rotating and scaling AFTER the mesh has been aligned to some radial vector. And this... MIGHT require yaw, pitch, and roll. Quaternions SEEM to be "around a radial"-based, right? *shrug* Maybe... the helper func should be mesh.rotationQuaternion.alignToVector(vector) *shrug* Just guessing. Thanks for thinking/talking about this stuff, you guys! Take your time. Quote Link to comment Share on other sites More sharing options...
jerome Posted May 13, 2015 Author Share Posted May 13, 2015 Well, the complex math problem underneath is : deduct a rotation matrix (or quaternion) just given the source and the image (the rotated source). ( beer offered in Rodez to the changeller ) I know the initial status, I know the target status (not in terms of rotation but in terms of world coordinates), I want to find out the needed rotation from initial to target status in order to apply it to the initial... and so to remain in the BJS engine flow : local => world => projection Using setVerticesData() is just a trick because it changes the original mesh vertex positions (the mesh is rebuilt rotated), it doesn't really rotate the mesh. Quote Link to comment Share on other sites More sharing options...
Alby Posted May 13, 2015 Share Posted May 13, 2015 ...Einstein speaking to Niel Bohr... ....http://fr.wikipedia.org/wiki/Niels_Bohr#/media/File:Niels_Bohr_Albert_Einstein2_by_Ehrenfest.jpg just wondering If I will follow your explanations one day!... let us have faith! Quote Link to comment Share on other sites More sharing options...
jerome Posted May 13, 2015 Author Share Posted May 13, 2015 aarff...Unless some genius finds out what I'm looking for (rotation matrix deduction) -in this case, I'll implement the rebase() method with this deducted rotation matrix and PR asap, I will give you the current rebase() function (this will not be integrated in BJS then). What does rebase() do ?You've got a just created mesh, say a plane.You want to set it at this position with its length aligned on this axis and its width aligned on this other axis for instance.Moreover, you have no idea how to rotate it to achieve this result. Well, you'll just use rebase(mesh, position, axis1, axis2, axis3) ! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted May 13, 2015 Share Posted May 13, 2015 Raanan, I thought answered this on stackoverflow through the use of source and destination normals. http://stackoverflow.com/questions/26907686/babylon-js-place-a-plane-normal-to-the-clicked-surface Maybe implement this for rebase. Quote Link to comment Share on other sites More sharing options...
dbawel Posted May 13, 2015 Share Posted May 13, 2015 I beg you to use quaternions when rotating objects. Otherwise you'll never get your object to rotate beyond -89.9 and 89.9 degrees (approximately.) And once you reach these limits, your object may appear to rotate on more than one axis - depending on it's beginning orientation. An example would be to rotate a carousel in your scene - using euler vectors the carousel would flip each time you reached these limits. However, using a constant function such as f(x) = C to provide a constant delta to a quaternion float, you are able to continually rotate the carousel around a single axis with continuity. At the bottom of this thread is a little primer on quaternion floats and values - not easy to visuallize, but if you just use: mesh.rotationQuaternion = new BABYLON.Quaternion(x, y, z, w); And place it in a scene and experiment by changing the values based on the explaination below, you'll most often use quaternions to rotate objects. 1. A quaternion is a complex number with w as the real part and x,y,z as imaginary parts.2. When a quaternion represents a rotation, then w = cos(theta / 2), where theta is the rotation anglearound the axis of the quaternion.3. The axis v(v1,v2,v3) of a rotation is encoded as a quaternion: x = v1 sin (theta /2), y = v2 sin (theta /2), z = v3 sin (theta /2).4. If w = 1 then the quaternion defines 0 rotation angle around an undefined axis v = (0,0,0).5. If w = 0 then the quaternion defines a half circle rotation since theta then would be +/- pi.6. If w = -1 the quaternion defines +/- 2pi rotation angle around an undefined axis v = (0,0,0).7. And a quarter circle rotation around a single axis causes w to be +/- 0.5 and x/y/z to be +/- 0.5 As Quaternions are four-dimensional, you need four properties. The x/y/z properties don't correspond to x/y/z in euler angles. With quaternions, each of the properties is a normalized float between 0 and 1, so for example a euler angle of 45/90/180 is represented by a quaternion as approximately .65/-.27/.65/.27.Got a headache yet? I hope not, as you simply cannot apply deltas to euler vectors for rotation transforms and return any reliable rotational behavior beyond the limits. Please, just play around with it and you'll get it. RaananW 1 Quote Link to comment Share on other sites More sharing options...
Alby Posted May 13, 2015 Share Posted May 13, 2015 Thank you Jerome and Dbawel for your attempts (success!) to explain simply the use of some of the mysterious genuine or created functions (for me!) of babylon world. I just find here some more historical informations about that stranger mathematical animal called named quaternion, culture is not incompatible with babylon, isn't it? So let us see what wiki said about it : "Quaternion algebra was introduced by Hamilton in 1843.Important precursors to this work included Euler's four-square identity (1748) and Olinde Rodrigues' parameterization of general rotations by four parameters (1840), but neither of these writers treated the four-parameter rotations as an algebra.Carl Friedrich Gauss had also discovered quaternions in 1819, but this work was not published until 1900.Hamilton knew that the complex numbers could be interpreted as points in a plane, and he was looking for a way to do the same for points in three-dimensional space. Points in space can be represented by their coordinates, which are triples of numbers, and for many years he had known how to add and subtract triples of numbers. However, Hamilton had been stuck on the problem of multiplication and division for a long time. He could not figure out how to calculate the quotient of the coordinates of two points in space.The great breakthrough in quaternions finally came on Monday 16 October 1843 in Dublin, when Hamilton was on his way to the Royal Irish Academy where he was going to preside at a council meeting. As he walked along the towpath of the Royal Canal with his wife, the concepts behind quaternions were taking shape in his mind. When the answer dawned on him, Hamilton could not resist the urge to carve the formula for the quaternions, i2 = j2 = k2 = ijk = −1,into the stone of Brougham Bridge as he paused on it.From the mid-1880s, quaternions began to be displaced by vector analysis, which had been developed by Josiah Willard Gibbs, Oliver Heaviside, and Hermann von Helmholtz. Vector analysis described the same phenomena as quaternions, so it borrowed some ideas and terminology liberally from the literature of quaternions. However, vector analysis was conceptually simpler and notationally cleaner, and eventually quaternions were relegated to a minor role in mathematics and physics. A side-effect of this transition is that Hamilton's work is difficult to comprehend for many modern readers. Hamilton's original definitions are unfamiliar and his writing style was wordy and difficult to understand.However, quaternions have had a revival since the late 20th century, primarily due to their utility in describing spatial rotations. The representations of rotations by quaternions are more compact and quicker to compute than the representations by matrices. In addition, unlike Euler angles they are not susceptible to gimbal lock. For this reason, quaternions are used in computer graphics,computer vision, robotics, control theory, signal processing, attitude control, physics, bioinformatics, molecular dynamics, computer simulations, and orbital mechanics. For example, it is common for the attitude-control systems of spacecraft to be commanded in terms of quaternions. Quaternions have received another boost from number theory because of their relationships with the quadratic forms." Be well! Quote Link to comment Share on other sites More sharing options...
jerome Posted May 14, 2015 Author Share Posted May 14, 2015 Alby collects all BJS internal methods AND all Wikipedia articles ... endless collection @JCPalmerI saw RaananW's solution, but it's more complex here : we don't know either axis rotation, either rotation angle.Everything about the transformation is unknown, we just know the result. @DBawelI wish I can use any kind of rotation (Euler or quaternions).My problem is discovering the angles used by the transformation from two coordinate status only. My background threaded brain just notified me yesterday night as I was reading some book :"hey guy, you're certainly not Isaas Newton, but look at this book in your left hand rotated in space and that you want to set on the bedside table ...Imagine the book in your hand is currently the target orientation and the bedside table position the origin orientation.Now you will rotate this book only three times on each of its local cartesian system axis and translate it once to set it back on the bedside.I'll show you how..." And it (the brain) showed me a way. Jumped onto a paper and a pen to write all that stuff down (means : kill -9 the background thread, I want to sleep please). Now I have to translate this sequence into some maths and a decent algo (quite many steps and conditions) but I think I can now deduct the 3 angles, I really hope, and I know a process to get the intermediate systems in between target and original status. 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.