nanogl-gltf
Version:
135 lines (134 loc) • 5.36 kB
TypeScript
import { vec3 } from 'gl-matrix';
import PbrMetallicRoughness from './PbrMetallicRoughness';
import NormalTextureInfo from './NormalTextureInfo';
import OcclusionTextureInfo from './OcclusionTextureInfo';
import TextureInfo from './TextureInfo';
import MaterialPass from 'nanogl-pbr/MaterialPass';
import Gltf2 from '../types/Gltf2';
import GltfLoader from '../io/GltfLoader';
import GltfTypes from '../types/GltfTypes';
import { default as BaseMaterial } from 'nanogl-pbr/Material';
import Primitive from './Primitive';
import Node from './Node';
import { IElement } from '../types/Elements';
import Gltf from '../Gltf';
import UnlitPass from 'nanogl-pbr/UnlitPass';
import ShaderVersion from 'nanogl-pbr/ShaderVersion';
import { StandardPass } from 'nanogl-pbr/StandardPass';
/**
* Interface for PbrMaterials that needs a method to setup a nanogl-pbr StandardPass
*/
export interface IPbrInputsData {
setupPass(pass: StandardPass): void;
}
/**
* Base interface for Material classes, adding a method to base Element interface to create a nanogl-pbr Material object.
*/
export interface IMaterial extends IElement {
readonly gltftype: GltfTypes.MATERIAL;
createMaterialForPrimitive(gltf: Gltf, node: Node, primitive: Primitive): BaseMaterial;
}
/**
* A simple nanogl-pbr MaterialPass but with a shader version attribute
*/
export declare type GltfMaterialPass = MaterialPass & {
version: ShaderVersion;
};
/**
* The GltfBaseMaterial element contains the base properties and methods for all Material classes coming from a glTF file
*/
export declare abstract class GltfBaseMaterial<TPass extends GltfMaterialPass> implements IMaterial {
readonly gltftype = GltfTypes.MATERIAL;
name: undefined | string;
extras: any;
/**
* PbrMetallicRoughness element, containing the base color, metallic, roughness and metallicRoughnessTexture properties.
*/
pbrMetallicRoughness?: PbrMetallicRoughness;
/**
* Normal texture
*/
normalTexture?: NormalTextureInfo;
/**
* Occlusion texture
*/
occlusionTexture?: OcclusionTextureInfo;
/**
* Emissive texture
*/
emissiveTexture?: TextureInfo;
/**
* Emissive factor, defining the strength applied on emissiveTexture. Default to [0,0,0]
*/
emissiveFactor: vec3;
/**
* Alpha rendering mode (OPAQUE, MASK or BLEND). Default to OPAQUE
*/
alphaMode: Gltf2.MaterialAlphaMode;
/**
* Alpha cutoff value used when alphaMode is MASK. Default to 0.5
*/
alphaCutoff: number;
/**
* Whether the material will be rendered on double sides. Default to false
*/
doubleSided: boolean;
/**
* Copy of pbrMetallicRoughness, used to setup the StandardPass
*/
pbrInputsData: IPbrInputsData;
/**
* Pass used to render the material, created in setupMaterials()
*/
protected _materialPass: TPass;
get materialPass(): TPass;
/**
* Create a nanogl-pbr Material object for a given Primitive, using the Pass created in setupMaterials().
* @param gltf GLTF where the Primitive comes from
* @param node Parent Node of the Primitive, unused here
* @param primitive Primitive to create the Material for
*/
createMaterialForPrimitive(gltf: Gltf, node: Node, primitive: Primitive): BaseMaterial;
/**
* Parse the Material data, fill the emissiveFactor, alphaMode, alphaCutoff and doubleSided properties,
* create the PbrMetallicRoughness, NormalTexture, OcclusionTexture and EmissiveTexture elements if needed,
* and call the setupMaterials() method.
*
* Is async as it may need to wait for PbrMetallicRoughness, NormalTexture, OcclusionTexture and EmissiveTexture elements to be created.
* @param gltfLoader GLTFLoader to use
* @param data Data to parse
*/
parse(gltfLoader: GltfLoader, data: Gltf2.IMaterial): Promise<any>;
/**
* Parse the PbrMetallicRoughness data, filling the pbrMetallicRoughness property with a new PbrMetallicRoughness element.
* @param gltfLoader GLTFLoader to use
* @param data Data to parse
*/
parsePbrInputsData(gltfLoader: GltfLoader, data: Gltf2.IMaterial): Promise<any>;
/**
* Configure PBR Surface for a given Pass with this Material's options.
* If this.pbrInputsData is defined, call its setupPass() method, otherwise set a MetalnessSurface.
* @param pass Pass to configure
*/
configurePbrSurface(pass: StandardPass): void;
/**
* Configure alpha rendering mode for a given Pass with this Material's options
* (depth mask, blend, blendFunc, mask, alphaMode and alphaCutoff uniform)
* @param pass Pass to configure
*/
configureAlpha(pass: StandardPass | UnlitPass): void;
/**
* Abstract class to setup the nanogl-pbr MaterialPass (enable depth test, cullface, alphaMode, attach textures samplers and factors, ...)
*/
abstract setupMaterials(): void;
}
/**
* Basic PBR implementation of GltfBaseMaterial using a nanogl-pbr StandardPass
*/
export default class Material extends GltfBaseMaterial<StandardPass> {
/**
* Creates a StandardPass and attach emissive, normal and occlusion textures with samplers and their strength factors.
* Also configure alpha rendering mode and PBR surface.
*/
setupMaterials(): void;
}