|
@@ -20,6 +20,10 @@ const _zeroScaleMatrix = new Matrix4().set(
|
|
|
|
|
|
// @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?
|
|
|
+// @TODO: Support uniform parameter per geometry
|
|
|
|
|
|
// copies data from attribute "src" into "target" starting at "targetOffset"
|
|
|
function copyAttributeData( src, target, targetOffset = 0 ) {
|
|
@@ -76,9 +80,6 @@ class BatchedMesh extends Mesh {
|
|
|
this._multiDrawCount = 0;
|
|
|
|
|
|
// Local matrix per geometry by using data texture
|
|
|
- // @TODO: Support uniform parameter per geometry
|
|
|
-
|
|
|
- this._matrices = [];
|
|
|
this._matricesTexture = null;
|
|
|
|
|
|
// @TODO: Calculate the entire binding box and make frustumCulled true
|
|
@@ -110,10 +111,6 @@ class BatchedMesh extends Mesh {
|
|
|
|
|
|
_initializeGeometry( reference ) {
|
|
|
|
|
|
- // @TODO: geometry.groups support?
|
|
|
- // @TODO: geometry.drawRange support?
|
|
|
- // @TODO: geometry.morphAttributes support?
|
|
|
-
|
|
|
const geometry = this.geometry;
|
|
|
const maxVertexCount = this._maxVertexCount;
|
|
|
const maxGeometryCount = this._maxGeometryCount;
|
|
@@ -328,7 +325,6 @@ class BatchedMesh extends Mesh {
|
|
|
const visible = this._visible;
|
|
|
const active = this._active;
|
|
|
const matricesTexture = this._matricesTexture;
|
|
|
- const matrices = this._matrices;
|
|
|
const matricesArray = this._matricesTexture.image.data;
|
|
|
|
|
|
// push new visibility states
|
|
@@ -340,7 +336,6 @@ class BatchedMesh extends Mesh {
|
|
|
this._geometryCount ++;
|
|
|
|
|
|
// initialize matrix information
|
|
|
- matrices.push( new Matrix4() );
|
|
|
_identityMatrix.toArray( matricesArray, geometryId * 16 );
|
|
|
matricesTexture.needsUpdate = true;
|
|
|
|
|
@@ -490,25 +485,18 @@ class BatchedMesh extends Mesh {
|
|
|
// @TODO: Map geometryId to index of the arrays because
|
|
|
// optimize() can make geometryId mismatch the index
|
|
|
|
|
|
- const visible = this._visible;
|
|
|
const active = this._active;
|
|
|
const matricesTexture = this._matricesTexture;
|
|
|
- const matrices = this._matrices;
|
|
|
const matricesArray = this._matricesTexture.image.data;
|
|
|
- if ( geometryId >= matrices.length || active[ geometryId ] === false ) {
|
|
|
+ const geometryCount = this._geometryCount;
|
|
|
+ if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( visible[ geometryId ] === true ) {
|
|
|
-
|
|
|
- matrix.toArray( matricesArray, geometryId * 16 );
|
|
|
- matricesTexture.needsUpdate = true;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- matrices[ geometryId ].copy( matrix );
|
|
|
+ matrix.toArray( matricesArray, geometryId * 16 );
|
|
|
+ matricesTexture.needsUpdate = true;
|
|
|
|
|
|
return this;
|
|
|
|
|
@@ -516,15 +504,16 @@ class BatchedMesh extends Mesh {
|
|
|
|
|
|
getMatrixAt( geometryId, matrix ) {
|
|
|
|
|
|
- const matrices = this._matrices;
|
|
|
const active = this._active;
|
|
|
- if ( geometryId >= matrices.length || active[ geometryId ] === false ) {
|
|
|
+ const matricesArray = this._matricesTexture.image.data;
|
|
|
+ const geometryCount = this._geometryCount;
|
|
|
+ if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
|
|
|
|
|
|
- return matrix;
|
|
|
+ return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
- return matrix.copy( matrices[ geometryId ] );
|
|
|
+ return matrix.fromArray( matricesArray, geometryId * 16 );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -532,14 +521,12 @@ class BatchedMesh extends Mesh {
|
|
|
|
|
|
const visible = this._visible;
|
|
|
const active = this._active;
|
|
|
- const matricesTexture = this._matricesTexture;
|
|
|
- const matrices = this._matrices;
|
|
|
- const matricesArray = this._matricesTexture.image.data;
|
|
|
+ const geometryCount = this._geometryCount;
|
|
|
|
|
|
// if the geometry is out of range, not active, or visibility state
|
|
|
// does not change then return early
|
|
|
if (
|
|
|
- geometryId >= visible.length ||
|
|
|
+ geometryId >= geometryCount ||
|
|
|
active[ geometryId ] === false ||
|
|
|
visible[ geometryId ] === value
|
|
|
) {
|
|
@@ -548,18 +535,6 @@ class BatchedMesh extends Mesh {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // scale the matrix to zero if it's hidden
|
|
|
- if ( value === true ) {
|
|
|
-
|
|
|
- matrices[ geometryId ].toArray( matricesArray, geometryId * 16 );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- _zeroScaleMatrix.toArray( matricesArray, geometryId * 16 );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- matricesTexture.needsUpdate = true;
|
|
|
visible[ geometryId ] = value;
|
|
|
return this;
|
|
|
|
|
@@ -569,9 +544,10 @@ class BatchedMesh extends Mesh {
|
|
|
|
|
|
const visible = this._visible;
|
|
|
const active = this._active;
|
|
|
+ const geometryCount = this._geometryCount;
|
|
|
|
|
|
// return early if the geometry is out of range or not active
|
|
|
- if ( geometryId >= visible.length || active[ geometryId ] === false ) {
|
|
|
+ if ( geometryId >= geometryCount || active[ geometryId ] === false ) {
|
|
|
|
|
|
return false;
|
|
|
|