Skip to content

Support models lacking the "materials" property or primitive/material association  #3279

@alexdaube

Description

@alexdaube

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

Screen Shot 2022-03-16 at 9 49 06 PM

In model-viewer/src/features/scene-graph/model.ts
Screen Shot 2022-03-16 at 9 49 44 PM

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

Screen Shot 2022-03-16 at 9 55 48 PM

In model-viewer/src/features/scene-graph/nodes/primitive-node.ts
Screen Shot 2022-03-16 at 9 55 16 PM

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

  • Chrome, version: latest
  • Edge
  • Firefox
  • IE
  • Safari

OS

  • Android
  • iOS
  • Linux
  • MacOS
  • Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions