@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
84 lines (83 loc) • 2.48 kB
JavaScript
"use strict";
import { TypedSopNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { InputCloneMode } from "../../poly/InputCloneMode";
import { getWFCSolver } from "../../../core/wfc/WFCRegister";
class WFCSolverUpdateSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param quadId */
this.quadId = ParamConfig.INTEGER(0, {
range: [0, 10],
rangeLocked: [true, false]
});
/** @param tileId */
this.tileId = ParamConfig.STRING("tile_straight");
/** @param rotation */
this.rotation = ParamConfig.INTEGER(1, {
range: [0, 3],
rangeLocked: [true, true]
});
/** @param iterations */
this.stepsCount = ParamConfig.INTEGER(-1, {
range: [-1, 1e3],
rangeLocked: [true, false]
});
/** @param max resolved quads */
// maxCount = ParamConfig.INTEGER(-1, {
// range: [-1, 1000],
// rangeLocked: [true, false],
// separatorAfter: true,
// });
/** @param quadSeed */
this.quadSeed = ParamConfig.INTEGER(0, {
range: [-100, 100],
rangeLocked: [false, false]
});
/** @param configSeed */
this.configSeed = ParamConfig.INTEGER(0, {
range: [-100, 100],
rangeLocked: [false, false]
});
}
}
const ParamsConfig = new WFCSolverUpdateSopParamsConfig();
export class WFCSolverUpdateSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "WFCSolverUpdate";
}
initializeNode() {
this.io.inputs.setCount(1);
this.io.inputs.initInputsClonedState([InputCloneMode.FROM_NODE]);
}
cook(inputCoreGroups) {
const coreGroup0 = inputCoreGroups[0];
const quadObjects = coreGroup0.quadObjects();
if (!quadObjects || quadObjects.length == 0) {
this.states.error.set("no quad objects found");
return;
}
for (const quadObject of quadObjects) {
const solver = getWFCSolver(quadObject);
if (!solver) {
this.states.error.set("no solver found");
return;
}
solver.addSoftContraint({
object: quadObject,
floorId: 0,
quadId: this.pv.quadId,
tileId: this.pv.tileId,
rotation: this.pv.rotation,
stepsCount: this.pv.stepsCount,
quadSeed: this.pv.quadSeed,
configSeed: this.pv.configSeed
});
}
this.setObjects(quadObjects);
}
}