mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-06 03:22:39 +08:00
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { Model } from '../scene/model';
|
|
import { MorphRenderingInstance } from '../../assets/morph';
|
|
import { Material } from '../../assets/material';
|
|
import { RenderingSubMesh } from '../../assets/mesh';
|
|
|
|
export class MorphModel extends Model {
|
|
private _morphRenderingInstance: MorphRenderingInstance | null = null;
|
|
private _usedMaterials = new Set<Material>();
|
|
|
|
public getMacroPatches (subModelIndex: number) : any {
|
|
if (this._morphRenderingInstance) {
|
|
return this._morphRenderingInstance.requiredPatches(subModelIndex);
|
|
} else {
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
public updateLocalBindings (psoci: number, submodelIdx: number) {
|
|
super.updateLocalBindings(psoci, submodelIdx);
|
|
|
|
if (this._morphRenderingInstance) {
|
|
this._morphRenderingInstance.adaptPipelineState(submodelIdx, psoci);
|
|
}
|
|
}
|
|
|
|
public initSubModel (subModelIndex: number, subMeshData: RenderingSubMesh, material: Material) {
|
|
return super.initSubModel(
|
|
subModelIndex,
|
|
subMeshData,
|
|
this._launderMaterial(material),
|
|
);
|
|
}
|
|
|
|
public setSubModelMaterial (subModelIndex: number, material: Material | null) {
|
|
return super.setSubModelMaterial(
|
|
subModelIndex,
|
|
material ? this._launderMaterial(material) : material,
|
|
);
|
|
}
|
|
|
|
private _launderMaterial (material: Material) {
|
|
return material;
|
|
// if (this._usedMaterials.has(material)) {
|
|
// return new MaterialInstance({
|
|
// parent: material,
|
|
// });
|
|
// } else {
|
|
// this._usedMaterials.add(material);
|
|
// return material;
|
|
// }
|
|
}
|
|
|
|
public setMorphRendering (morphRendering: MorphRenderingInstance) {
|
|
this._morphRenderingInstance = morphRendering;
|
|
}
|
|
}
|