Skip to content

MeshPhysicalMaterial attenuationDistance is null when exporting to JSON #24797

Closed
@davcri

Description

@davcri

Describe the bug

const mesh = new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshPhysicalMaterial())
console.log(mesh.material.attenuationDistance); // Infinity (correct)
const json = JSON.stringify(mesh.toJSON())
const x = new THREE.ObjectLoader().parse(JSON.parse(json))
console.log(x.material.attenuationDistance); // null, but it should be Infinity

Live example

Expected behavior

Serializing and deserializing should preserve the material appearance.

Probably we should avoid exporting attenuationDistance when it's equal to Infinity (the default value).

Related issue: #24622

Screenshots

I noticed this issue by exporting and re-importing a MeshPhysicalMaterial from the editor.

Attenuation distance is NaN after importing model.json with MeshPhysicalMaterial (with transmission = 1, roughness ~=0)

Platform:

  • Device: Desktop, Mobile
  • OS: Windows, MacOS, Linux, Android, iOS
  • Browser: Chrome, Firefox, Safari, Edge
  • Three.js version: dev

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions