Support models lacking the "materials" property or primitive/material association
- Dominant language
- TypeScript
- Stars
- 8.2k
- Forks
- 947
- PR merge metrics
- No merged PRs in 30d
Description
### Description
I have point cloud scans that yield models without any materials once converted to GLTF/GLB.
These models visually load, but then, break the code at a few places. This brought me to investigate further the situation.
As far as I can tell, I have encountered 2 situations where the code breaks with these unconventional files.
#### Case 1: File with no "materials" property in the GLTF

In `model-viewer/src/features/scene-graph/model.ts`

**Suggestion**: Don't use the `!` syntax in `gltf.materials!.entries()` and do a null check instead `gltf.materials?.entries() ?? []`
#### Case 2: File with the "materials" property in the GLTF but no material associated in the mesh primitives

In `model-viewer/src/features/scene-graph/nodes/primitive-node.ts`

**Suggestion**: Simple null check `materialMappings?.materials != null`
This is another case where I seem to be the only one having to deal with bizarre GLTF structures 😆 . I will open a PR for this if that is ok with you guys.
### Version
- model-viewer: v1.10.1
### Browser Affected
- [x] Chrome, version: latest
- [ ] Edge
- [ ] Firefox
- [ ] IE
- [ ] Safari
### OS
- [ ] Android
- [ ] iOS
- [ ] Linux
- [x] MacOS
- [ ] Windows
Contributor guide
Assessment
This issue has not been assessed yet.