@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
136 lines (135 loc) • 5.67 kB
JavaScript
"use strict";
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 { Vector3 } from "three";
import { CORE_PLAYER_INPUTS } from "../../../core/player/PlayerCommon";
import { CapsuleSopOperation } from "../../operations/sop/Capsule";
import { inputObject3D } from "./_BaseObject3D";
import { Poly } from "../../Poly";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
export var PlayerUpdateInput = /* @__PURE__ */ ((PlayerUpdateInput2) => {
PlayerUpdateInput2["COLLIDER"] = "collider";
return PlayerUpdateInput2;
})(PlayerUpdateInput || {});
export var PlayerUpdateOutput = /* @__PURE__ */ ((PlayerUpdateOutput2) => {
PlayerUpdateOutput2["VELOCITY"] = "velocity";
PlayerUpdateOutput2["ON_GROUND"] = "onGround";
return PlayerUpdateOutput2;
})(PlayerUpdateOutput || {});
class PlayerUpdateJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param travel speed */
this.speed = ParamConfig.FLOAT(2, {
range: [0, 10],
rangeLocked: [true, false]
});
/** @param run Allowed */
this.runAllowed = ParamConfig.BOOLEAN(true);
/** @param jump Force */
this.runSpeedMult = ParamConfig.FLOAT(2, {
range: [0, 10],
rangeLocked: [true, false],
visibleIf: { runAllowed: 1 }
});
/** @param jump Allowed */
this.jumpAllowed = ParamConfig.BOOLEAN(true);
/** @param jump Force */
this.jumpStrength = ParamConfig.FLOAT(10, {
range: [0, 100],
rangeLocked: [true, false],
visibleIf: { jumpAllowed: 1 }
});
/** @param physics Steps */
this.physicsSteps = ParamConfig.INTEGER(5, {
range: [1, 10],
rangeLocked: [true, false],
separatorBefore: true
});
/** @param gravity */
this.gravity = ParamConfig.VECTOR3([0, -9.8, 0]);
/** @param collision Capsule Radius */
this.capsuleRadius = ParamConfig.FLOAT(CapsuleSopOperation.DEFAULT_PARAMS.radius, {
range: [0, 1],
rangeLocked: [true, false]
});
/** @param collision Capsule Height */
this.capsuleHeight = ParamConfig.FLOAT(CapsuleSopOperation.DEFAULT_PARAMS.height, {
range: [0, 2],
rangeLocked: [true, false]
});
}
}
const ParamsConfig = new PlayerUpdateJsParamsConfig();
export class PlayerUpdateJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "playerUpdate";
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS),
// new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS),
new JsConnectionPoint("collider" /* COLLIDER */, 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),
new JsConnectionPoint("onGround" /* ON_GROUND */, JsConnectionPointType.BOOLEAN),
new JsConnectionPoint("velocity" /* VELOCITY */, JsConnectionPointType.VECTOR3)
]);
}
setTriggerableLines(shadersCollectionController) {
const object3D = inputObject3D(this, shadersCollectionController);
const collider = this.variableForInput(shadersCollectionController, "collider" /* COLLIDER */);
const data = { collider };
CORE_PLAYER_INPUTS.map((inputName) => {
data[inputName] = this.variableForInput(shadersCollectionController, inputName);
});
const coreInputDict = JSON.stringify(CORE_PLAYER_INPUTS);
const func = Poly.namedFunctionsRegister.getFunction("playerSimpleUpdate", this, shadersCollectionController);
const bodyLine = func.asString(object3D, coreInputDict);
shadersCollectionController.addTriggerableLines(this, [bodyLine]);
}
setLines(shadersCollectionController) {
const object3D = inputObject3D(this, shadersCollectionController);
const usedOutputNames = this.io.outputs.used_output_names();
const _b = (propertyName, functionName, type) => {
if (!usedOutputNames.includes(propertyName)) {
return;
}
const varName = this.jsVarName(propertyName);
const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: type,
varName,
value: func.asString(object3D)
}
]);
};
const _v3 = (propertyName, functionName, type) => {
if (!usedOutputNames.includes(propertyName)) {
return;
}
const varName = this.jsVarName(propertyName);
const tmpVarName = shadersCollectionController.addVariable(this, new Vector3());
const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: type,
varName,
value: func.asString(object3D, tmpVarName)
}
]);
};
_b("onGround" /* ON_GROUND */, "getPlayerSimplePropertyOnGround", JsConnectionPointType.BOOLEAN);
_v3("velocity" /* VELOCITY */, "getPlayerSimplePropertyVelocity", JsConnectionPointType.VECTOR3);
}
}