Skip to content

Commit eae49f6

Browse files
authored
Fix for cloned anim and render components (playcanvas#3463)
* fix for cloned anim and render components
1 parent fe4fe4f commit eae49f6

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/framework/components/anim/component.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,14 @@ class AnimComponent extends Component {
672672
});
673673
this._consumedTriggers.clear();
674674
}
675+
676+
resolveDuplicatedEntityReferenceProperties(oldAnim, duplicatedIdsMap) {
677+
if (oldAnim.rootBone && duplicatedIdsMap[oldAnim.rootBone.getGuid()]) {
678+
this.rootBone = duplicatedIdsMap[oldAnim.rootBone.getGuid()];
679+
} else {
680+
this.rebind();
681+
}
682+
}
675683
}
676684

677685
export { AnimComponent };

src/framework/components/render/component.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ class RenderComponent extends Component {
111111
_onRootBoneChanged() {
112112
// remove existing skin instances and create new ones, connected to new root bone
113113
this._clearSkinInstances();
114-
this._cloneSkinInstances();
114+
if (this.enabled && this.entity.enabled) {
115+
this._cloneSkinInstances();
116+
}
115117
}
116118

117119
destroyMeshInstances() {
@@ -200,6 +202,8 @@ class RenderComponent extends Component {
200202

201203
this._rootBone.onParentComponentEnable();
202204

205+
this._cloneSkinInstances();
206+
203207
scene.on("set:layers", this.onLayersChanged, this);
204208
if (scene.layers) {
205209
scene.layers.on("add", this.onLayerAdded, this);
@@ -741,6 +745,13 @@ class RenderComponent extends Component {
741745
this._onRenderAssetAdded();
742746
}
743747
}
748+
749+
resolveDuplicatedEntityReferenceProperties(oldRender, duplicatedIdsMap) {
750+
if (oldRender.rootBone && duplicatedIdsMap[oldRender.rootBone]) {
751+
this.rootBone = duplicatedIdsMap[oldRender.rootBone];
752+
}
753+
this._clearSkinInstances();
754+
}
744755
}
745756

746757
export { RenderComponent };

src/framework/entity.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,16 @@ function resolveDuplicatedEntityReferenceProperties(oldSubtreeRoot, oldEntity, n
477477
newEntity.script.resolveDuplicatedEntityReferenceProperties(components.script, duplicatedIdsMap);
478478
}
479479

480+
// Handle entity render attributes
481+
if (components.render) {
482+
newEntity.render.resolveDuplicatedEntityReferenceProperties(components.render, duplicatedIdsMap);
483+
}
484+
485+
// Handle entity anim attributes
486+
if (components.anim) {
487+
newEntity.anim.resolveDuplicatedEntityReferenceProperties(components.anim, duplicatedIdsMap);
488+
}
489+
480490
// Recurse into children. Note that we continue to pass in the same `oldSubtreeRoot`,
481491
// in order to correctly handle cases where a child has an entity reference
482492
// field that points to a parent or other ancestor that is still within the

src/resources/container.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ class ContainerResource {
175175
if (attachedMi) {
176176
entity.addComponent("render", Object.assign({
177177
type: "asset",
178-
meshInstances: attachedMi
178+
meshInstances: attachedMi,
179+
rootBone: root
179180
}, options));
180181
}
181182

0 commit comments

Comments
 (0)