UNPKG

@polygonjs/polygonjs

Version:

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

60 lines (59 loc) 2.16 kB
"use strict"; import { ParamEvent } from "./../../poly/ParamEvent"; import { TypedSopNode } from "./_Base"; import { FileGLTFSopOperation } from "../../operations/sop/FileGLTF"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { Poly } from "../../Poly"; import { SopTypeFile } from "../../poly/registers/nodes/types/Sop"; import { EXTENSIONS_BY_NODE_TYPE_BY_CONTEXT } from "../../../core/loader/FileExtensionRegister"; import { NodeContext } from "../../poly/NodeContext"; const DEFAULT = FileGLTFSopOperation.DEFAULT_PARAMS; class FileGLTFParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); /** @param url to load the geometry from */ this.url = ParamConfig.STRING(DEFAULT.url, { fileBrowse: { extensions: EXTENSIONS_BY_NODE_TYPE_BY_CONTEXT[NodeContext.SOP][SopTypeFile.FILE_GLTF] } }); /** @param uses draco compression */ this.draco = ParamConfig.BOOLEAN(DEFAULT.draco); /** @param uses ktx2 compression */ this.ktx2 = ParamConfig.BOOLEAN(DEFAULT.ktx2); /** @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) => { FileGLTFSopNode.PARAM_CALLBACK_reload(node); } }); } } const ParamsConfig = new FileGLTFParamsConfig(); export class FileGLTFSopNode extends TypedSopNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return SopTypeFile.FILE_GLTF; } dispose() { super.dispose(); Poly.blobs.clearBlobsForNode(this); } operation() { return this._operation = this._operation || new FileGLTFSopOperation(this.scene(), this.states, this); } async cook(inputCoreGroups) { const coreGroup = await this.operation().cook(inputCoreGroups, 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); } }