@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
52 lines (51 loc) • 1.93 kB
JavaScript
;
import { JsConnectionPoint, JsConnectionPointType } from "../utils/io/connections/Js";
import { TypedJsNode } from "./_Base";
import { Poly } from "../../Poly";
import { createVariable } from "./code/assemblers/_BaseJsPersistedConfigUtils";
import { ComputedValueJsDefinition } from "./utils/JsDefinition";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { DEFAULT_SMOOTH_AMOUNT } from "../../../core/camera/controls/DeviceOrientationControls";
class DeviceOrientationJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.smoothAmount = ParamConfig.FLOAT(DEFAULT_SMOOTH_AMOUNT, {
range: [0, 1],
rangeLocked: [true, true]
});
}
}
const ParamsConfig = new DeviceOrientationJsParamsConfig();
export class DeviceOrientationJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "deviceOrientation";
}
initializeNode() {
super.initializeNode();
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(JsConnectionPointType.QUATERNION, JsConnectionPointType.QUATERNION)
]);
}
setLines(linesController) {
const varName = this.jsVarName(JsConnectionPointType.QUATERNION);
const smoothAmount = this.variableForInputParam(linesController, this.p.smoothAmount);
const func = Poly.namedFunctionsRegister.getFunction("deviceOrientation", this, linesController);
const variable = createVariable(JsConnectionPointType.QUATERNION);
if (variable) {
const tmpVarName = linesController.addVariable(this, variable);
linesController.addDefinitions(this, [
new ComputedValueJsDefinition(
this,
linesController,
JsConnectionPointType.QUATERNION,
varName,
func.asString(tmpVarName, smoothAmount)
)
]);
}
}
}