@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
142 lines (141 loc) • 5.51 kB
JavaScript
;
import { ParamlessTypedJsNode } from "./_Base";
import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js";
import { Vector2, Vector3 } from "three";
import { Poly } from "../../Poly";
import { inputObject3D } from "./_BaseObject3D";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
export var GetIntersectionPropertyJsNodeOutputName = /* @__PURE__ */ ((GetIntersectionPropertyJsNodeOutputName2) => {
GetIntersectionPropertyJsNodeOutputName2["distance"] = "distance";
GetIntersectionPropertyJsNodeOutputName2["object"] = "object";
GetIntersectionPropertyJsNodeOutputName2["point"] = "point";
GetIntersectionPropertyJsNodeOutputName2["normal"] = "normal";
GetIntersectionPropertyJsNodeOutputName2["uv"] = "uv";
GetIntersectionPropertyJsNodeOutputName2["faceIndex"] = "faceIndex";
return GetIntersectionPropertyJsNodeOutputName2;
})(GetIntersectionPropertyJsNodeOutputName || {});
export class GetIntersectionPropertyJsNode extends ParamlessTypedJsNode {
static type() {
return "getIntersectionProperty";
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(
JsConnectionPointType.INTERSECTION,
JsConnectionPointType.INTERSECTION,
CONNECTION_OPTIONS
)
]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint("distance" /* distance */, JsConnectionPointType.FLOAT),
new JsConnectionPoint("object" /* object */, JsConnectionPointType.OBJECT_3D),
new JsConnectionPoint("point" /* point */, JsConnectionPointType.VECTOR3),
new JsConnectionPoint("normal" /* normal */, JsConnectionPointType.VECTOR3),
new JsConnectionPoint("uv" /* uv */, JsConnectionPointType.VECTOR2),
new JsConnectionPoint("faceIndex" /* faceIndex */, JsConnectionPointType.INT)
]);
}
setLines(shadersCollectionController) {
const usedOutputNames = this.io.outputs.used_output_names();
const object3D = inputObject3D(this, shadersCollectionController);
const intersection = this.variableForInput(shadersCollectionController, JsConnectionPointType.INTERSECTION);
const _i = (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(intersection)
}
]);
};
const _f = (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(intersection)
}
]);
};
const _v2 = (propertyName, functionName, type) => {
if (!usedOutputNames.includes(propertyName)) {
return;
}
const varName = this.jsVarName(propertyName);
const tmpVarName = shadersCollectionController.addVariable(this, new Vector2());
const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController);
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: type,
varName,
value: func.asString(intersection, tmpVarName)
}
]);
};
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(intersection, tmpVarName)
}
]);
};
const _object = (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, intersection)
}
]);
};
_i(
"faceIndex" /* faceIndex */,
"getIntersectionPropertyFaceIndex",
JsConnectionPointType.INT
);
_f(
"distance" /* distance */,
"getIntersectionPropertyDistance",
JsConnectionPointType.FLOAT
);
_v3(
"point" /* point */,
"getIntersectionPropertyPoint",
JsConnectionPointType.VECTOR3
);
_v3(
"normal" /* normal */,
"getIntersectionPropertyNormal",
JsConnectionPointType.VECTOR3
);
_v2("uv" /* uv */, "getIntersectionPropertyUv", JsConnectionPointType.VECTOR2);
_object(
"object" /* object */,
"getIntersectionPropertyObject",
JsConnectionPointType.OBJECT_3D
);
}
}