Skip to content

Commit fd7e0b6

Browse files
authored
StandardMaterial code cleanup (playcanvas#3391)
1 parent 7704145 commit fd7e0b6

File tree

7 files changed

+373
-586
lines changed

7 files changed

+373
-586
lines changed

src/resources/parser/material/json-standard-material.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class JsonStandardMaterialParser {
4848
}
4949

5050
if (data.chunks) {
51-
material.chunks.copy(data.chunks);
51+
material.chunks = { ...data.chunks };
5252
}
5353

5454
// initialize material values from the input data

src/scene/materials/basic-material.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class BasicMaterial extends Material {
5656
return clone;
5757
}
5858

59-
updateUniforms() {
59+
updateUniforms(device, scene) {
6060
this.clearParameters();
6161

6262
this.colorUniform[0] = this.color.r;

src/scene/materials/material.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class Material {
307307
}
308308
}
309309

310-
updateUniforms() {
310+
updateUniforms(device, scene) {
311311
}
312312

313313
updateShader(device, scene, objDefs) {

src/scene/materials/standard-material-options-builder.js

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ StandardMaterialOptionsBuilder.prototype._updateTexOptions = function (options,
273273
if (stdMat[uname] === 1 && !hasUv1) allow = false;
274274
if (allow) {
275275
options[mname] = !!stdMat[mname];
276-
options[tname] = this._getMapTransformID(stdMat[tname], stdMat[uname]);
276+
options[tname] = this._getMapTransformID(stdMat.getUniform(tname), stdMat[uname]);
277277
options[cname] = stdMat[cname];
278278
options[uname] = stdMat[uname];
279279
}
@@ -308,42 +308,34 @@ StandardMaterialOptionsBuilder.prototype._collectLights = function (lType, light
308308
}
309309
};
310310

311+
const arraysEqual = (a, b) => {
312+
if (a.length !== b.length) {
313+
return false;
314+
}
315+
for (let i = 0; i < a.length; ++i) {
316+
if (a[i] !== b[i]) {
317+
return false;
318+
}
319+
}
320+
return true;
321+
};
322+
311323
StandardMaterialOptionsBuilder.prototype._getMapTransformID = function (xform, uv) {
312324
if (!xform) return 0;
313-
if (!this._mapXForms[uv]) this._mapXForms[uv] = [];
314-
315-
var i, same;
316-
for (i = 0; i < this._mapXForms[uv].length; i++) {
317-
same = true;
318-
if (this._mapXForms[uv][i][0] !== xform.x) {
319-
same = false;
320-
break;
321-
}
322-
if (this._mapXForms[uv][i][1] !== xform.y) {
323-
same = false;
324-
break;
325-
}
326-
if (this._mapXForms[uv][i][2] !== xform.z) {
327-
same = false;
328-
break;
329-
}
330-
if (this._mapXForms[uv][i][3] !== xform.w) {
331-
same = false;
332-
break;
333-
}
334-
if (same) {
325+
326+
let xforms = this._mapXForms[uv];
327+
if (!xforms) {
328+
xforms = [];
329+
this._mapXForms[uv] = xforms;
330+
}
331+
332+
for (let i = 0; i < xforms.length; i++) {
333+
if (arraysEqual(xforms[i], xform)) {
335334
return i + 1;
336335
}
337336
}
338-
var newID = this._mapXForms[uv].length;
339-
this._mapXForms[uv][newID] = [];
340-
341-
this._mapXForms[uv][newID][0] = xform.x;
342-
this._mapXForms[uv][newID][1] = xform.y;
343-
this._mapXForms[uv][newID][2] = xform.z;
344-
this._mapXForms[uv][newID][3] = xform.w;
345337

346-
return newID + 1;
338+
return xforms.push(xform);
347339
};
348340

349341
export { StandardMaterialOptionsBuilder };

0 commit comments

Comments
 (0)