Skip to content

Commit e03060a

Browse files
authored
Merge pull request #7441 from processing/fix/mtl-color-loading
Fix MTL color loading when vertices are shared across different faces
2 parents 4e0f57a + cc47685 commit e03060a

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

src/webgl/loading.js

+9-21
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ function loading(p5, fn){
556556
// Map from source index → Map of material → destination index
557557
const usedVerts = {}; // Track colored vertices
558558
let currentMaterial = null;
559-
const coloredVerts = new Set(); //unique vertices with color
560559
let hasColoredVertices = false;
561560
let hasColorlessVertices = false;
562561
for (let line = 0; line < lines.length; ++line) {
@@ -622,8 +621,15 @@ function loading(p5, fn){
622621
if (currentMaterial
623622
&& materials[currentMaterial]
624623
&& materials[currentMaterial].diffuseColor) {
625-
// Mark this vertex as colored
626-
coloredVerts.add(loadedVerts.v[vertParts[0]]); //since a set would only push unique values
624+
hasColoredVertices = true;
625+
const materialDiffuseColor =
626+
materials[currentMaterial].diffuseColor;
627+
model.vertexColors.push(materialDiffuseColor[0]);
628+
model.vertexColors.push(materialDiffuseColor[1]);
629+
model.vertexColors.push(materialDiffuseColor[2]);
630+
model.vertexColors.push(1);
631+
} else {
632+
hasColorlessVertices = true;
627633
}
628634
} else {
629635
face.push(usedVerts[vertString][currentMaterial]);
@@ -636,24 +642,6 @@ function loading(p5, fn){
636642
face[1] !== face[2]
637643
) {
638644
model.faces.push(face);
639-
//same material for all vertices in a particular face
640-
if (currentMaterial
641-
&& materials[currentMaterial]
642-
&& materials[currentMaterial].diffuseColor) {
643-
hasColoredVertices = true;
644-
//flag to track color or no color model
645-
hasColoredVertices = true;
646-
const materialDiffuseColor =
647-
materials[currentMaterial].diffuseColor;
648-
for (let i = 0; i < face.length; i++) {
649-
model.vertexColors.push(materialDiffuseColor[0]);
650-
model.vertexColors.push(materialDiffuseColor[1]);
651-
model.vertexColors.push(materialDiffuseColor[2]);
652-
model.vertexColors.push(1);
653-
}
654-
} else {
655-
hasColorlessVertices = true;
656-
}
657645
}
658646
}
659647
}

0 commit comments

Comments
 (0)