UNPKG

@polygonjs/polygonjs

Version:

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

60 lines (59 loc) 1.61 kB
"use strict"; import { TypedSopNode } from "./_Base"; import { JSONDataParser } from "../../../core/loader/geometry/JSONDataParser"; const DEFAULT_DATA = [ { value: -40 }, { value: -30 }, { value: -20 }, { value: -10 }, { value: 0 }, { value: 10 }, { value: 20 }, { value: 30 }, { value: 40 }, { value: 50 }, { value: 60 }, { value: 70 }, { value: 80 } ]; const DEFAULT_DATA_STR = JSON.stringify(DEFAULT_DATA); import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { ObjectType } from "../../../core/geometry/Constant"; import { SopType } from "../../poly/registers/nodes/types/Sop"; class DataSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param json object used to create the geometry */ this.data = ParamConfig.STRING(DEFAULT_DATA_STR); } } const ParamsConfig = new DataSopParamsConfig(); export class DataSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.DATA; } cook() { let json = null; try { json = JSON.parse(this.pv.data); } catch (e) { this.states.error.set("could not parse json"); } if (json) { try { const loader = new JSONDataParser(); loader.setJSON(json); const geometry = loader.createObject(); this.setGeometry(geometry, ObjectType.POINTS); } catch (e) { this.states.error.set("could not build geometry from json"); } } else { this.cookController.endCook(); } } }