Skip to content

Commit

Permalink
fix: object is disabled after removeChild (#381)
Browse files Browse the repository at this point in the history
* chore: remove sample_candleflame maskMap

* fix: addChild and removeChild related

* chore: remove log
  • Loading branch information
Codeboy-cn authored Mar 21, 2024
1 parent 65bda50 commit 51ff3ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
22 changes: 15 additions & 7 deletions samples/base/Sample_AddRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ class Sample_AddRemove {
}

private async test() {
let list: Object3D[] = [];
let visibleList: Object3D[] = [];
let invisibleList: Object3D[] = [];
let player = await Engine3D.res.loadGltf('gltfs/anim/Minion_Lane_Super_Dawn/Minion_Lane_Super_Dawn.glb');
// gui
GUIHelp.init();
GUIHelp.addButton("add", async () => {
/******** player1 *******/
let clone = player.clone()
let clone: Object3D
if (invisibleList.length > 0) {
clone = invisibleList[invisibleList.length-1];
invisibleList.splice(invisibleList.length-1, 1);
} else {
clone = player.clone();
}
clone.transform.x = Math.random() * 100 - 50;
clone.transform.y = Math.random() * 100 - 50;
clone.transform.z = Math.random() * 100 - 50;
Expand All @@ -56,16 +63,17 @@ class Sample_AddRemove {
clone.transform.scaleZ = 20;

this.view.scene.addChild(clone);
list.push(clone);
visibleList.push(clone);
});

GUIHelp.addButton("remove", () => {
let index = Math.floor(list.length * Math.random());
let obj = list[index];
let index = Math.floor(visibleList.length * Math.random());
let obj = visibleList[index];
if (obj) {
list.splice(index, 1)
visibleList.splice(index, 1)
this.view.scene.removeChild(obj)
obj.destroy(true);
// obj.destroy(true);
invisibleList.push(obj)
}
});

Expand Down
1 change: 0 additions & 1 deletion src/components/renderer/RenderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ export class RenderNode extends ComponentBase {
}

public onDisable(): void {
this._enable = false;
EntityCollect.instance.removeRenderNode(this.transform.scene3D, this);
super.onDisable?.();
}
Expand Down
2 changes: 1 addition & 1 deletion src/loader/LoaderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class LoaderBase {
}
if (receivedArr.length > 0) {
for (let i = 0; i < chunks.length; i++) {
console.log(receivedArr[i]);
// console.log(receivedArr[i]);
if (loaderFunctions && loaderFunctions.onProgress) {
loaderFunctions.onProgress.call(this, receivedArr[i], receivedLength, url);
}
Expand Down

0 comments on commit 51ff3ee

Please sign in to comment.