Commit b9edf9e
fix: gracefully handle mixed-material OBJ models instead of crashing
Previously, `parseObj()` used `hasColoredVertices === hasColorlessVertices`
to detect inconsistent vertex coloring, but this condition is true in two
very different cases:
1. Both flags `false` → model has no faces at all (should never crash)
2. Both flags `true` → model has some faces with material colors and
some without (the genuine "mixed" case)
Real-world OBJ exports from Blender, Sketchfab, and other tools commonly
produce files where only some mesh groups have an explicit MTL material
assignment. The previous `throw` caused a hard crash for any such model,
which is a significant barrier for beginners trying to use pre-made 3D
assets in p5.js.
This commit changes the check to `hasColoredVertices && hasColorlessVertices`
(only the genuinely inconsistent case) and replaces the thrown error with a
`console.warn` + `model.vertexColors = []` reset, so the model still loads
and renders using the default fill color.
The existing test that expected a throw is updated to assert that the model
loads successfully with an empty vertexColors array.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 83415b7 commit b9edf9e
2 files changed
+25
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
652 | 652 | | |
653 | 653 | | |
654 | 654 | | |
655 | | - | |
656 | | - | |
657 | | - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
658 | 668 | | |
659 | 669 | | |
660 | 670 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
87 | 94 | | |
88 | 95 | | |
89 | 96 | | |
| |||
0 commit comments