@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
203 lines (202 loc) • 4.77 kB
JavaScript
;
import { Color, Vector2, Vector3, Vector4 } from "three";
import { touchParamRefFromParam } from "../../core/reactivity/ParamReactivity";
import { NamedFunction1, NamedFunction2, NamedFunction3 } from "./_Base";
export function dummyReadRefVal(value) {
}
const tmpColor = new Color();
const tmpV2 = new Vector2();
const tmpV3 = new Vector3();
const tmpV4 = new Vector4();
const tmpN2 = [0, 0];
const tmpN3 = [0, 0, 0];
const tmpN4 = [0, 0, 0, 0];
function _getParam(scene, paramPath) {
dummyReadRefVal(scene.graphNodesController.pathRef(paramPath).value);
const elements = paramPath.split("/");
const paramName = elements.pop();
const nodePath = elements.join("/");
const node = scene.node(nodePath);
if (!node) {
return;
}
const param = node.params.get(paramName);
if (!param) {
return;
}
return param;
}
export class getParam extends NamedFunction1 {
static type() {
return "getParam";
}
func(paramPath) {
return _getParam(this.scene, paramPath);
}
}
export class setParamBoolean extends NamedFunction2 {
static type() {
return "setParamBoolean";
}
func(param, value) {
if (param) {
param.set(value);
touchParamRefFromParam(param);
} else {
console.warn(`setParamBoolean: no param`);
}
}
}
export class setParamBooleanToggle extends NamedFunction1 {
static type() {
return "setParamBooleanToggle";
}
func(param) {
if (param) {
param.set(!param.value);
touchParamRefFromParam(param);
} else {
console.warn(`setParamBooleanToggle: no param`);
}
}
}
export class setParamColor extends NamedFunction3 {
static type() {
return "setParamColor";
}
func(param, value, lerp) {
if (param) {
if (lerp >= 1) {
param.set(value);
} else {
tmpColor.copy(param.value);
tmpColor.lerp(value, lerp);
tmpColor.toArray(tmpN3);
param.set(tmpN3);
}
touchParamRefFromParam(param);
} else {
console.warn(`setParamColor: no param`);
}
}
}
export class setParamFloat extends NamedFunction3 {
static type() {
return "setParamFloat";
}
func(param, value, lerp) {
if (param) {
if (lerp >= 1) {
param.set(value);
} else {
param.set(value * lerp + (1 - lerp) * param.value);
}
touchParamRefFromParam(param);
} else {
console.warn(`setParamFloat: no param`);
}
}
}
export class setParamInteger extends NamedFunction3 {
static type() {
return "setParamInteger";
}
func(param, value, lerp) {
if (param) {
if (lerp >= 1) {
param.set(value);
} else {
param.set(value * lerp + (1 - lerp) * param.value);
}
touchParamRefFromParam(param);
} else {
console.warn(`setParamInteger: no param`);
}
}
}
export class setParamString extends NamedFunction2 {
static type() {
return "setParamString";
}
func(param, value) {
if (param) {
param.set(value);
touchParamRefFromParam(param);
} else {
console.warn(`setParamString: no param`);
}
}
}
export class setParamVector2 extends NamedFunction3 {
static type() {
return "setParamVector2";
}
func(param, value, lerp) {
if (param) {
if (lerp >= 1) {
param.set(value);
} else {
tmpV2.copy(param.value);
tmpV2.lerp(value, lerp);
tmpV2.toArray(tmpN2);
param.set(tmpN2);
}
touchParamRefFromParam(param);
} else {
console.warn(`setParamVector2: no param`);
}
}
}
export class setParamVector3 extends NamedFunction3 {
static type() {
return "setParamVector3";
}
func(param, value, lerp) {
if (param) {
if (lerp >= 1) {
param.set(value);
} else {
tmpV3.copy(param.value);
tmpV3.lerp(value, lerp);
tmpV3.toArray(tmpN3);
param.set(tmpN3);
}
touchParamRefFromParam(param);
} else {
console.warn(`setParamVector3: no param`);
}
}
}
export class setParamVector4 extends NamedFunction3 {
static type() {
return "setParamVector4";
}
func(param, value, lerp) {
if (param) {
if (lerp >= 1) {
param.set(value);
} else {
tmpV4.copy(param.value);
tmpV4.lerp(value, lerp);
tmpV4.toArray(tmpN4);
param.set(tmpN4);
}
touchParamRefFromParam(param);
} else {
console.warn(`setParamVector4: no param`);
}
}
}
export class pressButtonParam extends NamedFunction1 {
static type() {
return "pressButtonParam";
}
func(param) {
if (param) {
param.pressButton();
touchParamRefFromParam(param);
} else {
console.warn(`pressButtonParam: no param`);
}
}
}