@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
70 lines (69 loc) • 2.22 kB
JavaScript
;
import { MeshNormalMaterial } from "three";
import { FrontSide } from "three";
import { PrimitiveMatNode } from "./_Base";
import { NodeParamsConfig } from "../utils/params/ParamsConfig";
import {
AdvancedCommonController,
AdvancedCommonParamConfig
} from "./utils/AdvancedCommonController";
import {
TextureBumpMapController,
BumpMapParamConfig
} from "./utils/TextureBumpMapController";
import {
TextureNormalMapController,
NormalMapParamConfig
} from "./utils/TextureNormalMapController";
import {
TextureDisplacementMapController,
DisplacementMapParamConfig
} from "./utils/TextureDisplacementMapController";
import { FlatShadingController, FlatShadingParamConfig } from "./utils/FlatShadingController";
import { TexturesFolderParamConfig } from "./utils/TexturesFolder";
import { DefaultFolderParamConfig } from "./utils/DefaultFolder";
import { MatType } from "../../poly/registers/nodes/types/Mat";
class MeshNormalMatParamsConfig extends AdvancedCommonParamConfig(
FlatShadingParamConfig(
/* advanced */
NormalMapParamConfig(
DisplacementMapParamConfig(
BumpMapParamConfig(
/* textures */
TexturesFolderParamConfig(DefaultFolderParamConfig(NodeParamsConfig))
)
)
)
)
) {
}
const ParamsConfig = new MeshNormalMatParamsConfig();
export class MeshNormalMatNode extends PrimitiveMatNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
this.controllers = {
advancedCommon: new AdvancedCommonController(this),
bumpMap: new TextureBumpMapController(this),
displacementMap: new TextureDisplacementMapController(this),
flatShading: new FlatShadingController(this),
normalMap: new TextureNormalMapController(this)
};
this.controllersList = Object.values(this.controllers);
}
static type() {
return MatType.MESH_NORMAL;
}
createMaterial() {
return new MeshNormalMaterial({
vertexColors: false,
side: FrontSide,
opacity: 1
});
}
async cook() {
this._material = this._material || this.createMaterial();
await Promise.all(this.controllersPromises(this._material));
this.setMaterial(this._material);
}
}