@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
57 lines (56 loc) • 1.62 kB
JavaScript
;
import { BaseController } from "./_BaseController";
import { TypedMatNode } from "../_Base";
import { NodeParamsConfig, ParamConfig } from "../../utils/params/ParamsConfig";
import { isBooleanTrue } from "../../../../core/BooleanValue";
export function PointsParamConfig(Base) {
return class Mixin extends Base {
constructor() {
super(...arguments);
this.size = ParamConfig.FLOAT(1, {
range: [0, 10],
rangeLocked: [true, false]
});
this.sizeAttenuation = ParamConfig.BOOLEAN(1, {
separatorAfter: true
});
}
};
}
class PointsParamsConfig extends PointsParamConfig(NodeParamsConfig) {
}
function isValidMaterial(material) {
if (!material) {
return false;
}
return material.size != null;
}
class PointsSizeMatNode extends TypedMatNode {
async material() {
const container = await this.compute();
return container.material();
}
}
export class PointsSizeController extends BaseController {
constructor(node) {
super(node);
this.node = node;
}
static async update(node) {
const material = await node.material();
if (!isValidMaterial(material)) {
return;
}
node.controllers.pointsSize.updateMaterial(material);
}
updateMaterial(material) {
const pv = this.node.pv;
material.size = pv.size;
const previousSizeAttenuation = material.sizeAttenuation;
const newSizeAttenuation = isBooleanTrue(pv.sizeAttenuation);
if (previousSizeAttenuation != newSizeAttenuation) {
material.sizeAttenuation = newSizeAttenuation;
material.needsUpdate = true;
}
}
}