Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glTFModel error #309

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions packages/loader/src/scene-loader/GLTFModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ export class GLTFModel extends Component {
}

set asset(value: GLTFResource) {
if (value && value.defaultSceneRoot === this.GLTFNode) {
const entity = this.glTFEntity;
if (value && value.defaultSceneRoot === this.glTFEntity) {
return;
}
if (!this._hasBuiltNode) {
(this.GLTFNode as any).clearChildren();
entity.clearChildren();
if (value !== null) {
if (this.GLTFNode) {
this.GLTFNode.destroy();
}
this.GLTFNode = value.defaultSceneRoot.clone();
this._animator = this.GLTFNode.getComponent(Animation);
this.entity.addChild(this.GLTFNode);
entity?.destroy();
const newEntity = value.defaultSceneRoot.clone();
this._animator = entity.getComponent(Animation);
this.entity.addChild(newEntity);
newEntity.isActive = this.enabled;
this.glTFEntity = newEntity;
}
}
this._asset = value;
Expand Down Expand Up @@ -69,7 +70,7 @@ export class GLTFModel extends Component {
public animationsNames: String[];

private _asset: GLTFResource;
private GLTFNode: Entity;
private glTFEntity: Entity;
private _loop: number;
private _autoPlay: string;
private _hasBuiltNode: boolean = false;
Expand All @@ -87,13 +88,13 @@ export class GLTFModel extends Component {
if (isClone) {
const rootName = (props as any).gltfRootName;
if (rootName) {
this.GLTFNode = this.entity.findByName(rootName);
this.glTFEntity = this.entity.findByName(rootName);
}
}
if (!this.GLTFNode) {
if (!this.glTFEntity) {
const rootName = `GLTF-${Date.now()}`;
(props as any).gltfRootName = rootName;
this.GLTFNode = this.entity.createChild(rootName);
this.glTFEntity = this.entity.createChild(rootName);
this._hasBuiltNode = false;
} else {
this._hasBuiltNode = true;
Expand All @@ -108,13 +109,13 @@ export class GLTFModel extends Component {
* @override
*/
_onEnable(): void {
this.GLTFNode && (this.GLTFNode.isActive = true);
this.glTFEntity && (this.glTFEntity.isActive = true);
}

/**
* @override
*/
_onDisable(): void {
this.GLTFNode && (this.GLTFNode.isActive = false);
this.glTFEntity && (this.glTFEntity.isActive = false);
}
}