Refactor Cesium material export contract

This commit is contained in:
2026-08-03 11:52:38 +08:00
parent 50dc5f4e5a
commit 0635c09458
16 changed files with 583 additions and 95 deletions

View File

@@ -61,12 +61,14 @@ MATERIALS = {
"diffuse": "leafy_grass_diff_1k.jpg",
"normal": "leafy_grass_nor_gl_1k.jpg",
"roughness": 0.92, "scale": 7.0,
"tint": (0.12, 0.48, 0.08), "tint_factor": 0.72},
"tint": (0.12, 0.48, 0.08), "tint_factor": 0.72,
"cesium": {"tint": ((0.12, 0.48, 0.08), 0.72)}},
"scrub": {"kind": "textured", "name": "Scrub Ground Cover",
"diffuse": "leafy_grass_diff_1k.jpg",
"normal": "leafy_grass_nor_gl_1k.jpg",
"roughness": 0.96, "scale": 15.0,
"tint": (0.085, 0.30, 0.065), "tint_factor": 0.46},
"tint": (0.085, 0.30, 0.065), "tint_factor": 0.46,
"cesium": {"tint": ((0.08, 0.28, 0.07), 0.28)}},
"fountain_stone": {"kind": "solid", "name": "Fountain Stone",
"color": (0.42, 0.45, 0.43), "roughness": 0.72},
@@ -81,25 +83,37 @@ MATERIALS = {
"diffuse": "white_plaster_02_diff_1k.jpg",
"normal": "white_plaster_02_nor_gl_1k.jpg",
"roughness": 0.82, "scale": 4.2, "metallic": 0.0,
"tint": (0.92, 0.94, 0.92), "tint_factor": 0.38},
"tint": (0.92, 0.94, 0.92), "tint_factor": 0.38,
"cesium": {"tint": ((0.92, 0.94, 0.92), 0.38),
"metallic": 0.0,
"base_color": (0.93, 0.94, 0.91),
"emission": ((0.93, 0.94, 0.91), 0.18)}},
"building_industrial": {"kind": "textured",
"name": "Industrial White Ribbed Facade",
"diffuse": "corrugated_iron_03_diff_1k.jpg",
"normal": "corrugated_iron_03_nor_gl_1k.jpg",
"roughness": 0.56, "scale": 2.4, "metallic": 0.16,
"tint": (0.86, 0.92, 0.94), "tint_factor": 0.68},
"tint": (0.86, 0.92, 0.94), "tint_factor": 0.68,
"cesium": {"tint": ((0.90, 0.93, 0.91), 0.86),
"metallic": 0.08,
"emission": ((0.90, 0.93, 0.91), 0.18)}},
"building_office_roof": {"kind": "textured", "name": "Office Light Flat Roof",
"diffuse": "concrete_floor_02_diff_1k.jpg",
"normal": "concrete_floor_02_bump_1k.jpg",
"roughness": 0.84, "scale": 5.0,
"normal_is_bump": True,
"tint": (0.82, 0.86, 0.88), "tint_factor": 0.35},
"tint": (0.82, 0.86, 0.88), "tint_factor": 0.35,
"cesium": {"tint": ((0.82, 0.86, 0.88), 0.35),
"base_color": (0.88, 0.90, 0.88),
"emission": ((0.88, 0.90, 0.88), 0.14)}},
"building_industrial_roof": {"kind": "textured",
"name": "Factory Blue Metal Roof",
"diffuse": "blue_metal_plate_diff_1k.jpg",
"normal": "blue_metal_plate_nor_gl_1k.jpg",
"roughness": 0.48, "scale": 3.4, "metallic": 0.28,
"tint": (0.03, 0.42, 0.78), "tint_factor": 0.45},
"tint": (0.03, 0.42, 0.78), "tint_factor": 0.45,
"cesium": {"tint": ((0.08, 0.50, 0.88), 0.58),
"emission": ((0.08, 0.50, 0.88), 0.12)}},
"building_glass": {"kind": "solid", "name": "Office Blue Gray Glass",
"color": (0.12, 0.20, 0.24), "roughness": 0.22,
"metallic": 0.10},
@@ -117,14 +131,18 @@ MATERIALS = {
(0.12, 0.36, 0.08)),
"scale": 3.2, "detail": 3.8,
"bump_strength": 0.08},
"cesium": {"tint": ((0.06, 0.22, 0.05), 0.18)}},
"cesium": {"tint": ((0.06, 0.22, 0.05), 0.18),
"base_color": (0.065, 0.24, 0.055),
"emission": ((0.025, 0.07, 0.02), 0.015)}},
"tree_crown_light": {"kind": "solid", "name": "Tree Crown Light",
"color": (0.13, 0.42, 0.09), "roughness": 0.88,
"procedural": {"colors": ((0.07, 0.25, 0.05),
(0.22, 0.56, 0.13)),
"scale": 3.6, "detail": 3.4,
"bump_strength": 0.07},
"cesium": {"tint": ((0.16, 0.42, 0.09), 0.16)}},
"cesium": {"tint": ((0.16, 0.42, 0.09), 0.16),
"base_color": (0.14, 0.40, 0.085),
"emission": ((0.045, 0.12, 0.03), 0.015)}},
"tree_crown": {"kind": "solid", "name": "Tree Crown",
"color": (0.10, 0.36, 0.08), "roughness": 0.88,
"procedural": {"colors": ((0.04, 0.18, 0.04),
@@ -136,22 +154,6 @@ MATERIALS = {
"emission": ((0.04, 0.11, 0.035), 0.02)}},
}
# Cesium-specific overrides that don't have a home in the material system yet:
# metallic overrides (flat values, not materials) and emission overrides for
# colours that export_cesium.py hand-tuned separately.
CESIUM_EXPORT = {
"metallic_overrides": {
"Office White Plaster Facade": 0.0,
"Industrial White Ribbed Facade": 0.08,
},
"emission_overrides": {
"Office White Plaster Facade": ((0.93, 0.94, 0.91), 0.18),
"Office Light Flat Roof": ((0.88, 0.90, 0.88), 0.14),
"Industrial White Ribbed Facade": ((0.90, 0.93, 0.91), 0.18),
"Factory Blue Metal Roof": ((0.08, 0.50, 0.88), 0.12),
},
}
def road_material_specs():
"""Road layer materials as MATERIALS-shaped specs, in draw order."""

View File

@@ -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)