Here is a suggested method
- Save the initial corner coordinates
There are various ways to accomplish this, but in this scenario we can simply extract the vertices:
const mesh = this.el.getObject3D("mesh")
// _vertices stores the original coordinates
const _vertices = mesh.geometry.attributes.position.array;
- Adjust the coordinates
We can find the "current" vertex coordinate by using the transformation matrix on the original coordinate:
const mesh = this.el.getObject3D("mesh");
const mtx = mesh.worldMatrix;
const vec = new THREE.Vector3(x, y, z);
vec.applyMatrix4(mtx);
// vec now holds the transformed x,y,z coordinates.
For instance:
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script>
AFRAME.registerComponent("track-position", {
init: function() {
// vector for future calculations
this.tmpV = new THREE.Vector3();
// <p> element for displaying output
this.textEl = document.querySelector("p")
},
tick: function() {
const mesh = this.el.getObject3D("mesh") // retrieve the mesh
// get the vertices from the buffer geometry
const verticesArr = mesh.geometry.attributes.position.array;
// obtain the world transform matrix
const mtx = mesh.matrixWorld;
var text = "vertices:<br>"
for (var i = 0; i < 4; i++) {
// populate the vector from the vertices array
this.tmpV.fromArray(verticesArr, i * 3);
// apply the transform matrix to the vector
this.tmpV.applyMatrix4(mtx)
// utilize the data
text += "x: " + this.tmpV.x.toFixed(2) + " , y: " + this.tmpV.y.toFixed(2) + " , z: " + this.tmpV.z.toFixed(2) + "<br>"
}
this.textEl.innerHTML = text;
}
})
</script>
<p style="position: fixed; z-index: 99">
Hello
</p>
<a-scene>
<a-plane position="0 0 -4" rotation="45 0 0" track-position width="4" height="4" color="#7BC8A4" material="side: double" animation="property: rotation; to: 405 0 0; loop: true; easing: linear; dur: 5000"></a-plane>
</a-scene>