Skip to content
bg2 engine

MaterialRenderer

Wraps a Material for rendering. One material renderer per material instance manages the material data binding to shaders during render operations.

import MaterialRenderer from "bg2e-js/ts/render/MaterialRenderer.js";
const material = await Material.Deserialize({
diffuse: [0.4, 0.3, 0.1],
roughness: 0.5,
metallic: 0.8
});
const matRenderer = myRenderer.factory.material(material);
PropertyTypeDescription
rendererRendererThe base renderer (WebGLRenderer).
materialMaterialThe wrapped material with its properties and textures.

getTextureRenderer(materialAttribute: keyof Material): TextureRenderer \| null

Section titled “getTextureRenderer(materialAttribute: keyof Material): TextureRenderer \| null”

Returns a TextureRenderer if the specified material attribute (e.g., “albedoTexturer”, normalMap, roughness) is a texture. Returns null otherwise or if the attribute is not a texture:

const texRenderer = matRenderer.getTextureRenderer("albedoTexture");
if (texRenderer) {
texRenderer.activeTexture(0);
texRenderer.bindTexture();
}