UNPKG

@polygonjs/polygonjs

Version:

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

33 lines (32 loc) 1.22 kB
"use strict"; import { LDrawLoader } from "three/examples/jsm/loaders/LDrawLoader"; import { BaseObject3DLoaderHandler } from "./_BaseLoaderHandler"; import { ThreejsCoreObject } from "../../geometry/modules/three/ThreejsCoreObject"; import { isString, isNumber, isArray } from "../../Type"; export class MPDLoaderHandler extends BaseObject3DLoaderHandler { async _getLoader() { return this._loader = this._loader || await new LDrawLoader(this.loadingManager); } _onLoadSuccess(o) { o.rotation.x = Math.PI; o.updateMatrix(); o.traverse((child) => { const attribNames = Object.keys(child.userData); for (const attribName of attribNames) { const value = child.userData[attribName]; if (value != null) { if (isString(value) || isNumber(value)) { ThreejsCoreObject.setAttribute(child, attribName, value); } else { if (isArray(value)) { const stringElements = value.filter((item) => isString(item)); const jointedStrings = stringElements.join(" "); ThreejsCoreObject.setAttribute(child, attribName, jointedStrings); } } } } }); return [o]; } }