Skip to content

Commit

Permalink
RenderObject: Fix geometry key for morph targets. (#30302)
Browse files Browse the repository at this point in the history
* RenderObject: Fix geometry key for morph targets.

* RenderObject: Clean up.

* RenderObject: Improve cache key names.
  • Loading branch information
Mugen87 authored Jan 10, 2025
1 parent 0a7d33c commit dd47363
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions docs/api/en/core/BufferAttribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ <h3>[property:Number gpuType]</h3>
<h3>[property:Boolean isBufferAttribute]</h3>
<p>Read-only flag to check if a given object is of type [name].</p>

<h3>[property:Integer id]</h3>
<p>Unique number for this attribute instance.</p>

<h3>[property:Integer itemSize]</h3>
<p>
The length of vectors that are being stored in the
Expand Down
4 changes: 4 additions & 0 deletions src/core/BufferAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { fromHalfFloat, toHalfFloat } from '../extras/DataUtils.js';
const _vector = /*@__PURE__*/ new Vector3();
const _vector2 = /*@__PURE__*/ new Vector2();

let _id = 0;

class BufferAttribute {

constructor( array, itemSize, normalized = false ) {
Expand All @@ -19,6 +21,8 @@ class BufferAttribute {

this.isBufferAttribute = true;

Object.defineProperty( this, 'id', { value: _id ++ } );

this.name = '';

this.array = array;
Expand Down
26 changes: 20 additions & 6 deletions src/renderers/common/RenderObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,26 @@ class RenderObject {

}

// structural equality isn't sufficient for morph targets since the
// data are maintained in textures. only if the targets are all equal
// the texture and thus the instance of `MorphNode` can be shared.

for ( const name of Object.keys( geometry.morphAttributes ).sort() ) {

const targets = geometry.morphAttributes[ name ];

cacheKey += 'morph-' + name + ',';

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

const attribute = targets[ i ];

cacheKey += attribute.id + ',';

}

}

if ( geometry.index ) {

cacheKey += 'index,';
Expand Down Expand Up @@ -641,12 +661,6 @@ class RenderObject {

}

if ( object.morphTargetInfluences ) {

cacheKey += object.morphTargetInfluences.length + ',';

}

if ( object.isBatchedMesh ) {

cacheKey += object._matricesTexture.uuid + ',';
Expand Down

0 comments on commit dd47363

Please sign in to comment.