Transform a THREE.CSS3DObject


SUBMITTED BY: Guest

DATE: Nov. 23, 2013, 10:40 a.m.

FORMAT: Text only

SIZE: 1.1 kB

HITS: 1130

  1. http://cur.lv/4x9e0 (Earn BTC)
  2. /**
  3. * Transform a THREE.CSS3DObject object so that it aligns to a given rectangle.
  4. *
  5. * @param object: A THREE.CSS3DObject object.
  6. * @param v: A list of the 4 vertices of the rectangle (clockwise order) on which to align the object.
  7. */
  8. function alignObject(object, v) {
  9. // width of DOM object wrapped via CSS3DObject
  10. var width = parseInt(object.element.style.width, 10);
  11. // compute rect vectors from rect vertices
  12. var v10 = v[1].clone().sub(v[0]);
  13. var v30 = v[3].clone().sub(v[0]);
  14. // compute (uniform) scaling
  15. var scale = v10.length() / width;
  16. // compute translation / new mid-point
  17. var position = new THREE.Vector3().addVectors(v10, v30).multiplyScalar(0.5).add(v[0]);
  18. // compute rotations
  19. var rotX = -v30.angleTo(new THREE.Vector3(0, -1, 0));
  20. // FIXME: rotY, rotZ
  21. // apply transformation
  22. object.scale.set(scale, scale, scale);
  23. object.position = position;
  24. object.rotateX(rotX);
  25. }

comments powered by Disqus