@@ -71,28 +71,27 @@ class RenderComponentSystem extends ComponentSystem {
71
71
}
72
72
73
73
cloneComponent ( entity , clone ) {
74
- var i ;
75
- var data = { } ;
76
74
77
- for ( i = 0 ; i < _properties . length ; i ++ ) {
75
+ // copy properties
76
+ const data = { } ;
77
+ for ( let i = 0 ; i < _properties . length ; i ++ ) {
78
78
data [ _properties [ i ] ] = entity . render [ _properties [ i ] ] ;
79
79
}
80
80
81
- // we cannot copy mesh instances, delete them and component recreates them properly
81
+ // mesh instances cannot be used this way, remove them and manually clone them later
82
82
delete data . meshInstances ;
83
83
84
- var component = this . addComponent ( clone , data ) ;
85
-
86
- // TODO: we should copy all relevant meshinstance properties here
87
- if ( entity . render ) {
88
- var meshInstances = entity . render . meshInstances ;
89
- var meshInstancesClone = component . meshInstances ;
90
- for ( i = 0 ; i < meshInstances . length && i < meshInstancesClone . length ; i ++ ) {
91
- meshInstancesClone [ i ] . mask = meshInstances [ i ] . mask ;
92
- meshInstancesClone [ i ] . material = meshInstances [ i ] . material ;
93
- meshInstancesClone [ i ] . layer = meshInstances [ i ] . layer ;
94
- meshInstancesClone [ i ] . receiveShadow = meshInstances [ i ] . receiveShadow ;
95
- }
84
+ // clone component
85
+ const component = this . addComponent ( clone , data ) ;
86
+
87
+ // clone mesh instances
88
+ const srcMeshInstances = entity . render . meshInstances ;
89
+ const meshes = srcMeshInstances . map ( mi => mi . mesh ) ;
90
+ component . _onSetMeshes ( meshes ) ;
91
+
92
+ // assign materials
93
+ for ( let m = 0 ; m < srcMeshInstances . length ; m ++ ) {
94
+ component . meshInstances [ m ] . material = srcMeshInstances [ m ] . material ;
96
95
}
97
96
}
98
97
0 commit comments