Skip to content

Commit

Permalink
refactor: fix gltf is not show (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
gz65555 authored Jun 7, 2021
1 parent 2d03247 commit ce71d73
Showing 1 changed file with 15 additions and 14 deletions.
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);
}
}

0 comments on commit ce71d73

Please sign in to comment.