UNPKG

@polygonjs/polygonjs

Version:

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

66 lines (65 loc) 2.23 kB
"use strict"; import { CADSopNode } from "./_BaseCAD"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { ParamEvent } from "../../poly/ParamEvent"; import { Poly } from "../../Poly"; import { EXTENSIONS_BY_NODE_TYPE_BY_CONTEXT } from "../../../core/loader/FileExtensionRegister"; import { NodeContext } from "../../poly/NodeContext"; import { STEPLoaderHandler } from "../../../core/loader/geometry/STEP"; class CADFileSTEPSopParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param url to load the geometry from */ this.url = ParamConfig.STRING("", { fileBrowse: { extensions: EXTENSIONS_BY_NODE_TYPE_BY_CONTEXT[NodeContext.SOP][SopType.CAD_FILE_STEP] } }); /** @param sets the matrixAutoUpdate attribute for the objects loaded */ this.matrixAutoUpdate = ParamConfig.BOOLEAN(0); /** @param reload the geometry */ this.reload = ParamConfig.BUTTON(null, { callback: (node) => { CADFileSTEPSopNode.PARAM_CALLBACK_reload(node); } }); } } const ParamsConfig = new CADFileSTEPSopParamsConfig(); export class CADFileSTEPSopNode extends CADSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopType.CAD_FILE_STEP; } dispose() { super.dispose(); Poly.blobs.clearBlobsForNode(this); } async cook(inputCoreGroups) { Poly.blobs.clearBlobsForNode(this); const loader = this._createGeoLoaderHandler(this.pv.url); const result = await loader.load({ node: this }); if (result) { const matrixAutoUpdate = this.pv.matrixAutoUpdate; for (const object of result) { object.traverse((child) => { child.matrixAutoUpdate = matrixAutoUpdate; }); } return this.setCADObjects(result); } return this.setCADObjects([]); } _createGeoLoaderHandler(url) { return new STEPLoaderHandler(url, this); } static PARAM_CALLBACK_reload(node) { node._paramCallbackReload(); } _paramCallbackReload() { this.p.url.setDirty(); this.p.url.emit(ParamEvent.ASSET_RELOAD_REQUEST); } }