UNPKG

polygonjs-engine

Version:

node-based webgl 3D engine https://polygonjs.com

63 lines (62 loc) 2.09 kB
import {TypedSopNode} from "./_Base"; import {FileType} from "../../params/utils/OptionsController"; import {NodeParamsConfig, ParamConfig} from "../utils/params/ParamsConfig"; import {ModuleName} from "../../poly/registers/modules/_BaseRegister"; import {SvgSopOperation} from "../../../core/operations/sop/Svg"; const DEFAULT = SvgSopOperation.DEFAULT_PARAMS; class SvgSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.url = ParamConfig.STRING(DEFAULT.url, { fileBrowse: {type: [FileType.GEOMETRY]} }); this.reload = ParamConfig.BUTTON(null, { callback: (node, param) => { SvgSopNode.PARAM_CALLBACK_reload(node); } }); this.drawFillShapes = ParamConfig.BOOLEAN(DEFAULT.drawFillShapes); this.fillShapesWireframe = ParamConfig.BOOLEAN(DEFAULT.fillShapesWireframe); this.drawStrokes = ParamConfig.BOOLEAN(DEFAULT.drawStrokes); this.strokesWireframe = ParamConfig.BOOLEAN(DEFAULT.strokesWireframe); } } const ParamsConfig2 = new SvgSopParamsConfig(); export class SvgSopNode extends TypedSopNode { constructor() { super(...arguments); this.params_config = ParamsConfig2; } static type() { return "svg"; } async requiredModules() { return [ModuleName.SVGLoader]; } initializeNode() { this.scene().dispatchController.onAddListener(() => { this.params.onParamsCreated("params_label", () => { this.params.label.init([this.p.url], () => { const url = this.pv.url; if (url) { const elements = url.split("/"); return elements[elements.length - 1]; } else { return ""; } }); }); }); } async cook(input_contents) { this._operation = this._operation || new SvgSopOperation(this.scene(), this.states); const core_group = await this._operation.cook(input_contents, this.pv); this.setCoreGroup(core_group); } static PARAM_CALLBACK_reload(node) { node.param_callback_reload(); } param_callback_reload() { this.p.url.setDirty(); } }