UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

60 lines (59 loc) 2.17 kB
"use strict"; import { NodeParamsConfig, ParamConfig } from "../../utils/params/ParamsConfig"; import { TypedMatNode } from "../_Base"; import { Box3, Material } from "three"; export function VolumeParamConfig(Base) { return class Mixin extends Base { constructor() { super(...arguments); /** @param color */ this.color = ParamConfig.COLOR([1, 1, 1]); /** @param stepSize. The smaller the value the more step the shader will make */ this.stepSize = ParamConfig.FLOAT(0.01); /** @param volume density */ this.density = ParamConfig.FLOAT(1); /** @param volume shadow density */ this.shadowDensity = ParamConfig.FLOAT(1); /** @param this volume material currently can only use a single white light, whose direction is defined by this parameter */ this.lightDir = ParamConfig.VECTOR3([-1, -1, -1]); } }; } class VolumeMaterial extends Material { } class VolumeParamsConfig extends VolumeParamConfig(NodeParamsConfig) { } class VolumeMatNode extends TypedMatNode { } export class VolumeController { constructor(node) { this.node = node; } static renderHook(renderer, scene, camera, geometry, material, group, object) { if (object) { this._objectBbox.setFromObject(object); const shader_material = material; shader_material.uniforms.u_BoundingBoxMin.value.copy(this._objectBbox.min); shader_material.uniforms.u_BoundingBoxMax.value.copy(this._objectBbox.max); } } updateUniformsFromParams(material) { const shaderMaterial = material; const uniforms = shaderMaterial.uniforms; if (!uniforms) { return; } uniforms.u_Color.value.copy(this.node.pv.color); uniforms.u_StepSize.value = this.node.pv.stepSize; uniforms.u_VolumeDensity.value = this.node.pv.density; uniforms.u_ShadowDensity.value = this.node.pv.shadowDensity; const dir_light = uniforms.u_DirectionalLightDirection.value; const pv_dir_light = this.node.pv.lightDir; if (dir_light) { dir_light.x = pv_dir_light.x; dir_light.y = pv_dir_light.y; dir_light.z = pv_dir_light.z; } } } VolumeController._objectBbox = new Box3();