mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
fix set material bug
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user