Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BatchedMesh: Cleanup #27201

Merged
merged 2 commits into from
Nov 17, 2023
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
2 changes: 1 addition & 1 deletion src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ class Object3D extends EventDispatcher {
object.drawRanges = this._drawRanges;
object.reservedRanges = this._reservedRanges;

object.visible = this._visible;
object.visibility = this._visibility;
object.active = this._active;
object.bounds = this._bounds.map( bound => ( {
boxInitialized: bound.boxInitialized,
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ class ObjectLoader extends Loader {
object._drawRanges = data.drawRanges;
object._reservedRanges = data.reservedRanges;

object._visible = data.visible;
object._visibility = data.visibility;
object._active = data.active;
object._bounds = data.bounds.map( bound => {

Expand Down
33 changes: 16 additions & 17 deletions src/objects/BatchedMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ const _mesh = new Mesh();
const _batchIntersects = [];

// @TODO: SkinnedMesh support?
// @TODO: Future work if needed. Move into the core. Can be optimized more with WEBGL_multi_draw.
// @TODO: geometry.groups support?
// @TODO: geometry.drawRange support?
// @TODO: geometry.morphAttributes support?
Expand Down Expand Up @@ -137,7 +136,7 @@ class BatchedMesh extends Mesh {
this._drawRanges = [];
this._reservedRanges = [];

this._visible = [];
this._visibility = [];
this._active = [];
this._bounds = [];

Expand Down Expand Up @@ -440,13 +439,13 @@ class BatchedMesh extends Mesh {

}

const visible = this._visible;
const visibility = this._visibility;
const active = this._active;
const matricesTexture = this._matricesTexture;
const matricesArray = this._matricesTexture.image.data;

// push new visibility states
visible.push( true );
visibility.push( true );
active.push( true );

// update id
Expand Down Expand Up @@ -751,7 +750,7 @@ class BatchedMesh extends Mesh {

setVisibleAt( geometryId, value ) {

const visible = this._visible;
const visibility = this._visibility;
const active = this._active;
const geometryCount = this._geometryCount;

Expand All @@ -760,21 +759,21 @@ class BatchedMesh extends Mesh {
if (
geometryId >= geometryCount ||
active[ geometryId ] === false ||
visible[ geometryId ] === value
visibility[ geometryId ] === value
) {

return this;

}

visible[ geometryId ] = value;
visibility[ geometryId ] = value;
return this;

}

getVisibleAt( geometryId ) {

const visible = this._visible;
const visibility = this._visibility;
const active = this._active;
const geometryCount = this._geometryCount;

Expand All @@ -785,13 +784,13 @@ class BatchedMesh extends Mesh {

}

return visible[ geometryId ];
return visibility[ geometryId ];

}

raycast( raycaster, intersects ) {

const visible = this._visible;
const visibility = this._visibility;
const active = this._active;
const drawRanges = this._drawRanges;
const geometryCount = this._geometryCount;
Expand All @@ -816,7 +815,7 @@ class BatchedMesh extends Mesh {

for ( let i = 0; i < geometryCount; i ++ ) {

if ( ! visible[ i ] || ! active[ i ] ) {
if ( ! visibility[ i ] || ! active[ i ] ) {

continue;

Expand Down Expand Up @@ -865,7 +864,7 @@ class BatchedMesh extends Mesh {
this._drawRanges = source._drawRanges.map( range => ( { ...range } ) );
this._reservedRanges = source._reservedRanges.map( range => ( { ...range } ) );

this._visible = source._visible.slice();
this._visibility = source._visibility.slice();
this._active = source._active.slice();
this._bounds = source._bounds.map( bound => ( {
boxInitialized: bound.boxInitialized,
Expand Down Expand Up @@ -909,7 +908,7 @@ class BatchedMesh extends Mesh {
const index = geometry.getIndex();
const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;

const visible = this._visible;
const visibility = this._visibility;
const multiDrawStarts = this._multiDrawStarts;
const multiDrawCounts = this._multiDrawCounts;
const drawRanges = this._drawRanges;
Expand All @@ -935,9 +934,9 @@ class BatchedMesh extends Mesh {
// get the camera position
_vector.setFromMatrixPosition( camera.matrixWorld );

for ( let i = 0, l = visible.length; i < l; i ++ ) {
for ( let i = 0, l = visibility.length; i < l; i ++ ) {

if ( visible[ i ] ) {
if ( visibility[ i ] ) {

this.getMatrixAt( i, _matrix );
this.getBoundingSphereAt( i, _sphere ).applyMatrix4( _matrix );
Expand Down Expand Up @@ -984,9 +983,9 @@ class BatchedMesh extends Mesh {

} else {

for ( let i = 0, l = visible.length; i < l; i ++ ) {
for ( let i = 0, l = visibility.length; i < l; i ++ ) {

if ( visible[ i ] ) {
if ( visibility[ i ] ) {

// determine whether the batched geometry is within the frustum
let culled = false;
Expand Down