Skip to content

Commit 7623576

Browse files
Removing custom material variable inside of LineMesh (#16767)
LineMesh uses its own private variable to hold the material of the mesh. The problem with this, is that Mesh has logic related to materials and LineMesh while inheriting from Mesh, is missing all this logic. I have removed the custom variable inside of LineMesh and adjusted the code to use the Material of the Mesh class instead. I have maintained the LineMesh interface where get/set material returns Material instead of Nullable<Material> like Mesh does.
1 parent 1e15a97 commit 7623576

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

packages/dev/core/src/Meshes/linesMesh.ts

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ export class LinesMesh extends Mesh {
4545
*/
4646
public intersectionThreshold: number;
4747

48-
private _lineMaterial: Material;
48+
private _isShaderMaterial(shader: Nullable<Material>): shader is ShaderMaterial {
49+
if (!shader) {
50+
return false;
51+
}
4952

50-
private _isShaderMaterial(shader: Material): shader is ShaderMaterial {
5153
return shader.getClassName() === "ShaderMaterial";
5254
}
5355

@@ -143,14 +145,6 @@ export class LinesMesh extends Mesh {
143145
}
144146
}
145147

146-
public override isReady() {
147-
if (!this._lineMaterial.isReady(this, !!this._userInstancedBuffersStorage || this.hasThinInstances)) {
148-
return false;
149-
}
150-
151-
return super.isReady();
152-
}
153-
154148
/**
155149
* @returns the string "LineMesh"
156150
*/
@@ -161,16 +155,18 @@ export class LinesMesh extends Mesh {
161155
/**
162156
* @internal
163157
*/
164-
public override get material(): Material {
165-
return this._lineMaterial;
158+
public override get material(): Nullable<Material> {
159+
return this._internalAbstractMeshDataInfo._material as Material;
166160
}
167161

168162
/**
169163
* @internal
170164
*/
171-
public override set material(value: Material) {
172-
this._lineMaterial = value;
173-
this._lineMaterial.fillMode = Material.LineListDrawMode;
165+
public override set material(value: Nullable<Material>) {
166+
this._setMaterial(value);
167+
if (this.material) {
168+
this.material.fillMode = Material.LineListDrawMode;
169+
}
174170
}
175171

176172
/**
@@ -201,10 +197,10 @@ export class LinesMesh extends Mesh {
201197
}
202198

203199
// Color
204-
if (!this.useVertexColor && this._isShaderMaterial(this._lineMaterial)) {
200+
if (!this.useVertexColor && this._isShaderMaterial(this.material)) {
205201
const { r, g, b } = this.color;
206202
this._color4.set(r, g, b, this.alpha);
207-
this._lineMaterial.setColor4("color", this._color4);
203+
this.material.setColor4("color", this._color4);
208204
}
209205

210206
return this;
@@ -230,20 +226,6 @@ export class LinesMesh extends Mesh {
230226
return this;
231227
}
232228

233-
/**
234-
* Disposes of the line mesh
235-
* @param doNotRecurse If children should be disposed
236-
* @param disposeMaterialAndTextures This parameter is not used by the LineMesh class
237-
* @param doNotDisposeMaterial If the material should not be disposed (default: false, meaning the material is disposed)
238-
*/
239-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
240-
public override dispose(doNotRecurse?: boolean, disposeMaterialAndTextures = false, doNotDisposeMaterial?: boolean): void {
241-
if (!doNotDisposeMaterial) {
242-
this._lineMaterial.dispose(false, false, true);
243-
}
244-
super.dispose(doNotRecurse);
245-
}
246-
247229
/**
248230
* Returns a new LineMesh object cloned from the current one.
249231
* @param name defines the cloned mesh name

0 commit comments

Comments
 (0)