Skip to content

Instantly share code, notes, and snippets.

@DMHYT
Created September 13, 2023 19:06
Show Gist options
  • Select an option

  • Save DMHYT/2fc38577ff097257410634e8ecb6dec8 to your computer and use it in GitHub Desktop.

Select an option

Save DMHYT/2fc38577ff097257410634e8ecb6dec8 to your computer and use it in GitHub Desktop.
QuadsConverter
const convertQuadsToTriangles = (objString: string) => {
const lines = objString.split("\n");
const newLines = [];
lines.forEach((line, i) => {
if(line.startsWith("f ")) {
const faceVertices = line.split(" ").slice(1);
if(faceVertices.length === 3) newLines.push(line);
else if(faceVertices.length === 4) {
newLines.push(
`f ${faceVertices[0]} ${faceVertices[1]} ${faceVertices[2]}`,
`f ${faceVertices[0]} ${faceVertices[2]} ${faceVertices[3]}`);
} else {
Logger.Log(`Invalid face with ${faceVertices.length} vertices: ${line} in line: ${i}`, "QuadsConverter");
newLines.push(line);
}
} else newLines.push(line);
});
return newLines.join("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment