Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MTL color loading when vertices are shared across different faces #7441

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions src/webgl/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ function loading(p5, fn){
// Map from source index → Map of material → destination index
const usedVerts = {}; // Track colored vertices
let currentMaterial = null;
const coloredVerts = new Set(); //unique vertices with color
let hasColoredVertices = false;
let hasColorlessVertices = false;
for (let line = 0; line < lines.length; ++line) {
Expand Down Expand Up @@ -622,8 +621,15 @@ function loading(p5, fn){
if (currentMaterial
&& materials[currentMaterial]
&& materials[currentMaterial].diffuseColor) {
// Mark this vertex as colored
coloredVerts.add(loadedVerts.v[vertParts[0]]); //since a set would only push unique values
hasColoredVertices = true;
const materialDiffuseColor =
materials[currentMaterial].diffuseColor;
model.vertexColors.push(materialDiffuseColor[0]);
model.vertexColors.push(materialDiffuseColor[1]);
model.vertexColors.push(materialDiffuseColor[2]);
model.vertexColors.push(1);
} else {
hasColorlessVertices = true;
}
} else {
face.push(usedVerts[vertString][currentMaterial]);
Expand All @@ -636,24 +642,6 @@ function loading(p5, fn){
face[1] !== face[2]
) {
model.faces.push(face);
//same material for all vertices in a particular face
if (currentMaterial
&& materials[currentMaterial]
&& materials[currentMaterial].diffuseColor) {
hasColoredVertices = true;
//flag to track color or no color model
hasColoredVertices = true;
const materialDiffuseColor =
materials[currentMaterial].diffuseColor;
for (let i = 0; i < face.length; i++) {
model.vertexColors.push(materialDiffuseColor[0]);
model.vertexColors.push(materialDiffuseColor[1]);
model.vertexColors.push(materialDiffuseColor[2]);
model.vertexColors.push(1);
}
} else {
hasColorlessVertices = true;
}
}
}
}
Expand Down
Loading