Skip to content

Commit a904498

Browse files
authored
Merge pull request #16267 from takahirox/FixGLTFExporter
Fix GLTFExporter bug
2 parents ce31c17 + 9bc496f commit a904498

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

examples/js/exporters/GLTFExporter.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,23 @@ THREE.GLTFExporter.prototype = {
123123

124124
var cachedCanvas;
125125

126+
var uids = new Map();
127+
var uid = 0;
128+
129+
/**
130+
* Assign and return a temporal unique id for an object
131+
* especially which doesn't have .uuid
132+
* @param {Object} object
133+
* @return {Integer}
134+
*/
135+
function getUID( object ) {
136+
137+
if ( ! uids.has( object ) ) uids.set( object, uid ++ );
138+
139+
return uids.get( object );
140+
141+
}
142+
126143
/**
127144
* Compare two arrays
128145
* @param {Array} array1 Array 1 to compare
@@ -1175,9 +1192,9 @@ THREE.GLTFExporter.prototype = {
11751192

11761193
}
11771194

1178-
if ( cachedData.attributes.has( attribute ) ) {
1195+
if ( cachedData.attributes.has( getUID( attribute ) ) ) {
11791196

1180-
attributes[ attributeName ] = cachedData.attributes.get( attribute );
1197+
attributes[ attributeName ] = cachedData.attributes.get( getUID( attribute ) );
11811198
continue;
11821199

11831200
}
@@ -1198,7 +1215,7 @@ THREE.GLTFExporter.prototype = {
11981215
if ( accessor !== null ) {
11991216

12001217
attributes[ attributeName ] = accessor;
1201-
cachedData.attributes.set( attribute, accessor );
1218+
cachedData.attributes.set( getUID( attribute ), accessor );
12021219

12031220
}
12041221

@@ -1264,9 +1281,9 @@ THREE.GLTFExporter.prototype = {
12641281

12651282
var baseAttribute = geometry.attributes[ attributeName ];
12661283

1267-
if ( cachedData.attributes.has( attribute ) ) {
1284+
if ( cachedData.attributes.has( getUID( attribute ) ) ) {
12681285

1269-
target[ gltfAttributeName ] = cachedData.attributes.get( attribute );
1286+
target[ gltfAttributeName ] = cachedData.attributes.get( getUID( attribute ) );
12701287
continue;
12711288

12721289
}
@@ -1286,7 +1303,7 @@ THREE.GLTFExporter.prototype = {
12861303
}
12871304

12881305
target[ gltfAttributeName ] = processAccessor( relativeAttribute, geometry );
1289-
cachedData.attributes.set( baseAttribute, target[ gltfAttributeName ] );
1306+
cachedData.attributes.set( getUID( baseAttribute ), target[ gltfAttributeName ] );
12901307

12911308
}
12921309

@@ -1355,7 +1372,13 @@ THREE.GLTFExporter.prototype = {
13551372

13561373
if ( geometry.index !== null ) {
13571374

1358-
var cacheKey = geometry.uuid + ':' + groups[ i ].start + ':' + groups[ i ].count;
1375+
var cacheKey = getUID( geometry.index );
1376+
1377+
if ( groups[ i ].start !== undefined || groups[ i ].count !== undefined ) {
1378+
1379+
cacheKey += ':' + groups[ i ].start + ':' + groups[ i ].count;
1380+
1381+
}
13591382

13601383
if ( cachedData.attributes.has( cacheKey ) ) {
13611384

0 commit comments

Comments
 (0)