Created
January 5, 2017 22:49
-
-
Save caseyyee/2e2e921593964b91049136ac1ce31d13 to your computer and use it in GitHub Desktop.
Extracting world coordinates from aframe entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AFRAME.registerComponent('c-example', { | |
init: function () { | |
var mesh = new THREE.Mesh(new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshLambertMaterial({color: 0xffff00})); | |
this.el.setObject3D('mesh', mesh); | |
this.calculatePosition(); | |
}, | |
calculatePosition: function () { | |
var mesh = this.el.object3D; | |
mesh.updateMatrixWorld(); | |
var pos = new THREE.Vector3(); | |
var rot = new THREE.Quaternion(); | |
var scale = new THREE.Vector3(); | |
mesh.matrixWorld.decompose(pos, rot, scale); | |
console.log(pos); | |
// returns 0, 1, 0 rather than expected global position of 0 1 -3 | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a-entity position="0 0 -3"> | |
<a-entity c-example position="0 1 0"></a-entity> | |
</a-entity> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment