diff --git a/cocos/3d/framework/model-component.ts b/cocos/3d/framework/model-component.ts index 201b134e1a..2488cfc3bd 100644 --- a/cocos/3d/framework/model-component.ts +++ b/cocos/3d/framework/model-component.ts @@ -163,15 +163,16 @@ export class ModelComponent extends RenderableComponent { } public onLoad () { - + super.onLoad(); } public onEnable () { this._updateModels(); this._updateCastShadow(); this._updateReceiveShadow(); + if (this._model) { - this._model.enabled = true; + this._model.enabled = this.enabledInHierarchy; } } @@ -189,23 +190,21 @@ export class ModelComponent extends RenderableComponent { protected _updateModels (forceUpdate: boolean = false) { if (!this.enabled || !this.node._scene || !this._mesh || (this._model && !forceUpdate)) { + if (this._model) { + this._model.enabled = false; + } return; } if (this._model) { this._model.destroy(); - this._model = null; + } else { + this._model = this._createModel(); } - this._model = this._createModel(); - this._model!.createBoundingShape(this._mesh.minPosition, this._mesh.maxPosition); this._updateModelParams(); - - if (this._model) { - this._model.enabled = this.enabledInHierarchy; - } } protected _createModel () { @@ -234,11 +233,13 @@ export class ModelComponent extends RenderableComponent { if (this._model == null) { return; } - this._model.setSubModelMaterial(idx, material); + this._onRebuildPSO(idx, material); } protected _onRebuildPSO (idx, material) { - this._onMaterialModified(idx, material); + if (this._model) { + this._model.setSubModelMaterial(idx, material); + } } protected _clearMaterials () { diff --git a/cocos/renderer/scene/submodel.ts b/cocos/renderer/scene/submodel.ts index 3e031746e5..ecc5427ff8 100644 --- a/cocos/renderer/scene/submodel.ts +++ b/cocos/renderer/scene/submodel.ts @@ -1,7 +1,7 @@ import { Material } from '../../3d/assets/material'; import { IRenderingSubmesh } from '../../3d/assets/mesh'; import { GFXCommandBuffer } from '../../gfx/command-buffer'; -import { GFXCommandBufferType } from '../../gfx/define'; +import { GFXCommandBufferType, GFXStatus } from '../../gfx/define'; import { GFXDevice } from '../../gfx/device'; import { GFXInputAssembler, IGFXInputAssemblerInfo } from '../../gfx/input-assembler'; import { GFXPipelineState } from '../../gfx/pipeline-state'; @@ -69,7 +69,11 @@ export class SubModel { if (this._subMeshObject!.indirectBuffer) { iaInfo.indirectBuffer = this._subMeshObject!.indirectBuffer; } - this._inputAssembler = (cc.director.root.device as GFXDevice).createInputAssembler(iaInfo); + if (this._inputAssembler) { + this._inputAssembler.initialize(iaInfo); + } else { + this._inputAssembler = (cc.director.root.device as GFXDevice).createInputAssembler(iaInfo); + } } get subMeshData () { @@ -128,6 +132,11 @@ export class SubModel { type: GFXCommandBufferType.SECONDARY, }; this._cmdBuffers[index] = device.createCommandBuffer(cmdBufferInfo); + } else if (this._cmdBuffers[index].status == GFXStatus.UNREADY) { + this._cmdBuffers[index].initialize({ + allocator: device.commandAllocator, + type: GFXCommandBufferType.SECONDARY, + }); } const inputAssembler = this._inputAssembler as GFXInputAssembler;