mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
@@ -163,7 +163,7 @@ export class ModelComponent extends RenderableComponent {
|
||||
this._model = null;
|
||||
}
|
||||
|
||||
get model () {
|
||||
get model() {
|
||||
return this._model;
|
||||
}
|
||||
|
||||
@@ -175,10 +175,13 @@ export class ModelComponent extends RenderableComponent {
|
||||
this._updateModels();
|
||||
this._updateCastShadow();
|
||||
this._updateReceiveShadow();
|
||||
this._model.enable = true;
|
||||
}
|
||||
|
||||
onDisable() {
|
||||
//this._getRenderScene().destroyModel(this._model);
|
||||
if (this._model) {
|
||||
this._model.enable = false;
|
||||
}
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
@@ -191,12 +194,12 @@ export class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
|
||||
if (this._model) {
|
||||
this._getRenderScene().destroyModel(this._model);
|
||||
this._model.destroy();
|
||||
} else {
|
||||
this._model = this._createModel();
|
||||
}
|
||||
|
||||
let model = this._createModel();
|
||||
model.createBoundingShape(this._mesh.minPosition, this._mesh.maxPosition);
|
||||
this._model = model;
|
||||
this._model.createBoundingShape(this._mesh.minPosition, this._mesh.maxPosition);
|
||||
|
||||
this._updateModelParams();
|
||||
}
|
||||
@@ -211,7 +214,7 @@ export class ModelComponent extends RenderableComponent {
|
||||
for (let i = 0; i < meshCount; ++i) {
|
||||
let material = this.getSharedMaterial(i);
|
||||
let subMeshData = this._mesh.renderingMesh.getSubmesh(i);
|
||||
this._model.setSubModel(i, subMeshData, material);
|
||||
this._model.initSubModel(i, subMeshData, material);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,6 +226,9 @@ export class ModelComponent extends RenderableComponent {
|
||||
}
|
||||
|
||||
_clearMaterials() {
|
||||
if (this._model == null) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < this._model.subModelNum; ++i) {
|
||||
this._onMaterialModified(i, null);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ export default class RecyclePool<T = any> {
|
||||
if (size > this._data.length) {
|
||||
for (let i = this._data.length; i < size; ++i) {
|
||||
this._data[i] = this._fn();
|
||||
this._objIdx.set(this._data[i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ const _temp_mat4 = mat4.create();
|
||||
|
||||
const _subMeshPool = new RecyclePool(() => {
|
||||
return new SubModel();
|
||||
}, 100);
|
||||
}, 32);
|
||||
|
||||
/**
|
||||
* A representation of a model
|
||||
@@ -41,7 +41,7 @@ export class Model {
|
||||
private _matPSORecord: Map<Material, GFXPipelineState[]>;
|
||||
private _matRefCount: Map<Material, number>;
|
||||
private _uboLocal: UBOLocal;
|
||||
private _localUBO: GFXBuffer;
|
||||
private _localUBO: GFXBuffer | null;
|
||||
|
||||
/**
|
||||
* Setup a default empty model
|
||||
@@ -69,6 +69,13 @@ export class Model {
|
||||
subModel.destroy();
|
||||
_subMeshPool.remove(subModel);
|
||||
}
|
||||
if (this._localUBO) {
|
||||
this._localUBO.destroy();
|
||||
this._localUBO = null;
|
||||
}
|
||||
this._worldBounds = null;
|
||||
this._modelBounds = null;
|
||||
this._subModels.splice(0);
|
||||
this._matPSORecord.clear();
|
||||
this._matRefCount.clear();
|
||||
}
|
||||
@@ -174,7 +181,7 @@ export class Model {
|
||||
return this._viewID;
|
||||
}
|
||||
|
||||
public setSubModel (idx: number, subMeshData: IRenderingSubmesh, mat: Material) {
|
||||
public initSubModel (idx: number, subMeshData: IRenderingSubmesh, mat: Material) {
|
||||
if (this._subModels[idx] == null) {
|
||||
this._subModels[idx] = _subMeshPool.add();
|
||||
} else {
|
||||
@@ -213,10 +220,19 @@ export class Model {
|
||||
}
|
||||
|
||||
protected createPipelineState (mat: Material): GFXPipelineState[] {
|
||||
if (this._localUBO) {
|
||||
this._localUBO = this._device.createBuffer({
|
||||
usage: GFXBufferUsageBit.UNIFORM | GFXBufferUsageBit.TRANSFER_DST,
|
||||
memUsage: GFXMemoryUsageBit.HOST,
|
||||
size: UBOLocal.SIZE,
|
||||
stride: UBOLocal.SIZE,
|
||||
});
|
||||
this._localUBO.update(this._uboLocal.view);
|
||||
}
|
||||
const ret = new Array<GFXPipelineState>(mat.passes.length);
|
||||
for (let i = 0; i < ret.length; i++) {
|
||||
ret[i] = mat.passes[i].createPipelineState()!;
|
||||
ret[i].pipelineLayout.layouts[0].bindBuffer(UBOLocal.BLOCK.binding, this.localUBO);
|
||||
ret[i].pipelineLayout.layouts[0].bindBuffer(UBOLocal.BLOCK.binding, this.localUBO!);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ export class SubModel {
|
||||
for (const cmdBuffer of this._cmdBuffers) {
|
||||
cmdBuffer.destroy();
|
||||
}
|
||||
this._cmdBuffers.splice(0);
|
||||
}
|
||||
|
||||
set priority (val: RenderPriority) {
|
||||
|
||||
Reference in New Issue
Block a user