@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
46 lines (45 loc) • 1.43 kB
JavaScript
;
import { BaseSopOperation } from "./_Base";
import { ASSETS_ROOT } from "../../../core/loader/AssetsUtils";
import { CoreSVGLoader } from "../../../core/loader/SVG";
import { SopTypeFile } from "../../poly/registers/nodes/types/Sop";
import { sanitizeUrl } from "../../../core/UrlHelper";
const DEFAULT_URL = sanitizeUrl(`${ASSETS_ROOT}/models/svg/tiger.svg`);
export class FileSVGSopOperation extends BaseSopOperation {
static type() {
return SopTypeFile.FILE_SVG;
}
async cook(input_contents, params) {
var _a;
const loader = new CoreSVGLoader(params.url, this._node);
try {
const group = await loader.load(params);
for (let child of group.children) {
this._ensureGeometryHasIndex(child);
}
return this.createCoreGroupFromObjects([...group.children]);
} catch (err) {
(_a = this.states) == null ? void 0 : _a.error.set(`fail to load SVG (${err.message})`);
return this.createCoreGroupFromObjects([]);
}
}
_ensureGeometryHasIndex(object) {
const mesh = object;
const geometry = mesh.geometry;
if (geometry) {
this.createIndexIfNone(geometry);
}
}
}
FileSVGSopOperation.DEFAULT_PARAMS = {
url: DEFAULT_URL,
drawFillShapes: true,
fillShapesWireframe: false,
drawStrokes: true,
strokesWireframe: false,
tStyleOverride: false,
strokeWidth: 1,
tadvanced: false,
isCCW: false
// noHoles: false,
};