polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
61 lines (55 loc) • 2.28 kB
text/typescript
/**
* Creates a Mesh Lambert Material
*
* @remarks
* This material needs lights to be visible. While not as photorealistic as the MeshStandardMaterial, it is very cheap to process.
*
*/
import {MeshLambertMaterial} from 'three/src/materials/MeshLambertMaterial';
import {FrontSide} from 'three/src/constants';
import {TypedMatNode} from './_Base';
import {NodeParamsConfig} from '../utils/params/ParamsConfig';
import {ColorsController, ColorParamConfig} from './utils/ColorsController';
import {SideController, SideParamConfig} from './utils/SideController';
import {DepthController, DepthParamConfig} from './utils/DepthController';
import {SkinningController, SkinningParamConfig} from './utils/SkinningController';
import {TextureMapController, TextureMapParamConfig} from './utils/TextureMapController';
import {TextureAlphaMapController, TextureAlphaMapParamConfig} from './utils/TextureAlphaMapController';
class MeshLambertMatParamsConfig extends TextureAlphaMapParamConfig(
TextureMapParamConfig(SkinningParamConfig(DepthParamConfig(SideParamConfig(ColorParamConfig(NodeParamsConfig)))))
) {}
const ParamsConfig = new MeshLambertMatParamsConfig();
export class MeshLambertMatNode extends TypedMatNode<MeshLambertMaterial, MeshLambertMatParamsConfig> {
params_config = ParamsConfig;
static type() {
return 'meshLambert';
}
create_material() {
return new MeshLambertMaterial({
vertexColors: false,
side: FrontSide,
color: 0xffffff,
opacity: 1,
});
}
readonly texture_map_controller: TextureMapController = new TextureMapController(this, {direct_params: true});
readonly texture_alpha_map_controller: TextureAlphaMapController = new TextureAlphaMapController(this, {
direct_params: true,
});
readonly depth_controller: DepthController = new DepthController(this);
initializeNode() {
this.params.onParamsCreated('init controllers', () => {
this.texture_map_controller.initializeNode();
this.texture_alpha_map_controller.initializeNode();
});
}
async cook() {
ColorsController.update(this);
SideController.update(this);
SkinningController.update(this);
this.texture_map_controller.update();
this.texture_alpha_map_controller.update();
this.depth_controller.update();
this.set_material(this.material);
}
}