materialDataOf static method

MaterialData materialDataOf(
  1. Primitive3D shape
)

shape's look as a glTF-style material: colours made linear, blended when it is not opaque, its texture (as texture 0) repeated Primitive3D.tiling times.

Implementation

static MaterialData materialDataOf(Primitive3D shape) {
  final (r, g, b) = linear(shape.color);
  final (er, eg, eb) = linear(shape.emission);
  final alpha = shape.opacity.clamp(0.0, 1.0) * shape.color.a;
  return MaterialData(
    name: shape.shapeName,
    baseColor: (r, g, b, alpha),
    metallic: shape.metallic.clamp(0.0, 1.0),
    roughness: shape.roughness.clamp(0.0, 1.0),
    emissive: (er, eg, eb),
    emissiveStrength: math.max(shape.emissionStrength, 0.0),
    alphaMode: alpha < 1 ? AlphaMode.blend : AlphaMode.opaque,
    doubleSided: shape.doubleSided,
    unlit: shape.unlit,
    baseColorTexture: shape.texture.isEmpty
        ? null
        : TextureRef(0, scale: (shape.tiling.x, shape.tiling.y)),
  );
}