[错误]: glTF alphaCutoff 从未被读取,因此 MASK 材质被导入为 BLEND
作者: kevin9327创建于 2026年9月10日更新于 2026年9月10日
import io import tempfile from pathlib import Path import numpy as np import pygltflib from PIL import Image import genesis as gs from genesis.utils.gltf import parse_mesh_glb
One row of pixels whose alpha ramp up, the shape a foliage or fence cutout has along its edge.
ALPHA = np.array([[0, 64, 128, 192, 255]], dtype=np.uint8) POSITIONS = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], dtype=np.float32) UVS = np.array([[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]], dtype=np.float32)
def write_glb(path, alpha_mode, alpha_cutoff): rgba = np.full((1, ALPHA.shape[1], 4), 255, dtype=np.uint8) rgba[..., 3] = ALPHA buffer = io.BytesIO() Image.fromarray(rgba, mode="RGBA").save(buffer, format="PNG")
blob = b""
buffer_views = []
for data in (buffer.getvalue(), POSITIONS.tobytes(), UVS.tobytes()):
blob += b"\x00" * ((4 - len(blob) % 4) % 4)
buffer_views.append(pygltflib.BufferView(buffer=0, byteOffset=len(blob), byteLength=len(data)))
blob += data内容来源: Genesis-Embodied-AI/genesis-world