fix set material bug

This commit is contained in:
zhuxuguang
2019-01-24 16:08:20 +08:00
parent 293e8974bf
commit 3d40193b3c
2 changed files with 23 additions and 13 deletions
+12 -11
View File
@@ -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 () {
+11 -2
View File
@@ -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;