@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
71 lines (70 loc) • 3.26 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 { inputObject3D } from "./_BaseObject3D";
import { Poly } from "../../Poly";
import { VectorArray } from "./code/assemblers/_BaseJsPersistedConfigUtils";
import { faceTrackingVector4Array } from "../../../core/computerVision/face/Data";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
export var TrackFaceJsNodeOutput = /* @__PURE__ */ ((TrackFaceJsNodeOutput2) => {
TrackFaceJsNodeOutput2["LANDMARKS"] = "landmarks";
return TrackFaceJsNodeOutput2;
})(TrackFaceJsNodeOutput || {});
class TrackFaceJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.faceIndex = ParamConfig.INTEGER(0, {
range: [0, 1],
rangeLocked: [true, false]
});
}
}
const ParamsConfig = new TrackFaceJsParamsConfig();
export class TrackFaceJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "trackFace";
}
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(JsConnectionPointType.TEXTURE, JsConnectionPointType.TEXTURE, CONNECTION_OPTIONS)
]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint("landmarks" /* LANDMARKS */, JsConnectionPointType.VECTOR4_ARRAY)
]);
}
setTriggerableLines(shadersCollectionController) {
const object3D = inputObject3D(this, shadersCollectionController);
const texture = this.variableForInput(shadersCollectionController, JsConnectionPointType.TEXTURE);
const func = Poly.namedFunctionsRegister.getFunction("trackFace", this, shadersCollectionController);
const bodyLine = func.asString(object3D, texture);
shadersCollectionController.addTriggerableLines(this, [bodyLine]);
}
setLines(shadersCollectionController) {
const object3D = inputObject3D(this, shadersCollectionController);
const usedOutputNames = this.io.outputs.used_output_names();
const faceIndex = this.variableForInputParam(shadersCollectionController, this.p.faceIndex);
const _v4 = (propertyName, functionName, type) => {
if (!usedOutputNames.includes(propertyName)) {
return;
}
const varName = this.jsVarName(propertyName);
const tmpVarName = shadersCollectionController.addVariable(this, new VectorArray(faceTrackingVector4Array()));
const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: type,
varName,
value: func.asString(object3D, faceIndex, tmpVarName)
}
]);
};
_v4("landmarks" /* LANDMARKS */, "trackFaceGetLandmarks", JsConnectionPointType.VECTOR4_ARRAY);
}
}