HomeWeb Components API Reference - v0.31.0
    Preparing search index...

    Class MaterialElement

    The MaterialElement interface provides properties and methods for manipulating <pc-material> elements. The MaterialElement interface also inherits the properties and methods of the HTMLElement interface.

    A pc-material must be a direct child of pc-app — elements placed elsewhere log a warning and never create a material. Elements inserted while the application is already running are created on insertion.

    The element is metal/rough by default: unlike a bare StandardMaterial it enables the metalness workflow, which is what the metalness-* attributes assume and what glTF means by PBR. It also defaults metalness to 0 rather than the engine's 1, because those two defaults have to be chosen together - the engine's 1 is unreachable under its own useMetalness of false, and with the workflow on it would make every material fully metallic, so <pc-material diffuse="crimson"> would render as dark tinted reflections of an environment that may not exist rather than as a crimson surface. metalness="1" remains one attribute away.

    The roughness and roughness-map attributes are aliases for gloss and gloss-map that additionally invert the gloss channel; do not mix the two families on one element.

    The two aliases are documented here rather than on an accessor, because they resolve to the gloss properties and would otherwise inherit gloss's description - which reads inverted.

    roughness - The roughness of the material, from 0 (shiny) to 1 (rough). An alias for gloss that also inverts it, so do not combine it with the gloss attributes.

    roughness-map - The id of the pc-asset to use as the roughness map. An alias for gloss-map that also inverts the gloss channel, so do not combine it with the gloss attributes.

    Hierarchy

    Index
    alphaDither: number | null

    The alpha used by opacity dithering, which needs an opacity-dither mode other than none. It ranges from 0 to 1, and lets a material be alpha blended by opacity and dithered by this at the same time. Defaults to null, which dithers by opacity.

    alphaTest: number

    The alpha test reference value. Fragments with an opacity below this value are discarded.

    alphaToCoverage: boolean

    Whether to use alpha to coverage. It resolves transparency using multisampling.

    aoIntensity: number

    The strength of the ambient occlusion map. It ranges from 0 to 1.

    aoMapChannel: ScalarChannel

    The color channel of the ambient occlusion map to sample.

    aoMapOffset: Vec2

    The 2D offset of the ambient occlusion map.

    aoMapRotation: number

    The 2D rotation of the ambient occlusion map. It is in degrees.

    aoMapTiling: Vec2

    The 2D tiling of the ambient occlusion map.

    aoMapUv: number

    The UV channel the ambient occlusion map samples.

    blendType: BlendType

    How the material is blended with the scene behind it.

    bumpiness: number

    The strength of the normal map. 0 is flat and 1 is the map's full effect.

    cull: CullMode

    Which faces of a mesh are culled.

    depthBias: number

    The offset applied to the depth of a fragment. It is used to resolve z-fighting.

    depthTest: boolean

    Whether fragments are tested against the depth buffer.

    depthWrite: boolean

    Whether fragments write to the depth buffer.

    diffuse: Color

    The diffuse color of the material. With the metalness workflow this doubles as the specular color where the surface is metallic.

    diffuseMapChannel: ColorChannel

    The color channels of the diffuse map to sample.

    diffuseMapOffset: Vec2

    The 2D offset of the diffuse map.

    diffuseMapRotation: number

    The 2D rotation of the diffuse map. It is in degrees.

    diffuseMapTiling: Vec2

    The 2D tiling of the diffuse map.

    diffuseMapUv: number

    The UV channel the diffuse map samples.

    emissive: Color

    The emissive color of the material. It is added to the lit result.

    emissiveIntensity: number

    The multiplier applied to the emissive color and map.

    emissiveMapChannel: ColorChannel

    The color channels of the emissive map to sample.

    emissiveMapOffset: Vec2

    The 2D offset of the emissive map.

    emissiveMapRotation: number

    The 2D rotation of the emissive map. It is in degrees.

    emissiveMapTiling: Vec2

    The 2D tiling of the emissive map.

    emissiveMapUv: number

    The UV channel the emissive map samples.

    enableGGXSpecular: boolean

    Whether to use the GGX specular model. It supports anisotropy.

    flatShading: boolean

    Whether the material is shaded with the geometric normal of each triangle. That is in place of the normals interpolated from its vertices, and gives the surface a faceted look.

    fresnelModel: FresnelModel

    The Fresnel model used for specular reflections at grazing angles.

    gloss: number

    The glossiness of the material. It ranges from 0 (rough) to 1 (shiny). See also roughness.

    glossInvert: boolean

    Whether the gloss value and map are inverted. Inverting them makes the material treat them as roughness. Setting roughness or roughness-map enables this automatically.

    glossMapChannel: ScalarChannel

    The color channel of the gloss map to sample.

    glossMapOffset: Vec2

    The 2D offset of the gloss map.

    glossMapRotation: number

    The 2D rotation of the gloss map. It is in degrees.

    glossMapTiling: Vec2

    The 2D tiling of the gloss map.

    glossMapUv: number

    The UV channel the gloss map samples.

    heightMapBase: number

    The height map value that sits at the level of the geometry. It ranges from 0 to 1: relief above it stands out of the surface and relief below it sinks in. Defaults to 0.5; 1 treats the map as pure depth and 0 as pure elevation.

    heightMapChannel: ScalarChannel

    The color channel of the height map to sample.

    heightMapFactor: number

    The strength of the parallax effect driven by the height map.

    heightMapOffset: Vec2

    The 2D offset of the height map.

    heightMapRotation: number

    The 2D rotation of the height map. It is in degrees.

    heightMapTiling: Vec2

    The 2D tiling of the height map.

    heightMapUv: number

    The UV channel the height map samples.

    material: StandardMaterial | null = null

    The material. null until the containing application has created it — an element present at startup has its material once the application is ready.

    metalness: number

    How metallic the surface is. It ranges from 0 (dielectric) to 1 (metal).

    metalnessMapChannel: ScalarChannel

    The color channel of the metalness map to sample.

    metalnessMapOffset: Vec2

    The 2D offset of the metalness map.

    metalnessMapRotation: number

    The 2D rotation of the metalness map. It is in degrees.

    metalnessMapTiling: Vec2

    The 2D tiling of the metalness map.

    metalnessMapUv: number

    The UV channel the metalness map samples.

    name: string

    The name of the material - the label shown wherever materials surface by name, such as profilers, GPU captures and the assignments pc-model.hierarchy() reports. Purely a label: element references resolve through id.

    normalMapOffset: Vec2

    The 2D offset of the normal map.

    normalMapRotation: number

    The 2D rotation of the normal map. It is in degrees.

    normalMapTiling: Vec2

    The 2D tiling of the normal map.

    normalMapUv: number

    The UV channel the normal map samples.

    occludeDirect: boolean

    Whether ambient occlusion also attenuates direct lighting.

    occludeSpecular: OccludeSpecular

    How specular reflections are occluded.

    opacity: number

    The opacity of the material, which requires a blend-type other than none to have any visible effect. It ranges from 0 (transparent) to 1 (opaque).

    opacityDither: OpacityDither

    The dithering used to render opacity. It approximates transparency without blending.

    opacityFadesSpecular: boolean

    Whether specular highlights fade out as the material becomes transparent.

    opacityMapChannel: ScalarChannel

    The color channel of the opacity map to sample.

    opacityMapOffset: Vec2

    The 2D offset of the opacity map.

    opacityMapRotation: number

    The 2D rotation of the opacity map. It is in degrees.

    opacityMapTiling: Vec2

    The 2D tiling of the opacity map.

    opacityMapUv: number

    The UV channel the opacity map samples.

    parallaxMode: ParallaxMode

    How the height map offsets the UVs of the other maps. Can be:

    • offset - A single tap of the height map.
    • occlusion - Marches the view ray through the height field, for deeper relief without smearing at the cost of several taps per pixel. The silhouette of the mesh is unchanged.

    Defaults to offset.

    parallaxSamples: number

    The maximum number of height map taps along the view ray, which applies only when parallax-mode is occlusion. Defaults to 16.

    parallaxShadowSamples: number

    The maximum number of height map taps towards each directional light, which applies only when parallax-mode is occlusion. The taps soft-shadow the relief against itself. Defaults to 0, no self-shadowing.

    slopeDepthBias: number

    The depth offset applied in proportion to a surface's slope. It is used to resolve z-fighting.

    specular: Color

    The specular color of the material, which applies only when the metalness workflow is disabled or use-metalness-specular-color is enabled.

    specularityFactor: number

    The strength of specular reflections at direct angles, which applies only when use-metalness-specular-color is enabled. It ranges from 0 to 1.

    twoSidedLighting: boolean

    Whether back faces are lit as though their normals were flipped.

    useFog: boolean

    Whether the material is affected by scene fog.

    useLighting: boolean

    Whether the material is affected by scene lights. When disabled the material renders unlit, using the diffuse color and map alone.

    useMetalness: boolean

    Whether to use the metalness workflow. The alternative is the older specular workflow. Unlike a bare StandardMaterial this defaults to true, because the metalness-* attributes have no effect without it.

    useMetalnessSpecularColor: boolean

    Whether the specular color tints reflections while the metalness workflow is in use.

    useSkybox: boolean

    Whether the material is lit by the scene's skybox.

    useTonemap: boolean

    Whether the camera's tone mapping is applied to the material.

    • get aoMap(): string

      Gets the id of the pc-asset used as the ambient occlusion map.

      Returns string

      The asset id.

    • set aoMap(value: string): void

      Sets the id of the pc-asset to use as the ambient occlusion map.

      Parameters

      • value: string

        The asset id.

      Returns void

    • get diffuseMap(): string

      Gets the id of the pc-asset used as the diffuse map.

      Returns string

      The asset id.

    • set diffuseMap(value: string): void

      Sets the id of the pc-asset to use as the diffuse map.

      Parameters

      • value: string

        The asset id.

      Returns void

    • get emissiveMap(): string

      Gets the id of the pc-asset used as the emissive map.

      Returns string

      The asset id.

    • set emissiveMap(value: string): void

      Sets the id of the pc-asset to use as the emissive map.

      Parameters

      • value: string

        The asset id.

      Returns void

    • get glossMap(): string

      Gets the id of the pc-asset used as the gloss map.

      Returns string

      The asset id.

    • set glossMap(value: string): void

      Sets the id of the pc-asset to use as the gloss map. See also roughnessMap.

      Parameters

      • value: string

        The asset id.

      Returns void

    • get heightMap(): string

      Gets the id of the pc-asset used as the height map.

      Returns string

      The asset id.

    • set heightMap(value: string): void

      Sets the id of the pc-asset to use as the height map, which drives parallax mapping.

      Parameters

      • value: string

        The asset id.

      Returns void

    • get metalnessMap(): string

      Gets the id of the pc-asset used as the metalness map.

      Returns string

      The asset id.

    • set metalnessMap(value: string): void

      Sets the id of the pc-asset to use as the metalness map.

      Parameters

      • value: string

        The asset id.

      Returns void

    • get normalMap(): string

      Gets the id of the pc-asset used as the normal map.

      Returns string

      The asset id.

    • set normalMap(value: string): void

      Sets the id of the pc-asset to use as the normal map.

      Parameters

      • value: string

        The asset id.

      Returns void

    • get opacityMap(): string

      Gets the id of the pc-asset used as the opacity map.

      Returns string

      The asset id.

    • set opacityMap(value: string): void

      Sets the id of the pc-asset to use as the opacity map.

      Parameters

      • value: string

        The asset id.

      Returns void

    • get roughness(): number

      Gets the roughness of the material.

      Returns number

      The roughness.

    • set roughness(value: number): void

      Sets the roughness of the material, from 0 (shiny) to 1 (rough). This is an alias for gloss that also inverts the gloss channel, so do not combine it with the gloss attributes.

      Parameters

      • value: number

        The roughness.

      Returns void

    • get roughnessMap(): string

      Gets the id of the pc-asset used as the roughness map.

      Returns string

      The asset id.

    • set roughnessMap(value: string): void

      Sets the id of the pc-asset to use as the roughness map. This is an alias for glossMap that also inverts the gloss channel, so do not combine it with the gloss attributes.

      Parameters

      • value: string

        The asset id.

      Returns void

    • Returns the StandardMaterial created by the <pc-material> element with the given id, or undefined if there is no such element or its material has not been created yet.

      The id is an element id. Given the element that refers to the material, it is looked for in that element's <pc-app> first and then in the tree the element is in, which is the document unless the application is inside a shadow root. That is how the library's own elements resolve a material, and what keeps two applications that use the same id apart. Without an element, only the document is searched.

      Parameters

      • id: string

        The id of the <pc-material> element.

      • Optionalfrom: Element

        The element that refers to the material.

      Returns StandardMaterial | undefined

      The material, or undefined.