Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

World to Local #1833

Merged
merged 1 commit into from May 5, 2012

Conversation

4 participants
Contributor

zz85 commented Apr 28, 2012

As per commit notes.

There should be the convenience methods for switching between the scene/world/global/absolute coordinates to the local/child/relative coordinates with Object3D, which is part of the scene graph, rather than the Vector class.

Hopefully helps resolves issues: #1752, #1043, 025fb62 and baf0f65

worldToLocal() and localToWorld() coordinates conversion for Object3D.
I struggled with this for quite a while, but I think this should be the right thing - having convenience methods for switching between the scene/world/global/absolute coordinates to the local/child/relative coordinates right with Object3D, which is part of the scene graph, rather than the Vector class.

Related issues: #1752, #1043, commits 025fb62 and baf0f65

@zz85 zz85 referenced this pull request May 2, 2012

Closed

Absolute Object3D.lookAt? #1752

Owner

mrdoob commented May 5, 2012

Thanks for fighting with this :)

@mrdoob mrdoob merged commit da0373a into mrdoob:dev May 5, 2012

Collaborator

WestLangley commented May 5, 2012

What was the rationale for adding __inverseMatrixWorld as a property of the object inside worldToLocal() ?

Contributor

zz85 commented May 5, 2012

yeah! \o/ \o

@WestLangley the rationale was not to create new Matrix objects to be created for every worldToLocal() is called, and neither do we want to have an additional new Matrix object created for every Object3D generated, so its generated on ad-hoc basics once and cached.

Collaborator

WestLangley commented May 5, 2012

@zz85 I hear you, but why not create just one?

worldToLocal: function ( vector ) {

    return THREE.Object3D.__mat4.getInverse( this.matrixWorld ).multiplyVector3( vector );

}

THREE.Object3D.__mat4 = new THREE.Matrix4();
Contributor

zz85 commented May 5, 2012

oh yes, i think that should actually work better too, thanks! :)

Contributor

zz85 commented May 5, 2012

hmm... then again, i was probably thinking along the lines that matrices were usually kept for its own object purposes, for example matrixRotationWorld. but since inverseMatrixWorld is never used, we could use the __mat4 as you have proposed..

zz85 added a commit to zz85/three.js that referenced this pull request May 5, 2012

Contributor

alteredq commented May 5, 2012

Hmmm, could we maybe have some separate steps for this?

I'm just thinking for some use case where you would do many of object.worldToLocal in a row, it seems very very wasteful to compute inverse matrix every time.

Contributor

zz85 commented May 17, 2012

@alteredq what would you mean separate steps?

Contributor

alteredq commented May 17, 2012

Something that would allow to compute inverse world matrix only once per frame instead of in every call to worldToLocal.

If object transform didn't change, and you would need to compute worldToLocal many times for different points, there is no need to compute expensive matrix inverse every time.

Contributor

zz85 commented May 17, 2012

hmm... perhaps we could have

worldToLocal( vector, recalculate )

where recalculate set to true will force recalculation?

so

toLocal = new THREE.Vector();
object.worldToLocal(toLocal); // this will recalculate by default

for (i=0;i<100;i++) {
    object.worldToLocal(toLocal, false); // this will prevent inverse matrix calculation 
}

wvl pushed a commit to wvl/three.js that referenced this pull request Nov 28, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment