Refactor Cesium material export contract
This commit is contained in:
@@ -6,11 +6,14 @@ the catalog importable by plain Python, and by anything else that wants to read
|
||||
the scene's material definitions without launching Blender.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
CESIUM_EXPORT_PROPERTY = "cesium_export"
|
||||
|
||||
TEXTURE_ROOT = os.path.abspath(os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)), "..", "..",
|
||||
"assets", "textures", "polyhaven"
|
||||
@@ -195,15 +198,26 @@ def link_alpha_clip(material, alpha_output, bsdf, cutoff=0.5):
|
||||
material.use_backface_culling = False
|
||||
|
||||
|
||||
def apply_cesium_contract(material, spec):
|
||||
contract = spec.get("cesium")
|
||||
if contract is None:
|
||||
if CESIUM_EXPORT_PROPERTY in material:
|
||||
del material[CESIUM_EXPORT_PROPERTY]
|
||||
return material
|
||||
material[CESIUM_EXPORT_PROPERTY] = json.dumps(contract, sort_keys=True)
|
||||
return material
|
||||
|
||||
|
||||
def from_spec(spec):
|
||||
"""Build a material from a `catalog.MATERIALS` entry."""
|
||||
if spec["kind"] == "textured":
|
||||
return make_textured_material(
|
||||
material = make_textured_material(
|
||||
spec["name"], spec["diffuse"], spec["normal"],
|
||||
roughness=spec.get("roughness", 0.8), scale=spec["scale"],
|
||||
normal_is_bump=spec.get("normal_is_bump", False),
|
||||
metallic=spec.get("metallic", 0.0),
|
||||
tint=spec.get("tint"), tint_factor=spec.get("tint_factor", 0.0))
|
||||
return apply_cesium_contract(material, spec)
|
||||
|
||||
material = make_material(spec["name"], spec["color"],
|
||||
spec.get("roughness", 0.8),
|
||||
@@ -215,4 +229,4 @@ def from_spec(spec):
|
||||
detail=procedural["detail"],
|
||||
bump_strength=procedural["bump_strength"],
|
||||
object_space=procedural.get("object_space", False))
|
||||
return material
|
||||
return apply_cesium_contract(material, spec)
|
||||
|
||||
Reference in New Issue
Block a user