Skip to content

Instantly share code, notes, and snippets.

@caseyyee
Created January 5, 2017 22:49
Show Gist options
  • Save caseyyee/2e2e921593964b91049136ac1ce31d13 to your computer and use it in GitHub Desktop.
Save caseyyee/2e2e921593964b91049136ac1ce31d13 to your computer and use it in GitHub Desktop.
Extracting world coordinates from aframe entity
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
}
});
<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