Skip to content

Commit dd47363

Browse files
authored
RenderObject: Fix geometry key for morph targets. (#30302)
* RenderObject: Fix geometry key for morph targets. * RenderObject: Clean up. * RenderObject: Improve cache key names.
1 parent 0a7d33c commit dd47363

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

docs/api/en/core/BufferAttribute.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ <h3>[property:Number gpuType]</h3>
7070
<h3>[property:Boolean isBufferAttribute]</h3>
7171
<p>Read-only flag to check if a given object is of type [name].</p>
7272

73+
<h3>[property:Integer id]</h3>
74+
<p>Unique number for this attribute instance.</p>
75+
7376
<h3>[property:Integer itemSize]</h3>
7477
<p>
7578
The length of vectors that are being stored in the

src/core/BufferAttribute.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { fromHalfFloat, toHalfFloat } from '../extras/DataUtils.js';
77
const _vector = /*@__PURE__*/ new Vector3();
88
const _vector2 = /*@__PURE__*/ new Vector2();
99

10+
let _id = 0;
11+
1012
class BufferAttribute {
1113

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

2022
this.isBufferAttribute = true;
2123

24+
Object.defineProperty( this, 'id', { value: _id ++ } );
25+
2226
this.name = '';
2327

2428
this.array = array;

src/renderers/common/RenderObject.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,26 @@ class RenderObject {
558558

559559
}
560560

561+
// structural equality isn't sufficient for morph targets since the
562+
// data are maintained in textures. only if the targets are all equal
563+
// the texture and thus the instance of `MorphNode` can be shared.
564+
565+
for ( const name of Object.keys( geometry.morphAttributes ).sort() ) {
566+
567+
const targets = geometry.morphAttributes[ name ];
568+
569+
cacheKey += 'morph-' + name + ',';
570+
571+
for ( let i = 0, l = targets.length; i < l; i ++ ) {
572+
573+
const attribute = targets[ i ];
574+
575+
cacheKey += attribute.id + ',';
576+
577+
}
578+
579+
}
580+
561581
if ( geometry.index ) {
562582

563583
cacheKey += 'index,';
@@ -641,12 +661,6 @@ class RenderObject {
641661

642662
}
643663

644-
if ( object.morphTargetInfluences ) {
645-
646-
cacheKey += object.morphTargetInfluences.length + ',';
647-
648-
}
649-
650664
if ( object.isBatchedMesh ) {
651665

652666
cacheKey += object._matricesTexture.uuid + ',';

0 commit comments

Comments
 (0)