-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BABYLON.Mesh.prototype.{s,g}etLocalTranslation #116
Conversation
Fixed BABYLON.Mesh.prototype.{s,g}etLocalTranslation to take into account the parent. Renamed BABYLON.Mesh.prototype.{s,g}etLocalTranslation respectively by BABYLON.Mesh.prototype.setPositionWithLocalVector and BABYLON.Mesh.prototype.getPositionExpressedInLocalSpace Added BABYLON.Mesh.prototype.locallyTranslate BABYLON.Mesh.prototype.locallyTranslate adds the passed vector3 (expressed in local space; the origin of vector3 is the origin of the local space) after conversion to the parent space to the position (expressed in parent space) whereas BABYLON.Mesh.prototype.setPositionWithLocalVector sets the position (expressed in parent space) to the passed vector3 (expressed in local space but which the origin is the origin of the parent space) once it has been converted. The following code for BABYLON.Mesh.prototype.setPositionWithLocalVector could also be used. It explains itself the relation between setPositionWithLocalVector and locallyTranslate. BABYLON.Mesh.prototype.setPositionWithLocalVector = function(vector3) { this.position = BABYLON.Vector3.Zero(); this.locallyTranslate(vector3); };
I updated https://github.com/BabylonJS/Babylon.js/wiki/How-to-handle-rotations-and-translations. I thought it would do a pull-request for it. Sorry. You probably want to change the wiki git repository settings to avoid this kind of mistake. |
I think there is an issue with : because if we do that, we cannot do the following (because in this case worldMatrix and localWorld are the same): (There is no problem with the wiki update^^) |
so I could use this.worldMatrix = this.localWorld.clone() instead Although this.localWorld.multiplyToRef(this.parent.getWorldMatrix(), this.worldMatrix) should never happen when this.worldMatrix = this.localWorld since it happens only when the mesh has a parent and the second one when it has no parent, you're right it could happen somewhere else. |
Yes but the cost of the clone is high when it comes to performance. I rather suggest duplicating this line: (I agree the bug should never happen, but you know bugs... :)) |
Works for me and thanks to you I learn new things :) |
Left old functions with a comment (and a console.warn) on them to tag them as deprecated.
BABYLON.Mesh.prototype.{s,g}etLocalTranslation
Fixed BABYLON.Mesh.prototype.{s,g}etLocalTranslation to take into account the parent.
Renamed BABYLON.Mesh.prototype.{s,g}etLocalTranslation respectively by BABYLON.Mesh.prototype.setPositionWithLocalVector and BABYLON.Mesh.prototype.getPositionExpressedInLocalSpace
Added BABYLON.Mesh.prototype.locallyTranslate
BABYLON.Mesh.prototype.locallyTranslate adds the passed vector3 (expressed in local space; the origin of vector3 is the origin of the local space) after conversion to the parent space to the position (expressed in parent space)
whereas BABYLON.Mesh.prototype.setPositionWithLocalVector sets the position (expressed in parent space) to the passed vector3 (expressed in local space but which the origin is the origin of the parent space) once it has been converted.
The following code for BABYLON.Mesh.prototype.setPositionWithLocalVector could also be used. It explains itself the relation between setPositionWithLocalVector and locallyTranslate.
And here is a jsfiddle to illustrate it: http://jsfiddle.net/gwenaelhagenmuller/35uFf/12/