UNPKG

@polygonjs/polygonjs

Version:

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

48 lines (47 loc) 1.31 kB
"use strict"; import { BaseSopOperation } from "../../_Base"; import { Poly } from "../../../../Poly"; export class BaseFileSopOperation extends BaseSopOperation { async cook(inputCoreGroups, params) { if (this._node) { Poly.blobs.clearBlobsForNode(this._node); const loader = this._createGeoLoaderHandler(params); const result = await this._load(loader, params); if (result) { const processedObjects = this._onLoad(result, params); return this.createCoreGroupFromObjects(processedObjects); } } return this.createCoreGroupFromObjects([]); } async _load(loader, params) { if (this._node) { return await loader.load({ node: this._node }); } } _onLoad(objects, params) { for (let object of objects) { object.traverse((child) => { this._ensureGeometryHasIndex(child); if (!params.matrixAutoUpdate) { child.updateMatrix(); } child.matrixAutoUpdate = params.matrixAutoUpdate; }); } return objects; } _ensureGeometryHasIndex(object) { const mesh = object; const geometry = mesh.geometry; if (geometry) { this.createIndexIfNone(geometry); } } } BaseFileSopOperation.DEFAULT_PARAMS = { url: ``, matrixAutoUpdate: false };