Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 100 additions & 54 deletions build/three.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright 2010-2026 Three.js Authors
* SPDX-License-Identifier: MIT
*/
const REVISION = '185';
const REVISION = '186dev';

/**
* Represents mouse buttons and interaction types in context of controls.
Expand Down Expand Up @@ -22385,10 +22385,6 @@ const _segCenter = /*@__PURE__*/ new Vector3();
const _segDir = /*@__PURE__*/ new Vector3();
const _diff = /*@__PURE__*/ new Vector3();

const _edge1 = /*@__PURE__*/ new Vector3();
const _edge2 = /*@__PURE__*/ new Vector3();
const _normal$1 = /*@__PURE__*/ new Vector3();

/**
* A ray that emits from an origin in a certain direction. The class is used by
* {@link Raycaster} to assist with raycasting. Raycasting is used for
Expand Down Expand Up @@ -22919,76 +22915,128 @@ class Ray {
*/
intersectTriangle( a, b, c, backfaceCulling, target ) {

// Compute the offset origin, edges, and normal.
// Watertight ray/triangle intersection. Reference: Woop, Benthin, Wald,
// "Watertight Ray/Triangle Intersection", JCGT vol. 2 no. 1 (2013), Appendix A.
// https://jcgt.org/published/0002/01/05/

const origin = this.origin;
const direction = this.direction;

const dx = direction.x;
const dy = direction.y;
const dz = direction.z;

// triangle vertices relative to the ray origin

const aox = a.x - origin.x, aoy = a.y - origin.y, aoz = a.z - origin.z;
const box = b.x - origin.x, boy = b.y - origin.y, boz = b.z - origin.z;
const cox = c.x - origin.x, coy = c.y - origin.y, coz = c.z - origin.z;

// Use the dimension where the ray direction is maximal as the projection
// axis (kz) and read every component already permuted into (kx, ky, kz).
// kx and ky are swapped when the direction's kz component is negative, to
// preserve the winding order of triangles.

const adx = Math.abs( dx ), ady = Math.abs( dy ), adz = Math.abs( dz );

let dkx, dky, dkz;
let akx, aky, akz, bkx, bky, bkz, ckx, cky, ckz;

if ( adx >= ady && adx >= adz ) {

dkz = dx; akz = aox; bkz = box; ckz = cox;

if ( dx >= 0 ) {

// from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
dkx = dy; dky = dz;
akx = aoy; aky = aoz; bkx = boy; bky = boz; ckx = coy; cky = coz;

_edge1.subVectors( b, a );
_edge2.subVectors( c, a );
_normal$1.crossVectors( _edge1, _edge2 );
} else {

dkx = dz; dky = dy;
akx = aoz; aky = aoy; bkx = boz; bky = boy; ckx = coz; cky = coy;

}

} else if ( ady >= adz ) {

dkz = dy; akz = aoy; bkz = boy; ckz = coy;

// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
// |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
let DdN = this.direction.dot( _normal$1 );
let sign;
if ( dy >= 0 ) {

if ( DdN > 0 ) {
dkx = dz; dky = dx;
akx = aoz; aky = aox; bkx = boz; bky = box; ckx = coz; cky = cox;

if ( backfaceCulling ) return null;
sign = 1;
} else {

} else if ( DdN < 0 ) {
dkx = dx; dky = dz;
akx = aox; aky = aoz; bkx = box; bky = boz; ckx = cox; cky = coz;

sign = -1;
DdN = - DdN;
}

} else {

return null;
dkz = dz; akz = aoz; bkz = boz; ckz = coz;

}
if ( dz >= 0 ) {

_diff.subVectors( this.origin, a );
const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
dkx = dx; dky = dy;
akx = aox; aky = aoy; bkx = box; bky = boy; ckx = cox; cky = coy;

// b1 < 0, no intersection
if ( DdQxE2 < 0 ) {
} else {

return null;
dkx = dy; dky = dx;
akx = aoy; aky = aox; bkx = boy; bky = box; ckx = coy; cky = cox;

}

}

const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
// a zero direction has no maximal axis and cannot intersect

// b2 < 0, no intersection
if ( DdE1xQ < 0 ) {
if ( dkz === 0 ) return null;

return null;
// shear constants that align the ray with the +kz axis

}
const sx = dkx / dkz, sy = dky / dkz, sz = 1 / dkz;

// b1+b2 > 1, no intersection
if ( DdQxE2 + DdE1xQ > DdN ) {
// sheared and scaled vertices

return null;
const ax = akx - sx * akz, ay = aky - sy * akz;
const bx = bkx - sx * bkz, by = bky - sy * bkz;
const cx = ckx - sx * ckz, cy = cky - sy * ckz;

}
// scaled barycentric coordinates (signed edge functions); the shear makes a
// shared edge evaluate identically for both adjacent triangles, so the ray
// can never fall between them

// Line intersects triangle, check if ray does.
const QdN = - sign * _diff.dot( _normal$1 );
const u = cx * by - cy * bx;
const v = ax * cy - ay * cx;
const w = bx * ay - by * ax;

// t < 0, no intersection
if ( QdN < 0 ) {
if ( backfaceCulling ) {

return null;
if ( u < 0 || v < 0 || w < 0 ) return null;

} else {

if ( ( u < 0 || v < 0 || w < 0 ) && ( u > 0 || v > 0 || w > 0 ) ) return null;

}

// Ray intersects triangle.
return this.at( QdN / DdN, target );
const det = u + v + w;

// ray is co-planar with the triangle

if ( det === 0 ) return null;

// scaled hit distance; t = tScaled / det must lie in front of the origin

const tScaled = sz * ( u * akz + v * bkz + w * ckz );

if ( det > 0 ? tScaled < 0 : tScaled > 0 ) return null;

return this.at( tScaled / det, target );

}

Expand Down Expand Up @@ -56137,6 +56185,10 @@ class Raycaster {
* be detected. To raycast against both faces of an object, you'll want to set {@link Material#side}
* to `THREE.DoubleSide`.
*
* Note that a ray hitting a triangle mesh exactly along an edge shared by two faces may be
* reported by both faces, resulting in two coincident intersections (identical point and
* distance) in the returned array.
*
* @param {Object3D} object - The 3D object to check for intersection with the ray.
* @param {boolean} [recursive=true] - If set to `true`, it also checks all descendants.
* Otherwise it only checks intersection with the object.
Expand Down Expand Up @@ -59505,7 +59557,8 @@ class ShapePath {
for ( let j = i - 1; j >= 0; j -- ) {

const candidate = entries[ j ];
if ( ! candidate.boundingBox.containsPoint( entry.interiorPoint ) ) continue;

if ( ! candidate.boundingBox.containsBox( entry.boundingBox ) ) continue;
if ( ! pointInPolygon( entry.interiorPoint, candidate.points ) ) continue;

entry.container = candidate.exclude ? candidate.container : candidate;
Expand Down Expand Up @@ -59653,13 +59706,6 @@ class Controls extends EventDispatcher {
*/
connect( element ) {

if ( element === undefined ) {

warn( 'Controls: connect() now requires an element.' ); // @deprecated, the warning can be removed with r185
return;

}

if ( this.domElement !== null ) this.disconnect();

this.domElement = element;
Expand Down
4 changes: 2 additions & 2 deletions build/three.tsl.js

Large diffs are not rendered by default.

Loading
Loading