import { Vector2 } from 'three/src/math/Vector2.js'; import { Vector3 } from 'three/src/math/Vector3.js'; import { Euler } from 'three/src/math/Euler.js'; import { Quaternion } from 'three/src/math/Quaternion.js'; import { Matrix4 } from 'three/src/math/Matrix4.js'; import { Box2 } from 'three/src/math/Box2.js'; import { Box3 } from 'three/src/math/Box3.js'; import { Sphere } from 'three/src/math/Sphere.js'; import { Ray } from 'three/src/math/Ray.js'; import { Plane } from 'three/src/math/Plane.js'; import { Triangle } from 'three/src/math/Triangle.js'; import { Frustum } from 'three/src/math/Frustum.js'; import { Spherical } from 'three/src/math/Spherical.js'; import { Cylindrical } from 'three/src/math/Cylindrical.js'; import { generateUUID, seededRandom } from 'three/src/math/MathUtils.js'; const euler = new Euler(0, 0, 0); const quaternion = new Quaternion().setFromEuler(euler); console.log('rotation', quaternion.x, quaternion.y, quaternion.z, quaternion.w, euler.order); Euler.DEFAULT_ORDER = 'ZYX'; console.log('default', new Euler().order, euler.order); Euler.DEFAULT_ORDER = 'XYZ'; euler.set(0, Math.PI / 2, 0); const rotated = new Vector3(1, 0, 0).applyEuler(euler); console.log('rotated', Math.round(rotated.x), Math.round(rotated.y), Math.round(rotated.z)); const box = new Box3(new Vector3(-1, -1, -1), new Vector3(1, 1, 1)); console.log('box', box.containsPoint(new Vector3()), box.containsPoint(new Vector3(2, 0, 0))); box.expandByPoint(new Vector3(2, 3, 4)); const size = box.getSize(new Vector3()); console.log('size', size.x, size.y, size.z); const sphere = new Sphere(new Vector3(), 1); console.log('sphere', sphere.containsPoint(new Vector3(0, 0.5, 0)), sphere.intersectsBox(box)); console.log('separated', sphere.intersectsSphere(new Sphere(new Vector3(5, 0, 0), 1))); const ray = new Ray(new Vector3(0, 0, 8), new Vector3(0, 0, -1)); const hit = ray.intersectBox(box, new Vector3()); console.log('box hit', hit.x, hit.y, hit.z); const sphereHit = ray.intersectSphere(sphere, new Vector3()); console.log('sphere hit', sphereHit.x, sphereHit.y, sphereHit.z); const miss = new Ray(new Vector3(10, 10, 10), new Vector3(1, 0, 0)); console.log('miss', miss.intersectBox(box, new Vector3()) === null, miss.intersectSphere(sphere, new Vector3()) === null); const plane = new Plane(new Vector3(0, 0, 1), -2); const planeHit = ray.intersectPlane(plane, new Vector3()); console.log('plane', planeHit.z, plane.distanceToPoint(new Vector3(0, 0, 5))); const triangle = new Triangle(new Vector3(0, 0, 0), new Vector3(2, 0, 0), new Vector3(0, 2, 0)); console.log('triangle', triangle.getArea(), triangle.getNormal(new Vector3()).z); const barycentric = triangle.getBarycoord(new Vector3(0.5, 0.5, 0), new Vector3()); console.log('barycentric', barycentric.x, barycentric.y, barycentric.z); const projection = new Matrix4().makePerspective(-1, 1, 1, -1, 1, 10); const frustum = new Frustum().setFromProjectionMatrix(projection); console.log('frustum', frustum.containsPoint(new Vector3(0, 0, -2)), frustum.containsPoint(new Vector3(0, 0, 2))); console.log('visible', frustum.intersectsSphere(new Sphere(new Vector3(0, 0, -3), 0.5)), frustum.intersectsSphere(new Sphere(new Vector3(20, 0, -3), 0.5))); const box2 = new Box2().setFromPoints([new Vector2(-1, -2), new Vector2(3, 4)]); console.log('box2', box2.min.x, box2.max.y, box2.containsPoint(new Vector2(0, 0))); const spherical = new Spherical().setFromVector3(new Vector3(0, 0, 2)); const cylindrical = new Cylindrical().setFromVector3(new Vector3(0, 3, 2)); console.log('coordinates', spherical.radius, cylindrical.radius, cylindrical.y); console.log('uuid', /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(generateUUID())); console.log('seed', seededRandom(42).toFixed(6), seededRandom().toFixed(6));