UNPKG

@polygonjs/polygonjs

Version:

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

75 lines (74 loc) 2.43 kB
"use strict"; import { ParamEvent } from "./../../../../poly/ParamEvent"; import { TypedSopNode } from "./../../_Base"; import { NodeParamsConfig, ParamConfig } from "../../../utils/params/ParamsConfig"; import { Poly } from "../../../../Poly"; import { BaseFileSopOperation } from "../../../../operations/sop/utils/File/_BaseFileOperation"; class BaseFileParamsConfigResult extends NodeParamsConfig { constructor() { super(...arguments); this.url = ParamConfig.STRING(""); this.matrixAutoUpdate = ParamConfig.BOOLEAN(0); this.reload = ParamConfig.BUTTON(null); } } export class FileDummySopOperation extends BaseFileSopOperation { static type() { return "fileDummy"; } _createGeoLoaderHandler(params) { return 0; } } export class BaseFileSopNodeFactoryResult extends TypedSopNode { } export function fileSopNodeFactory(options) { const DEFAULT = options.operation.DEFAULT_PARAMS; class BaseFileParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param url to load the geometry from */ this.url = ParamConfig.STRING(DEFAULT.url, { fileBrowse: { extensions: options.extensions } }); /** @param sets the matrixAutoUpdate attribute for the objects loaded */ this.matrixAutoUpdate = ParamConfig.BOOLEAN(DEFAULT.matrixAutoUpdate); /** @param reload the geometry */ this.reload = ParamConfig.BUTTON(null, { callback: (node) => { BaseFileSopNode.PARAM_CALLBACK_reload(node); } }); } } const ParamsConfig = new BaseFileParamsConfig(); class BaseFileSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return options.type; } dispose() { super.dispose(); Poly.blobs.clearBlobsForNode(this); } operation() { const operation = options.operation; return this._operation = this._operation || new operation(this.scene(), this.states, this); } async cook(inputContents) { const coreGroup = await this.operation().cook(inputContents, this.pv); this.setCoreGroup(coreGroup); } static PARAM_CALLBACK_reload(node) { node._paramCallbackReload(); } _paramCallbackReload() { this.p.url.setDirty(); this.p.url.emit(ParamEvent.ASSET_RELOAD_REQUEST); } } return BaseFileSopNode; }