@@ -268,23 +268,59 @@ class BatchManager {
268268 }
269269 }
270270
271+ /**
272+ * Filter out mesh instances that have skin or morph, as these are not supported by batching.
273+ * If any mesh instance has skin/morph, the entire set is excluded.
274+ *
275+ * @param {MeshInstance[] } meshInstances - The mesh instances to filter.
276+ * @param {string } nodeName - The node name for warning messages.
277+ * @returns {MeshInstance[]|null } The mesh instances if none have skin/morph, or null if any do.
278+ * @private
279+ */
280+ _filterBatchableInstances ( meshInstances , nodeName ) {
281+ let hasUnsupported = false ;
282+ let hasSupported = false ;
283+ for ( let i = 0 ; i < meshInstances . length ; i ++ ) {
284+ if ( meshInstances [ i ] . skinInstance || meshInstances [ i ] . morphInstance ) {
285+ hasUnsupported = true ;
286+ } else {
287+ hasSupported = true ;
288+ }
289+ }
290+
291+ if ( hasUnsupported ) {
292+ if ( hasSupported ) {
293+ Debug . warnOnce ( `BatchManager: Some mesh instances on entity "${ nodeName } " have skin/morph and the whole entity will be excluded from batching.` ) ;
294+ }
295+ return null ;
296+ }
297+
298+ return meshInstances ;
299+ }
300+
271301 _extractRender ( node , arr , group , groupMeshInstances ) {
272302 if ( node . render ) {
273- arr = groupMeshInstances [ node . render . batchGroupId ] = arr . concat ( node . render . meshInstances ) ;
274- node . render . removeFromLayers ( ) ;
303+ const valid = this . _filterBatchableInstances ( node . render . meshInstances , node . name ) ;
304+ if ( valid ) {
305+ arr = groupMeshInstances [ node . render . batchGroupId ] = arr . concat ( valid ) ;
306+ node . render . removeFromLayers ( ) ;
307+ }
275308 }
276309
277310 return arr ;
278311 }
279312
280313 _extractModel ( node , arr , group , groupMeshInstances ) {
281314 if ( node . model && node . model . model ) {
282- arr = groupMeshInstances [ node . model . batchGroupId ] = arr . concat ( node . model . meshInstances ) ;
283- node . model . removeModelFromLayers ( ) ;
284-
285- // #if _DEBUG
286- node . model . _batchGroup = group ;
287- // #endif
315+ const valid = this . _filterBatchableInstances ( node . model . meshInstances , node . name ) ;
316+ if ( valid ) {
317+ arr = groupMeshInstances [ node . model . batchGroupId ] = arr . concat ( valid ) ;
318+ node . model . removeModelFromLayers ( ) ;
319+
320+ // #if _DEBUG
321+ node . model . _batchGroup = group ;
322+ // #endif
323+ }
288324 }
289325
290326 return arr ;
0 commit comments