Skip to content
Closed
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
2 changes: 1 addition & 1 deletion examples/jsm/renderers/Projector.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class Projector {
} else if ( object.isMesh || object.isLine || object.isPoints ) {

if ( object.material.visible === false ) return;
if ( object.frustumCulled === true && _frustum.intersectsObject( object ) === false ) return;
if ( object.frustumCulled === true && object.intersectsFrustum( _frustum ) === false ) return;

addObject( object );

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/webgpu/WebGPURenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ class WebGPURenderer {

} else if ( object.isMesh || object.isLine || object.isPoints ) {

if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
if ( ! object.frustumCulled || object.intersectsFrustum( _frustum ) ) {

if ( this.sortObjects === true ) {

Expand Down
1 change: 1 addition & 0 deletions src/Three.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export { Skeleton } from './objects/Skeleton.js';
export { Bone } from './objects/Bone.js';
export { Mesh } from './objects/Mesh.js';
export { InstancedMesh } from './objects/InstancedMesh.js';
export { InstancedMeshCulled } from './objects/InstancedMeshCulled.js';
export { LineSegments } from './objects/LineSegments.js';
export { LineLoop } from './objects/LineLoop.js';
export { Line } from './objects/Line.js';
Expand Down
6 changes: 6 additions & 0 deletions src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ class Object3D extends EventDispatcher {

raycast( /* raycaster, intersects */ ) {}

intersectsFrustum( frustum ) {

return frustum.intersectsObject( this );

}

traverse( callback ) {

callback( this );
Expand Down
64 changes: 64 additions & 0 deletions src/objects/InstancedMeshCulled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { InstancedMesh } from './InstancedMesh.js';
import { Sphere } from '../math/Sphere.js';
import { Vector3 } from '../math/Vector3.js';


class InstancedMeshCulled extends InstancedMesh {

constructor( geometry, material, count ) {

super( geometry, material, count );

this.frustumCulled = true;
this.boundingSphere = null;

}

computeBoundingSphere() {

if ( this.geometry.boundingSphere === null ) this.geometry.computeBoundingSphere();

const min = new Vector3( Infinity, Infinity, Infinity );
const max = new Vector3( - Infinity, - Infinity, - Infinity );
const position = new Vector3();

for ( let m = 0; m < this.count; m ++ ) {

const x = this.instanceMatrix[ m * 16 + 12 ];
const y = this.instanceMatrix[ m * 16 + 13 ];
const z = this.instanceMatrix[ m * 16 + 14 ];
position.set( x, y, z );
min.min( position );
max.max( position );

}

let radius = 0;
const center = new Vector3().addVectors( min, max ).multiply( 0.5 );
for ( let m = 0; m < this.count; m ++ ) {

const x = this.instanceMatrix[ m * 16 + 12 ];
const y = this.instanceMatrix[ m * 16 + 13 ];
const z = this.instanceMatrix[ m * 16 + 14 ];
position.set( x, y, z );
const distance = position.distanceTo( center );
// note: we assume no scaling - computing scale from instance matrix is not trivial
const r = distance + this.geometry.boundingSphere.radius;
if ( r > radius ) radius = r;

}

this.boundingSphere = new Sphere( center, radius );

}

intersectsFrustum( frustum ) {

if ( this.boundingSphere === null ) this.computeBoundingSphere();
frustum.intersectsSphere( this.boundingSphere );

}

}

export { InstancedMeshCulled };
2 changes: 1 addition & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ function WebGLRenderer( parameters = {} ) {

}

if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
if ( ! object.frustumCulled || object.intersectsFrustum( _frustum ) ) {

if ( sortObjects ) {

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl/WebGLShadowMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ function WebGLShadowMap( _renderer, _objects, _capabilities ) {

if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {

if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || object.intersectsFrustum( _frustum ) ) ) {

object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );

Expand Down