Created
September 13, 2023 19:06
-
-
Save DMHYT/2fc38577ff097257410634e8ecb6dec8 to your computer and use it in GitHub Desktop.
QuadsConverter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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