Vector3Extention.js 749 B

12345678910111213141516171819202122232425262728293031
  1. Object.assign( THREE.Vector3.prototype, {
  2. xyzFixedEq: function (vector, digit) {
  3. if (this.x.toFixed(digit) - 0 == vector.x.toFixed(digit) - 0 &&
  4. this.y.toFixed(digit) - 0 == vector.y.toFixed(digit) - 0 &&
  5. this.z.toFixed(digit) - 0 == vector.z.toFixed(digit) - 0)
  6. {
  7. return true;
  8. }
  9. return false;
  10. }});
  11. function tryAddDistinctVector3(array, item) {
  12. if (!vectorContains(array, item)) {
  13. array.push(item);
  14. return true;
  15. }
  16. return false;
  17. function vectorContains(array, item) {
  18. let index = array.findIndex(vector => vector.xyzFixedEq(item, 4));
  19. if (index > -1) {
  20. return true;
  21. }
  22. return false;
  23. }
  24. }