@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
88 lines (87 loc) • 3.41 kB
JavaScript
;
import { TRIGGER_CONNECTION_NAME, TypedJsNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js";
import { CORE_PLAYER_INPUTS } from "../../../core/player/PlayerCommon";
import { inputObject3D } from "./_BaseObject3D";
import { Poly } from "../../Poly";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
class PhysicsPlayerUpdateJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param travel speed */
this.speed = ParamConfig.FLOAT(0.5, {
range: [0, 10],
rangeLocked: [true, false]
});
/** @param run Allowed */
this.runAllowed = ParamConfig.BOOLEAN(true);
/** @param jump Force */
this.runSpeedMult = ParamConfig.FLOAT(3, {
range: [0, 10],
rangeLocked: [true, false],
visibleIf: { runAllowed: 1 }
});
/** @param jump Allowed */
this.jumpAllowed = ParamConfig.BOOLEAN(true);
/** @param jump Force */
this.jumpStrength = ParamConfig.FLOAT(0.2, {
range: [0, 10],
rangeLocked: [true, false],
visibleIf: { jumpAllowed: 1 }
});
/** @param reset if position is below a threshold */
this.resetIfBelowThreshold = ParamConfig.BOOLEAN(true);
/** @param height under which the player gets reset */
this.resetThreshold = ParamConfig.FLOAT(-5, {
range: [-10, 10],
rangeLocked: [false, false],
visibleIf: { resetIfBelowThreshold: 1 }
});
}
}
const ParamsConfig = new PhysicsPlayerUpdateJsParamsConfig();
export class PhysicsPlayerUpdateJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "physicsPlayerUpdate";
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS),
new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS),
...CORE_PLAYER_INPUTS.map(
(inputName) => new JsConnectionPoint(inputName, JsConnectionPointType.BOOLEAN, CONNECTION_OPTIONS)
)
]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER)
]);
}
setTriggerableLines(shadersCollectionController) {
const object3D = inputObject3D(this, shadersCollectionController);
const data = {};
CORE_PLAYER_INPUTS.forEach((inputName) => {
data[inputName] = this.variableForInput(shadersCollectionController, inputName);
});
const params = [
this.p.speed,
this.p.runAllowed,
this.p.runSpeedMult,
this.p.jumpAllowed,
this.p.jumpStrength,
this.p.resetIfBelowThreshold,
this.p.resetThreshold
];
params.forEach((param) => {
data[param.name()] = this.variableForInputParam(shadersCollectionController, param);
});
const coreInputDict = JSON.stringify(data).replace(/\"/g, "");
const func = Poly.namedFunctionsRegister.getFunction("playerPhysicsUpdate", this, shadersCollectionController);
const bodyLine = func.asString(object3D, coreInputDict);
shadersCollectionController.addTriggerableLines(this, [bodyLine]);
}
}