1 line
58 KiB
Plaintext
1 line
58 KiB
Plaintext
|
|
{"version":3,"file":"3MFLoader.cjs","sources":["../../src/loaders/3MFLoader.js"],"sourcesContent":["import {\n BufferAttribute,\n BufferGeometry,\n ClampToEdgeWrapping,\n Color,\n FileLoader,\n Float32BufferAttribute,\n Group,\n LinearFilter,\n LinearMipmapLinearFilter,\n Loader,\n LoaderUtils,\n Matrix4,\n Mesh,\n MeshPhongMaterial,\n MeshStandardMaterial,\n MirroredRepeatWrapping,\n NearestFilter,\n RepeatWrapping,\n TextureLoader,\n} from 'three'\nimport { unzipSync } from 'fflate'\nimport { decodeText } from '../_polyfill/LoaderUtils'\n\n/**\n *\n * 3D Manufacturing Format (3MF) specification: https://3mf.io/specification/\n *\n * The following features from the core specification are supported:\n *\n * - 3D Models\n * - Object Resources (Meshes and Components)\n * - Material Resources (Base Materials)\n *\n * 3MF Materials and Properties Extension are only partially supported.\n *\n * - Texture 2D\n * - Texture 2D Groups\n * - Color Groups (Vertex Colors)\n * - Metallic Display Properties (PBR)\n */\n\nclass ThreeMFLoader extends Loader {\n constructor(manager) {\n super(manager)\n this.availableExtensions = []\n }\n\n load(url, onLoad, onProgress, onError) {\n const scope = this\n const loader = new FileLoader(scope.manager)\n loader.setPath(scope.path)\n loader.setResponseType('arraybuffer')\n loader.setRequestHeader(scope.requestHeader)\n loader.setWithCredentials(scope.withCredentials)\n loader.load(\n url,\n function (buffer) {\n try {\n onLoad(scope.parse(buffer))\n } catch (e) {\n if (onError) {\n onError(e)\n } else {\n console.error(e)\n }\n\n scope.manager.itemError(url)\n }\n },\n onProgress,\n onError,\n )\n }\n\n parse(data) {\n const scope = this\n const textureLoader = new TextureLoader(this.manager)\n\n function loadDocument(data) {\n let zip = null\n let file = null\n\n let relsName\n let modelRelsName\n const modelPartNames = []\n const printTicketPartNames = []\n const texturesPartNames = []\n const otherPartNames = []\n\n let modelRels\n const modelParts = {}\n const printTicketParts = {}\n const texturesParts = {}\n const otherParts = {}\n\n try {\n zip = unzipSync(new Uint8Array(data))\n } catch (e) {\n if (e instanceof ReferenceError) {\n console.error('THREE.3MFLoader: fflate missing and file is compressed.')\n return null\n }\n }\n\n for (file in zip) {\n if (file.match(/\\_rels\\/.rels$/)) {\n relsName = file\n } else if (file.match(/3D\\/_rels\\/.*\\.model\\.rels$/)) {\n modelRelsName = file\n } else if (file.match(/^3D\\/.*\\.model$/)) {\n modelPartNames.push(file)\n } else if (file.match(/^3D\\/Metadata\\/.*\\.xml$/)) {\n printTicketPartNames.push(file)\n } else if (file.match(/^3D\\/Textures?\\/.*/)) {\n texturesPartNames.push(file)\n } else if (file.match(/^3D\\/Other\\/.*/)) {\n otherPartNames.push(file)\n }\n }\n\n //\n\n const relsView = zip[relsName]\n const relsFileText = decodeText(relsView)\n const rels = parseRelsXml(relsFileText)\n\n //\n\n if (modelRelsName) {\n const relsView = zip[modelRelsName]\n const relsFileText = decodeText(relsView)\n modelRels = parseRelsXml(relsFileText)\n }\n\n //\n\n for (let i = 0; i < modelPartNames.length; i++) {\n const modelPart = modelPartNames[i]\n const view = zip[modelPart]\n\n const fileText = decodeText(view)\n const xmlData = new DOMParser().parseFromString(fileText, 'application/xml')\n\n if (xmlData.documentElement.nodeName.toLowerCase() !== 'model') {\n console.error('THREE.3MFLoader: Error loading 3MF - no 3MF document found: ', modelPart)\n }\n\n const modelNode = xmlData.querySelector('model')\n cons
|