@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
75 lines (74 loc) • 2.57 kB
JavaScript
"use strict";
import { TetSopNode } from "./_BaseTet";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { SopType } from "../../poly/registers/nodes/types/Sop";
import { tetrahedralize } from "../../../core/geometry/modules/tet/utils/tetrahedralize";
import { ThreeMeshBVHHelper } from "../../../core/geometry/bvh/ThreeMeshBVHHelper";
import { Vector3 } from "three";
import { mergeFaces } from "../../../core/geometry/operation/Fuse";
import { jitterPositions } from "../../../core/geometry/operation/Jitter";
const jitterMult = new Vector3(1, 1, 1);
class TetrahedralizeSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
this.fuseDist = ParamConfig.FLOAT(1e-3);
this.jitter = ParamConfig.FLOAT(1e-3);
this.innerPointsResolution = ParamConfig.INTEGER(5, {
range: [0, 10]
});
this.minQuality = ParamConfig.FLOAT(0.25, {
range: [0, 1],
rangeLocked: [true, true]
});
this.stepByStep = ParamConfig.BOOLEAN(0, {
separatorBefore: true
});
this.step = ParamConfig.INTEGER(-1, {
range: [-1, 5e3],
rangeLocked: [true, false],
visibleIf: { stepByStep: 1 }
});
this.deleteOutsideTets = ParamConfig.BOOLEAN(1, {
visibleIf: { stepByStep: 1 }
});
}
}
const ParamsConfig = new TetrahedralizeSopParamsConfig();
export class TetrahedralizeSopNode extends TetSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.TETRAHEDRALIZE;
}
initializeNode() {
this.io.inputs.setCount(1);
}
cook(inputCoreGroups) {
const coreGroup = inputCoreGroups[0];
const inputMeshes = coreGroup.threejsObjectsWithGeo();
for (const inputMesh of inputMeshes) {
mergeFaces(inputMesh.geometry, this.pv.fuseDist);
}
jitterPositions(coreGroup, {
amount: this.pv.jitter,
mult: jitterMult,
seed: 0
});
const tetGeometries = [];
for (const inputMesh of inputMeshes) {
ThreeMeshBVHHelper.assignDefaultBVHIfNone(inputMesh);
const tetGeometry = tetrahedralize({
mesh: inputMesh,
jitterAmount: this.pv.jitter,
innerPointsResolution: this.pv.innerPointsResolution,
minQuality: this.pv.minQuality,
stage: this.pv.stepByStep ? this.pv.step >= 0 ? this.pv.step : null : null,
deleteOutsideTets: this.pv.stepByStep ? this.pv.deleteOutsideTets : true
});
tetGeometries.push(tetGeometry);
}
this.setTetGeometries(tetGeometries);
}
}