Skip to content

Commit

Permalink
remove render default material
Browse files Browse the repository at this point in the history
  • Loading branch information
QTED committed Jun 15, 2024
1 parent 098518e commit bd4e9a9
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 59 deletions.
54 changes: 0 additions & 54 deletions src/layaAir/laya/d3/core/MeshRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ export class MeshRenderer extends BaseRender {
renderElement = this._renderElements[i] = this._renderElements[i] ? this._renderElements[i] : this._createRenderElement();
this.owner && renderElement.setTransform((this.owner as Sprite3D)._transform);
renderElement.render = this;

materials[i] = materials[i] || BlinnPhongMaterial.defaultMaterial;
}
renderElement.setGeometry(mesh.getSubMesh(i));
}
Expand All @@ -346,58 +344,6 @@ export class MeshRenderer extends BaseRender {
// }
}


/**
* @internal
* 开启多材质 多element模式
*/
updateMulPassRender(): void {
const filter = this.owner.getComponent(MeshFilter);
if (!filter)
return;
const mesh = filter.sharedMesh;
if (mesh) {
var subCount: number = mesh.subMeshCount;
var matCount = this._sharedMaterials.length;
if (subCount > matCount) {
let count = subCount
this._renderElements.length = count;
for (var i: number = 0; i < count; i++) {
var renderElement: RenderElement = this._renderElements[i];
if (!renderElement) {
var material: Material = this.sharedMaterials[i];
renderElement = this._renderElements[i] = this._renderElements[i] ? this._renderElements[i] : this._createRenderElement();
renderElement.setTransform((this.owner as Sprite3D)._transform);
renderElement.render = this;
renderElement.material = material ? material : BlinnPhongMaterial.defaultMaterial;//确保有材质,由默认材质代替。
}
renderElement.setGeometry(mesh.getSubMesh(i));
}
} else {
let count = matCount;
this._renderElements.length = count;
for (var i: number = 0; i < count; i++) {
var renderElement: RenderElement = this._renderElements[i];
if (!renderElement) {
var material: Material = this.sharedMaterials[i];
renderElement = this._renderElements[i] = this._renderElements[i] ? this._renderElements[i] : this._createRenderElement();
renderElement.setTransform((this.owner as Sprite3D)._transform);
renderElement.render = this;
renderElement.material = material ? material : BlinnPhongMaterial.defaultMaterial;//确保有材质,由默认材质代替。
}
}
renderElement.setGeometry(mesh.getSubMesh(count % subCount));
}

} else {
this._renderElements.length = 0;
}
this.boundsChange = true;
// if (this._octreeNode && this._indexInOctreeMotionList === -1) {
// this._octreeNode.getManagerNode().addMotionObject(this);
// }
}

/**
* @inheritDoc
* @override
Expand Down
4 changes: 3 additions & 1 deletion src/layaAir/laya/d3/core/SkinnedMeshRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ export class SkinnedMeshRenderer extends MeshRenderer {
this._mesh = mesh;
var count: number = mesh.subMeshCount;
this._renderElements.length = count;
let materials = this.sharedMaterials;
materials.length = count;
for (var i: number = 0; i < count; i++) {
var renderElement: SkinRenderElement = this._renderElements[i];
if (!renderElement) {
Expand All @@ -235,10 +237,10 @@ export class SkinnedMeshRenderer extends MeshRenderer {
renderElement.setTransform((this.owner as Sprite3D)._transform);
}
renderElement.render = this;
renderElement.material = material ? material : BlinnPhongMaterial.defaultMaterial;//确保有材质,由默认材质代替。
}
renderElement.setGeometry(mesh.getSubMesh(i));
}
this.sharedMaterials = materials;
} else if (!mesh) {
this._renderElements.length = 0;
this._mesh = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class ShurikenParticleRenderer extends BaseRender {
element.render = this;
element.setGeometry(this._particleSystem);

this.sharedMaterial = this.sharedMaterial || ShurikenParticleMaterial.defaultMaterial;
this.sharedMaterial = this.sharedMaterial;
}

protected _onEnable(): void {
Expand Down
2 changes: 1 addition & 1 deletion src/layaAir/laya/d3/core/render/BaseRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class BaseRender extends Component implements IBoundsCell {
sharedMats.length = count;
}
else {
throw new Error("BaseRender: shadredMaterials value can't be null.");
this._sharedMaterials = [];
}
this._isSupportRenderFeature();
}
Expand Down
3 changes: 1 addition & 2 deletions src/layaAir/laya/d3/core/trail/TrailFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ export class TrailFilter {
element.setGeometry(this._trialGeometry);
elements.push(element);

render.sharedMaterial = render.sharedMaterial || TrailMaterial.defaultMaterial;
element.material = render.sharedMaterial;
render.sharedMaterial = render.sharedMaterial;
}

/**
Expand Down

0 comments on commit bd4e9a9

Please sign in to comment.