three-stdlib 2.22.0 → 2.22.2
Sign up to get free protection for your applications and to get access to all the features.
- package/_polyfill/CompressedArrayTexture.cjs.js +1 -0
- package/_polyfill/CompressedArrayTexture.js +13 -0
- package/_polyfill/Data3DTexture.cjs.js +1 -0
- package/_polyfill/Data3DTexture.js +23 -0
- package/index.cjs.js +1 -1
- package/interactive/HTMLMesh.cjs.js +1 -1
- package/interactive/HTMLMesh.js +3 -2
- package/lights/LightProbeGenerator.cjs.js +1 -1
- package/lights/LightProbeGenerator.js +19 -20
- package/loaders/3MFLoader.cjs.js +1 -1
- package/loaders/3MFLoader.js +3 -2
- package/loaders/EXRLoader.cjs.js +1 -1
- package/loaders/EXRLoader.js +4 -4
- package/loaders/FBXLoader.cjs.js +1 -1
- package/loaders/FBXLoader.js +5 -5
- package/loaders/GLTFLoader.cjs.js +1 -1
- package/loaders/GLTFLoader.js +7 -6
- package/loaders/HDRCubeTextureLoader.cjs.js +1 -1
- package/loaders/HDRCubeTextureLoader.js +3 -8
- package/loaders/KTX2Loader.cjs.js +1 -1
- package/loaders/KTX2Loader.js +12 -16
- package/loaders/LUT3dlLoader.cjs.js +1 -1
- package/loaders/LUT3dlLoader.js +2 -1
- package/loaders/LUTCubeLoader.cjs.js +1 -1
- package/loaders/LUTCubeLoader.js +2 -1
- package/loaders/NodeMaterialLoader.cjs.js +1 -1
- package/loaders/RGBELoader.cjs.js +1 -1
- package/loaders/RGBELoader.js +3 -2
- package/loaders/VOXLoader.cjs.js +1 -1
- package/loaders/VOXLoader.js +2 -1
- package/misc/MD2Character.cjs.js +1 -1
- package/misc/MD2Character.js +2 -2
- package/misc/MD2CharacterComplex.cjs.js +1 -1
- package/misc/MD2CharacterComplex.js +2 -2
- package/nodes/Nodes.cjs.js +1 -1
- package/nodes/core/NodeBuilder.cjs.js +1 -1
- package/nodes/core/NodeBuilder.js +4 -4
- package/nodes/display/ColorSpaceNode.cjs.js +1 -1
- package/nodes/display/ColorSpaceNode.js +2 -3
- package/nodes/loaders/NodeLoader.cjs.js +1 -1
- package/nodes/loaders/NodeObjectLoader.cjs.js +1 -1
- package/objects/Reflector.cjs.js +1 -1
- package/objects/Reflector.js +1 -1
- package/objects/ReflectorForSSRPass.cjs.js +1 -1
- package/objects/ReflectorForSSRPass.js +1 -1
- package/objects/Refractor.cjs.js +1 -1
- package/objects/Refractor.js +1 -1
- package/objects/Water2.cjs.js +1 -1
- package/objects/Water2.js +2 -2
- package/package.json +1 -1
- package/postprocessing/SSRPass.cjs.js +1 -1
- package/postprocessing/SSRPass.js +8 -1
- package/renderers/webgpu/WebGPUTextures.cjs.js +1 -1
- package/renderers/webgpu/WebGPUTextures.js +6 -6
- /package/{Nodes-9aa16d74.js → Nodes-8d3adda1.js} +0 -0
- /package/{Nodes-4f766d71.js → Nodes-b3c0e6fc.js} +0 -0
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Mesh{constructor(t){const
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Mesh{constructor(t){const n=new o(t),s=new e.PlaneGeometry(.001*n.image.width,.001*n.image.height),r=new e.MeshBasicMaterial({map:n,toneMapped:!1,transparent:!0});function l(e){r.map.dispatchDOMEvent(e)}super(s,r),this.addEventListener("mousedown",l),this.addEventListener("mousemove",l),this.addEventListener("mouseup",l),this.addEventListener("click",l),this.dispose=function(){s.dispose(),r.dispose(),r.map.dispose(),i.delete(t),this.removeEventListener("mousedown",l),this.removeEventListener("mousemove",l),this.removeEventListener("mouseup",l),this.removeEventListener("click",l)}}}class o extends e.CanvasTexture{constructor(t){super(n(t)),this.dom=t,this.anisotropy=16,"colorSpace"in this?this.colorSpace="srgb":this.encoding=3001,this.minFilter=e.LinearFilter,this.magFilter=e.LinearFilter;const o=new MutationObserver((()=>{this.scheduleUpdate||(this.scheduleUpdate=setTimeout((()=>this.update()),16))}));o.observe(t,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),this.observer=o}dispatchDOMEvent(e){e.data&&function(e,t,o,i){const n={clientX:o*e.offsetWidth+e.offsetLeft,clientY:i*e.offsetHeight+e.offsetTop,view:e.ownerDocument.defaultView};window.dispatchEvent(new MouseEvent(t,n));const s=e.getBoundingClientRect();function r(e){if(e.nodeType!==Node.TEXT_NODE&&e.nodeType!==Node.COMMENT_NODE){const s=e.getBoundingClientRect();if(o>s.left&&o<s.right&&i>s.top&&i<s.bottom&&(e.dispatchEvent(new MouseEvent(t,n)),e instanceof HTMLInputElement&&"range"===e.type&&("mousedown"===t||"click"===t))){const[t,i]=["min","max"].map((t=>parseFloat(e[t]))),n=s.width,r=(o-s.x)/n;e.value=t+(i-t)*r,e.dispatchEvent(new InputEvent("input",{bubbles:!0}))}for(let t=0;t<e.childNodes.length;t++)r(e.childNodes[t])}}o=o*s.width+s.left,i=i*s.height+s.top,r(e)}(this.dom,e.type,e.data.x,e.data.y)}update(){this.image=n(this.dom),this.needsUpdate=!0,this.scheduleUpdate=null}dispose(){this.observer&&this.observer.disconnect(),this.scheduleUpdate=clearTimeout(this.scheduleUpdate),super.dispose()}}const i=new WeakMap;function n(t){const o=document.createRange(),n=new e.Color;function s(e,t,o,i){""!==i&&("uppercase"===e.textTransform&&(i=i.toUpperCase()),c.font=e.fontWeight+" "+e.fontSize+" "+e.fontFamily,c.textBaseline="top",c.fillStyle=e.color,c.fillText(i,t,o+.1*parseFloat(e.fontSize)))}function r(e,t,o,i,n){o<2*n&&(n=o/2),i<2*n&&(n=i/2),c.beginPath(),c.moveTo(e+n,t),c.arcTo(e+o,t,e+o,t+i,n),c.arcTo(e+o,t+i,e,t+i,n),c.arcTo(e,t+i,e,t,n),c.arcTo(e,t,e+o,t,n),c.closePath()}function l(e,t,o,i,n,s){const r=e[t+"Width"],l=e[t+"Style"],d=e[t+"Color"];"0px"!==r&&"none"!==l&&"transparent"!==d&&"rgba(0, 0, 0, 0)"!==d&&(c.strokeStyle=d,c.lineWidth=parseFloat(r),c.beginPath(),c.moveTo(o,i),c.lineTo(o+n,i+s),c.stroke())}const d=t.getBoundingClientRect();let a=i.get(t);void 0===a&&(a=document.createElement("canvas"),a.width=d.width,a.height=d.height,i.set(t,a));const c=a.getContext("2d"),h=new function(e){const t=[];let o=!1;function i(){if(o&&(o=!1,e.restore()),0===t.length)return;let i=-1/0,n=-1/0,s=1/0,r=1/0;for(let e=0;e<t.length;e++){const o=t[e];i=Math.max(i,o.x),n=Math.max(n,o.y),s=Math.min(s,o.x+o.width),r=Math.min(r,o.y+o.height)}e.save(),e.beginPath(),e.rect(i,n,s-i,r-n),e.clip(),o=!0}return{add:function(e){t.push(e),i()},remove:function(){t.pop(),i()}}}(c);return function e(t,i){let a=0,p=0,f=0,u=0;if(t.nodeType===Node.TEXT_NODE){o.selectNode(t);const e=o.getBoundingClientRect();a=e.left-d.left-.5,p=e.top-d.top-.5,f=e.width,u=e.height,s(i,a,p,t.nodeValue.trim())}else{if(t.nodeType===Node.COMMENT_NODE)return;if(t instanceof HTMLCanvasElement){if("none"===t.style.display)return;c.save();const e=window.devicePixelRatio;c.scale(1/e,1/e),c.drawImage(t,0,0),c.restore()}else{if("none"===t.style.display)return;const e=t.getBoundingClientRect();a=e.left-d.left-.5,p=e.top-d.top-.5,f=e.width,u=e.height,i=window.getComputedStyle(t),r(a,p,f,u,parseFloat(i.borderRadius));const o=i.backgroundColor;"transparent"!==o&&"rgba(0, 0, 0, 0)"!==o&&(c.fillStyle=o,c.fill());const m=["borderTop","borderLeft","borderBottom","borderRight"];let g=!0,v=null;for(const e of m){if(null!==v&&(g=i[e+"Width"]===i[v+"Width"]&&i[e+"Color"]===i[v+"Color"]&&i[e+"Style"]===i[v+"Style"]),!1===g)break;v=e}if(!0===g){const e=parseFloat(i.borderTopWidth);"0px"!==i.borderTopWidth&&"none"!==i.borderTopStyle&&"transparent"!==i.borderTopColor&&"rgba(0, 0, 0, 0)"!==i.borderTopColor&&(c.strokeStyle=i.borderTopColor,c.lineWidth=e,c.stroke())}else l(i,"borderTop",a,p,f,0),l(i,"borderLeft",a,p,0,u),l(i,"borderBottom",a,p+u,f,0),l(i,"borderRight",a+f,p,0,u);if(t instanceof HTMLInputElement){let e=i.accentColor;void 0!==e&&"auto"!==e||(e=i.color),n.set(e);const o=Math.sqrt(.299*n.r**2+.587*n.g**2+.114*n.b**2)<.5?"white":"#111111";if("radio"===t.type&&(r(a,p,f,u,u),c.fillStyle="white",c.strokeStyle=e,c.lineWidth=1,c.fill(),c.stroke(),t.checked&&(r(a+2,p+2,f-4,u-4,u),c.fillStyle=e,c.strokeStyle=o,c.lineWidth=2,c.fill(),c.stroke())),"checkbox"===t.type&&(r(a,p,f,u,2),c.fillStyle=t.checked?e:"white",c.strokeStyle=t.checked?o:e,c.lineWidth=1,c.stroke(),c.fill(),t.checked)){const e=c.textAlign;c.textAlign="center";s({color:o,fontFamily:i.fontFamily,fontSize:u+"px",fontWeight:"bold"},a+f/2,p,"✔"),c.textAlign=e}if("range"===t.type){const[i,n,s]=["min","max","value"].map((e=>parseFloat(t[e]))),l=(s-i)/(n-i)*(f-u);r(a,p+u/4,f,u/2,u/4),c.fillStyle=o,c.strokeStyle=e,c.lineWidth=1,c.fill(),c.stroke(),r(a,p+u/4,l+u/2,u/2,u/4),c.fillStyle=e,c.fill(),r(a+l,p,u,u,u/2),c.fillStyle=e,c.fill()}"color"!==t.type&&"text"!==t.type&&"number"!==t.type||(h.add({x:a,y:p,width:f,height:u}),s(i,a+parseInt(i.paddingLeft),p+parseInt(i.paddingTop),t.value),h.remove())}}}const m="auto"===i.overflow||"hidden"===i.overflow;m&&h.add({x:a,y:p,width:f,height:u});for(let o=0;o<t.childNodes.length;o++)e(t.childNodes[o],i);m&&h.remove()}(t),a}exports.HTMLMesh=t;
|
package/interactive/HTMLMesh.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Mesh, PlaneGeometry, MeshBasicMaterial, CanvasTexture,
|
1
|
+
import { Mesh, PlaneGeometry, MeshBasicMaterial, CanvasTexture, LinearFilter, Color } from 'three';
|
2
2
|
|
3
3
|
class HTMLMesh extends Mesh {
|
4
4
|
constructor(dom) {
|
@@ -39,7 +39,8 @@ class HTMLTexture extends CanvasTexture {
|
|
39
39
|
super(html2canvas(dom));
|
40
40
|
this.dom = dom;
|
41
41
|
this.anisotropy = 16;
|
42
|
-
this.encoding = sRGBEncoding
|
42
|
+
if ('colorSpace' in this) this.colorSpace = 'srgb';else this.encoding = 3001; // sRGBEncoding
|
43
|
+
|
43
44
|
this.minFilter = LinearFilter;
|
44
45
|
this.magFilter = LinearFilter; // Create an observer on the DOM, and run html2canvas update in the next loop
|
45
46
|
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r={fromCubeTexture:function(r){var a,
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r={fromCubeTexture:function(r){var t,a,o,c=0,n=new e.Vector3,s=new e.Vector3,i=new e.Color,l=[0,0,0,0,0,0,0,0,0],h=new e.SphericalHarmonics3,g=h.coefficients;for(let t=0;t<6;t++){var b=r.image[t],f=b.width,w=b.height,v=document.createElement("canvas");v.width=f,v.height=w;var d=v.getContext("2d");d.drawImage(b,0,0,f,w);var u=d.getImageData(0,0,f,w),S=u.data,m=u.width,p=2/m;for(let h=0,b=S.length;h<b;h+=4){i.setRGB(S[h]/255,S[h+1]/255,S[h+2]/255),"colorSpace"in r?"srgb"===r.colorSpace&&i.convertSRGBToLinear():3001===r.encoding&&i.convertSRGBToLinear();var x=h/4,k=(x%m+.5)*p-1,y=1-(Math.floor(x/m)+.5)*p;switch(t){case 0:n.set(-1,y,-k);break;case 1:n.set(1,y,k);break;case 2:n.set(-k,1,-y);break;case 3:n.set(-k,-1,y);break;case 4:n.set(-k,y,1);break;case 5:n.set(k,y,-1)}a=n.lengthSq(),c+=o=4/(Math.sqrt(a)*a),s.copy(n).normalize(),e.SphericalHarmonics3.getBasisAt(s,l);for(let e=0;e<9;e++)g[e].x+=l[e]*i.r*o,g[e].y+=l[e]*i.g*o,g[e].z+=l[e]*i.b*o}}t=4*Math.PI/c;for(let e=0;e<9;e++)g[e].x*=t,g[e].y*=t,g[e].z*=t;return new e.LightProbe(h)},fromCubeRenderTarget:function(r,t){var a,o,c,n=0,s=new e.Vector3,i=new e.Vector3,l=new e.Color,h=[0,0,0,0,0,0,0,0,0],g=new e.SphericalHarmonics3,b=g.coefficients;for(let a=0;a<6;a++){var f=t.width,w=new Uint8Array(f*f*4);r.readRenderTargetPixels(t,0,0,f,f,w,a);var v=2/f;for(let r=0,g=w.length;r<g;r+=4){l.setRGB(w[r]/255,w[r+1]/255,w[r+2]/255),"colorSpace"in t.texture?"srgb"===t.texture.colorSpace&&l.convertSRGBToLinear():3001===t.texture.encoding&&l.convertSRGBToLinear();var d=r/4,u=(d%f+.5)*v-1,S=1-(Math.floor(d/f)+.5)*v;switch(a){case 0:s.set(1,S,-u);break;case 1:s.set(-1,S,u);break;case 2:s.set(u,1,-S);break;case 3:s.set(u,-1,S);break;case 4:s.set(u,S,1);break;case 5:s.set(-u,S,-1)}o=s.lengthSq(),n+=c=4/(Math.sqrt(o)*o),i.copy(s).normalize(),e.SphericalHarmonics3.getBasisAt(i,h);for(let e=0;e<9;e++)b[e].x+=h[e]*l.r*c,b[e].y+=h[e]*l.g*c,b[e].z+=h[e]*l.b*c}}a=4*Math.PI/n;for(let e=0;e<9;e++)b[e].x*=a,b[e].y*=a,b[e].z*=a;return new e.LightProbe(g)}};exports.LightProbeGenerator=r;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Vector3, Color, SphericalHarmonics3, LightProbe
|
1
|
+
import { Vector3, Color, SphericalHarmonics3, LightProbe } from 'three';
|
2
2
|
|
3
3
|
var LightProbeGenerator = {
|
4
4
|
// https://www.ppsloan.org/publications/StupidSH36.pdf
|
@@ -34,7 +34,15 @@ var LightProbeGenerator = {
|
|
34
34
|
// pixel color
|
35
35
|
color.setRGB(data[i] / 255, data[i + 1] / 255, data[i + 2] / 255); // convert to linear color space
|
36
36
|
|
37
|
-
|
37
|
+
if ('colorSpace' in cubeTexture) {
|
38
|
+
if (cubeTexture.colorSpace === 'srgb') {
|
39
|
+
color.convertSRGBToLinear();
|
40
|
+
}
|
41
|
+
} else if (cubeTexture.encoding === 3001) {
|
42
|
+
// sRGBEncoding
|
43
|
+
color.convertSRGBToLinear();
|
44
|
+
} // pixel coordinate on unit cube
|
45
|
+
|
38
46
|
|
39
47
|
var pixelIndex = i / 4;
|
40
48
|
var col = -1 + (pixelIndex % imageWidth + 0.5) * pixelSize;
|
@@ -119,7 +127,15 @@ var LightProbeGenerator = {
|
|
119
127
|
// pixel color
|
120
128
|
color.setRGB(data[i] / 255, data[i + 1] / 255, data[i + 2] / 255); // convert to linear color space
|
121
129
|
|
122
|
-
|
130
|
+
if ('colorSpace' in cubeRenderTarget.texture) {
|
131
|
+
if (cubeRenderTarget.texture.colorSpace === 'srgb') {
|
132
|
+
color.convertSRGBToLinear();
|
133
|
+
}
|
134
|
+
} else if (cubeRenderTarget.texture.encoding === 3001) {
|
135
|
+
// sRGBEncoding
|
136
|
+
color.convertSRGBToLinear();
|
137
|
+
} // pixel coordinate on unit cube
|
138
|
+
|
123
139
|
|
124
140
|
var pixelIndex = i / 4;
|
125
141
|
var col = -1 + (pixelIndex % imageWidth + 0.5) * pixelSize;
|
@@ -181,21 +197,4 @@ var LightProbeGenerator = {
|
|
181
197
|
}
|
182
198
|
};
|
183
199
|
|
184
|
-
var convertColorToLinear = function (color, encoding) {
|
185
|
-
switch (encoding) {
|
186
|
-
case sRGBEncoding:
|
187
|
-
color.convertSRGBToLinear();
|
188
|
-
break;
|
189
|
-
|
190
|
-
case LinearEncoding:
|
191
|
-
break;
|
192
|
-
|
193
|
-
default:
|
194
|
-
console.warn('WARNING: LightProbeGenerator convertColorToLinear() encountered an unsupported encoding.');
|
195
|
-
break;
|
196
|
-
}
|
197
|
-
|
198
|
-
return color;
|
199
|
-
};
|
200
|
-
|
201
200
|
export { LightProbeGenerator };
|
package/loaders/3MFLoader.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("fflate");class r extends e.Loader{constructor(e){super(e),this.availableExtensions=[]}load(t,r,n,o){const s=this,i=new e.FileLoader(s.manager);i.setPath(s.path),i.setResponseType("arraybuffer"),i.setRequestHeader(s.requestHeader),i.setWithCredentials(s.withCredentials),i.load(t,(function(e){try{r(s.parse(e))}catch(e){o?o(e):console.error(e),s.manager.itemError(t)}}),n,o)}parse(r){const n=this,o=new e.TextureLoader(this.manager);function s(e){const t=[],r=(new DOMParser).parseFromString(e,"application/xml").querySelectorAll("Relationship");for(let e=0;e<r.length;e++){const n=r[e],o={target:n.getAttribute("Target"),id:n.getAttribute("Id"),type:n.getAttribute("Type")};t.push(o)}return t}function i(e){const t={id:e.getAttribute("id"),basematerials:[]},r=e.querySelectorAll("base");for(let e=0;e<r.length;e++){const n=c(r[e]);n.index=e,t.basematerials.push(n)}return t}function l(e){const t={id:e.getAttribute("id"),texid:e.getAttribute("texid"),displaypropertiesid:e.getAttribute("displaypropertiesid")},r=e.querySelectorAll("tex2coord"),n=[];for(let e=0;e<r.length;e++){const t=r[e],o=t.getAttribute("u"),s=t.getAttribute("v");n.push(parseFloat(o),parseFloat(s))}return t.uvs=new Float32Array(n),t}function a(t){const r={id:t.getAttribute("id"),displaypropertiesid:t.getAttribute("displaypropertiesid")},n=t.querySelectorAll("color"),o=[],s=new e.Color;for(let e=0;e<n.length;e++){const t=n[e].getAttribute("color");s.setStyle(t.substring(0,7)),s.convertSRGBToLinear(),o.push(s.r,s.g,s.b)}return r.colors=new Float32Array(o),r}function u(e){const t={id:e.getAttribute("id")},r=e.querySelectorAll("pbmetallic"),n=[];for(let e=0;e<r.length;e++){const t=r[e];n.push({name:t.getAttribute("name"),metallicness:parseFloat(t.getAttribute("metallicness")),roughness:parseFloat(t.getAttribute("roughness"))})}return t.data=n,t}function c(e){const t={};return t.name=e.getAttribute("name"),t.displaycolor=e.getAttribute("displaycolor"),t.displaypropertiesid=e.getAttribute("displaypropertiesid"),t}function p(e){const t={};t.objectId=e.getAttribute("objectid");const r=e.getAttribute("transform");return r&&(t.transform=d(r)),t}function d(t){const r=[];t.split(" ").forEach((function(e){r.push(parseFloat(e))}));const n=new e.Matrix4;return n.set(r[0],r[3],r[6],r[9],r[1],r[4],r[7],r[10],r[2],r[5],r[8],r[11],0,0,0,1),n}function h(e){const t={type:e.getAttribute("type")},r=e.getAttribute("id");r&&(t.id=r);const n=e.getAttribute("pid");n&&(t.pid=n);const o=e.getAttribute("pindex");o&&(t.pindex=o);const s=e.getAttribute("thumbnail");s&&(t.thumbnail=s);const i=e.getAttribute("partnumber");i&&(t.partnumber=i);const l=e.getAttribute("name");l&&(t.name=l);const a=e.querySelector("mesh");a&&(t.mesh=function(e){const t={},r=[],n=e.querySelectorAll("vertices vertex");for(let e=0;e<n.length;e++){const t=n[e],o=t.getAttribute("x"),s=t.getAttribute("y"),i=t.getAttribute("z");r.push(parseFloat(o),parseFloat(s),parseFloat(i))}t.vertices=new Float32Array(r);const o=[],s=[],i=e.querySelectorAll("triangles triangle");for(let e=0;e<i.length;e++){const t=i[e],r=t.getAttribute("v1"),n=t.getAttribute("v2"),l=t.getAttribute("v3"),a=t.getAttribute("p1"),u=t.getAttribute("p2"),c=t.getAttribute("p3"),p=t.getAttribute("pid"),d={};d.v1=parseInt(r,10),d.v2=parseInt(n,10),d.v3=parseInt(l,10),s.push(d.v1,d.v2,d.v3),a&&(d.p1=parseInt(a,10)),u&&(d.p2=parseInt(u,10)),c&&(d.p3=parseInt(c,10)),p&&(d.pid=p),0<Object.keys(d).length&&o.push(d)}return t.triangleProperties=o,t.triangles=new Uint32Array(s),t}(a));const u=e.querySelector("components");return u&&(t.components=function(e){const t=[],r=e.querySelectorAll("component");for(let e=0;e<r.length;e++){const n=p(r[e]);t.push(n)}return t}(u)),t}function g(e){const t={unit:e.getAttribute("unit")||"millimeter"},r=e.querySelectorAll("metadata");r&&(t.metadata=function(e){const t={};for(let r=0;r<e.length;r++){const n=e[r],o=n.getAttribute("name");0<=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate"].indexOf(o)&&(t[o]=n.textContent)}return t}(r));const n=e.querySelector("resources");n&&(t.resources=function(e){const t={basematerials:{}},r=e.querySelectorAll("basematerials");for(let e=0;e<r.length;e++){const n=i(r[e]);t.basematerials[n.id]=n}t.texture2d={};const n=e.querySelectorAll("texture2d");for(let e=0;e<n.length;e++){const r={id:(o=n[e]).getAttribute("id"),path:o.getAttribute("path"),contenttype:o.getAttribute("contenttype"),tilestyleu:o.getAttribute("tilestyleu"),tilestylev:o.getAttribute("tilestylev"),filter:o.getAttribute("filter")};t.texture2d[r.id]=r}var o;t.colorgroup={};const s=e.querySelectorAll("colorgroup");for(let e=0;e<s.length;e++){const r=a(s[e]);t.colorgroup[r.id]=r}t.pbmetallicdisplayproperties={};const c=e.querySelectorAll("pbmetallicdisplayproperties");for(let e=0;e<c.length;e++){const r=u(c[e]);t.pbmetallicdisplayproperties[r.id]=r}t.texture2dgroup={};const p=e.querySelectorAll("texture2dgroup");for(let e=0;e<p.length;e++){const r=l(p[e]);t.texture2dgroup[r.id]=r}t.object={};const d=e.querySelectorAll("object");for(let e=0;e<d.length;e++){const r=h(d[e]);t.object[r.id]=r}return t}(n));const o=e.querySelector("build");return o&&(t.build=function(e){const t=[],r=e.querySelectorAll("item");for(let e=0;e<r.length;e++){const n=r[e],o={objectId:n.getAttribute("objectid")},s=n.getAttribute("transform");s&&(o.transform=d(s)),t.push(o)}return t}(o)),t}function f(t,r,n,s){const i=t.texid,l=n.resources.texture2d[i];if(l){const t=s[l.path],r=l.contenttype,n=new Blob([t],{type:r}),i=URL.createObjectURL(n),a=o.load(i,(function(){URL.revokeObjectURL(i)}));switch(a.encoding=e.sRGBEncoding,l.tilestyleu){case"wrap":a.wrapS=e.RepeatWrapping;break;case"mirror":a.wrapS=e.MirroredRepeatWrapping;break;case"none":case"clamp":a.wrapS=e.ClampToEdgeWrapping;break;default:a.wrapS=e.RepeatWrapping}switch(l.tilestylev){case"wrap":a.wrapT=e.RepeatWrapping;break;case"mirror":a.wrapT=e.MirroredRepeatWrapping;break;case"none":case"clamp":a.wrapT=e.ClampToEdgeWrapping;break;default:a.wrapT=e.RepeatWrapping}switch(l.filter){case"auto":a.magFilter=e.LinearFilter,a.minFilter=e.LinearMipmapLinearFilter;break;case"linear":a.magFilter=e.LinearFilter,a.minFilter=e.LinearFilter;break;case"nearest":a.magFilter=e.NearestFilter,a.minFilter=e.NearestFilter;break;default:a.magFilter=e.LinearFilter,a.minFilter=e.LinearMipmapLinearFilter}return a}return null}function b(t,r,n,o,s,i,l){const a=l.pindex,u={};for(let e=0,t=r.length;e<t;e++){const t=r[e],n=void 0!==t.p1?t.p1:a;void 0===u[n]&&(u[n]=[]),u[n].push(t)}const c=Object.keys(u),p=[];for(let r=0,a=c.length;r<a;r++){const a=c[r],d=u[a],h=w(t.basematerials[a],o,s,i,l,F),g=new e.BufferGeometry,f=[],b=n.vertices;for(let e=0,t=d.length;e<t;e++){const t=d[e];f.push(b[3*t.v1+0]),f.push(b[3*t.v1+1]),f.push(b[3*t.v1+2]),f.push(b[3*t.v2+0]),f.push(b[3*t.v2+1]),f.push(b[3*t.v2+2]),f.push(b[3*t.v3+0]),f.push(b[3*t.v3+1]),f.push(b[3*t.v3+2])}g.setAttribute("position",new e.Float32BufferAttribute(f,3));const m=new e.Mesh(g,h);p.push(m)}return p}function m(t,r,n,o,s,i,l){const a=new e.BufferGeometry,u=[],c=[],p=n.vertices,d=t.uvs;for(let e=0,t=r.length;e<t;e++){const t=r[e];u.push(p[3*t.v1+0]),u.push(p[3*t.v1+1]),u.push(p[3*t.v1+2]),u.push(p[3*t.v2+0]),u.push(p[3*t.v2+1]),u.push(p[3*t.v2+2]),u.push(p[3*t.v3+0]),u.push(p[3*t.v3+1]),u.push(p[3*t.v3+2]),c.push(d[2*t.p1+0]),c.push(d[2*t.p1+1]),c.push(d[2*t.p2+0]),c.push(d[2*t.p2+1]),c.push(d[2*t.p3+0]),c.push(d[2*t.p3+1])}a.setAttribute("position",new e.Float32BufferAttribute(u,3)),a.setAttribute("uv",new e.Float32BufferAttribute(c,2));const h=w(t,o,s,i,l,f),g=new e.MeshPhongMaterial({map:h,flatShading:!0});return new e.Mesh(a,g)}function A(t,r,n,o,s,i){const l=new e.BufferGeometry,a=[],u=[],c=n.vertices,p=t.colors;for(let e=0,t=r.length;e<t;e++){const t=r[e],n=t.v1,o=t.v2,s=t.v3;a.push(c[3*n+0]),a.push(c[3*n+1]),a.push(c[3*n+2]),a.push(c[3*o+0]),a.push(c[3*o+1]),a.push(c[3*o+2]),a.push(c[3*s+0]),a.push(c[3*s+1]),a.push(c[3*s+2]);const l=void 0!==t.p1?t.p1:i.pindex,d=void 0!==t.p2?t.p2:l,h=void 0!==t.p3?t.p3:l;u.push(p[3*l+0]),u.push(p[3*l+1]),u.push(p[3*l+2]),u.push(p[3*d+0]),u.push(p[3*d+1]),u.push(p[3*d+2]),u.push(p[3*h+0]),u.push(p[3*h+1]),u.push(p[3*h+2])}l.setAttribute("position",new e.Float32BufferAttribute(a,3)),l.setAttribute("color",new e.Float32BufferAttribute(u,3));const d=new e.MeshPhongMaterial({vertexColors:!0,flatShading:!0});return new e.Mesh(l,d)}function y(t){const r=new e.BufferGeometry;r.setIndex(new e.BufferAttribute(t.triangles,1)),r.setAttribute("position",new e.BufferAttribute(t.vertices,3));const n=new e.MeshPhongMaterial({color:11184895,flatShading:!0});return new e.Mesh(r,n)}function v(e,t){return void 0!==t.resources.texture2dgroup[e]?"texture":void 0!==t.resources.basematerials[e]?"material":void 0!==t.resources.colorgroup[e]?"vertexColors":"default"===e?"default":void 0}function x(t,r,n,o,s){const i=new e.Group,l=function(e,t,r,n,o,s){const i=Object.keys(e),l=[];for(let a=0,u=i.length;a<u;a++){const u=i[a],c=e[u];switch(v(u,n)){case"material":const e=b(n.resources.basematerials[u],c,t,r,n,o,s);for(let t=0,r=e.length;t<r;t++)l.push(e[t]);break;case"texture":const i=n.resources.texture2dgroup[u];l.push(m(i,c,t,r,n,o,s));break;case"vertexColors":const a=n.resources.colorgroup[u];l.push(A(a,c,t,0,0,s));break;case"default":l.push(y(t));break;default:console.error("THREE.3MFLoader: Unsupported resource type.")}}return l}(function(e,t,r){const n={},o=t.triangleProperties,s=r.pid;for(let e=0,t=o.length;e<t;e++){const t=o[e];let r=void 0!==t.pid?t.pid:s;void 0===r&&(r="default"),void 0===n[r]&&(n[r]=[]),n[r].push(t)}return n}(0,t,s),t,r,n,o,s);for(let e=0,t=l.length;e<t;e++)i.add(l[e]);return i}function w(e,t,r,n,o,s){return void 0!==e.build||(e.build=s(e,t,r,n,o)),e.build}function F(t,r,n){let o;const s=t.displaypropertiesid,i=n.resources.pbmetallicdisplayproperties;if(null!==s&&void 0!==i[s]){const r=i[s].data[t.index];o=new e.MeshStandardMaterial({flatShading:!0,roughness:r.roughness,metalness:r.metallicness})}else o=new e.MeshPhongMaterial({flatShading:!0});o.name=t.name;const l=t.displaycolor,a=l.substring(0,7);return o.color.setStyle(a),o.color.convertSRGBToLinear(),9===l.length&&(o.opacity=parseInt(l.charAt(7)+l.charAt(8),16)/255),o}function S(t,r,n,o){const s=new e.Group;for(let e=0;e<t.length;e++){const i=t[e];let l=r[i.objectId];void 0===l&&(M(i.objectId,r,n,o),l=r[i.objectId]);const a=l.clone(),u=i.transform;u&&a.applyMatrix4(u),s.add(a)}return s}function M(e,t,r,o){const s=r.resources.object[e];if(s.mesh){const e=s.mesh;!function(e,t,r){if(!e)return;const o=[],s=Object.keys(e);for(let e=0;e<s.length;e++){const t=s[e];for(let e=0;e<n.availableExtensions.length;e++){const r=n.availableExtensions[e];r.ns===t&&o.push(r)}}for(let n=0;n<o.length;n++){const s=o[n];s.apply(r,e[s.ns],t)}}(r.extensions,e,r.xml),t[s.id]=w(e,t,r,o,s,x)}else{const e=s.components;t[s.id]=w(e,t,r,o,s,S)}}const L=function(r){let n,o,i=null,l=null;const a=[],u=[];let c;const p={},d={};try{i=t.unzipSync(new Uint8Array(r))}catch(e){if(e instanceof ReferenceError)return console.error("THREE.3MFLoader: fflate missing and file is compressed."),null}for(l in i)l.match(/\_rels\/.rels$/)?n=l:l.match(/3D\/_rels\/.*\.model\.rels$/)?o=l:l.match(/^3D\/.*\.model$/)?a.push(l):l.match(/^3D\/Metadata\/.*\.xml$/)||(l.match(/^3D\/Textures?\/.*/)?u.push(l):l.match(/^3D\/Other\/.*/));const h=i[n],f=s(e.LoaderUtils.decodeText(h));if(o){const t=i[o];c=s(e.LoaderUtils.decodeText(t))}for(let t=0;t<a.length;t++){const r=a[t],n=i[r],o=e.LoaderUtils.decodeText(n),s=(new DOMParser).parseFromString(o,"application/xml");"model"!==s.documentElement.nodeName.toLowerCase()&&console.error("THREE.3MFLoader: Error loading 3MF - no 3MF document found: ",r);const l=s.querySelector("model"),u={};for(let e=0;e<l.attributes.length;e++){const t=l.attributes[e];t.name.match(/^xmlns:(.+)$/)&&(u[t.value]=RegExp.$1)}const c=g(l);c.xml=l,0<Object.keys(u).length&&(c.extensions=u),p[r]=c}for(let e=0;e<u.length;e++){const t=u[e];d[t]=i[t].buffer}return{rels:f,modelRels:c,model:p,printTicket:{},texture:d,other:{}}}(r);return function(t,r){const n=new e.Group,o=function(e){for(let t=0;t<e.length;t++){const r=e[t];if("model"===r.target.split(".").pop().toLowerCase())return r}}(r.rels),s=r.model[o.target.substring(1)].build;for(let e=0;e<s.length;e++){const r=s[e],o=t[r.objectId],i=r.transform;i&&o.applyMatrix4(i),n.add(o)}return n}(function(e){const t=e.model,r=e.modelRels,n={},o=Object.keys(t),s={};if(r)for(let t=0,n=r.length;t<n;t++){const n=r[t],o=n.target.substring(1);e.texture[o]&&(s[n.target]=e.texture[o])}for(let e=0;e<o.length;e++){const r=t[o[e]],i=Object.keys(r.resources.object);for(let e=0;e<i.length;e++){M(i[e],n,r,s)}}return n}(L),L)}addExtension(e){this.availableExtensions.push(e)}}exports.ThreeMFLoader=r;
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("fflate");class r extends e.Loader{constructor(e){super(e),this.availableExtensions=[]}load(t,r,n,o){const s=this,i=new e.FileLoader(s.manager);i.setPath(s.path),i.setResponseType("arraybuffer"),i.setRequestHeader(s.requestHeader),i.setWithCredentials(s.withCredentials),i.load(t,(function(e){try{r(s.parse(e))}catch(e){o?o(e):console.error(e),s.manager.itemError(t)}}),n,o)}parse(r){const n=this,o=new e.TextureLoader(this.manager);function s(e){const t=[],r=(new DOMParser).parseFromString(e,"application/xml").querySelectorAll("Relationship");for(let e=0;e<r.length;e++){const n=r[e],o={target:n.getAttribute("Target"),id:n.getAttribute("Id"),type:n.getAttribute("Type")};t.push(o)}return t}function i(e){const t={id:e.getAttribute("id"),basematerials:[]},r=e.querySelectorAll("base");for(let e=0;e<r.length;e++){const n=c(r[e]);n.index=e,t.basematerials.push(n)}return t}function l(e){const t={id:e.getAttribute("id"),texid:e.getAttribute("texid"),displaypropertiesid:e.getAttribute("displaypropertiesid")},r=e.querySelectorAll("tex2coord"),n=[];for(let e=0;e<r.length;e++){const t=r[e],o=t.getAttribute("u"),s=t.getAttribute("v");n.push(parseFloat(o),parseFloat(s))}return t.uvs=new Float32Array(n),t}function a(t){const r={id:t.getAttribute("id"),displaypropertiesid:t.getAttribute("displaypropertiesid")},n=t.querySelectorAll("color"),o=[],s=new e.Color;for(let e=0;e<n.length;e++){const t=n[e].getAttribute("color");s.setStyle(t.substring(0,7)),s.convertSRGBToLinear(),o.push(s.r,s.g,s.b)}return r.colors=new Float32Array(o),r}function u(e){const t={id:e.getAttribute("id")},r=e.querySelectorAll("pbmetallic"),n=[];for(let e=0;e<r.length;e++){const t=r[e];n.push({name:t.getAttribute("name"),metallicness:parseFloat(t.getAttribute("metallicness")),roughness:parseFloat(t.getAttribute("roughness"))})}return t.data=n,t}function c(e){const t={};return t.name=e.getAttribute("name"),t.displaycolor=e.getAttribute("displaycolor"),t.displaypropertiesid=e.getAttribute("displaypropertiesid"),t}function p(e){const t={};t.objectId=e.getAttribute("objectid");const r=e.getAttribute("transform");return r&&(t.transform=d(r)),t}function d(t){const r=[];t.split(" ").forEach((function(e){r.push(parseFloat(e))}));const n=new e.Matrix4;return n.set(r[0],r[3],r[6],r[9],r[1],r[4],r[7],r[10],r[2],r[5],r[8],r[11],0,0,0,1),n}function h(e){const t={type:e.getAttribute("type")},r=e.getAttribute("id");r&&(t.id=r);const n=e.getAttribute("pid");n&&(t.pid=n);const o=e.getAttribute("pindex");o&&(t.pindex=o);const s=e.getAttribute("thumbnail");s&&(t.thumbnail=s);const i=e.getAttribute("partnumber");i&&(t.partnumber=i);const l=e.getAttribute("name");l&&(t.name=l);const a=e.querySelector("mesh");a&&(t.mesh=function(e){const t={},r=[],n=e.querySelectorAll("vertices vertex");for(let e=0;e<n.length;e++){const t=n[e],o=t.getAttribute("x"),s=t.getAttribute("y"),i=t.getAttribute("z");r.push(parseFloat(o),parseFloat(s),parseFloat(i))}t.vertices=new Float32Array(r);const o=[],s=[],i=e.querySelectorAll("triangles triangle");for(let e=0;e<i.length;e++){const t=i[e],r=t.getAttribute("v1"),n=t.getAttribute("v2"),l=t.getAttribute("v3"),a=t.getAttribute("p1"),u=t.getAttribute("p2"),c=t.getAttribute("p3"),p=t.getAttribute("pid"),d={};d.v1=parseInt(r,10),d.v2=parseInt(n,10),d.v3=parseInt(l,10),s.push(d.v1,d.v2,d.v3),a&&(d.p1=parseInt(a,10)),u&&(d.p2=parseInt(u,10)),c&&(d.p3=parseInt(c,10)),p&&(d.pid=p),0<Object.keys(d).length&&o.push(d)}return t.triangleProperties=o,t.triangles=new Uint32Array(s),t}(a));const u=e.querySelector("components");return u&&(t.components=function(e){const t=[],r=e.querySelectorAll("component");for(let e=0;e<r.length;e++){const n=p(r[e]);t.push(n)}return t}(u)),t}function g(e){const t={unit:e.getAttribute("unit")||"millimeter"},r=e.querySelectorAll("metadata");r&&(t.metadata=function(e){const t={};for(let r=0;r<e.length;r++){const n=e[r],o=n.getAttribute("name");0<=["Title","Designer","Description","Copyright","LicenseTerms","Rating","CreationDate","ModificationDate"].indexOf(o)&&(t[o]=n.textContent)}return t}(r));const n=e.querySelector("resources");n&&(t.resources=function(e){const t={basematerials:{}},r=e.querySelectorAll("basematerials");for(let e=0;e<r.length;e++){const n=i(r[e]);t.basematerials[n.id]=n}t.texture2d={};const n=e.querySelectorAll("texture2d");for(let e=0;e<n.length;e++){const r={id:(o=n[e]).getAttribute("id"),path:o.getAttribute("path"),contenttype:o.getAttribute("contenttype"),tilestyleu:o.getAttribute("tilestyleu"),tilestylev:o.getAttribute("tilestylev"),filter:o.getAttribute("filter")};t.texture2d[r.id]=r}var o;t.colorgroup={};const s=e.querySelectorAll("colorgroup");for(let e=0;e<s.length;e++){const r=a(s[e]);t.colorgroup[r.id]=r}t.pbmetallicdisplayproperties={};const c=e.querySelectorAll("pbmetallicdisplayproperties");for(let e=0;e<c.length;e++){const r=u(c[e]);t.pbmetallicdisplayproperties[r.id]=r}t.texture2dgroup={};const p=e.querySelectorAll("texture2dgroup");for(let e=0;e<p.length;e++){const r=l(p[e]);t.texture2dgroup[r.id]=r}t.object={};const d=e.querySelectorAll("object");for(let e=0;e<d.length;e++){const r=h(d[e]);t.object[r.id]=r}return t}(n));const o=e.querySelector("build");return o&&(t.build=function(e){const t=[],r=e.querySelectorAll("item");for(let e=0;e<r.length;e++){const n=r[e],o={objectId:n.getAttribute("objectid")},s=n.getAttribute("transform");s&&(o.transform=d(s)),t.push(o)}return t}(o)),t}function f(t,r,n,s){const i=t.texid,l=n.resources.texture2d[i];if(l){const t=s[l.path],r=l.contenttype,n=new Blob([t],{type:r}),i=URL.createObjectURL(n),a=o.load(i,(function(){URL.revokeObjectURL(i)}));switch("colorSpace"in a?a.colorSpace="srgb":a.encoding=3001,l.tilestyleu){case"wrap":a.wrapS=e.RepeatWrapping;break;case"mirror":a.wrapS=e.MirroredRepeatWrapping;break;case"none":case"clamp":a.wrapS=e.ClampToEdgeWrapping;break;default:a.wrapS=e.RepeatWrapping}switch(l.tilestylev){case"wrap":a.wrapT=e.RepeatWrapping;break;case"mirror":a.wrapT=e.MirroredRepeatWrapping;break;case"none":case"clamp":a.wrapT=e.ClampToEdgeWrapping;break;default:a.wrapT=e.RepeatWrapping}switch(l.filter){case"auto":a.magFilter=e.LinearFilter,a.minFilter=e.LinearMipmapLinearFilter;break;case"linear":a.magFilter=e.LinearFilter,a.minFilter=e.LinearFilter;break;case"nearest":a.magFilter=e.NearestFilter,a.minFilter=e.NearestFilter;break;default:a.magFilter=e.LinearFilter,a.minFilter=e.LinearMipmapLinearFilter}return a}return null}function b(t,r,n,o,s,i,l){const a=l.pindex,u={};for(let e=0,t=r.length;e<t;e++){const t=r[e],n=void 0!==t.p1?t.p1:a;void 0===u[n]&&(u[n]=[]),u[n].push(t)}const c=Object.keys(u),p=[];for(let r=0,a=c.length;r<a;r++){const a=c[r],d=u[a],h=w(t.basematerials[a],o,s,i,l,F),g=new e.BufferGeometry,f=[],b=n.vertices;for(let e=0,t=d.length;e<t;e++){const t=d[e];f.push(b[3*t.v1+0]),f.push(b[3*t.v1+1]),f.push(b[3*t.v1+2]),f.push(b[3*t.v2+0]),f.push(b[3*t.v2+1]),f.push(b[3*t.v2+2]),f.push(b[3*t.v3+0]),f.push(b[3*t.v3+1]),f.push(b[3*t.v3+2])}g.setAttribute("position",new e.Float32BufferAttribute(f,3));const m=new e.Mesh(g,h);p.push(m)}return p}function m(t,r,n,o,s,i,l){const a=new e.BufferGeometry,u=[],c=[],p=n.vertices,d=t.uvs;for(let e=0,t=r.length;e<t;e++){const t=r[e];u.push(p[3*t.v1+0]),u.push(p[3*t.v1+1]),u.push(p[3*t.v1+2]),u.push(p[3*t.v2+0]),u.push(p[3*t.v2+1]),u.push(p[3*t.v2+2]),u.push(p[3*t.v3+0]),u.push(p[3*t.v3+1]),u.push(p[3*t.v3+2]),c.push(d[2*t.p1+0]),c.push(d[2*t.p1+1]),c.push(d[2*t.p2+0]),c.push(d[2*t.p2+1]),c.push(d[2*t.p3+0]),c.push(d[2*t.p3+1])}a.setAttribute("position",new e.Float32BufferAttribute(u,3)),a.setAttribute("uv",new e.Float32BufferAttribute(c,2));const h=w(t,o,s,i,l,f),g=new e.MeshPhongMaterial({map:h,flatShading:!0});return new e.Mesh(a,g)}function A(t,r,n,o,s,i){const l=new e.BufferGeometry,a=[],u=[],c=n.vertices,p=t.colors;for(let e=0,t=r.length;e<t;e++){const t=r[e],n=t.v1,o=t.v2,s=t.v3;a.push(c[3*n+0]),a.push(c[3*n+1]),a.push(c[3*n+2]),a.push(c[3*o+0]),a.push(c[3*o+1]),a.push(c[3*o+2]),a.push(c[3*s+0]),a.push(c[3*s+1]),a.push(c[3*s+2]);const l=void 0!==t.p1?t.p1:i.pindex,d=void 0!==t.p2?t.p2:l,h=void 0!==t.p3?t.p3:l;u.push(p[3*l+0]),u.push(p[3*l+1]),u.push(p[3*l+2]),u.push(p[3*d+0]),u.push(p[3*d+1]),u.push(p[3*d+2]),u.push(p[3*h+0]),u.push(p[3*h+1]),u.push(p[3*h+2])}l.setAttribute("position",new e.Float32BufferAttribute(a,3)),l.setAttribute("color",new e.Float32BufferAttribute(u,3));const d=new e.MeshPhongMaterial({vertexColors:!0,flatShading:!0});return new e.Mesh(l,d)}function y(t){const r=new e.BufferGeometry;r.setIndex(new e.BufferAttribute(t.triangles,1)),r.setAttribute("position",new e.BufferAttribute(t.vertices,3));const n=new e.MeshPhongMaterial({color:11184895,flatShading:!0});return new e.Mesh(r,n)}function v(e,t){return void 0!==t.resources.texture2dgroup[e]?"texture":void 0!==t.resources.basematerials[e]?"material":void 0!==t.resources.colorgroup[e]?"vertexColors":"default"===e?"default":void 0}function x(t,r,n,o,s){const i=new e.Group,l=function(e,t,r,n,o,s){const i=Object.keys(e),l=[];for(let a=0,u=i.length;a<u;a++){const u=i[a],c=e[u];switch(v(u,n)){case"material":const e=b(n.resources.basematerials[u],c,t,r,n,o,s);for(let t=0,r=e.length;t<r;t++)l.push(e[t]);break;case"texture":const i=n.resources.texture2dgroup[u];l.push(m(i,c,t,r,n,o,s));break;case"vertexColors":const a=n.resources.colorgroup[u];l.push(A(a,c,t,0,0,s));break;case"default":l.push(y(t));break;default:console.error("THREE.3MFLoader: Unsupported resource type.")}}return l}(function(e,t,r){const n={},o=t.triangleProperties,s=r.pid;for(let e=0,t=o.length;e<t;e++){const t=o[e];let r=void 0!==t.pid?t.pid:s;void 0===r&&(r="default"),void 0===n[r]&&(n[r]=[]),n[r].push(t)}return n}(0,t,s),t,r,n,o,s);for(let e=0,t=l.length;e<t;e++)i.add(l[e]);return i}function w(e,t,r,n,o,s){return void 0!==e.build||(e.build=s(e,t,r,n,o)),e.build}function F(t,r,n){let o;const s=t.displaypropertiesid,i=n.resources.pbmetallicdisplayproperties;if(null!==s&&void 0!==i[s]){const r=i[s].data[t.index];o=new e.MeshStandardMaterial({flatShading:!0,roughness:r.roughness,metalness:r.metallicness})}else o=new e.MeshPhongMaterial({flatShading:!0});o.name=t.name;const l=t.displaycolor,a=l.substring(0,7);return o.color.setStyle(a),o.color.convertSRGBToLinear(),9===l.length&&(o.opacity=parseInt(l.charAt(7)+l.charAt(8),16)/255),o}function S(t,r,n,o){const s=new e.Group;for(let e=0;e<t.length;e++){const i=t[e];let l=r[i.objectId];void 0===l&&(M(i.objectId,r,n,o),l=r[i.objectId]);const a=l.clone(),u=i.transform;u&&a.applyMatrix4(u),s.add(a)}return s}function M(e,t,r,o){const s=r.resources.object[e];if(s.mesh){const e=s.mesh;!function(e,t,r){if(!e)return;const o=[],s=Object.keys(e);for(let e=0;e<s.length;e++){const t=s[e];for(let e=0;e<n.availableExtensions.length;e++){const r=n.availableExtensions[e];r.ns===t&&o.push(r)}}for(let n=0;n<o.length;n++){const s=o[n];s.apply(r,e[s.ns],t)}}(r.extensions,e,r.xml),t[s.id]=w(e,t,r,o,s,x)}else{const e=s.components;t[s.id]=w(e,t,r,o,s,S)}}const L=function(r){let n,o,i=null,l=null;const a=[],u=[];let c;const p={},d={};try{i=t.unzipSync(new Uint8Array(r))}catch(e){if(e instanceof ReferenceError)return console.error("THREE.3MFLoader: fflate missing and file is compressed."),null}for(l in i)l.match(/\_rels\/.rels$/)?n=l:l.match(/3D\/_rels\/.*\.model\.rels$/)?o=l:l.match(/^3D\/.*\.model$/)?a.push(l):l.match(/^3D\/Metadata\/.*\.xml$/)||(l.match(/^3D\/Textures?\/.*/)?u.push(l):l.match(/^3D\/Other\/.*/));const h=i[n],f=s(e.LoaderUtils.decodeText(h));if(o){const t=i[o];c=s(e.LoaderUtils.decodeText(t))}for(let t=0;t<a.length;t++){const r=a[t],n=i[r],o=e.LoaderUtils.decodeText(n),s=(new DOMParser).parseFromString(o,"application/xml");"model"!==s.documentElement.nodeName.toLowerCase()&&console.error("THREE.3MFLoader: Error loading 3MF - no 3MF document found: ",r);const l=s.querySelector("model"),u={};for(let e=0;e<l.attributes.length;e++){const t=l.attributes[e];t.name.match(/^xmlns:(.+)$/)&&(u[t.value]=RegExp.$1)}const c=g(l);c.xml=l,0<Object.keys(u).length&&(c.extensions=u),p[r]=c}for(let e=0;e<u.length;e++){const t=u[e];d[t]=i[t].buffer}return{rels:f,modelRels:c,model:p,printTicket:{},texture:d,other:{}}}(r);return function(t,r){const n=new e.Group,o=function(e){for(let t=0;t<e.length;t++){const r=e[t];if("model"===r.target.split(".").pop().toLowerCase())return r}}(r.rels),s=r.model[o.target.substring(1)].build;for(let e=0;e<s.length;e++){const r=s[e],o=t[r.objectId],i=r.transform;i&&o.applyMatrix4(i),n.add(o)}return n}(function(e){const t=e.model,r=e.modelRels,n={},o=Object.keys(t),s={};if(r)for(let t=0,n=r.length;t<n;t++){const n=r[t],o=n.target.substring(1);e.texture[o]&&(s[n.target]=e.texture[o])}for(let e=0;e<o.length;e++){const r=t[o[e]],i=Object.keys(r.resources.object);for(let e=0;e<i.length;e++){M(i[e],n,r,s)}}return n}(L),L)}addExtension(e){this.availableExtensions.push(e)}}exports.ThreeMFLoader=r;
|
package/loaders/3MFLoader.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Loader, FileLoader, TextureLoader, LoaderUtils, Group, Color, Matrix4, BufferGeometry, Float32BufferAttribute, Mesh, MeshPhongMaterial, BufferAttribute, MeshStandardMaterial,
|
1
|
+
import { Loader, FileLoader, TextureLoader, LoaderUtils, Group, Color, Matrix4, BufferGeometry, Float32BufferAttribute, Mesh, MeshPhongMaterial, BufferAttribute, MeshStandardMaterial, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, LinearFilter, LinearMipmapLinearFilter, NearestFilter } from 'three';
|
2
2
|
import { unzipSync } from 'fflate';
|
3
3
|
|
4
4
|
/**
|
@@ -569,7 +569,8 @@ class ThreeMFLoader extends Loader {
|
|
569
569
|
const texture = textureLoader.load(sourceURI, function () {
|
570
570
|
URL.revokeObjectURL(sourceURI);
|
571
571
|
});
|
572
|
-
texture.encoding =
|
572
|
+
if ('colorSpace' in texture) texture.colorSpace = 'srgb';else texture.encoding = 3001; // sRGBEncoding
|
573
|
+
// texture parameters
|
573
574
|
|
574
575
|
switch (texture2d.tilestyleu) {
|
575
576
|
case 'wrap':
|
package/loaders/EXRLoader.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("fflate");class n extends e.DataTextureLoader{constructor(r){super(r),this.type=e.HalfFloatType}parse(n){const t=65536,a=14,i=65537,o=16384,l=Math.pow(2.7182818,2.2);const s={l:0,c:0,lc:0};function u(e,r,n,t,a){for(;n<e;)r=r<<8|V(t,a),n+=8;n-=e,s.l=r>>n&(1<<e)-1,s.c=r,s.lc=n}const c=new Array(59);function f(e,r,n,t,a,o,l){for(var f=n,v=0,h=0;a<=o;a++){if(f.value-n.value>t)return!1;u(6,v,h,e,f);var p=s.l;if(v=s.c,h=s.lc,l[a]=p,63==p){if(f.value-n.value>t)throw"Something wrong with hufUnpackEncTable";u(8,v,h,e,f);var w=s.l+6;if(v=s.c,h=s.lc,a+w>o+1)throw"Something wrong with hufUnpackEncTable";for(;w--;)l[a++]=0;a--}else if(p>=59){if(a+(w=p-59+2)>o+1)throw"Something wrong with hufUnpackEncTable";for(;w--;)l[a++]=0;a--}}!function(e){for(var r=0;r<=58;++r)c[r]=0;for(r=0;r<i;++r)c[e[r]]+=1;var n=0;for(r=58;r>0;--r){var t=n+c[r]>>1;c[r]=n,n=t}for(r=0;r<i;++r){var a=e[r];a>0&&(e[r]=a|c[a]++<<6)}}(l)}function v(e){return 63&e}function h(e){return e>>6}const p={c:0,lc:0};function w(e,r,n,t){e=e<<8|V(n,t),r+=8,p.c=e,p.lc=r}const d={c:0,lc:0};function y(e,r,n,t,a,i,o,l,s,u){if(e==r){t<8&&(w(n,t,a,o),n=p.c,t=p.lc);var c=n>>(t-=8);c=new Uint8Array([c])[0];if(s.value+c>u)return!1;for(var f=l[s.value-1];c-- >0;)l[s.value++]=f}else{if(!(s.value<u))return!1;l[s.value++]=e}d.c=n,d.lc=t}function S(e){return 65535&e}function g(e){var r=S(e);return r>32767?r-65536:r}const b={a:0,b:0};function m(e,r){var n=g(e),t=g(r),a=n+(1&t)+(t>>1),i=a,o=a-t;b.a=i,b.b=o}function A(e,r){var n=S(e),t=S(r),a=n-(t>>1)&65535,i=t+a-32768&65535;b.a=i,b.b=a}function U(e,r,n,t,a,i,o){for(var l,s=o<16384,u=n>a?a:n,c=1;c<=u;)c<<=1;for(l=c>>=1,c>>=1;c>=1;){for(var f,v,h,p,w=0,d=w+i*(a-l),y=i*c,S=i*l,g=t*c,U=t*l;w<=d;w+=S){for(var M=w,z=w+t*(n-l);M<=z;M+=U){var C=M+g,E=(O=M+y)+g;s?(m(e[M+r],e[O+r]),f=b.a,h=b.b,m(e[C+r],e[E+r]),v=b.a,p=b.b,m(f,v),e[M+r]=b.a,e[C+r]=b.b,m(h,p),e[O+r]=b.a,e[E+r]=b.b):(A(e[M+r],e[O+r]),f=b.a,h=b.b,A(e[C+r],e[E+r]),v=b.a,p=b.b,A(f,v),e[M+r]=b.a,e[C+r]=b.b,A(h,p),e[O+r]=b.a,e[E+r]=b.b)}if(n&c){var O=M+y;s?m(e[M+r],e[O+r]):A(e[M+r],e[O+r]),f=b.a,e[O+r]=b.b,e[M+r]=f}}if(a&c)for(M=w,z=w+t*(n-l);M<=z;M+=U){C=M+g;s?m(e[M+r],e[C+r]):A(e[M+r],e[C+r]),f=b.a,e[C+r]=b.b,e[M+r]=f}l=c,c>>=1}return w}function M(e,r,n,t,l,s){var u=n.value,c=H(r,n),S=H(r,n);n.value+=4;var g=H(r,n);if(n.value+=4,c<0||c>=i||S<0||S>=i)throw"Something wrong with HUF_ENCSIZE";var b=new Array(i),m=new Array(o);if(function(e){for(var r=0;r<o;r++)e[r]={},e[r].len=0,e[r].lit=0,e[r].p=null}(m),f(e,0,n,t-(n.value-u),c,S,b),g>8*(t-(n.value-u)))throw"Something wrong with hufUncompress";!function(e,r,n,t){for(;r<=n;r++){var i=h(e[r]),o=v(e[r]);if(i>>o)throw"Invalid table entry";if(o>a){if((c=t[i>>o-a]).len)throw"Invalid table entry";if(c.lit++,c.p){var l=c.p;c.p=new Array(c.lit);for(var s=0;s<c.lit-1;++s)c.p[s]=l[s]}else c.p=new Array(1);c.p[c.lit-1]=r}else if(o){var u=0;for(s=1<<a-o;s>0;s--){var c;if((c=t[(i<<a-o)+u]).len||c.p)throw"Invalid table entry";c.len=o,c.lit=r,u++}}}}(b,c,S,m),function(e,r,n,t,i,o,l,s,u,c){for(var f=0,S=0,g=s,b=Math.trunc(i.value+(o+7)/8);i.value<b;)for(w(f,S,n,i),f=p.c,S=p.lc;S>=a;)if((M=r[f>>S-a&16383]).len)S-=M.len,y(M.lit,l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc;else{if(!M.p)throw"hufDecode issues";var m;for(m=0;m<M.lit;m++){for(var A=v(e[M.p[m]]);S<A&&i.value<b;)w(f,S,n,i),f=p.c,S=p.lc;if(S>=A&&h(e[M.p[m]])==(f>>S-A&(1<<A)-1)){S-=A,y(M.p[m],l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc;break}}if(m==M.lit)throw"hufDecode issues"}var U=8-o&7;for(f>>=U,S-=U;S>0;){var M;if(!(M=r[f<<a-S&16383]).len)throw"hufDecode issues";S-=M.len,y(M.lit,l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc}}(b,m,e,0,n,g,S,s,l,{value:0})}function z(e){for(var r=1;r<e.length;r++){var n=e[r-1]+e[r]-128;e[r]=n}}function C(e,r){for(var n=0,t=Math.floor((e.length+1)/2),a=0,i=e.length-1;!(a>i||(r[a++]=e[n++],a>i));)r[a++]=e[t++]}function E(e){for(var r=e.byteLength,n=new Array,t=0,a=new DataView(e);r>0;){var i=a.getInt8(t++);if(i<0){r-=(l=-i)+1;for(var o=0;o<l;o++)n.push(a.getUint8(t++))}else{var l=i;r-=2;var s=a.getUint8(t++);for(o=0;o<l+1;o++)n.push(s)}}return n}function O(e,r,n){for(var t,a=1;a<64;)65280==(t=r[e.value])?a=64:t>>8==255?a+=255&t:(n[a]=t,a++),e.value++}function R(e,r){r[0]=q(e[0]),r[1]=q(e[1]),r[2]=q(e[5]),r[3]=q(e[6]),r[4]=q(e[14]),r[5]=q(e[15]),r[6]=q(e[27]),r[7]=q(e[28]),r[8]=q(e[2]),r[9]=q(e[4]),r[10]=q(e[7]),r[11]=q(e[13]),r[12]=q(e[16]),r[13]=q(e[26]),r[14]=q(e[29]),r[15]=q(e[42]),r[16]=q(e[3]),r[17]=q(e[8]),r[18]=q(e[12]),r[19]=q(e[17]),r[20]=q(e[25]),r[21]=q(e[30]),r[22]=q(e[41]),r[23]=q(e[43]),r[24]=q(e[9]),r[25]=q(e[11]),r[26]=q(e[18]),r[27]=q(e[24]),r[28]=q(e[31]),r[29]=q(e[40]),r[30]=q(e[44]),r[31]=q(e[53]),r[32]=q(e[10]),r[33]=q(e[19]),r[34]=q(e[23]),r[35]=q(e[32]),r[36]=q(e[39]),r[37]=q(e[45]),r[38]=q(e[52]),r[39]=q(e[54]),r[40]=q(e[20]),r[41]=q(e[22]),r[42]=q(e[33]),r[43]=q(e[38]),r[44]=q(e[46]),r[45]=q(e[51]),r[46]=q(e[55]),r[47]=q(e[60]),r[48]=q(e[21]),r[49]=q(e[34]),r[50]=q(e[37]),r[51]=q(e[47]),r[52]=q(e[50]),r[53]=q(e[56]),r[54]=q(e[59]),r[55]=q(e[61]),r[56]=q(e[35]),r[57]=q(e[36]),r[58]=q(e[48]),r[59]=q(e[49]),r[60]=q(e[57]),r[61]=q(e[58]),r[62]=q(e[62]),r[63]=q(e[63])}function I(e){const r=.5*Math.cos(.7853975),n=.5*Math.cos(3.14159/16),t=.5*Math.cos(3.14159/8),a=.5*Math.cos(3*3.14159/16),i=.5*Math.cos(.981746875),o=.5*Math.cos(3*3.14159/8),l=.5*Math.cos(1.374445625);for(var s=new Array(4),u=new Array(4),c=new Array(4),f=new Array(4),v=0;v<8;++v){var h=8*v;s[0]=t*e[h+2],s[1]=o*e[h+2],s[2]=t*e[h+6],s[3]=o*e[h+6],u[0]=n*e[h+1]+a*e[h+3]+i*e[h+5]+l*e[h+7],u[1]=a*e[h+1]-l*e[h+3]-n*e[h+5]-i*e[h+7],u[2]=i*e[h+1]-n*e[h+3]+l*e[h+5]+a*e[h+7],u[3]=l*e[h+1]-i*e[h+3]+a*e[h+5]-n*e[h+7],c[0]=r*(e[h+0]+e[h+4]),c[3]=r*(e[h+0]-e[h+4]),c[1]=s[0]+s[3],c[2]=s[1]-s[2],f[0]=c[0]+c[1],f[1]=c[3]+c[2],f[2]=c[3]-c[2],f[3]=c[0]-c[1],e[h+0]=f[0]+u[0],e[h+1]=f[1]+u[1],e[h+2]=f[2]+u[2],e[h+3]=f[3]+u[3],e[h+4]=f[3]-u[3],e[h+5]=f[2]-u[2],e[h+6]=f[1]-u[1],e[h+7]=f[0]-u[0]}for(var p=0;p<8;++p)s[0]=t*e[16+p],s[1]=o*e[16+p],s[2]=t*e[48+p],s[3]=o*e[48+p],u[0]=n*e[8+p]+a*e[24+p]+i*e[40+p]+l*e[56+p],u[1]=a*e[8+p]-l*e[24+p]-n*e[40+p]-i*e[56+p],u[2]=i*e[8+p]-n*e[24+p]+l*e[40+p]+a*e[56+p],u[3]=l*e[8+p]-i*e[24+p]+a*e[40+p]-n*e[56+p],c[0]=r*(e[p]+e[32+p]),c[3]=r*(e[p]-e[32+p]),c[1]=s[0]+s[3],c[2]=s[1]-s[2],f[0]=c[0]+c[1],f[1]=c[3]+c[2],f[2]=c[3]-c[2],f[3]=c[0]-c[1],e[0+p]=f[0]+u[0],e[8+p]=f[1]+u[1],e[16+p]=f[2]+u[2],e[24+p]=f[3]+u[3],e[32+p]=f[3]-u[3],e[40+p]=f[2]-u[2],e[48+p]=f[1]-u[1],e[56+p]=f[0]-u[0]}function x(e){for(var r=0;r<64;++r){var n=e[0][r],t=e[1][r],a=e[2][r];e[0][r]=n+1.5747*a,e[1][r]=n-.1873*t-.4682*a,e[2][r]=n+1.8556*t}}function k(r,n,t){for(var a=0;a<64;++a)n[t+a]=e.DataUtils.toHalfFloat(P(r[a]))}function P(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(l,Math.abs(e)-1)}function N(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function D(e){var r=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),n=new Uint8Array(E(r)),t=new Uint8Array(n.length);return z(n),C(n,t),new DataView(t.buffer)}function L(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),t=r.unzlibSync(n),a=new Uint8Array(t.length);return z(t),C(t,a),new DataView(a.buffer)}function _(e){for(var r=e.viewer,n={value:e.offset.value},a=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),i=new Uint8Array(8192),o=0,l=new Array(e.channels),s=0;s<e.channels;s++)l[s]={},l[s].start=o,l[s].end=l[s].start,l[s].nx=e.width,l[s].ny=e.lines,l[s].size=e.type,o+=l[s].nx*l[s].ny*l[s].size;var u=j(r,n),c=j(r,n);if(c>=8192)throw"Something is wrong with PIZ_COMPRESSION BITMAP_SIZE";if(u<=c)for(s=0;s<c-u+1;s++)i[s+u]=W(r,n);var f=new Uint16Array(t),v=function(e,r){for(var n=0,a=0;a<t;++a)(0==a||e[a>>3]&1<<(7&a))&&(r[n++]=a);for(var i=n-1;n<t;)r[n++]=0;return i}(i,f),h=H(r,n);M(e.array,r,n,h,a,o);for(s=0;s<e.channels;++s)for(var p=l[s],w=0;w<l[s].size;++w)U(a,p.start+w,p.nx,p.size,p.ny,p.nx*p.size,v);!function(e,r,n){for(var t=0;t<n;++t)r[t]=e[r[t]]}(f,a,o);for(var d=0,y=new Uint8Array(a.buffer.byteLength),S=0;S<e.lines;S++)for(var g=0;g<e.channels;g++){var b=(p=l[g]).nx*p.size,m=new Uint8Array(a.buffer,2*p.end,2*b);y.set(m,d),d+=2*b,p.end+=b}return new DataView(y.buffer)}function T(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),t=r.unzlibSync(n);const a=e.lines*e.channels*e.width,i=1==e.type?new Uint16Array(a):new Uint32Array(a);let o=0,l=0;const s=new Array(4);for(let r=0;r<e.lines;r++)for(let r=0;r<e.channels;r++){let r=0;switch(e.type){case 1:s[0]=o,s[1]=s[0]+e.width,o=s[1]+e.width;for(let n=0;n<e.width;++n){r+=t[s[0]++]<<8|t[s[1]++],i[l]=r,l++}break;case 2:s[0]=o,s[1]=s[0]+e.width,s[2]=s[1]+e.width,o=s[2]+e.width;for(let n=0;n<e.width;++n){r+=t[s[0]++]<<24|t[s[1]++]<<16|t[s[2]++]<<8,i[l]=r,l++}}}return new DataView(i.buffer)}function F(e){var n=e.viewer,t={value:e.offset.value},a=new Uint8Array(e.width*e.lines*(e.channels*e.type*2)),i={version:Z(n,t),unknownUncompressedSize:Z(n,t),unknownCompressedSize:Z(n,t),acCompressedSize:Z(n,t),dcCompressedSize:Z(n,t),rleCompressedSize:Z(n,t),rleUncompressedSize:Z(n,t),rleRawSize:Z(n,t),totalAcUncompressedCount:Z(n,t),totalDcUncompressedCount:Z(n,t),acCompression:Z(n,t)};if(i.version<2)throw"EXRLoader.parse: "+re.compression+" version "+i.version+" is unsupported";for(var o=new Array,l=j(n,t)-2;l>0;){var s=B(n.buffer,t),u=W(n,t),c=u>>2&3,f=new Int8Array([(u>>4)-1])[0],v=W(n,t);o.push({name:s,index:f,type:v,compression:c}),l-=s.length+3}for(var h=re.channels,p=new Array(e.channels),w=0;w<e.channels;++w){var d=p[w]={},y=h[w];d.name=y.name,d.compression=0,d.decoded=!1,d.type=y.pixelType,d.pLinear=y.pLinear,d.width=e.width,d.height=e.lines}for(var S={idx:new Array(3)},g=0;g<e.channels;++g)for(d=p[g],w=0;w<o.length;++w){var b=o[w];d.name==b.name&&(d.compression=b.compression,b.index>=0&&(S.idx[b.index]=g),d.offset=g)}if(i.acCompressedSize>0)switch(i.acCompression){case 0:var m=new Uint16Array(i.totalAcUncompressedCount);M(e.array,n,t,i.acCompressedSize,m,i.totalAcUncompressedCount);break;case 1:var A=e.array.slice(t.value,t.value+i.totalAcUncompressedCount),U=r.unzlibSync(A);m=new Uint16Array(U.buffer);t.value+=i.totalAcUncompressedCount}if(i.dcCompressedSize>0){var z={array:e.array,offset:t,size:i.dcCompressedSize},C=new Uint16Array(L(z).buffer);t.value+=i.dcCompressedSize}if(i.rleRawSize>0){A=e.array.slice(t.value,t.value+i.rleCompressedSize);var P=E((U=r.unzlibSync(A)).buffer);t.value+=i.rleCompressedSize}var N=0,D=new Array(p.length);for(w=0;w<D.length;++w)D[w]=new Array;for(var _=0;_<e.lines;++_)for(var T=0;T<p.length;++T)D[T].push(N),N+=p[T].width*e.type*2;!function(e,r,n,t,a,i){var o=new DataView(i.buffer),l=n[e.idx[0]].width,s=n[e.idx[0]].height,u=Math.floor(l/8),c=Math.ceil(l/8),f=Math.ceil(s/8),v=l-8*(c-1),h=s-8*(f-1),p={value:0},w=new Array(3),d=new Array(3),y=new Array(3),S=new Array(3),g=new Array(3);for(let n=0;n<3;++n)g[n]=r[e.idx[n]],w[n]=n<1?0:w[n-1]+c*f,d[n]=new Float32Array(64),y[n]=new Uint16Array(64),S[n]=new Uint16Array(64*c);for(let r=0;r<f;++r){var b=8;r==f-1&&(b=h);var m=8;for(let e=0;e<c;++e){e==c-1&&(m=v);for(let e=0;e<3;++e)y[e].fill(0),y[e][0]=a[w[e]++],O(p,t,y[e]),R(y[e],d[e]),I(d[e]);x(d);for(let r=0;r<3;++r)k(d[r],S[r],64*e)}let i=0;for(let t=0;t<3;++t){const a=n[e.idx[t]].type;for(let e=8*r;e<8*r+b;++e){i=g[t][e];for(let r=0;r<u;++r){const n=64*r+8*(7&e);o.setUint16(i+0*a,S[t][n+0],!0),o.setUint16(i+2*a,S[t][n+1],!0),o.setUint16(i+4*a,S[t][n+2],!0),o.setUint16(i+6*a,S[t][n+3],!0),o.setUint16(i+8*a,S[t][n+4],!0),o.setUint16(i+10*a,S[t][n+5],!0),o.setUint16(i+12*a,S[t][n+6],!0),o.setUint16(i+14*a,S[t][n+7],!0),i+=16*a}}if(u!=c)for(let e=8*r;e<8*r+b;++e){const r=g[t][e]+8*u*2*a,n=64*u+8*(7&e);for(let e=0;e<m;++e)o.setUint16(r+2*e*a,S[t][n+e],!0)}}}for(var A=new Uint16Array(l),U=(o=new DataView(i.buffer),0);U<3;++U){n[e.idx[U]].decoded=!0;var M=n[e.idx[U]].type;if(2==n[U].type)for(var z=0;z<s;++z){const e=g[U][z];for(var C=0;C<l;++C)A[C]=o.getUint16(e+2*C*M,!0);for(C=0;C<l;++C)o.setFloat32(e+2*C*M,q(A[C]),!0)}}}(S,D,p,m,C,a);for(w=0;w<p.length;++w){if(!(d=p[w]).decoded)switch(d.compression){case 2:var F=0,X=0;for(_=0;_<e.lines;++_){for(var H=D[w][F],V=0;V<d.width;++V){for(var Y=0;Y<2*d.type;++Y)a[H++]=P[X+Y*d.width*d.height];X++}F++}break;case 1:default:throw"EXRLoader.parse: unsupported channel compression"}}return new DataView(a.buffer)}function B(e,r){for(var n=new Uint8Array(e),t=0;0!=n[r.value+t];)t+=1;var a=(new TextDecoder).decode(n.slice(r.value,r.value+t));return r.value=r.value+t+1,a}function X(e,r){var n=e.getInt32(r.value,!0);return r.value=r.value+4,n}function H(e,r){var n=e.getUint32(r.value,!0);return r.value=r.value+4,n}function V(e,r){var n=e[r.value];return r.value=r.value+1,n}function W(e,r){var n=e.getUint8(r.value);return r.value=r.value+1,n}const Z=function(e,r){let n;return n="getBigInt64"in DataView.prototype?Number(e.getBigInt64(r.value,!0)):e.getUint32(r.value+4,!0)+Number(e.getUint32(r.value,!0)<<32),r.value+=8,n};function Y(e,r){var n=e.getFloat32(r.value,!0);return r.value+=4,n}function G(r,n){return e.DataUtils.toHalfFloat(Y(r,n))}function q(e){var r=(31744&e)>>10,n=1023&e;return(e>>15?-1:1)*(r?31===r?n?NaN:1/0:Math.pow(2,r-15)*(1+n/1024):n/1024*6103515625e-14)}function j(e,r){var n=e.getUint16(r.value,!0);return r.value+=2,n}function $(e,r){return q(j(e,r))}function J(e,r,n,t,a){return"string"===t||"stringvector"===t||"iccProfile"===t?function(e,r,n){var t=(new TextDecoder).decode(new Uint8Array(e).slice(r.value,r.value+n));return r.value=r.value+n,t}(r,n,a):"chlist"===t?function(e,r,n,t){for(var a=n.value,i=[];n.value<a+t-1;){var o=B(r,n),l=X(e,n),s=W(e,n);n.value+=3;var u=X(e,n),c=X(e,n);i.push({name:o,pixelType:l,pLinear:s,xSampling:u,ySampling:c})}return n.value+=1,i}(e,r,n,a):"chromaticities"===t?function(e,r){return{redX:Y(e,r),redY:Y(e,r),greenX:Y(e,r),greenY:Y(e,r),blueX:Y(e,r),blueY:Y(e,r),whiteX:Y(e,r),whiteY:Y(e,r)}}(e,n):"compression"===t?function(e,r){return["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"][W(e,r)]}(e,n):"box2i"===t?function(e,r){return{xMin:H(e,r),yMin:H(e,r),xMax:H(e,r),yMax:H(e,r)}}(e,n):"lineOrder"===t?function(e,r){return["INCREASING_Y"][W(e,r)]}(e,n):"float"===t?Y(e,n):"v2f"===t?function(e,r){return[Y(e,r),Y(e,r)]}(e,n):"v3f"===t?function(e,r){return[Y(e,r),Y(e,r),Y(e,r)]}(e,n):"int"===t?X(e,n):"rational"===t?function(e,r){return[X(e,r),H(e,r)]}(e,n):"timecode"===t?function(e,r){return[H(e,r),H(e,r)]}(e,n):"preview"===t?(n.value+=a,"skipped"):void(n.value+=a)}const K=new DataView(n),Q=new Uint8Array(n),ee={value:0},re=function(e,r,n){const t={};if(20000630!=e.getUint32(0,!0))throw"THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.";t.version=e.getUint8(4);const a=e.getUint8(5);t.spec={singleTile:!!(2&a),longName:!!(4&a),deepFormat:!!(8&a),multiPart:!!(16&a)},n.value=8;for(var i=!0;i;){var o=B(r,n);if(0==o)i=!1;else{var l=B(r,n),s=J(e,r,n,l,H(e,n));void 0===s?console.warn(`EXRLoader.parse: skipped unknown header attribute type '${l}'.`):t[o]=s}}if(0!=a)throw console.error("EXRHeader:",t),"THREE.EXRLoader: provided file is currently unsupported.";return t}(K,n,ee),ne=function(r,n,t,a,i){const o={size:0,viewer:n,array:t,offset:a,width:r.dataWindow.xMax-r.dataWindow.xMin+1,height:r.dataWindow.yMax-r.dataWindow.yMin+1,channels:r.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:r.channels[0].pixelType,uncompress:null,getter:null,format:null,encoding:null};switch(r.compression){case"NO_COMPRESSION":o.lines=1,o.uncompress=N;break;case"RLE_COMPRESSION":o.lines=1,o.uncompress=D;break;case"ZIPS_COMPRESSION":o.lines=1,o.uncompress=L;break;case"ZIP_COMPRESSION":o.lines=16,o.uncompress=L;break;case"PIZ_COMPRESSION":o.lines=32,o.uncompress=_;break;case"PXR24_COMPRESSION":o.lines=16,o.uncompress=T;break;case"DWAA_COMPRESSION":o.lines=32,o.uncompress=F;break;case"DWAB_COMPRESSION":o.lines=256,o.uncompress=F;break;default:throw"EXRLoader.parse: "+r.compression+" is unsupported"}if(o.scanlineBlockSize=o.lines,1==o.type)switch(i){case e.FloatType:o.getter=$,o.inputSize=2;break;case e.HalfFloatType:o.getter=j,o.inputSize=2}else{if(2!=o.type)throw"EXRLoader.parse: unsupported pixelType "+o.type+" for "+r.compression+".";switch(i){case e.FloatType:o.getter=Y,o.inputSize=4;break;case e.HalfFloatType:o.getter=G,o.inputSize=4}}o.blockCount=(r.dataWindow.yMax+1)/o.scanlineBlockSize;for(var l=0;l<o.blockCount;l++)Z(n,a);o.outputChannels=3==o.channels?4:o.channels;const s=o.width*o.height*o.outputChannels;switch(i){case e.FloatType:o.byteArray=new Float32Array(s),o.channels<o.outputChannels&&o.byteArray.fill(1,0,s);break;case e.HalfFloatType:o.byteArray=new Uint16Array(s),o.channels<o.outputChannels&&o.byteArray.fill(15360,0,s);break;default:console.error("THREE.EXRLoader: unsupported type: ",i)}return o.bytesPerLine=o.width*o.inputSize*o.channels,4==o.outputChannels?(o.format=e.RGBAFormat,o.encoding=e.LinearEncoding):(o.format=e.RedFormat,o.encoding=e.LinearEncoding),o}(re,K,Q,ee,this.type),te={value:0},ae={R:0,G:1,B:2,A:3,Y:0};for(let e=0;e<ne.height/ne.scanlineBlockSize;e++){const r=H(K,ee);ne.size=H(K,ee),ne.lines=r+ne.scanlineBlockSize>ne.height?ne.height-r:ne.scanlineBlockSize;const n=ne.size<ne.lines*ne.bytesPerLine?ne.uncompress(ne):N(ne);ee.value+=ne.size;for(let r=0;r<ne.scanlineBlockSize;r++){const t=r+e*ne.scanlineBlockSize;if(t>=ne.height)break;for(let e=0;e<ne.channels;e++){const a=ae[re.channels[e].name];for(let i=0;i<ne.width;i++){te.value=(r*(ne.channels*ne.width)+e*ne.width+i)*ne.inputSize;const o=(ne.height-1-t)*(ne.width*ne.outputChannels)+i*ne.outputChannels+a;ne.byteArray[o]=ne.getter(n,te)}}}}return{header:re,width:ne.width,height:ne.height,data:ne.byteArray,format:ne.format,encoding:ne.encoding,type:this.type}}setDataType(e){return this.type=e,this}load(r,n,t,a){return super.load(r,(function(r,t){r.encoding=t.encoding,r.minFilter=e.LinearFilter,r.magFilter=e.LinearFilter,r.generateMipmaps=!1,r.flipY=!1,n&&n(r,t)}),t,a)}}exports.EXRLoader=n;
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("fflate");class n extends e.DataTextureLoader{constructor(r){super(r),this.type=e.HalfFloatType}parse(n){const t=65536,a=14,i=65537,o=16384,l=Math.pow(2.7182818,2.2);const s={l:0,c:0,lc:0};function u(e,r,n,t,a){for(;n<e;)r=r<<8|V(t,a),n+=8;n-=e,s.l=r>>n&(1<<e)-1,s.c=r,s.lc=n}const c=new Array(59);function f(e,r,n,t,a,o,l){for(var f=n,v=0,h=0;a<=o;a++){if(f.value-n.value>t)return!1;u(6,v,h,e,f);var p=s.l;if(v=s.c,h=s.lc,l[a]=p,63==p){if(f.value-n.value>t)throw"Something wrong with hufUnpackEncTable";u(8,v,h,e,f);var w=s.l+6;if(v=s.c,h=s.lc,a+w>o+1)throw"Something wrong with hufUnpackEncTable";for(;w--;)l[a++]=0;a--}else if(p>=59){if(a+(w=p-59+2)>o+1)throw"Something wrong with hufUnpackEncTable";for(;w--;)l[a++]=0;a--}}!function(e){for(var r=0;r<=58;++r)c[r]=0;for(r=0;r<i;++r)c[e[r]]+=1;var n=0;for(r=58;r>0;--r){var t=n+c[r]>>1;c[r]=n,n=t}for(r=0;r<i;++r){var a=e[r];a>0&&(e[r]=a|c[a]++<<6)}}(l)}function v(e){return 63&e}function h(e){return e>>6}const p={c:0,lc:0};function w(e,r,n,t){e=e<<8|V(n,t),r+=8,p.c=e,p.lc=r}const d={c:0,lc:0};function y(e,r,n,t,a,i,o,l,s,u){if(e==r){t<8&&(w(n,t,a,o),n=p.c,t=p.lc);var c=n>>(t-=8);c=new Uint8Array([c])[0];if(s.value+c>u)return!1;for(var f=l[s.value-1];c-- >0;)l[s.value++]=f}else{if(!(s.value<u))return!1;l[s.value++]=e}d.c=n,d.lc=t}function S(e){return 65535&e}function g(e){var r=S(e);return r>32767?r-65536:r}const b={a:0,b:0};function m(e,r){var n=g(e),t=g(r),a=n+(1&t)+(t>>1),i=a,o=a-t;b.a=i,b.b=o}function A(e,r){var n=S(e),t=S(r),a=n-(t>>1)&65535,i=t+a-32768&65535;b.a=i,b.b=a}function U(e,r,n,t,a,i,o){for(var l,s=o<16384,u=n>a?a:n,c=1;c<=u;)c<<=1;for(l=c>>=1,c>>=1;c>=1;){for(var f,v,h,p,w=0,d=w+i*(a-l),y=i*c,S=i*l,g=t*c,U=t*l;w<=d;w+=S){for(var M=w,z=w+t*(n-l);M<=z;M+=U){var C=M+g,E=(O=M+y)+g;s?(m(e[M+r],e[O+r]),f=b.a,h=b.b,m(e[C+r],e[E+r]),v=b.a,p=b.b,m(f,v),e[M+r]=b.a,e[C+r]=b.b,m(h,p),e[O+r]=b.a,e[E+r]=b.b):(A(e[M+r],e[O+r]),f=b.a,h=b.b,A(e[C+r],e[E+r]),v=b.a,p=b.b,A(f,v),e[M+r]=b.a,e[C+r]=b.b,A(h,p),e[O+r]=b.a,e[E+r]=b.b)}if(n&c){var O=M+y;s?m(e[M+r],e[O+r]):A(e[M+r],e[O+r]),f=b.a,e[O+r]=b.b,e[M+r]=f}}if(a&c)for(M=w,z=w+t*(n-l);M<=z;M+=U){C=M+g;s?m(e[M+r],e[C+r]):A(e[M+r],e[C+r]),f=b.a,e[C+r]=b.b,e[M+r]=f}l=c,c>>=1}return w}function M(e,r,n,t,l,s){var u=n.value,c=H(r,n),S=H(r,n);n.value+=4;var g=H(r,n);if(n.value+=4,c<0||c>=i||S<0||S>=i)throw"Something wrong with HUF_ENCSIZE";var b=new Array(i),m=new Array(o);if(function(e){for(var r=0;r<o;r++)e[r]={},e[r].len=0,e[r].lit=0,e[r].p=null}(m),f(e,0,n,t-(n.value-u),c,S,b),g>8*(t-(n.value-u)))throw"Something wrong with hufUncompress";!function(e,r,n,t){for(;r<=n;r++){var i=h(e[r]),o=v(e[r]);if(i>>o)throw"Invalid table entry";if(o>a){if((c=t[i>>o-a]).len)throw"Invalid table entry";if(c.lit++,c.p){var l=c.p;c.p=new Array(c.lit);for(var s=0;s<c.lit-1;++s)c.p[s]=l[s]}else c.p=new Array(1);c.p[c.lit-1]=r}else if(o){var u=0;for(s=1<<a-o;s>0;s--){var c;if((c=t[(i<<a-o)+u]).len||c.p)throw"Invalid table entry";c.len=o,c.lit=r,u++}}}}(b,c,S,m),function(e,r,n,t,i,o,l,s,u,c){for(var f=0,S=0,g=s,b=Math.trunc(i.value+(o+7)/8);i.value<b;)for(w(f,S,n,i),f=p.c,S=p.lc;S>=a;)if((M=r[f>>S-a&16383]).len)S-=M.len,y(M.lit,l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc;else{if(!M.p)throw"hufDecode issues";var m;for(m=0;m<M.lit;m++){for(var A=v(e[M.p[m]]);S<A&&i.value<b;)w(f,S,n,i),f=p.c,S=p.lc;if(S>=A&&h(e[M.p[m]])==(f>>S-A&(1<<A)-1)){S-=A,y(M.p[m],l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc;break}}if(m==M.lit)throw"hufDecode issues"}var U=8-o&7;for(f>>=U,S-=U;S>0;){var M;if(!(M=r[f<<a-S&16383]).len)throw"hufDecode issues";S-=M.len,y(M.lit,l,f,S,n,0,i,u,c,g),f=d.c,S=d.lc}}(b,m,e,0,n,g,S,s,l,{value:0})}function z(e){for(var r=1;r<e.length;r++){var n=e[r-1]+e[r]-128;e[r]=n}}function C(e,r){for(var n=0,t=Math.floor((e.length+1)/2),a=0,i=e.length-1;!(a>i||(r[a++]=e[n++],a>i));)r[a++]=e[t++]}function E(e){for(var r=e.byteLength,n=new Array,t=0,a=new DataView(e);r>0;){var i=a.getInt8(t++);if(i<0){r-=(l=-i)+1;for(var o=0;o<l;o++)n.push(a.getUint8(t++))}else{var l=i;r-=2;var s=a.getUint8(t++);for(o=0;o<l+1;o++)n.push(s)}}return n}function O(e,r,n){for(var t,a=1;a<64;)65280==(t=r[e.value])?a=64:t>>8==255?a+=255&t:(n[a]=t,a++),e.value++}function R(e,r){r[0]=q(e[0]),r[1]=q(e[1]),r[2]=q(e[5]),r[3]=q(e[6]),r[4]=q(e[14]),r[5]=q(e[15]),r[6]=q(e[27]),r[7]=q(e[28]),r[8]=q(e[2]),r[9]=q(e[4]),r[10]=q(e[7]),r[11]=q(e[13]),r[12]=q(e[16]),r[13]=q(e[26]),r[14]=q(e[29]),r[15]=q(e[42]),r[16]=q(e[3]),r[17]=q(e[8]),r[18]=q(e[12]),r[19]=q(e[17]),r[20]=q(e[25]),r[21]=q(e[30]),r[22]=q(e[41]),r[23]=q(e[43]),r[24]=q(e[9]),r[25]=q(e[11]),r[26]=q(e[18]),r[27]=q(e[24]),r[28]=q(e[31]),r[29]=q(e[40]),r[30]=q(e[44]),r[31]=q(e[53]),r[32]=q(e[10]),r[33]=q(e[19]),r[34]=q(e[23]),r[35]=q(e[32]),r[36]=q(e[39]),r[37]=q(e[45]),r[38]=q(e[52]),r[39]=q(e[54]),r[40]=q(e[20]),r[41]=q(e[22]),r[42]=q(e[33]),r[43]=q(e[38]),r[44]=q(e[46]),r[45]=q(e[51]),r[46]=q(e[55]),r[47]=q(e[60]),r[48]=q(e[21]),r[49]=q(e[34]),r[50]=q(e[37]),r[51]=q(e[47]),r[52]=q(e[50]),r[53]=q(e[56]),r[54]=q(e[59]),r[55]=q(e[61]),r[56]=q(e[35]),r[57]=q(e[36]),r[58]=q(e[48]),r[59]=q(e[49]),r[60]=q(e[57]),r[61]=q(e[58]),r[62]=q(e[62]),r[63]=q(e[63])}function I(e){const r=.5*Math.cos(.7853975),n=.5*Math.cos(3.14159/16),t=.5*Math.cos(3.14159/8),a=.5*Math.cos(3*3.14159/16),i=.5*Math.cos(.981746875),o=.5*Math.cos(3*3.14159/8),l=.5*Math.cos(1.374445625);for(var s=new Array(4),u=new Array(4),c=new Array(4),f=new Array(4),v=0;v<8;++v){var h=8*v;s[0]=t*e[h+2],s[1]=o*e[h+2],s[2]=t*e[h+6],s[3]=o*e[h+6],u[0]=n*e[h+1]+a*e[h+3]+i*e[h+5]+l*e[h+7],u[1]=a*e[h+1]-l*e[h+3]-n*e[h+5]-i*e[h+7],u[2]=i*e[h+1]-n*e[h+3]+l*e[h+5]+a*e[h+7],u[3]=l*e[h+1]-i*e[h+3]+a*e[h+5]-n*e[h+7],c[0]=r*(e[h+0]+e[h+4]),c[3]=r*(e[h+0]-e[h+4]),c[1]=s[0]+s[3],c[2]=s[1]-s[2],f[0]=c[0]+c[1],f[1]=c[3]+c[2],f[2]=c[3]-c[2],f[3]=c[0]-c[1],e[h+0]=f[0]+u[0],e[h+1]=f[1]+u[1],e[h+2]=f[2]+u[2],e[h+3]=f[3]+u[3],e[h+4]=f[3]-u[3],e[h+5]=f[2]-u[2],e[h+6]=f[1]-u[1],e[h+7]=f[0]-u[0]}for(var p=0;p<8;++p)s[0]=t*e[16+p],s[1]=o*e[16+p],s[2]=t*e[48+p],s[3]=o*e[48+p],u[0]=n*e[8+p]+a*e[24+p]+i*e[40+p]+l*e[56+p],u[1]=a*e[8+p]-l*e[24+p]-n*e[40+p]-i*e[56+p],u[2]=i*e[8+p]-n*e[24+p]+l*e[40+p]+a*e[56+p],u[3]=l*e[8+p]-i*e[24+p]+a*e[40+p]-n*e[56+p],c[0]=r*(e[p]+e[32+p]),c[3]=r*(e[p]-e[32+p]),c[1]=s[0]+s[3],c[2]=s[1]-s[2],f[0]=c[0]+c[1],f[1]=c[3]+c[2],f[2]=c[3]-c[2],f[3]=c[0]-c[1],e[0+p]=f[0]+u[0],e[8+p]=f[1]+u[1],e[16+p]=f[2]+u[2],e[24+p]=f[3]+u[3],e[32+p]=f[3]-u[3],e[40+p]=f[2]-u[2],e[48+p]=f[1]-u[1],e[56+p]=f[0]-u[0]}function x(e){for(var r=0;r<64;++r){var n=e[0][r],t=e[1][r],a=e[2][r];e[0][r]=n+1.5747*a,e[1][r]=n-.1873*t-.4682*a,e[2][r]=n+1.8556*t}}function k(r,n,t){for(var a=0;a<64;++a)n[t+a]=e.DataUtils.toHalfFloat(P(r[a]))}function P(e){return e<=1?Math.sign(e)*Math.pow(Math.abs(e),2.2):Math.sign(e)*Math.pow(l,Math.abs(e)-1)}function N(e){return new DataView(e.array.buffer,e.offset.value,e.size)}function D(e){var r=e.viewer.buffer.slice(e.offset.value,e.offset.value+e.size),n=new Uint8Array(E(r)),t=new Uint8Array(n.length);return z(n),C(n,t),new DataView(t.buffer)}function _(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),t=r.unzlibSync(n),a=new Uint8Array(t.length);return z(t),C(t,a),new DataView(a.buffer)}function T(e){for(var r=e.viewer,n={value:e.offset.value},a=new Uint16Array(e.width*e.scanlineBlockSize*(e.channels*e.type)),i=new Uint8Array(8192),o=0,l=new Array(e.channels),s=0;s<e.channels;s++)l[s]={},l[s].start=o,l[s].end=l[s].start,l[s].nx=e.width,l[s].ny=e.lines,l[s].size=e.type,o+=l[s].nx*l[s].ny*l[s].size;var u=j(r,n),c=j(r,n);if(c>=8192)throw"Something is wrong with PIZ_COMPRESSION BITMAP_SIZE";if(u<=c)for(s=0;s<c-u+1;s++)i[s+u]=W(r,n);var f=new Uint16Array(t),v=function(e,r){for(var n=0,a=0;a<t;++a)(0==a||e[a>>3]&1<<(7&a))&&(r[n++]=a);for(var i=n-1;n<t;)r[n++]=0;return i}(i,f),h=H(r,n);M(e.array,r,n,h,a,o);for(s=0;s<e.channels;++s)for(var p=l[s],w=0;w<l[s].size;++w)U(a,p.start+w,p.nx,p.size,p.ny,p.nx*p.size,v);!function(e,r,n){for(var t=0;t<n;++t)r[t]=e[r[t]]}(f,a,o);for(var d=0,y=new Uint8Array(a.buffer.byteLength),S=0;S<e.lines;S++)for(var g=0;g<e.channels;g++){var b=(p=l[g]).nx*p.size,m=new Uint8Array(a.buffer,2*p.end,2*b);y.set(m,d),d+=2*b,p.end+=b}return new DataView(y.buffer)}function L(e){var n=e.array.slice(e.offset.value,e.offset.value+e.size),t=r.unzlibSync(n);const a=e.lines*e.channels*e.width,i=1==e.type?new Uint16Array(a):new Uint32Array(a);let o=0,l=0;const s=new Array(4);for(let r=0;r<e.lines;r++)for(let r=0;r<e.channels;r++){let r=0;switch(e.type){case 1:s[0]=o,s[1]=s[0]+e.width,o=s[1]+e.width;for(let n=0;n<e.width;++n){r+=t[s[0]++]<<8|t[s[1]++],i[l]=r,l++}break;case 2:s[0]=o,s[1]=s[0]+e.width,s[2]=s[1]+e.width,o=s[2]+e.width;for(let n=0;n<e.width;++n){r+=t[s[0]++]<<24|t[s[1]++]<<16|t[s[2]++]<<8,i[l]=r,l++}}}return new DataView(i.buffer)}function F(e){var n=e.viewer,t={value:e.offset.value},a=new Uint8Array(e.width*e.lines*(e.channels*e.type*2)),i={version:Z(n,t),unknownUncompressedSize:Z(n,t),unknownCompressedSize:Z(n,t),acCompressedSize:Z(n,t),dcCompressedSize:Z(n,t),rleCompressedSize:Z(n,t),rleUncompressedSize:Z(n,t),rleRawSize:Z(n,t),totalAcUncompressedCount:Z(n,t),totalDcUncompressedCount:Z(n,t),acCompression:Z(n,t)};if(i.version<2)throw"EXRLoader.parse: "+re.compression+" version "+i.version+" is unsupported";for(var o=new Array,l=j(n,t)-2;l>0;){var s=B(n.buffer,t),u=W(n,t),c=u>>2&3,f=new Int8Array([(u>>4)-1])[0],v=W(n,t);o.push({name:s,index:f,type:v,compression:c}),l-=s.length+3}for(var h=re.channels,p=new Array(e.channels),w=0;w<e.channels;++w){var d=p[w]={},y=h[w];d.name=y.name,d.compression=0,d.decoded=!1,d.type=y.pixelType,d.pLinear=y.pLinear,d.width=e.width,d.height=e.lines}for(var S={idx:new Array(3)},g=0;g<e.channels;++g)for(d=p[g],w=0;w<o.length;++w){var b=o[w];d.name==b.name&&(d.compression=b.compression,b.index>=0&&(S.idx[b.index]=g),d.offset=g)}if(i.acCompressedSize>0)switch(i.acCompression){case 0:var m=new Uint16Array(i.totalAcUncompressedCount);M(e.array,n,t,i.acCompressedSize,m,i.totalAcUncompressedCount);break;case 1:var A=e.array.slice(t.value,t.value+i.totalAcUncompressedCount),U=r.unzlibSync(A);m=new Uint16Array(U.buffer);t.value+=i.totalAcUncompressedCount}if(i.dcCompressedSize>0){var z={array:e.array,offset:t,size:i.dcCompressedSize},C=new Uint16Array(_(z).buffer);t.value+=i.dcCompressedSize}if(i.rleRawSize>0){A=e.array.slice(t.value,t.value+i.rleCompressedSize);var P=E((U=r.unzlibSync(A)).buffer);t.value+=i.rleCompressedSize}var N=0,D=new Array(p.length);for(w=0;w<D.length;++w)D[w]=new Array;for(var T=0;T<e.lines;++T)for(var L=0;L<p.length;++L)D[L].push(N),N+=p[L].width*e.type*2;!function(e,r,n,t,a,i){var o=new DataView(i.buffer),l=n[e.idx[0]].width,s=n[e.idx[0]].height,u=Math.floor(l/8),c=Math.ceil(l/8),f=Math.ceil(s/8),v=l-8*(c-1),h=s-8*(f-1),p={value:0},w=new Array(3),d=new Array(3),y=new Array(3),S=new Array(3),g=new Array(3);for(let n=0;n<3;++n)g[n]=r[e.idx[n]],w[n]=n<1?0:w[n-1]+c*f,d[n]=new Float32Array(64),y[n]=new Uint16Array(64),S[n]=new Uint16Array(64*c);for(let r=0;r<f;++r){var b=8;r==f-1&&(b=h);var m=8;for(let e=0;e<c;++e){e==c-1&&(m=v);for(let e=0;e<3;++e)y[e].fill(0),y[e][0]=a[w[e]++],O(p,t,y[e]),R(y[e],d[e]),I(d[e]);x(d);for(let r=0;r<3;++r)k(d[r],S[r],64*e)}let i=0;for(let t=0;t<3;++t){const a=n[e.idx[t]].type;for(let e=8*r;e<8*r+b;++e){i=g[t][e];for(let r=0;r<u;++r){const n=64*r+8*(7&e);o.setUint16(i+0*a,S[t][n+0],!0),o.setUint16(i+2*a,S[t][n+1],!0),o.setUint16(i+4*a,S[t][n+2],!0),o.setUint16(i+6*a,S[t][n+3],!0),o.setUint16(i+8*a,S[t][n+4],!0),o.setUint16(i+10*a,S[t][n+5],!0),o.setUint16(i+12*a,S[t][n+6],!0),o.setUint16(i+14*a,S[t][n+7],!0),i+=16*a}}if(u!=c)for(let e=8*r;e<8*r+b;++e){const r=g[t][e]+8*u*2*a,n=64*u+8*(7&e);for(let e=0;e<m;++e)o.setUint16(r+2*e*a,S[t][n+e],!0)}}}for(var A=new Uint16Array(l),U=(o=new DataView(i.buffer),0);U<3;++U){n[e.idx[U]].decoded=!0;var M=n[e.idx[U]].type;if(2==n[U].type)for(var z=0;z<s;++z){const e=g[U][z];for(var C=0;C<l;++C)A[C]=o.getUint16(e+2*C*M,!0);for(C=0;C<l;++C)o.setFloat32(e+2*C*M,q(A[C]),!0)}}}(S,D,p,m,C,a);for(w=0;w<p.length;++w){if(!(d=p[w]).decoded)switch(d.compression){case 2:var F=0,X=0;for(T=0;T<e.lines;++T){for(var H=D[w][F],V=0;V<d.width;++V){for(var Y=0;Y<2*d.type;++Y)a[H++]=P[X+Y*d.width*d.height];X++}F++}break;case 1:default:throw"EXRLoader.parse: unsupported channel compression"}}return new DataView(a.buffer)}function B(e,r){for(var n=new Uint8Array(e),t=0;0!=n[r.value+t];)t+=1;var a=(new TextDecoder).decode(n.slice(r.value,r.value+t));return r.value=r.value+t+1,a}function X(e,r){var n=e.getInt32(r.value,!0);return r.value=r.value+4,n}function H(e,r){var n=e.getUint32(r.value,!0);return r.value=r.value+4,n}function V(e,r){var n=e[r.value];return r.value=r.value+1,n}function W(e,r){var n=e.getUint8(r.value);return r.value=r.value+1,n}const Z=function(e,r){let n;return n="getBigInt64"in DataView.prototype?Number(e.getBigInt64(r.value,!0)):e.getUint32(r.value+4,!0)+Number(e.getUint32(r.value,!0)<<32),r.value+=8,n};function Y(e,r){var n=e.getFloat32(r.value,!0);return r.value+=4,n}function G(r,n){return e.DataUtils.toHalfFloat(Y(r,n))}function q(e){var r=(31744&e)>>10,n=1023&e;return(e>>15?-1:1)*(r?31===r?n?NaN:1/0:Math.pow(2,r-15)*(1+n/1024):n/1024*6103515625e-14)}function j(e,r){var n=e.getUint16(r.value,!0);return r.value+=2,n}function $(e,r){return q(j(e,r))}function J(e,r,n,t,a){return"string"===t||"stringvector"===t||"iccProfile"===t?function(e,r,n){var t=(new TextDecoder).decode(new Uint8Array(e).slice(r.value,r.value+n));return r.value=r.value+n,t}(r,n,a):"chlist"===t?function(e,r,n,t){for(var a=n.value,i=[];n.value<a+t-1;){var o=B(r,n),l=X(e,n),s=W(e,n);n.value+=3;var u=X(e,n),c=X(e,n);i.push({name:o,pixelType:l,pLinear:s,xSampling:u,ySampling:c})}return n.value+=1,i}(e,r,n,a):"chromaticities"===t?function(e,r){return{redX:Y(e,r),redY:Y(e,r),greenX:Y(e,r),greenY:Y(e,r),blueX:Y(e,r),blueY:Y(e,r),whiteX:Y(e,r),whiteY:Y(e,r)}}(e,n):"compression"===t?function(e,r){return["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"][W(e,r)]}(e,n):"box2i"===t?function(e,r){return{xMin:H(e,r),yMin:H(e,r),xMax:H(e,r),yMax:H(e,r)}}(e,n):"lineOrder"===t?function(e,r){return["INCREASING_Y"][W(e,r)]}(e,n):"float"===t?Y(e,n):"v2f"===t?function(e,r){return[Y(e,r),Y(e,r)]}(e,n):"v3f"===t?function(e,r){return[Y(e,r),Y(e,r),Y(e,r)]}(e,n):"int"===t?X(e,n):"rational"===t?function(e,r){return[X(e,r),H(e,r)]}(e,n):"timecode"===t?function(e,r){return[H(e,r),H(e,r)]}(e,n):"preview"===t?(n.value+=a,"skipped"):void(n.value+=a)}const K=new DataView(n),Q=new Uint8Array(n),ee={value:0},re=function(e,r,n){const t={};if(20000630!=e.getUint32(0,!0))throw"THREE.EXRLoader: provided file doesn't appear to be in OpenEXR format.";t.version=e.getUint8(4);const a=e.getUint8(5);t.spec={singleTile:!!(2&a),longName:!!(4&a),deepFormat:!!(8&a),multiPart:!!(16&a)},n.value=8;for(var i=!0;i;){var o=B(r,n);if(0==o)i=!1;else{var l=B(r,n),s=J(e,r,n,l,H(e,n));void 0===s?console.warn(`EXRLoader.parse: skipped unknown header attribute type '${l}'.`):t[o]=s}}if(0!=a)throw console.error("EXRHeader:",t),"THREE.EXRLoader: provided file is currently unsupported.";return t}(K,n,ee),ne=function(r,n,t,a,i){const o={size:0,viewer:n,array:t,offset:a,width:r.dataWindow.xMax-r.dataWindow.xMin+1,height:r.dataWindow.yMax-r.dataWindow.yMin+1,channels:r.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:r.channels[0].pixelType,uncompress:null,getter:null,format:null,encoding:null};switch(r.compression){case"NO_COMPRESSION":o.lines=1,o.uncompress=N;break;case"RLE_COMPRESSION":o.lines=1,o.uncompress=D;break;case"ZIPS_COMPRESSION":o.lines=1,o.uncompress=_;break;case"ZIP_COMPRESSION":o.lines=16,o.uncompress=_;break;case"PIZ_COMPRESSION":o.lines=32,o.uncompress=T;break;case"PXR24_COMPRESSION":o.lines=16,o.uncompress=L;break;case"DWAA_COMPRESSION":o.lines=32,o.uncompress=F;break;case"DWAB_COMPRESSION":o.lines=256,o.uncompress=F;break;default:throw"EXRLoader.parse: "+r.compression+" is unsupported"}if(o.scanlineBlockSize=o.lines,1==o.type)switch(i){case e.FloatType:o.getter=$,o.inputSize=2;break;case e.HalfFloatType:o.getter=j,o.inputSize=2}else{if(2!=o.type)throw"EXRLoader.parse: unsupported pixelType "+o.type+" for "+r.compression+".";switch(i){case e.FloatType:o.getter=Y,o.inputSize=4;break;case e.HalfFloatType:o.getter=G,o.inputSize=4}}o.blockCount=(r.dataWindow.yMax+1)/o.scanlineBlockSize;for(var l=0;l<o.blockCount;l++)Z(n,a);o.outputChannels=3==o.channels?4:o.channels;const s=o.width*o.height*o.outputChannels;switch(i){case e.FloatType:o.byteArray=new Float32Array(s),o.channels<o.outputChannels&&o.byteArray.fill(1,0,s);break;case e.HalfFloatType:o.byteArray=new Uint16Array(s),o.channels<o.outputChannels&&o.byteArray.fill(15360,0,s);break;default:console.error("THREE.EXRLoader: unsupported type: ",i)}return o.bytesPerLine=o.width*o.inputSize*o.channels,4==o.outputChannels?(o.format=e.RGBAFormat,o.encoding=3e3):(o.format=e.RedFormat,o.encoding=3e3),o}(re,K,Q,ee,this.type),te={value:0},ae={R:0,G:1,B:2,A:3,Y:0};for(let e=0;e<ne.height/ne.scanlineBlockSize;e++){const r=H(K,ee);ne.size=H(K,ee),ne.lines=r+ne.scanlineBlockSize>ne.height?ne.height-r:ne.scanlineBlockSize;const n=ne.size<ne.lines*ne.bytesPerLine?ne.uncompress(ne):N(ne);ee.value+=ne.size;for(let r=0;r<ne.scanlineBlockSize;r++){const t=r+e*ne.scanlineBlockSize;if(t>=ne.height)break;for(let e=0;e<ne.channels;e++){const a=ae[re.channels[e].name];for(let i=0;i<ne.width;i++){te.value=(r*(ne.channels*ne.width)+e*ne.width+i)*ne.inputSize;const o=(ne.height-1-t)*(ne.width*ne.outputChannels)+i*ne.outputChannels+a;ne.byteArray[o]=ne.getter(n,te)}}}}return{header:re,width:ne.width,height:ne.height,data:ne.byteArray,format:ne.format,encoding:ne.encoding,type:this.type}}setDataType(e){return this.type=e,this}load(r,n,t,a){return super.load(r,(function(r,t){"colorSpace"in r?r.colorSpace=3001===t.encoding?"srgb":"srgb-linear":r.encoding=t.encoding,r.minFilter=e.LinearFilter,r.magFilter=e.LinearFilter,r.generateMipmaps=!1,r.flipY=!1,n&&n(r,t)}),t,a)}}exports.EXRLoader=n;
|
package/loaders/EXRLoader.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { DataTextureLoader, HalfFloatType, FloatType, RGBAFormat,
|
1
|
+
import { DataTextureLoader, HalfFloatType, FloatType, RGBAFormat, RedFormat, LinearFilter, DataUtils } from 'three';
|
2
2
|
import { unzlibSync } from 'fflate';
|
3
3
|
|
4
4
|
/**
|
@@ -1609,10 +1609,10 @@ class EXRLoader extends DataTextureLoader {
|
|
1609
1609
|
|
1610
1610
|
if (EXRDecoder.outputChannels == 4) {
|
1611
1611
|
EXRDecoder.format = RGBAFormat;
|
1612
|
-
EXRDecoder.encoding = LinearEncoding
|
1612
|
+
EXRDecoder.encoding = 3000; // LinearEncoding
|
1613
1613
|
} else {
|
1614
1614
|
EXRDecoder.format = RedFormat;
|
1615
|
-
EXRDecoder.encoding = LinearEncoding
|
1615
|
+
EXRDecoder.encoding = 3000; // LinearEncoding
|
1616
1616
|
}
|
1617
1617
|
|
1618
1618
|
return EXRDecoder;
|
@@ -1683,7 +1683,7 @@ class EXRLoader extends DataTextureLoader {
|
|
1683
1683
|
|
1684
1684
|
load(url, onLoad, onProgress, onError) {
|
1685
1685
|
function onLoadCallback(texture, texData) {
|
1686
|
-
texture.encoding = texData.encoding;
|
1686
|
+
if ('colorSpace' in texture) texture.colorSpace = texData.encoding === 3001 ? 'srgb' : 'srgb-linear';else texture.encoding = texData.encoding;
|
1687
1687
|
texture.minFilter = LinearFilter;
|
1688
1688
|
texture.magFilter = LinearFilter;
|
1689
1689
|
texture.generateMipmaps = false;
|
package/loaders/FBXLoader.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("fflate"),r=require("../curves/NURBSCurve.cjs.js");let n,o,a;require("../curves/NURBSUtils.cjs.js");class s extends e.Loader{constructor(e){super(e)}load(t,r,n,o){const a=this,s=""===a.path?e.LoaderUtils.extractUrlBase(t):a.path,i=new e.FileLoader(this.manager);i.setPath(a.path),i.setResponseType("arraybuffer"),i.setRequestHeader(a.requestHeader),i.setWithCredentials(a.withCredentials),i.load(t,(function(e){try{r(a.parse(e,s))}catch(e){o?o(e):console.error(e),a.manager.itemError(t)}}),n,o)}parse(t,r){if(function(e){const t="Kaydara FBX Binary \0";return e.byteLength>=t.length&&t===T(e,0,t.length)}(t))n=(new p).parse(t);else{const e=T(t);if(!function(e){const t=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let r=0;function n(t){const n=e[t-1];return e=e.slice(r+t),r++,n}for(let e=0;e<t.length;++e){if(n(1)===t[e])return!1}return!0}(e))throw new Error("THREE.FBXLoader: Unknown format.");if(f(e)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+f(e));n=(new u).parse(e)}const o=new e.TextureLoader(this.manager).setPath(this.resourcePath||r).setCrossOrigin(this.crossOrigin);return new i(o,this.manager).parse(n)}}class i{constructor(e,t){this.textureLoader=e,this.manager=t}parse(){o=this.parseConnections();const e=this.parseImages(),t=this.parseTextures(e),r=this.parseMaterials(t),n=this.parseDeformers(),s=(new l).parse(n);return this.parseScene(n,s,r),a}parseConnections(){const e=new Map;if("Connections"in n){n.Connections.connections.forEach((function(t){const r=t[0],n=t[1],o=t[2];e.has(r)||e.set(r,{parents:[],children:[]});const a={ID:n,relationship:o};e.get(r).parents.push(a),e.has(n)||e.set(n,{parents:[],children:[]});const s={ID:r,relationship:o};e.get(n).children.push(s)}))}return e}parseImages(){const e={},t={};if("Video"in n.Objects){const r=n.Objects.Video;for(const n in r){const o=r[n];if(e[parseInt(n)]=o.RelativeFilename||o.Filename,"Content"in o){const e=o.Content instanceof ArrayBuffer&&o.Content.byteLength>0,a="string"==typeof o.Content&&""!==o.Content;if(e||a){const e=this.parseImage(r[n]);t[o.RelativeFilename||o.Filename]=e}}}}for(const r in e){const n=e[r];void 0!==t[n]?e[r]=t[n]:e[r]=e[r].split("\\").pop()}return e}parseImage(e){const t=e.Content,r=e.RelativeFilename||e.Filename,n=r.slice(r.lastIndexOf(".")+1).toLowerCase();let o;switch(n){case"bmp":o="image/bmp";break;case"jpg":case"jpeg":o="image/jpeg";break;case"png":o="image/png";break;case"tif":o="image/tiff";break;case"tga":null===this.manager.getHandler(".tga")&&console.warn("FBXLoader: TGA loader not found, skipping ",r),o="image/tga";break;default:return void console.warn('FBXLoader: Image type "'+n+'" is not supported.')}if("string"==typeof t)return"data:"+o+";base64,"+t;{const e=new Uint8Array(t);return window.URL.createObjectURL(new Blob([e],{type:o}))}}parseTextures(e){const t=new Map;if("Texture"in n.Objects){const r=n.Objects.Texture;for(const n in r){const o=this.parseTexture(r[n],e);t.set(parseInt(n),o)}}return t}parseTexture(t,r){const n=this.loadTexture(t,r);n.ID=t.id,n.name=t.attrName;const o=t.WrapModeU,a=t.WrapModeV,s=void 0!==o?o.value:0,i=void 0!==a?a.value:0;if(n.wrapS=0===s?e.RepeatWrapping:e.ClampToEdgeWrapping,n.wrapT=0===i?e.RepeatWrapping:e.ClampToEdgeWrapping,"Scaling"in t){const e=t.Scaling.value;n.repeat.x=e[0],n.repeat.y=e[1]}return n}loadTexture(t,r){let n;const a=this.textureLoader.path,s=o.get(t.id).children;let i;void 0!==s&&s.length>0&&void 0!==r[s[0].ID]&&(n=r[s[0].ID],0!==n.indexOf("blob:")&&0!==n.indexOf("data:")||this.textureLoader.setPath(void 0));const l=t.FileName.slice(-3).toLowerCase();if("tga"===l){const r=this.manager.getHandler(".tga");null===r?(console.warn("FBXLoader: TGA loader not found, creating placeholder texture for",t.RelativeFilename),i=new e.Texture):(r.setPath(this.textureLoader.path),i=r.load(n))}else"psd"===l?(console.warn("FBXLoader: PSD textures are not supported, creating placeholder texture for",t.RelativeFilename),i=new e.Texture):i=this.textureLoader.load(n);return this.textureLoader.setPath(a),i}parseMaterials(e){const t=new Map;if("Material"in n.Objects){const r=n.Objects.Material;for(const n in r){const o=this.parseMaterial(r[n],e);null!==o&&t.set(parseInt(n),o)}}return t}parseMaterial(t,r){const n=t.id,a=t.attrName;let s=t.ShadingModel;if("object"==typeof s&&(s=s.value),!o.has(n))return null;const i=this.parseParameters(t,r,n);let l;switch(s.toLowerCase()){case"phong":l=new e.MeshPhongMaterial;break;case"lambert":l=new e.MeshLambertMaterial;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',s),l=new e.MeshPhongMaterial}return l.setValues(i),l.name=a,l}parseParameters(t,r,n){const a={};t.BumpFactor&&(a.bumpScale=t.BumpFactor.value),t.Diffuse?a.color=(new e.Color).fromArray(t.Diffuse.value):!t.DiffuseColor||"Color"!==t.DiffuseColor.type&&"ColorRGB"!==t.DiffuseColor.type||(a.color=(new e.Color).fromArray(t.DiffuseColor.value)),t.DisplacementFactor&&(a.displacementScale=t.DisplacementFactor.value),t.Emissive?a.emissive=(new e.Color).fromArray(t.Emissive.value):!t.EmissiveColor||"Color"!==t.EmissiveColor.type&&"ColorRGB"!==t.EmissiveColor.type||(a.emissive=(new e.Color).fromArray(t.EmissiveColor.value)),t.EmissiveFactor&&(a.emissiveIntensity=parseFloat(t.EmissiveFactor.value)),t.Opacity&&(a.opacity=parseFloat(t.Opacity.value)),a.opacity<1&&(a.transparent=!0),t.ReflectionFactor&&(a.reflectivity=t.ReflectionFactor.value),t.Shininess&&(a.shininess=t.Shininess.value),t.Specular?a.specular=(new e.Color).fromArray(t.Specular.value):t.SpecularColor&&"Color"===t.SpecularColor.type&&(a.specular=(new e.Color).fromArray(t.SpecularColor.value));const s=this;return o.get(n).children.forEach((function(t){const n=t.relationship;switch(n){case"Bump":a.bumpMap=s.getTexture(r,t.ID);break;case"Maya|TEX_ao_map":a.aoMap=s.getTexture(r,t.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":a.map=s.getTexture(r,t.ID),void 0!==a.map&&(a.map.encoding=e.sRGBEncoding);break;case"DisplacementColor":a.displacementMap=s.getTexture(r,t.ID);break;case"EmissiveColor":a.emissiveMap=s.getTexture(r,t.ID),void 0!==a.emissiveMap&&(a.emissiveMap.encoding=e.sRGBEncoding);break;case"NormalMap":case"Maya|TEX_normal_map":a.normalMap=s.getTexture(r,t.ID);break;case"ReflectionColor":a.envMap=s.getTexture(r,t.ID),void 0!==a.envMap&&(a.envMap.mapping=e.EquirectangularReflectionMapping,a.envMap.encoding=e.sRGBEncoding);break;case"SpecularColor":a.specularMap=s.getTexture(r,t.ID),void 0!==a.specularMap&&(a.specularMap.encoding=e.sRGBEncoding);break;case"TransparentColor":case"TransparencyFactor":a.alphaMap=s.getTexture(r,t.ID),a.transparent=!0;break;case"AmbientColor":case"ShininessExponent":case"SpecularFactor":case"VectorDisplacementColor":default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",n)}})),a}getTexture(e,t){return"LayeredTexture"in n.Objects&&t in n.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=o.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in n.Objects){const r=n.Objects.Deformer;for(const n in r){const a=r[n],s=o.get(parseInt(n));if("Skin"===a.attrType){const t=this.parseSkeleton(s,r);t.ID=n,s.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),t.geometryID=s.parents[0].ID,e[n]=t}else if("BlendShape"===a.attrType){const e={id:n};e.rawTargets=this.parseMorphTargets(s,r),e.id=n,s.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[n]=e}}}return{skeletons:e,morphTargets:t}}parseSkeleton(t,r){const n=[];return t.children.forEach((function(t){const o=r[t.ID];if("Cluster"!==o.attrType)return;const a={ID:t.ID,indices:[],weights:[],transformLink:(new e.Matrix4).fromArray(o.TransformLink.a)};"Indexes"in o&&(a.indices=o.Indexes.a,a.weights=o.Weights.a),n.push(a)})),{rawBones:n,bones:[]}}parseMorphTargets(e,t){const r=[];for(let n=0;n<e.children.length;n++){const a=e.children[n],s=t[a.ID],i={name:s.attrName,initialWeight:s.DeformPercent,id:s.id,fullWeights:s.FullWeights.a};if("BlendShapeChannel"!==s.attrType)return;i.geoID=o.get(parseInt(a.ID)).children.filter((function(e){return void 0===e.relationship}))[0].ID,r.push(i)}return r}parseScene(t,r,s){a=new e.Group;const i=this.parseModels(t.skeletons,r,s),l=n.Objects.Model,u=this;i.forEach((function(e){const t=l[e.ID];u.setLookAtProperties(e,t);o.get(e.ID).parents.forEach((function(t){const r=i.get(t.ID);void 0!==r&&r.add(e)})),null===e.parent&&a.add(e)})),this.bindSkeleton(t.skeletons,r,i),this.createAmbientLight(),a.traverse((function(e){if(e.userData.transformData){e.parent&&(e.userData.transformData.parentMatrix=e.parent.matrix,e.userData.transformData.parentMatrixWorld=e.parent.matrixWorld);const t=I(e.userData.transformData);e.applyMatrix4(t),e.updateWorldMatrix()}}));const p=(new c).parse();1===a.children.length&&a.children[0].isGroup&&(a.children[0].animations=p,a=a.children[0]),a.animations=p}parseModels(t,r,a){const s=new Map,i=n.Objects.Model;for(const n in i){const l=parseInt(n),c=i[n],u=o.get(l);let p=this.buildSkeleton(u,t,l,c.attrName);if(!p){switch(c.attrType){case"Camera":p=this.createCamera(u);break;case"Light":p=this.createLight(u);break;case"Mesh":p=this.createMesh(u,r,a);break;case"NurbsCurve":p=this.createCurve(u,r);break;case"LimbNode":case"Root":p=new e.Bone;break;case"Null":default:p=new e.Group}p.name=c.attrName?e.PropertyBinding.sanitizeNodeName(c.attrName):"",p.ID=l}this.getTransformData(p,c),s.set(l,p)}return s}buildSkeleton(t,r,n,o){let a=null;return t.parents.forEach((function(t){for(const s in r){const i=r[s];i.rawBones.forEach((function(r,s){if(r.ID===t.ID){const t=a;a=new e.Bone,a.matrixWorld.copy(r.transformLink),a.name=o?e.PropertyBinding.sanitizeNodeName(o):"",a.ID=n,i.bones[s]=a,null!==t&&a.add(t)}}))}})),a}createCamera(t){let r,o;if(t.children.forEach((function(e){const t=n.Objects.NodeAttribute[e.ID];void 0!==t&&(o=t)})),void 0===o)r=new e.Object3D;else{let t=0;void 0!==o.CameraProjectionType&&1===o.CameraProjectionType.value&&(t=1);let n=1;void 0!==o.NearPlane&&(n=o.NearPlane.value/1e3);let a=1e3;void 0!==o.FarPlane&&(a=o.FarPlane.value/1e3);let s=window.innerWidth,i=window.innerHeight;void 0!==o.AspectWidth&&void 0!==o.AspectHeight&&(s=o.AspectWidth.value,i=o.AspectHeight.value);const l=s/i;let c=45;void 0!==o.FieldOfView&&(c=o.FieldOfView.value);const u=o.FocalLength?o.FocalLength.value:null;switch(t){case 0:r=new e.PerspectiveCamera(c,l,n,a),null!==u&&r.setFocalLength(u);break;case 1:r=new e.OrthographicCamera(-s/2,s/2,i/2,-i/2,n,a);break;default:console.warn("THREE.FBXLoader: Unknown camera type "+t+"."),r=new e.Object3D}}return r}createLight(t){let r,o;if(t.children.forEach((function(e){const t=n.Objects.NodeAttribute[e.ID];void 0!==t&&(o=t)})),void 0===o)r=new e.Object3D;else{let t;t=void 0===o.LightType?0:o.LightType.value;let n=16777215;void 0!==o.Color&&(n=(new e.Color).fromArray(o.Color.value));let a=void 0===o.Intensity?1:o.Intensity.value/100;void 0!==o.CastLightOnObject&&0===o.CastLightOnObject.value&&(a=0);let s=0;void 0!==o.FarAttenuationEnd&&(s=void 0!==o.EnableFarAttenuation&&0===o.EnableFarAttenuation.value?0:o.FarAttenuationEnd.value);const i=1;switch(t){case 0:r=new e.PointLight(n,a,s,i);break;case 1:r=new e.DirectionalLight(n,a);break;case 2:let t=Math.PI/3;void 0!==o.InnerAngle&&(t=e.MathUtils.degToRad(o.InnerAngle.value));let l=0;void 0!==o.OuterAngle&&(l=e.MathUtils.degToRad(o.OuterAngle.value),l=Math.max(l,1)),r=new e.SpotLight(n,a,s,t,l,i);break;default:console.warn("THREE.FBXLoader: Unknown light type "+o.LightType.value+", defaulting to a PointLight."),r=new e.PointLight(n,a)}void 0!==o.CastShadows&&1===o.CastShadows.value&&(r.castShadow=!0)}return r}createMesh(t,r,n){let o,a=null,s=null;const i=[];return t.children.forEach((function(e){r.has(e.ID)&&(a=r.get(e.ID)),n.has(e.ID)&&i.push(n.get(e.ID))})),i.length>1?s=i:i.length>0?s=i[0]:(s=new e.MeshPhongMaterial({color:13421772}),i.push(s)),"color"in a.attributes&&i.forEach((function(e){e.vertexColors=!0})),a.FBX_Deformer?(o=new e.SkinnedMesh(a,s),o.normalizeSkinWeights()):o=new e.Mesh(a,s),o}createCurve(t,r){const n=t.children.reduce((function(e,t){return r.has(t.ID)&&(e=r.get(t.ID)),e}),null),o=new e.LineBasicMaterial({color:3342591,linewidth:1});return new e.Line(n,o)}getTransformData(e,t){const r={};"InheritType"in t&&(r.inheritType=parseInt(t.InheritType.value)),r.eulerOrder="RotationOrder"in t?x(t.RotationOrder.value):"ZYX","Lcl_Translation"in t&&(r.translation=t.Lcl_Translation.value),"PreRotation"in t&&(r.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(r.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(r.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(r.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(r.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(r.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(r.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(r.rotationPivot=t.RotationPivot.value),e.userData.transformData=r}setLookAtProperties(t,r){if("LookAtProperty"in r){o.get(t.ID).children.forEach((function(r){if("LookAtProperty"===r.relationship){const o=n.Objects.Model[r.ID];if("Lcl_Translation"in o){const r=o.Lcl_Translation.value;void 0!==t.target?(t.target.position.fromArray(r),a.add(t.target)):t.lookAt((new e.Vector3).fromArray(r))}}}))}}bindSkeleton(t,r,n){const a=this.parsePoseNodes();for(const s in t){const i=t[s];o.get(parseInt(i.ID)).parents.forEach((function(t){if(r.has(t.ID)){const r=t.ID;o.get(r).parents.forEach((function(t){if(n.has(t.ID)){n.get(t.ID).bind(new e.Skeleton(i.bones),a[t.ID])}}))}}))}}parsePoseNodes(){const t={};if("Pose"in n.Objects){const r=n.Objects.Pose;for(const n in r)if("BindPose"===r[n].attrType&&r[n].NbPoseNodes>0){const o=r[n].PoseNode;Array.isArray(o)?o.forEach((function(r){t[r.Node]=(new e.Matrix4).fromArray(r.Matrix.a)})):t[o.Node]=(new e.Matrix4).fromArray(o.Matrix.a)}}return t}createAmbientLight(){if("GlobalSettings"in n&&"AmbientColor"in n.GlobalSettings){const t=n.GlobalSettings.AmbientColor.value,r=t[0],o=t[1],s=t[2];if(0!==r||0!==o||0!==s){const t=new e.Color(r,o,s);a.add(new e.AmbientLight(t,1))}}}}class l{parse(e){const t=new Map;if("Geometry"in n.Objects){const r=n.Objects.Geometry;for(const n in r){const a=o.get(parseInt(n)),s=this.parseGeometry(a,r[n],e);t.set(parseInt(n),s)}}return t}parseGeometry(e,t,r){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,r);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,r){const o=r.skeletons,a=[],s=e.parents.map((function(e){return n.Objects.Model[e.ID]}));if(0===s.length)return;const i=e.children.reduce((function(e,t){return void 0!==o[t.ID]&&(e=o[t.ID]),e}),null);e.children.forEach((function(e){void 0!==r.morphTargets[e.ID]&&a.push(r.morphTargets[e.ID])}));const l=s[0],c={};"RotationOrder"in l&&(c.eulerOrder=x(l.RotationOrder.value)),"InheritType"in l&&(c.inheritType=parseInt(l.InheritType.value)),"GeometricTranslation"in l&&(c.translation=l.GeometricTranslation.value),"GeometricRotation"in l&&(c.rotation=l.GeometricRotation.value),"GeometricScaling"in l&&(c.scale=l.GeometricScaling.value);const u=I(c);return this.genGeometry(t,i,a,u)}genGeometry(t,r,n,o){const a=new e.BufferGeometry;t.attrName&&(a.name=t.attrName);const s=this.parseGeoNode(t,r),i=this.genBuffers(s),l=new e.Float32BufferAttribute(i.vertex,3);if(l.applyMatrix4(o),a.setAttribute("position",l),i.colors.length>0&&a.setAttribute("color",new e.Float32BufferAttribute(i.colors,3)),r&&(a.setAttribute("skinIndex",new e.Uint16BufferAttribute(i.weightsIndices,4)),a.setAttribute("skinWeight",new e.Float32BufferAttribute(i.vertexWeights,4)),a.FBX_Deformer=r),i.normal.length>0){const t=(new e.Matrix3).getNormalMatrix(o),r=new e.Float32BufferAttribute(i.normal,3);r.applyNormalMatrix(t),a.setAttribute("normal",r)}if(i.uvs.forEach((function(t,r){let n="uv"+(r+1).toString();0===r&&(n="uv"),a.setAttribute(n,new e.Float32BufferAttribute(i.uvs[r],2))})),s.material&&"AllSame"!==s.material.mappingType){let e=i.materialIndex[0],t=0;if(i.materialIndex.forEach((function(r,n){r!==e&&(a.addGroup(t,n-t,e),e=r,t=n)})),a.groups.length>0){const t=a.groups[a.groups.length-1],r=t.start+t.count;r!==i.materialIndex.length&&a.addGroup(r,i.materialIndex.length-r,e)}0===a.groups.length&&a.addGroup(0,i.materialIndex.length,i.materialIndex[0])}return this.addMorphTargets(a,t,n,o),a}parseGeoNode(e,t){const r={};if(r.vertexPositions=void 0!==e.Vertices?e.Vertices.a:[],r.vertexIndices=void 0!==e.PolygonVertexIndex?e.PolygonVertexIndex.a:[],e.LayerElementColor&&(r.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(r.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(r.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){r.uv=[];let t=0;for(;e.LayerElementUV[t];)e.LayerElementUV[t].UV&&r.uv.push(this.parseUVs(e.LayerElementUV[t])),t++}return r.weightTable={},null!==t&&(r.skeleton=t,t.rawBones.forEach((function(e,t){e.indices.forEach((function(n,o){void 0===r.weightTable[n]&&(r.weightTable[n]=[]),r.weightTable[n].push({id:t,weight:e.weights[o]})}))}))),r}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let r=0,n=0,o=!1,a=[],s=[],i=[],l=[],c=[],u=[];const p=this;return e.vertexIndices.forEach((function(h,d){let f,m=!1;h<0&&(h^=-1,m=!0);let g=[],y=[];if(a.push(3*h,3*h+1,3*h+2),e.color){const t=v(d,r,h,e.color);i.push(t[0],t[1],t[2])}if(e.skeleton){if(void 0!==e.weightTable[h]&&e.weightTable[h].forEach((function(e){y.push(e.weight),g.push(e.id)})),y.length>4){o||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),o=!0);const e=[0,0,0,0],t=[0,0,0,0];y.forEach((function(r,n){let o=r,a=g[n];t.forEach((function(t,r,n){if(o>t){n[r]=o,o=t;const s=e[r];e[r]=a,a=s}}))})),g=e,y=t}for(;y.length<4;)y.push(0),g.push(0);for(let e=0;e<4;++e)c.push(y[e]),u.push(g[e])}if(e.normal){const t=v(d,r,h,e.normal);s.push(t[0],t[1],t[2])}e.material&&"AllSame"!==e.material.mappingType&&(f=v(d,r,h,e.material)[0]),e.uv&&e.uv.forEach((function(e,t){const n=v(d,r,h,e);void 0===l[t]&&(l[t]=[]),l[t].push(n[0]),l[t].push(n[1])})),n++,m&&(p.genFace(t,e,a,f,s,i,l,c,u,n),r++,n=0,a=[],s=[],i=[],l=[],c=[],u=[])})),t}genFace(e,t,r,n,o,a,s,i,l,c){for(let u=2;u<c;u++)e.vertex.push(t.vertexPositions[r[0]]),e.vertex.push(t.vertexPositions[r[1]]),e.vertex.push(t.vertexPositions[r[2]]),e.vertex.push(t.vertexPositions[r[3*(u-1)]]),e.vertex.push(t.vertexPositions[r[3*(u-1)+1]]),e.vertex.push(t.vertexPositions[r[3*(u-1)+2]]),e.vertex.push(t.vertexPositions[r[3*u]]),e.vertex.push(t.vertexPositions[r[3*u+1]]),e.vertex.push(t.vertexPositions[r[3*u+2]]),t.skeleton&&(e.vertexWeights.push(i[0]),e.vertexWeights.push(i[1]),e.vertexWeights.push(i[2]),e.vertexWeights.push(i[3]),e.vertexWeights.push(i[4*(u-1)]),e.vertexWeights.push(i[4*(u-1)+1]),e.vertexWeights.push(i[4*(u-1)+2]),e.vertexWeights.push(i[4*(u-1)+3]),e.vertexWeights.push(i[4*u]),e.vertexWeights.push(i[4*u+1]),e.vertexWeights.push(i[4*u+2]),e.vertexWeights.push(i[4*u+3]),e.weightsIndices.push(l[0]),e.weightsIndices.push(l[1]),e.weightsIndices.push(l[2]),e.weightsIndices.push(l[3]),e.weightsIndices.push(l[4*(u-1)]),e.weightsIndices.push(l[4*(u-1)+1]),e.weightsIndices.push(l[4*(u-1)+2]),e.weightsIndices.push(l[4*(u-1)+3]),e.weightsIndices.push(l[4*u]),e.weightsIndices.push(l[4*u+1]),e.weightsIndices.push(l[4*u+2]),e.weightsIndices.push(l[4*u+3])),t.color&&(e.colors.push(a[0]),e.colors.push(a[1]),e.colors.push(a[2]),e.colors.push(a[3*(u-1)]),e.colors.push(a[3*(u-1)+1]),e.colors.push(a[3*(u-1)+2]),e.colors.push(a[3*u]),e.colors.push(a[3*u+1]),e.colors.push(a[3*u+2])),t.material&&"AllSame"!==t.material.mappingType&&(e.materialIndex.push(n),e.materialIndex.push(n),e.materialIndex.push(n)),t.normal&&(e.normal.push(o[0]),e.normal.push(o[1]),e.normal.push(o[2]),e.normal.push(o[3*(u-1)]),e.normal.push(o[3*(u-1)+1]),e.normal.push(o[3*(u-1)+2]),e.normal.push(o[3*u]),e.normal.push(o[3*u+1]),e.normal.push(o[3*u+2])),t.uv&&t.uv.forEach((function(t,r){void 0===e.uvs[r]&&(e.uvs[r]=[]),e.uvs[r].push(s[r][0]),e.uvs[r].push(s[r][1]),e.uvs[r].push(s[r][2*(u-1)]),e.uvs[r].push(s[r][2*(u-1)+1]),e.uvs[r].push(s[r][2*u]),e.uvs[r].push(s[r][2*u+1])}))}addMorphTargets(e,t,r,o){if(0===r.length)return;e.morphTargetsRelative=!0,e.morphAttributes.position=[];const a=this;r.forEach((function(r){r.rawTargets.forEach((function(r){const s=n.Objects.Geometry[r.geoID];void 0!==s&&a.genMorphGeometry(e,t,s,o,r.name)}))}))}genMorphGeometry(t,r,n,o,a){const s=void 0!==r.PolygonVertexIndex?r.PolygonVertexIndex.a:[],i=void 0!==n.Vertices?n.Vertices.a:[],l=void 0!==n.Indexes?n.Indexes.a:[],c=3*t.attributes.position.count,u=new Float32Array(c);for(let e=0;e<l.length;e++){const t=3*l[e];u[t]=i[3*e],u[t+1]=i[3*e+1],u[t+2]=i[3*e+2]}const p={vertexIndices:s,vertexPositions:u},h=this.genBuffers(p),d=new e.Float32BufferAttribute(h.vertex,3);d.name=a||n.attrName,d.applyMatrix4(o),t.morphAttributes.position.push(d)}parseNormals(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.Normals.a;let o=[];return"IndexToDirect"===r&&("NormalIndex"in e?o=e.NormalIndex.a:"NormalsIndex"in e&&(o=e.NormalsIndex.a)),{dataSize:3,buffer:n,indices:o,mappingType:t,referenceType:r}}parseUVs(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.UV.a;let o=[];return"IndexToDirect"===r&&(o=e.UVIndex.a),{dataSize:2,buffer:n,indices:o,mappingType:t,referenceType:r}}parseVertexColors(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.Colors.a;let o=[];return"IndexToDirect"===r&&(o=e.ColorIndex.a),{dataSize:4,buffer:n,indices:o,mappingType:t,referenceType:r}}parseMaterialIndices(e){const t=e.MappingInformationType,r=e.ReferenceInformationType;if("NoMappingInformation"===t)return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:r};const n=e.Materials.a,o=[];for(let e=0;e<n.length;++e)o.push(e);return{dataSize:1,buffer:n,indices:o,mappingType:t,referenceType:r}}parseNurbsGeometry(t){if(void 0===r.NURBSCurve)return console.error("THREE.FBXLoader: The loader relies on NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry."),new e.BufferGeometry;const n=parseInt(t.Order);if(isNaN(n))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",t.Order,t.id),new e.BufferGeometry;const o=n-1,a=t.KnotVector.a,s=[],i=t.Points.a;for(let t=0,r=i.length;t<r;t+=4)s.push((new e.Vector4).fromArray(i,t));let l,c;if("Closed"===t.Form)s.push(s[0]);else if("Periodic"===t.Form){l=o,c=a.length-1-l;for(let e=0;e<o;++e)s.push(s[e])}const u=new r.NURBSCurve(o,a,s,l,c).getPoints(12*s.length);return(new e.BufferGeometry).setFromPoints(u)}}class c{parse(){const e=[],t=this.parseClips();if(void 0!==t)for(const r in t){const n=t[r],o=this.addClip(n);e.push(o)}return e}parseClips(){if(void 0===n.Objects.AnimationCurve)return;const e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);const t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}parseAnimationCurveNodes(){const e=n.Objects.AnimationCurveNode,t=new Map;for(const r in e){const n=e[r];if(null!==n.attrName.match(/S|R|T|DeformPercent/)){const e={id:n.id,attr:n.attrName,curves:{}};t.set(e.id,e)}}return t}parseAnimationCurves(e){const t=n.Objects.AnimationCurve;for(const r in t){const n={id:t[r].id,times:t[r].KeyTime.a.map(m),values:t[r].KeyValueFloat.a},a=o.get(n.id);if(void 0!==a){const t=a.parents[0].ID,r=a.parents[0].relationship;r.match(/X/)?e.get(t).curves.x=n:r.match(/Y/)?e.get(t).curves.y=n:r.match(/Z/)?e.get(t).curves.z=n:r.match(/d|DeformPercent/)&&e.has(t)&&(e.get(t).curves.morph=n)}}}parseAnimationLayers(t){const r=n.Objects.AnimationLayer,s=new Map;for(const i in r){const r=[],l=o.get(parseInt(i));if(void 0!==l){l.children.forEach((function(s,i){if(t.has(s.ID)){const l=t.get(s.ID);if(void 0!==l.curves.x||void 0!==l.curves.y||void 0!==l.curves.z){if(void 0===r[i]){const t=o.get(s.ID).parents.filter((function(e){return void 0!==e.relationship}))[0].ID;if(void 0!==t){const o=n.Objects.Model[t.toString()];if(void 0===o)return void console.warn("THREE.FBXLoader: Encountered a unused curve.",s);const l={modelName:o.attrName?e.PropertyBinding.sanitizeNodeName(o.attrName):"",ID:o.id,initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1]};a.traverse((function(e){e.ID===o.id&&(l.transform=e.matrix,e.userData.transformData&&(l.eulerOrder=e.userData.transformData.eulerOrder))})),l.transform||(l.transform=new e.Matrix4),"PreRotation"in o&&(l.preRotation=o.PreRotation.value),"PostRotation"in o&&(l.postRotation=o.PostRotation.value),r[i]=l}}r[i]&&(r[i][l.attr]=l)}else if(void 0!==l.curves.morph){if(void 0===r[i]){const t=o.get(s.ID).parents.filter((function(e){return void 0!==e.relationship}))[0].ID,a=o.get(t).parents[0].ID,l=o.get(a).parents[0].ID,c=o.get(l).parents[0].ID,u=n.Objects.Model[c],p={modelName:u.attrName?e.PropertyBinding.sanitizeNodeName(u.attrName):"",morphName:n.Objects.Deformer[t].attrName};r[i]=p}r[i][l.attr]=l}}})),s.set(parseInt(i),r)}}return s}parseAnimStacks(e){const t=n.Objects.AnimationStack,r={};for(const n in t){const a=o.get(parseInt(n)).children;a.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const s=e.get(a[0].ID);r[n]={name:t[n].attrName,layer:s}}return r}addClip(t){let r=[];const n=this;return t.layer.forEach((function(e){r=r.concat(n.generateTracks(e))})),new e.AnimationClip(t.name,-1,r)}generateTracks(t){const r=[];let n=new e.Vector3,o=new e.Quaternion,a=new e.Vector3;if(t.transform&&t.transform.decompose(n,o,a),n=n.toArray(),o=(new e.Euler).setFromQuaternion(o,t.eulerOrder).toArray(),a=a.toArray(),void 0!==t.T&&Object.keys(t.T.curves).length>0){const e=this.generateVectorTrack(t.modelName,t.T.curves,n,"position");void 0!==e&&r.push(e)}if(void 0!==t.R&&Object.keys(t.R.curves).length>0){const e=this.generateRotationTrack(t.modelName,t.R.curves,o,t.preRotation,t.postRotation,t.eulerOrder);void 0!==e&&r.push(e)}if(void 0!==t.S&&Object.keys(t.S.curves).length>0){const e=this.generateVectorTrack(t.modelName,t.S.curves,a,"scale");void 0!==e&&r.push(e)}if(void 0!==t.DeformPercent){const e=this.generateMorphTrack(t);void 0!==e&&r.push(e)}return r}generateVectorTrack(t,r,n,o){const a=this.getTimesForAllAxes(r),s=this.getKeyframeTrackValues(a,r,n);return new e.VectorKeyframeTrack(t+"."+o,a,s)}generateRotationTrack(t,r,n,o,a,s){void 0!==r.x&&(this.interpolateRotations(r.x),r.x.values=r.x.values.map(e.MathUtils.degToRad)),void 0!==r.y&&(this.interpolateRotations(r.y),r.y.values=r.y.values.map(e.MathUtils.degToRad)),void 0!==r.z&&(this.interpolateRotations(r.z),r.z.values=r.z.values.map(e.MathUtils.degToRad));const i=this.getTimesForAllAxes(r),l=this.getKeyframeTrackValues(i,r,n);void 0!==o&&((o=o.map(e.MathUtils.degToRad)).push(s),o=(new e.Euler).fromArray(o),o=(new e.Quaternion).setFromEuler(o)),void 0!==a&&((a=a.map(e.MathUtils.degToRad)).push(s),a=(new e.Euler).fromArray(a),a=(new e.Quaternion).setFromEuler(a).invert());const c=new e.Quaternion,u=new e.Euler,p=[];for(let e=0;e<l.length;e+=3)u.set(l[e],l[e+1],l[e+2],s),c.setFromEuler(u),void 0!==o&&c.premultiply(o),void 0!==a&&c.multiply(a),c.toArray(p,e/3*4);return new e.QuaternionKeyframeTrack(t+".quaternion",i,p)}generateMorphTrack(t){const r=t.DeformPercent.curves.morph,n=r.values.map((function(e){return e/100})),o=a.getObjectByName(t.modelName).morphTargetDictionary[t.morphName];return new e.NumberKeyframeTrack(t.modelName+".morphTargetInfluences["+o+"]",r.times,n)}getTimesForAllAxes(e){let t=[];if(void 0!==e.x&&(t=t.concat(e.x.times)),void 0!==e.y&&(t=t.concat(e.y.times)),void 0!==e.z&&(t=t.concat(e.z.times)),t=t.sort((function(e,t){return e-t})),t.length>1){let e=1,r=t[0];for(let n=1;n<t.length;n++){const o=t[n];o!==r&&(t[e]=o,r=o,e++)}t=t.slice(0,e)}return t}getKeyframeTrackValues(e,t,r){const n=r,o=[];let a=-1,s=-1,i=-1;return e.forEach((function(e){if(t.x&&(a=t.x.times.indexOf(e)),t.y&&(s=t.y.times.indexOf(e)),t.z&&(i=t.z.times.indexOf(e)),-1!==a){const e=t.x.values[a];o.push(e),n[0]=e}else o.push(n[0]);if(-1!==s){const e=t.y.values[s];o.push(e),n[1]=e}else o.push(n[1]);if(-1!==i){const e=t.z.values[i];o.push(e),n[2]=e}else o.push(n[2])})),o}interpolateRotations(e){for(let t=1;t<e.values.length;t++){const r=e.values[t-1],n=e.values[t]-r,o=Math.abs(n);if(o>=180){const a=o/180,s=n/a;let i=r+s;const l=e.times[t-1],c=(e.times[t]-l)/a;let u=l+c;const p=[],h=[];for(;u<e.times[t];)p.push(u),u+=c,h.push(i),i+=s;e.times=E(e.times,t,p),e.values=E(e.values,t,h)}}}}class u{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new d,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,r=e.split(/[\r\n]+/);return r.forEach((function(e,n){const o=e.match(/^[\s\t]*;/),a=e.match(/^[\s\t]*$/);if(o||a)return;const s=e.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),i=e.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),l=e.match("^\\t{"+(t.currentIndent-1)+"}}");s?t.parseNodeBegin(e,s):i?t.parseNodeProperty(e,i,r[++n]):l?t.popStack():e.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(e)})),this.allNodes}parseNodeBegin(e,t){const r=t[1].trim().replace(/^"/,"").replace(/"$/,""),n=t[2].split(",").map((function(e){return e.trim().replace(/^"/,"").replace(/"$/,"")})),o={name:r},a=this.parseNodeAttr(n),s=this.getCurrentNode();0===this.currentIndent?this.allNodes.add(r,o):r in s?("PoseNode"===r?s.PoseNode.push(o):void 0!==s[r].id&&(s[r]={},s[r][s[r].id]=s[r]),""!==a.id&&(s[r][a.id]=o)):"number"==typeof a.id?(s[r]={},s[r][a.id]=o):"Properties70"!==r&&(s[r]="PoseNode"===r?[o]:o),"number"==typeof a.id&&(o.id=a.id),""!==a.name&&(o.attrName=a.name),""!==a.type&&(o.attrType=a.type),this.pushStack(o)}parseNodeAttr(e){let t=e[0];""!==e[0]&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let r="",n="";return e.length>1&&(r=e[1].replace(/^(\w+)::/,""),n=e[2]),{id:t,name:r,type:n}}parseNodeProperty(e,t,r){let n=t[1].replace(/^"/,"").replace(/"$/,"").trim(),o=t[2].replace(/^"/,"").replace(/"$/,"").trim();"Content"===n&&","===o&&(o=r.replace(/"/g,"").replace(/,$/,"").trim());const a=this.getCurrentNode();if("Properties70"!==a.name){if("C"===n){const e=o.split(",").slice(1),t=parseInt(e[0]),r=parseInt(e[1]);let s=o.split(",").slice(3);s=s.map((function(e){return e.trim().replace(/^"/,"")})),n="connections",o=[t,r],function(e,t){for(let r=0,n=e.length,o=t.length;r<o;r++,n++)e[n]=t[r]}(o,s),void 0===a[n]&&(a[n]=[])}"Node"===n&&(a.id=o),n in a&&Array.isArray(a[n])?a[n].push(o):"a"!==n?a[n]=o:a.a=o,this.setCurrentProp(a,n),"a"===n&&","!==o.slice(-1)&&(a.a=b(o))}else this.parseNodeSpecialProperty(e,n,o)}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,","!==e.slice(-1)&&(t.a=b(t.a))}parseNodeSpecialProperty(e,t,r){const n=r.split('",').map((function(e){return e.trim().replace(/^\"/,"").replace(/\s/,"_")})),o=n[0],a=n[1],s=n[2],i=n[3];let l=n[4];switch(a){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":l=parseFloat(l);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":l=b(l)}this.getPrevNode()[o]={type:a,type2:s,flag:i,value:l},this.setCurrentProp(this.getPrevNode(),o)}}class p{parse(e){const t=new h(e);t.skip(23);const r=t.getUint32();if(r<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+r);const n=new d;for(;!this.endOfContent(t);){const e=this.parseNode(t,r);null!==e&&n.add(e.name,e)}return n}endOfContent(e){return e.size()%16==0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const r={},n=t>=7500?e.getUint64():e.getUint32(),o=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const a=e.getUint8(),s=e.getString(a);if(0===n)return null;const i=[];for(let t=0;t<o;t++)i.push(this.parseProperty(e));const l=i.length>0?i[0]:"",c=i.length>1?i[1]:"",u=i.length>2?i[2]:"";for(r.singleProperty=1===o&&e.getOffset()===n;n>e.getOffset();){const n=this.parseNode(e,t);null!==n&&this.parseSubNode(s,r,n)}return r.propertyList=i,"number"==typeof l&&(r.id=l),""!==c&&(r.attrName=c),""!==u&&(r.attrType=u),""!==s&&(r.name=s),r}parseSubNode(e,t,r){if(!0===r.singleProperty){const e=r.propertyList[0];Array.isArray(e)?(t[r.name]=r,r.a=e):t[r.name]=e}else if("Connections"===e&&"C"===r.name){const e=[];r.propertyList.forEach((function(t,r){0!==r&&e.push(t)})),void 0===t.connections&&(t.connections=[]),t.connections.push(e)}else if("Properties70"===r.name){Object.keys(r).forEach((function(e){t[e]=r[e]}))}else if("Properties70"===e&&"P"===r.name){let e=r.propertyList[0],n=r.propertyList[1];const o=r.propertyList[2],a=r.propertyList[3];let s;0===e.indexOf("Lcl ")&&(e=e.replace("Lcl ","Lcl_")),0===n.indexOf("Lcl ")&&(n=n.replace("Lcl ","Lcl_")),s="Color"===n||"ColorRGB"===n||"Vector"===n||"Vector3D"===n||0===n.indexOf("Lcl_")?[r.propertyList[4],r.propertyList[5],r.propertyList[6]]:r.propertyList[4],t[e]={type:n,type2:o,flag:a,value:s}}else void 0===t[r.name]?"number"==typeof r.id?(t[r.name]={},t[r.name][r.id]=r):t[r.name]=r:"PoseNode"===r.name?(Array.isArray(t[r.name])||(t[r.name]=[t[r.name]]),t[r.name].push(r)):void 0===t[r.name][r.id]&&(t[r.name][r.id]=r)}parseProperty(e){const r=e.getString(1);let n;switch(r){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return n=e.getUint32(),e.getArrayBuffer(n);case"S":return n=e.getUint32(),e.getString(n);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const o=e.getUint32(),a=e.getUint32(),s=e.getUint32();if(0===a)switch(r){case"b":case"c":return e.getBooleanArray(o);case"d":return e.getFloat64Array(o);case"f":return e.getFloat32Array(o);case"i":return e.getInt32Array(o);case"l":return e.getInt64Array(o)}const i=t.unzlibSync(new Uint8Array(e.getArrayBuffer(s))),l=new h(i.buffer);switch(r){case"b":case"c":return l.getBooleanArray(o);case"d":return l.getFloat64Array(o);case"f":return l.getFloat32Array(o);case"i":return l.getInt32Array(o);case"l":return l.getInt64Array(o)}default:throw new Error("THREE.FBXLoader: Unknown property type "+r)}}}class h{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=void 0===t||t}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return 1==(1&this.getUint8())}getBooleanArray(e){const t=[];for(let r=0;r<e;r++)t.push(this.getBoolean());return t}getUint8(){const e=this.dv.getUint8(this.offset);return this.offset+=1,e}getInt16(){const e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}getInt32(){const e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}getInt32Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getInt32());return t}getUint32(){const e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}getInt64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),2147483648&t?(t=4294967295&~t,e=4294967295&~e,4294967295===e&&(t=t+1&4294967295),e=e+1&4294967295,-(4294967296*t+e)):4294967296*t+e}getInt64Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getInt64());return t}getUint64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),4294967296*t+e}getFloat32(){const e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}getFloat32Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getFloat32());return t}getFloat64(){const e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}getFloat64Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getFloat64());return t}getArrayBuffer(e){const t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}getString(t){let r=[];for(let e=0;e<t;e++)r[e]=this.getUint8();const n=r.indexOf(0);return n>=0&&(r=r.slice(0,n)),e.LoaderUtils.decodeText(new Uint8Array(r))}}class d{add(e,t){this[e]=t}}function f(e){const t=e.match(/FBXVersion: (\d+)/);if(t){return parseInt(t[1])}throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function m(e){return e/46186158e3}const g=[];function v(e,t,r,n){let o;switch(n.mappingType){case"ByPolygonVertex":o=e;break;case"ByPolygon":o=t;break;case"ByVertice":o=r;break;case"AllSame":o=n.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+n.mappingType)}"IndexToDirect"===n.referenceType&&(o=n.indices[o]);const a=o*n.dataSize,s=a+n.dataSize;return function(e,t,r,n){for(let o=r,a=0;o<n;o++,a++)e[a]=t[o];return e}(g,n.buffer,a,s)}const y=new e.Euler,w=new e.Vector3;function I(t){const r=new e.Matrix4,n=new e.Matrix4,o=new e.Matrix4,a=new e.Matrix4,s=new e.Matrix4,i=new e.Matrix4,l=new e.Matrix4,c=new e.Matrix4,u=new e.Matrix4,p=new e.Matrix4,h=new e.Matrix4,d=new e.Matrix4,f=t.inheritType?t.inheritType:0;if(t.translation&&r.setPosition(w.fromArray(t.translation)),t.preRotation){const r=t.preRotation.map(e.MathUtils.degToRad);r.push(t.eulerOrder),n.makeRotationFromEuler(y.fromArray(r))}if(t.rotation){const r=t.rotation.map(e.MathUtils.degToRad);r.push(t.eulerOrder),o.makeRotationFromEuler(y.fromArray(r))}if(t.postRotation){const r=t.postRotation.map(e.MathUtils.degToRad);r.push(t.eulerOrder),a.makeRotationFromEuler(y.fromArray(r)),a.invert()}t.scale&&s.scale(w.fromArray(t.scale)),t.scalingOffset&&l.setPosition(w.fromArray(t.scalingOffset)),t.scalingPivot&&i.setPosition(w.fromArray(t.scalingPivot)),t.rotationOffset&&c.setPosition(w.fromArray(t.rotationOffset)),t.rotationPivot&&u.setPosition(w.fromArray(t.rotationPivot)),t.parentMatrixWorld&&(h.copy(t.parentMatrix),p.copy(t.parentMatrixWorld));const m=n.clone().multiply(o).multiply(a),g=new e.Matrix4;g.extractRotation(p);const v=new e.Matrix4;v.copyPosition(p);const I=v.clone().invert().multiply(p),x=g.clone().invert().multiply(I),b=s,T=new e.Matrix4;if(0===f)T.copy(g).multiply(m).multiply(x).multiply(b);else if(1===f)T.copy(g).multiply(x).multiply(m).multiply(b);else{const t=(new e.Matrix4).scale((new e.Vector3).setFromMatrixScale(h)).clone().invert(),r=x.clone().multiply(t);T.copy(g).multiply(m).multiply(r).multiply(b)}const E=u.clone().invert(),M=i.clone().invert();let A=r.clone().multiply(c).multiply(u).multiply(n).multiply(o).multiply(a).multiply(E).multiply(l).multiply(i).multiply(s).multiply(M);const D=(new e.Matrix4).copyPosition(A),P=p.clone().multiply(D);return d.copyPosition(P),A=d.clone().multiply(T),A.premultiply(p.invert()),A}function x(e){const t=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return 6===(e=e||0)?(console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),t[0]):t[e]}function b(e){return e.split(",").map((function(e){return parseFloat(e)}))}function T(t,r,n){return void 0===r&&(r=0),void 0===n&&(n=t.byteLength),e.LoaderUtils.decodeText(new Uint8Array(t,r,n))}function E(e,t,r){return e.slice(0,t).concat(r).concat(e.slice(t))}exports.FBXLoader=s;
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("fflate"),r=require("../curves/NURBSCurve.cjs.js");let n,o,a;require("../curves/NURBSUtils.cjs.js");class s extends e.Loader{constructor(e){super(e)}load(t,r,n,o){const a=this,s=""===a.path?e.LoaderUtils.extractUrlBase(t):a.path,i=new e.FileLoader(this.manager);i.setPath(a.path),i.setResponseType("arraybuffer"),i.setRequestHeader(a.requestHeader),i.setWithCredentials(a.withCredentials),i.load(t,(function(e){try{r(a.parse(e,s))}catch(e){o?o(e):console.error(e),a.manager.itemError(t)}}),n,o)}parse(t,r){if(function(e){const t="Kaydara FBX Binary \0";return e.byteLength>=t.length&&t===T(e,0,t.length)}(t))n=(new p).parse(t);else{const e=T(t);if(!function(e){const t=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let r=0;function n(t){const n=e[t-1];return e=e.slice(r+t),r++,n}for(let e=0;e<t.length;++e){if(n(1)===t[e])return!1}return!0}(e))throw new Error("THREE.FBXLoader: Unknown format.");if(f(e)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+f(e));n=(new u).parse(e)}const o=new e.TextureLoader(this.manager).setPath(this.resourcePath||r).setCrossOrigin(this.crossOrigin);return new i(o,this.manager).parse(n)}}class i{constructor(e,t){this.textureLoader=e,this.manager=t}parse(){o=this.parseConnections();const e=this.parseImages(),t=this.parseTextures(e),r=this.parseMaterials(t),n=this.parseDeformers(),s=(new l).parse(n);return this.parseScene(n,s,r),a}parseConnections(){const e=new Map;if("Connections"in n){n.Connections.connections.forEach((function(t){const r=t[0],n=t[1],o=t[2];e.has(r)||e.set(r,{parents:[],children:[]});const a={ID:n,relationship:o};e.get(r).parents.push(a),e.has(n)||e.set(n,{parents:[],children:[]});const s={ID:r,relationship:o};e.get(n).children.push(s)}))}return e}parseImages(){const e={},t={};if("Video"in n.Objects){const r=n.Objects.Video;for(const n in r){const o=r[n];if(e[parseInt(n)]=o.RelativeFilename||o.Filename,"Content"in o){const e=o.Content instanceof ArrayBuffer&&o.Content.byteLength>0,a="string"==typeof o.Content&&""!==o.Content;if(e||a){const e=this.parseImage(r[n]);t[o.RelativeFilename||o.Filename]=e}}}}for(const r in e){const n=e[r];void 0!==t[n]?e[r]=t[n]:e[r]=e[r].split("\\").pop()}return e}parseImage(e){const t=e.Content,r=e.RelativeFilename||e.Filename,n=r.slice(r.lastIndexOf(".")+1).toLowerCase();let o;switch(n){case"bmp":o="image/bmp";break;case"jpg":case"jpeg":o="image/jpeg";break;case"png":o="image/png";break;case"tif":o="image/tiff";break;case"tga":null===this.manager.getHandler(".tga")&&console.warn("FBXLoader: TGA loader not found, skipping ",r),o="image/tga";break;default:return void console.warn('FBXLoader: Image type "'+n+'" is not supported.')}if("string"==typeof t)return"data:"+o+";base64,"+t;{const e=new Uint8Array(t);return window.URL.createObjectURL(new Blob([e],{type:o}))}}parseTextures(e){const t=new Map;if("Texture"in n.Objects){const r=n.Objects.Texture;for(const n in r){const o=this.parseTexture(r[n],e);t.set(parseInt(n),o)}}return t}parseTexture(t,r){const n=this.loadTexture(t,r);n.ID=t.id,n.name=t.attrName;const o=t.WrapModeU,a=t.WrapModeV,s=void 0!==o?o.value:0,i=void 0!==a?a.value:0;if(n.wrapS=0===s?e.RepeatWrapping:e.ClampToEdgeWrapping,n.wrapT=0===i?e.RepeatWrapping:e.ClampToEdgeWrapping,"Scaling"in t){const e=t.Scaling.value;n.repeat.x=e[0],n.repeat.y=e[1]}return n}loadTexture(t,r){let n;const a=this.textureLoader.path,s=o.get(t.id).children;let i;void 0!==s&&s.length>0&&void 0!==r[s[0].ID]&&(n=r[s[0].ID],0!==n.indexOf("blob:")&&0!==n.indexOf("data:")||this.textureLoader.setPath(void 0));const l=t.FileName.slice(-3).toLowerCase();if("tga"===l){const r=this.manager.getHandler(".tga");null===r?(console.warn("FBXLoader: TGA loader not found, creating placeholder texture for",t.RelativeFilename),i=new e.Texture):(r.setPath(this.textureLoader.path),i=r.load(n))}else"psd"===l?(console.warn("FBXLoader: PSD textures are not supported, creating placeholder texture for",t.RelativeFilename),i=new e.Texture):i=this.textureLoader.load(n);return this.textureLoader.setPath(a),i}parseMaterials(e){const t=new Map;if("Material"in n.Objects){const r=n.Objects.Material;for(const n in r){const o=this.parseMaterial(r[n],e);null!==o&&t.set(parseInt(n),o)}}return t}parseMaterial(t,r){const n=t.id,a=t.attrName;let s=t.ShadingModel;if("object"==typeof s&&(s=s.value),!o.has(n))return null;const i=this.parseParameters(t,r,n);let l;switch(s.toLowerCase()){case"phong":l=new e.MeshPhongMaterial;break;case"lambert":l=new e.MeshLambertMaterial;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',s),l=new e.MeshPhongMaterial}return l.setValues(i),l.name=a,l}parseParameters(t,r,n){const a={};t.BumpFactor&&(a.bumpScale=t.BumpFactor.value),t.Diffuse?a.color=(new e.Color).fromArray(t.Diffuse.value):!t.DiffuseColor||"Color"!==t.DiffuseColor.type&&"ColorRGB"!==t.DiffuseColor.type||(a.color=(new e.Color).fromArray(t.DiffuseColor.value)),t.DisplacementFactor&&(a.displacementScale=t.DisplacementFactor.value),t.Emissive?a.emissive=(new e.Color).fromArray(t.Emissive.value):!t.EmissiveColor||"Color"!==t.EmissiveColor.type&&"ColorRGB"!==t.EmissiveColor.type||(a.emissive=(new e.Color).fromArray(t.EmissiveColor.value)),t.EmissiveFactor&&(a.emissiveIntensity=parseFloat(t.EmissiveFactor.value)),t.Opacity&&(a.opacity=parseFloat(t.Opacity.value)),a.opacity<1&&(a.transparent=!0),t.ReflectionFactor&&(a.reflectivity=t.ReflectionFactor.value),t.Shininess&&(a.shininess=t.Shininess.value),t.Specular?a.specular=(new e.Color).fromArray(t.Specular.value):t.SpecularColor&&"Color"===t.SpecularColor.type&&(a.specular=(new e.Color).fromArray(t.SpecularColor.value));const s=this;return o.get(n).children.forEach((function(t){const n=t.relationship;switch(n){case"Bump":a.bumpMap=s.getTexture(r,t.ID);break;case"Maya|TEX_ao_map":a.aoMap=s.getTexture(r,t.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":a.map=s.getTexture(r,t.ID),void 0!==a.map&&("colorSpace"in a.map?a.map.colorSpace="srgb":a.map.encoding=3001);break;case"DisplacementColor":a.displacementMap=s.getTexture(r,t.ID);break;case"EmissiveColor":a.emissiveMap=s.getTexture(r,t.ID),void 0!==a.emissiveMap&&("colorSpace"in a.emissiveMap?a.emissiveMap.colorSpace="srgb":a.emissiveMap.encoding=3001);break;case"NormalMap":case"Maya|TEX_normal_map":a.normalMap=s.getTexture(r,t.ID);break;case"ReflectionColor":a.envMap=s.getTexture(r,t.ID),void 0!==a.envMap&&(a.envMap.mapping=e.EquirectangularReflectionMapping,"colorSpace"in a.envMap?a.envMap.colorSpace="srgb":a.envMap.encoding=3001);break;case"SpecularColor":a.specularMap=s.getTexture(r,t.ID),void 0!==a.specularMap&&("colorSpace"in a.specularMap?a.specularMap.colorSpace="srgb":a.specularMap.encoding=3001);break;case"TransparentColor":case"TransparencyFactor":a.alphaMap=s.getTexture(r,t.ID),a.transparent=!0;break;case"AmbientColor":case"ShininessExponent":case"SpecularFactor":case"VectorDisplacementColor":default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",n)}})),a}getTexture(e,t){return"LayeredTexture"in n.Objects&&t in n.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=o.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in n.Objects){const r=n.Objects.Deformer;for(const n in r){const a=r[n],s=o.get(parseInt(n));if("Skin"===a.attrType){const t=this.parseSkeleton(s,r);t.ID=n,s.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),t.geometryID=s.parents[0].ID,e[n]=t}else if("BlendShape"===a.attrType){const e={id:n};e.rawTargets=this.parseMorphTargets(s,r),e.id=n,s.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[n]=e}}}return{skeletons:e,morphTargets:t}}parseSkeleton(t,r){const n=[];return t.children.forEach((function(t){const o=r[t.ID];if("Cluster"!==o.attrType)return;const a={ID:t.ID,indices:[],weights:[],transformLink:(new e.Matrix4).fromArray(o.TransformLink.a)};"Indexes"in o&&(a.indices=o.Indexes.a,a.weights=o.Weights.a),n.push(a)})),{rawBones:n,bones:[]}}parseMorphTargets(e,t){const r=[];for(let n=0;n<e.children.length;n++){const a=e.children[n],s=t[a.ID],i={name:s.attrName,initialWeight:s.DeformPercent,id:s.id,fullWeights:s.FullWeights.a};if("BlendShapeChannel"!==s.attrType)return;i.geoID=o.get(parseInt(a.ID)).children.filter((function(e){return void 0===e.relationship}))[0].ID,r.push(i)}return r}parseScene(t,r,s){a=new e.Group;const i=this.parseModels(t.skeletons,r,s),l=n.Objects.Model,u=this;i.forEach((function(e){const t=l[e.ID];u.setLookAtProperties(e,t);o.get(e.ID).parents.forEach((function(t){const r=i.get(t.ID);void 0!==r&&r.add(e)})),null===e.parent&&a.add(e)})),this.bindSkeleton(t.skeletons,r,i),this.createAmbientLight(),a.traverse((function(e){if(e.userData.transformData){e.parent&&(e.userData.transformData.parentMatrix=e.parent.matrix,e.userData.transformData.parentMatrixWorld=e.parent.matrixWorld);const t=I(e.userData.transformData);e.applyMatrix4(t),e.updateWorldMatrix()}}));const p=(new c).parse();1===a.children.length&&a.children[0].isGroup&&(a.children[0].animations=p,a=a.children[0]),a.animations=p}parseModels(t,r,a){const s=new Map,i=n.Objects.Model;for(const n in i){const l=parseInt(n),c=i[n],u=o.get(l);let p=this.buildSkeleton(u,t,l,c.attrName);if(!p){switch(c.attrType){case"Camera":p=this.createCamera(u);break;case"Light":p=this.createLight(u);break;case"Mesh":p=this.createMesh(u,r,a);break;case"NurbsCurve":p=this.createCurve(u,r);break;case"LimbNode":case"Root":p=new e.Bone;break;case"Null":default:p=new e.Group}p.name=c.attrName?e.PropertyBinding.sanitizeNodeName(c.attrName):"",p.ID=l}this.getTransformData(p,c),s.set(l,p)}return s}buildSkeleton(t,r,n,o){let a=null;return t.parents.forEach((function(t){for(const s in r){const i=r[s];i.rawBones.forEach((function(r,s){if(r.ID===t.ID){const t=a;a=new e.Bone,a.matrixWorld.copy(r.transformLink),a.name=o?e.PropertyBinding.sanitizeNodeName(o):"",a.ID=n,i.bones[s]=a,null!==t&&a.add(t)}}))}})),a}createCamera(t){let r,o;if(t.children.forEach((function(e){const t=n.Objects.NodeAttribute[e.ID];void 0!==t&&(o=t)})),void 0===o)r=new e.Object3D;else{let t=0;void 0!==o.CameraProjectionType&&1===o.CameraProjectionType.value&&(t=1);let n=1;void 0!==o.NearPlane&&(n=o.NearPlane.value/1e3);let a=1e3;void 0!==o.FarPlane&&(a=o.FarPlane.value/1e3);let s=window.innerWidth,i=window.innerHeight;void 0!==o.AspectWidth&&void 0!==o.AspectHeight&&(s=o.AspectWidth.value,i=o.AspectHeight.value);const l=s/i;let c=45;void 0!==o.FieldOfView&&(c=o.FieldOfView.value);const u=o.FocalLength?o.FocalLength.value:null;switch(t){case 0:r=new e.PerspectiveCamera(c,l,n,a),null!==u&&r.setFocalLength(u);break;case 1:r=new e.OrthographicCamera(-s/2,s/2,i/2,-i/2,n,a);break;default:console.warn("THREE.FBXLoader: Unknown camera type "+t+"."),r=new e.Object3D}}return r}createLight(t){let r,o;if(t.children.forEach((function(e){const t=n.Objects.NodeAttribute[e.ID];void 0!==t&&(o=t)})),void 0===o)r=new e.Object3D;else{let t;t=void 0===o.LightType?0:o.LightType.value;let n=16777215;void 0!==o.Color&&(n=(new e.Color).fromArray(o.Color.value));let a=void 0===o.Intensity?1:o.Intensity.value/100;void 0!==o.CastLightOnObject&&0===o.CastLightOnObject.value&&(a=0);let s=0;void 0!==o.FarAttenuationEnd&&(s=void 0!==o.EnableFarAttenuation&&0===o.EnableFarAttenuation.value?0:o.FarAttenuationEnd.value);const i=1;switch(t){case 0:r=new e.PointLight(n,a,s,i);break;case 1:r=new e.DirectionalLight(n,a);break;case 2:let t=Math.PI/3;void 0!==o.InnerAngle&&(t=e.MathUtils.degToRad(o.InnerAngle.value));let l=0;void 0!==o.OuterAngle&&(l=e.MathUtils.degToRad(o.OuterAngle.value),l=Math.max(l,1)),r=new e.SpotLight(n,a,s,t,l,i);break;default:console.warn("THREE.FBXLoader: Unknown light type "+o.LightType.value+", defaulting to a PointLight."),r=new e.PointLight(n,a)}void 0!==o.CastShadows&&1===o.CastShadows.value&&(r.castShadow=!0)}return r}createMesh(t,r,n){let o,a=null,s=null;const i=[];return t.children.forEach((function(e){r.has(e.ID)&&(a=r.get(e.ID)),n.has(e.ID)&&i.push(n.get(e.ID))})),i.length>1?s=i:i.length>0?s=i[0]:(s=new e.MeshPhongMaterial({color:13421772}),i.push(s)),"color"in a.attributes&&i.forEach((function(e){e.vertexColors=!0})),a.FBX_Deformer?(o=new e.SkinnedMesh(a,s),o.normalizeSkinWeights()):o=new e.Mesh(a,s),o}createCurve(t,r){const n=t.children.reduce((function(e,t){return r.has(t.ID)&&(e=r.get(t.ID)),e}),null),o=new e.LineBasicMaterial({color:3342591,linewidth:1});return new e.Line(n,o)}getTransformData(e,t){const r={};"InheritType"in t&&(r.inheritType=parseInt(t.InheritType.value)),r.eulerOrder="RotationOrder"in t?x(t.RotationOrder.value):"ZYX","Lcl_Translation"in t&&(r.translation=t.Lcl_Translation.value),"PreRotation"in t&&(r.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(r.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(r.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(r.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(r.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(r.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(r.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(r.rotationPivot=t.RotationPivot.value),e.userData.transformData=r}setLookAtProperties(t,r){if("LookAtProperty"in r){o.get(t.ID).children.forEach((function(r){if("LookAtProperty"===r.relationship){const o=n.Objects.Model[r.ID];if("Lcl_Translation"in o){const r=o.Lcl_Translation.value;void 0!==t.target?(t.target.position.fromArray(r),a.add(t.target)):t.lookAt((new e.Vector3).fromArray(r))}}}))}}bindSkeleton(t,r,n){const a=this.parsePoseNodes();for(const s in t){const i=t[s];o.get(parseInt(i.ID)).parents.forEach((function(t){if(r.has(t.ID)){const r=t.ID;o.get(r).parents.forEach((function(t){if(n.has(t.ID)){n.get(t.ID).bind(new e.Skeleton(i.bones),a[t.ID])}}))}}))}}parsePoseNodes(){const t={};if("Pose"in n.Objects){const r=n.Objects.Pose;for(const n in r)if("BindPose"===r[n].attrType&&r[n].NbPoseNodes>0){const o=r[n].PoseNode;Array.isArray(o)?o.forEach((function(r){t[r.Node]=(new e.Matrix4).fromArray(r.Matrix.a)})):t[o.Node]=(new e.Matrix4).fromArray(o.Matrix.a)}}return t}createAmbientLight(){if("GlobalSettings"in n&&"AmbientColor"in n.GlobalSettings){const t=n.GlobalSettings.AmbientColor.value,r=t[0],o=t[1],s=t[2];if(0!==r||0!==o||0!==s){const t=new e.Color(r,o,s);a.add(new e.AmbientLight(t,1))}}}}class l{parse(e){const t=new Map;if("Geometry"in n.Objects){const r=n.Objects.Geometry;for(const n in r){const a=o.get(parseInt(n)),s=this.parseGeometry(a,r[n],e);t.set(parseInt(n),s)}}return t}parseGeometry(e,t,r){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,r);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,r){const o=r.skeletons,a=[],s=e.parents.map((function(e){return n.Objects.Model[e.ID]}));if(0===s.length)return;const i=e.children.reduce((function(e,t){return void 0!==o[t.ID]&&(e=o[t.ID]),e}),null);e.children.forEach((function(e){void 0!==r.morphTargets[e.ID]&&a.push(r.morphTargets[e.ID])}));const l=s[0],c={};"RotationOrder"in l&&(c.eulerOrder=x(l.RotationOrder.value)),"InheritType"in l&&(c.inheritType=parseInt(l.InheritType.value)),"GeometricTranslation"in l&&(c.translation=l.GeometricTranslation.value),"GeometricRotation"in l&&(c.rotation=l.GeometricRotation.value),"GeometricScaling"in l&&(c.scale=l.GeometricScaling.value);const u=I(c);return this.genGeometry(t,i,a,u)}genGeometry(t,r,n,o){const a=new e.BufferGeometry;t.attrName&&(a.name=t.attrName);const s=this.parseGeoNode(t,r),i=this.genBuffers(s),l=new e.Float32BufferAttribute(i.vertex,3);if(l.applyMatrix4(o),a.setAttribute("position",l),i.colors.length>0&&a.setAttribute("color",new e.Float32BufferAttribute(i.colors,3)),r&&(a.setAttribute("skinIndex",new e.Uint16BufferAttribute(i.weightsIndices,4)),a.setAttribute("skinWeight",new e.Float32BufferAttribute(i.vertexWeights,4)),a.FBX_Deformer=r),i.normal.length>0){const t=(new e.Matrix3).getNormalMatrix(o),r=new e.Float32BufferAttribute(i.normal,3);r.applyNormalMatrix(t),a.setAttribute("normal",r)}if(i.uvs.forEach((function(t,r){let n="uv"+(r+1).toString();0===r&&(n="uv"),a.setAttribute(n,new e.Float32BufferAttribute(i.uvs[r],2))})),s.material&&"AllSame"!==s.material.mappingType){let e=i.materialIndex[0],t=0;if(i.materialIndex.forEach((function(r,n){r!==e&&(a.addGroup(t,n-t,e),e=r,t=n)})),a.groups.length>0){const t=a.groups[a.groups.length-1],r=t.start+t.count;r!==i.materialIndex.length&&a.addGroup(r,i.materialIndex.length-r,e)}0===a.groups.length&&a.addGroup(0,i.materialIndex.length,i.materialIndex[0])}return this.addMorphTargets(a,t,n,o),a}parseGeoNode(e,t){const r={};if(r.vertexPositions=void 0!==e.Vertices?e.Vertices.a:[],r.vertexIndices=void 0!==e.PolygonVertexIndex?e.PolygonVertexIndex.a:[],e.LayerElementColor&&(r.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(r.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(r.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){r.uv=[];let t=0;for(;e.LayerElementUV[t];)e.LayerElementUV[t].UV&&r.uv.push(this.parseUVs(e.LayerElementUV[t])),t++}return r.weightTable={},null!==t&&(r.skeleton=t,t.rawBones.forEach((function(e,t){e.indices.forEach((function(n,o){void 0===r.weightTable[n]&&(r.weightTable[n]=[]),r.weightTable[n].push({id:t,weight:e.weights[o]})}))}))),r}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let r=0,n=0,o=!1,a=[],s=[],i=[],l=[],c=[],u=[];const p=this;return e.vertexIndices.forEach((function(h,d){let f,m=!1;h<0&&(h^=-1,m=!0);let g=[],y=[];if(a.push(3*h,3*h+1,3*h+2),e.color){const t=v(d,r,h,e.color);i.push(t[0],t[1],t[2])}if(e.skeleton){if(void 0!==e.weightTable[h]&&e.weightTable[h].forEach((function(e){y.push(e.weight),g.push(e.id)})),y.length>4){o||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),o=!0);const e=[0,0,0,0],t=[0,0,0,0];y.forEach((function(r,n){let o=r,a=g[n];t.forEach((function(t,r,n){if(o>t){n[r]=o,o=t;const s=e[r];e[r]=a,a=s}}))})),g=e,y=t}for(;y.length<4;)y.push(0),g.push(0);for(let e=0;e<4;++e)c.push(y[e]),u.push(g[e])}if(e.normal){const t=v(d,r,h,e.normal);s.push(t[0],t[1],t[2])}e.material&&"AllSame"!==e.material.mappingType&&(f=v(d,r,h,e.material)[0]),e.uv&&e.uv.forEach((function(e,t){const n=v(d,r,h,e);void 0===l[t]&&(l[t]=[]),l[t].push(n[0]),l[t].push(n[1])})),n++,m&&(p.genFace(t,e,a,f,s,i,l,c,u,n),r++,n=0,a=[],s=[],i=[],l=[],c=[],u=[])})),t}genFace(e,t,r,n,o,a,s,i,l,c){for(let u=2;u<c;u++)e.vertex.push(t.vertexPositions[r[0]]),e.vertex.push(t.vertexPositions[r[1]]),e.vertex.push(t.vertexPositions[r[2]]),e.vertex.push(t.vertexPositions[r[3*(u-1)]]),e.vertex.push(t.vertexPositions[r[3*(u-1)+1]]),e.vertex.push(t.vertexPositions[r[3*(u-1)+2]]),e.vertex.push(t.vertexPositions[r[3*u]]),e.vertex.push(t.vertexPositions[r[3*u+1]]),e.vertex.push(t.vertexPositions[r[3*u+2]]),t.skeleton&&(e.vertexWeights.push(i[0]),e.vertexWeights.push(i[1]),e.vertexWeights.push(i[2]),e.vertexWeights.push(i[3]),e.vertexWeights.push(i[4*(u-1)]),e.vertexWeights.push(i[4*(u-1)+1]),e.vertexWeights.push(i[4*(u-1)+2]),e.vertexWeights.push(i[4*(u-1)+3]),e.vertexWeights.push(i[4*u]),e.vertexWeights.push(i[4*u+1]),e.vertexWeights.push(i[4*u+2]),e.vertexWeights.push(i[4*u+3]),e.weightsIndices.push(l[0]),e.weightsIndices.push(l[1]),e.weightsIndices.push(l[2]),e.weightsIndices.push(l[3]),e.weightsIndices.push(l[4*(u-1)]),e.weightsIndices.push(l[4*(u-1)+1]),e.weightsIndices.push(l[4*(u-1)+2]),e.weightsIndices.push(l[4*(u-1)+3]),e.weightsIndices.push(l[4*u]),e.weightsIndices.push(l[4*u+1]),e.weightsIndices.push(l[4*u+2]),e.weightsIndices.push(l[4*u+3])),t.color&&(e.colors.push(a[0]),e.colors.push(a[1]),e.colors.push(a[2]),e.colors.push(a[3*(u-1)]),e.colors.push(a[3*(u-1)+1]),e.colors.push(a[3*(u-1)+2]),e.colors.push(a[3*u]),e.colors.push(a[3*u+1]),e.colors.push(a[3*u+2])),t.material&&"AllSame"!==t.material.mappingType&&(e.materialIndex.push(n),e.materialIndex.push(n),e.materialIndex.push(n)),t.normal&&(e.normal.push(o[0]),e.normal.push(o[1]),e.normal.push(o[2]),e.normal.push(o[3*(u-1)]),e.normal.push(o[3*(u-1)+1]),e.normal.push(o[3*(u-1)+2]),e.normal.push(o[3*u]),e.normal.push(o[3*u+1]),e.normal.push(o[3*u+2])),t.uv&&t.uv.forEach((function(t,r){void 0===e.uvs[r]&&(e.uvs[r]=[]),e.uvs[r].push(s[r][0]),e.uvs[r].push(s[r][1]),e.uvs[r].push(s[r][2*(u-1)]),e.uvs[r].push(s[r][2*(u-1)+1]),e.uvs[r].push(s[r][2*u]),e.uvs[r].push(s[r][2*u+1])}))}addMorphTargets(e,t,r,o){if(0===r.length)return;e.morphTargetsRelative=!0,e.morphAttributes.position=[];const a=this;r.forEach((function(r){r.rawTargets.forEach((function(r){const s=n.Objects.Geometry[r.geoID];void 0!==s&&a.genMorphGeometry(e,t,s,o,r.name)}))}))}genMorphGeometry(t,r,n,o,a){const s=void 0!==r.PolygonVertexIndex?r.PolygonVertexIndex.a:[],i=void 0!==n.Vertices?n.Vertices.a:[],l=void 0!==n.Indexes?n.Indexes.a:[],c=3*t.attributes.position.count,u=new Float32Array(c);for(let e=0;e<l.length;e++){const t=3*l[e];u[t]=i[3*e],u[t+1]=i[3*e+1],u[t+2]=i[3*e+2]}const p={vertexIndices:s,vertexPositions:u},h=this.genBuffers(p),d=new e.Float32BufferAttribute(h.vertex,3);d.name=a||n.attrName,d.applyMatrix4(o),t.morphAttributes.position.push(d)}parseNormals(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.Normals.a;let o=[];return"IndexToDirect"===r&&("NormalIndex"in e?o=e.NormalIndex.a:"NormalsIndex"in e&&(o=e.NormalsIndex.a)),{dataSize:3,buffer:n,indices:o,mappingType:t,referenceType:r}}parseUVs(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.UV.a;let o=[];return"IndexToDirect"===r&&(o=e.UVIndex.a),{dataSize:2,buffer:n,indices:o,mappingType:t,referenceType:r}}parseVertexColors(e){const t=e.MappingInformationType,r=e.ReferenceInformationType,n=e.Colors.a;let o=[];return"IndexToDirect"===r&&(o=e.ColorIndex.a),{dataSize:4,buffer:n,indices:o,mappingType:t,referenceType:r}}parseMaterialIndices(e){const t=e.MappingInformationType,r=e.ReferenceInformationType;if("NoMappingInformation"===t)return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:r};const n=e.Materials.a,o=[];for(let e=0;e<n.length;++e)o.push(e);return{dataSize:1,buffer:n,indices:o,mappingType:t,referenceType:r}}parseNurbsGeometry(t){if(void 0===r.NURBSCurve)return console.error("THREE.FBXLoader: The loader relies on NURBSCurve for any nurbs present in the model. Nurbs will show up as empty geometry."),new e.BufferGeometry;const n=parseInt(t.Order);if(isNaN(n))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",t.Order,t.id),new e.BufferGeometry;const o=n-1,a=t.KnotVector.a,s=[],i=t.Points.a;for(let t=0,r=i.length;t<r;t+=4)s.push((new e.Vector4).fromArray(i,t));let l,c;if("Closed"===t.Form)s.push(s[0]);else if("Periodic"===t.Form){l=o,c=a.length-1-l;for(let e=0;e<o;++e)s.push(s[e])}const u=new r.NURBSCurve(o,a,s,l,c).getPoints(12*s.length);return(new e.BufferGeometry).setFromPoints(u)}}class c{parse(){const e=[],t=this.parseClips();if(void 0!==t)for(const r in t){const n=t[r],o=this.addClip(n);e.push(o)}return e}parseClips(){if(void 0===n.Objects.AnimationCurve)return;const e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);const t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}parseAnimationCurveNodes(){const e=n.Objects.AnimationCurveNode,t=new Map;for(const r in e){const n=e[r];if(null!==n.attrName.match(/S|R|T|DeformPercent/)){const e={id:n.id,attr:n.attrName,curves:{}};t.set(e.id,e)}}return t}parseAnimationCurves(e){const t=n.Objects.AnimationCurve;for(const r in t){const n={id:t[r].id,times:t[r].KeyTime.a.map(m),values:t[r].KeyValueFloat.a},a=o.get(n.id);if(void 0!==a){const t=a.parents[0].ID,r=a.parents[0].relationship;r.match(/X/)?e.get(t).curves.x=n:r.match(/Y/)?e.get(t).curves.y=n:r.match(/Z/)?e.get(t).curves.z=n:r.match(/d|DeformPercent/)&&e.has(t)&&(e.get(t).curves.morph=n)}}}parseAnimationLayers(t){const r=n.Objects.AnimationLayer,s=new Map;for(const i in r){const r=[],l=o.get(parseInt(i));if(void 0!==l){l.children.forEach((function(s,i){if(t.has(s.ID)){const l=t.get(s.ID);if(void 0!==l.curves.x||void 0!==l.curves.y||void 0!==l.curves.z){if(void 0===r[i]){const t=o.get(s.ID).parents.filter((function(e){return void 0!==e.relationship}))[0].ID;if(void 0!==t){const o=n.Objects.Model[t.toString()];if(void 0===o)return void console.warn("THREE.FBXLoader: Encountered a unused curve.",s);const l={modelName:o.attrName?e.PropertyBinding.sanitizeNodeName(o.attrName):"",ID:o.id,initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1]};a.traverse((function(e){e.ID===o.id&&(l.transform=e.matrix,e.userData.transformData&&(l.eulerOrder=e.userData.transformData.eulerOrder))})),l.transform||(l.transform=new e.Matrix4),"PreRotation"in o&&(l.preRotation=o.PreRotation.value),"PostRotation"in o&&(l.postRotation=o.PostRotation.value),r[i]=l}}r[i]&&(r[i][l.attr]=l)}else if(void 0!==l.curves.morph){if(void 0===r[i]){const t=o.get(s.ID).parents.filter((function(e){return void 0!==e.relationship}))[0].ID,a=o.get(t).parents[0].ID,l=o.get(a).parents[0].ID,c=o.get(l).parents[0].ID,u=n.Objects.Model[c],p={modelName:u.attrName?e.PropertyBinding.sanitizeNodeName(u.attrName):"",morphName:n.Objects.Deformer[t].attrName};r[i]=p}r[i][l.attr]=l}}})),s.set(parseInt(i),r)}}return s}parseAnimStacks(e){const t=n.Objects.AnimationStack,r={};for(const n in t){const a=o.get(parseInt(n)).children;a.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const s=e.get(a[0].ID);r[n]={name:t[n].attrName,layer:s}}return r}addClip(t){let r=[];const n=this;return t.layer.forEach((function(e){r=r.concat(n.generateTracks(e))})),new e.AnimationClip(t.name,-1,r)}generateTracks(t){const r=[];let n=new e.Vector3,o=new e.Quaternion,a=new e.Vector3;if(t.transform&&t.transform.decompose(n,o,a),n=n.toArray(),o=(new e.Euler).setFromQuaternion(o,t.eulerOrder).toArray(),a=a.toArray(),void 0!==t.T&&Object.keys(t.T.curves).length>0){const e=this.generateVectorTrack(t.modelName,t.T.curves,n,"position");void 0!==e&&r.push(e)}if(void 0!==t.R&&Object.keys(t.R.curves).length>0){const e=this.generateRotationTrack(t.modelName,t.R.curves,o,t.preRotation,t.postRotation,t.eulerOrder);void 0!==e&&r.push(e)}if(void 0!==t.S&&Object.keys(t.S.curves).length>0){const e=this.generateVectorTrack(t.modelName,t.S.curves,a,"scale");void 0!==e&&r.push(e)}if(void 0!==t.DeformPercent){const e=this.generateMorphTrack(t);void 0!==e&&r.push(e)}return r}generateVectorTrack(t,r,n,o){const a=this.getTimesForAllAxes(r),s=this.getKeyframeTrackValues(a,r,n);return new e.VectorKeyframeTrack(t+"."+o,a,s)}generateRotationTrack(t,r,n,o,a,s){void 0!==r.x&&(this.interpolateRotations(r.x),r.x.values=r.x.values.map(e.MathUtils.degToRad)),void 0!==r.y&&(this.interpolateRotations(r.y),r.y.values=r.y.values.map(e.MathUtils.degToRad)),void 0!==r.z&&(this.interpolateRotations(r.z),r.z.values=r.z.values.map(e.MathUtils.degToRad));const i=this.getTimesForAllAxes(r),l=this.getKeyframeTrackValues(i,r,n);void 0!==o&&((o=o.map(e.MathUtils.degToRad)).push(s),o=(new e.Euler).fromArray(o),o=(new e.Quaternion).setFromEuler(o)),void 0!==a&&((a=a.map(e.MathUtils.degToRad)).push(s),a=(new e.Euler).fromArray(a),a=(new e.Quaternion).setFromEuler(a).invert());const c=new e.Quaternion,u=new e.Euler,p=[];for(let e=0;e<l.length;e+=3)u.set(l[e],l[e+1],l[e+2],s),c.setFromEuler(u),void 0!==o&&c.premultiply(o),void 0!==a&&c.multiply(a),c.toArray(p,e/3*4);return new e.QuaternionKeyframeTrack(t+".quaternion",i,p)}generateMorphTrack(t){const r=t.DeformPercent.curves.morph,n=r.values.map((function(e){return e/100})),o=a.getObjectByName(t.modelName).morphTargetDictionary[t.morphName];return new e.NumberKeyframeTrack(t.modelName+".morphTargetInfluences["+o+"]",r.times,n)}getTimesForAllAxes(e){let t=[];if(void 0!==e.x&&(t=t.concat(e.x.times)),void 0!==e.y&&(t=t.concat(e.y.times)),void 0!==e.z&&(t=t.concat(e.z.times)),t=t.sort((function(e,t){return e-t})),t.length>1){let e=1,r=t[0];for(let n=1;n<t.length;n++){const o=t[n];o!==r&&(t[e]=o,r=o,e++)}t=t.slice(0,e)}return t}getKeyframeTrackValues(e,t,r){const n=r,o=[];let a=-1,s=-1,i=-1;return e.forEach((function(e){if(t.x&&(a=t.x.times.indexOf(e)),t.y&&(s=t.y.times.indexOf(e)),t.z&&(i=t.z.times.indexOf(e)),-1!==a){const e=t.x.values[a];o.push(e),n[0]=e}else o.push(n[0]);if(-1!==s){const e=t.y.values[s];o.push(e),n[1]=e}else o.push(n[1]);if(-1!==i){const e=t.z.values[i];o.push(e),n[2]=e}else o.push(n[2])})),o}interpolateRotations(e){for(let t=1;t<e.values.length;t++){const r=e.values[t-1],n=e.values[t]-r,o=Math.abs(n);if(o>=180){const a=o/180,s=n/a;let i=r+s;const l=e.times[t-1],c=(e.times[t]-l)/a;let u=l+c;const p=[],h=[];for(;u<e.times[t];)p.push(u),u+=c,h.push(i),i+=s;e.times=M(e.times,t,p),e.values=M(e.values,t,h)}}}}class u{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new d,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,r=e.split(/[\r\n]+/);return r.forEach((function(e,n){const o=e.match(/^[\s\t]*;/),a=e.match(/^[\s\t]*$/);if(o||a)return;const s=e.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),i=e.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),l=e.match("^\\t{"+(t.currentIndent-1)+"}}");s?t.parseNodeBegin(e,s):i?t.parseNodeProperty(e,i,r[++n]):l?t.popStack():e.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(e)})),this.allNodes}parseNodeBegin(e,t){const r=t[1].trim().replace(/^"/,"").replace(/"$/,""),n=t[2].split(",").map((function(e){return e.trim().replace(/^"/,"").replace(/"$/,"")})),o={name:r},a=this.parseNodeAttr(n),s=this.getCurrentNode();0===this.currentIndent?this.allNodes.add(r,o):r in s?("PoseNode"===r?s.PoseNode.push(o):void 0!==s[r].id&&(s[r]={},s[r][s[r].id]=s[r]),""!==a.id&&(s[r][a.id]=o)):"number"==typeof a.id?(s[r]={},s[r][a.id]=o):"Properties70"!==r&&(s[r]="PoseNode"===r?[o]:o),"number"==typeof a.id&&(o.id=a.id),""!==a.name&&(o.attrName=a.name),""!==a.type&&(o.attrType=a.type),this.pushStack(o)}parseNodeAttr(e){let t=e[0];""!==e[0]&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let r="",n="";return e.length>1&&(r=e[1].replace(/^(\w+)::/,""),n=e[2]),{id:t,name:r,type:n}}parseNodeProperty(e,t,r){let n=t[1].replace(/^"/,"").replace(/"$/,"").trim(),o=t[2].replace(/^"/,"").replace(/"$/,"").trim();"Content"===n&&","===o&&(o=r.replace(/"/g,"").replace(/,$/,"").trim());const a=this.getCurrentNode();if("Properties70"!==a.name){if("C"===n){const e=o.split(",").slice(1),t=parseInt(e[0]),r=parseInt(e[1]);let s=o.split(",").slice(3);s=s.map((function(e){return e.trim().replace(/^"/,"")})),n="connections",o=[t,r],function(e,t){for(let r=0,n=e.length,o=t.length;r<o;r++,n++)e[n]=t[r]}(o,s),void 0===a[n]&&(a[n]=[])}"Node"===n&&(a.id=o),n in a&&Array.isArray(a[n])?a[n].push(o):"a"!==n?a[n]=o:a.a=o,this.setCurrentProp(a,n),"a"===n&&","!==o.slice(-1)&&(a.a=b(o))}else this.parseNodeSpecialProperty(e,n,o)}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,","!==e.slice(-1)&&(t.a=b(t.a))}parseNodeSpecialProperty(e,t,r){const n=r.split('",').map((function(e){return e.trim().replace(/^\"/,"").replace(/\s/,"_")})),o=n[0],a=n[1],s=n[2],i=n[3];let l=n[4];switch(a){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":l=parseFloat(l);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":l=b(l)}this.getPrevNode()[o]={type:a,type2:s,flag:i,value:l},this.setCurrentProp(this.getPrevNode(),o)}}class p{parse(e){const t=new h(e);t.skip(23);const r=t.getUint32();if(r<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+r);const n=new d;for(;!this.endOfContent(t);){const e=this.parseNode(t,r);null!==e&&n.add(e.name,e)}return n}endOfContent(e){return e.size()%16==0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const r={},n=t>=7500?e.getUint64():e.getUint32(),o=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const a=e.getUint8(),s=e.getString(a);if(0===n)return null;const i=[];for(let t=0;t<o;t++)i.push(this.parseProperty(e));const l=i.length>0?i[0]:"",c=i.length>1?i[1]:"",u=i.length>2?i[2]:"";for(r.singleProperty=1===o&&e.getOffset()===n;n>e.getOffset();){const n=this.parseNode(e,t);null!==n&&this.parseSubNode(s,r,n)}return r.propertyList=i,"number"==typeof l&&(r.id=l),""!==c&&(r.attrName=c),""!==u&&(r.attrType=u),""!==s&&(r.name=s),r}parseSubNode(e,t,r){if(!0===r.singleProperty){const e=r.propertyList[0];Array.isArray(e)?(t[r.name]=r,r.a=e):t[r.name]=e}else if("Connections"===e&&"C"===r.name){const e=[];r.propertyList.forEach((function(t,r){0!==r&&e.push(t)})),void 0===t.connections&&(t.connections=[]),t.connections.push(e)}else if("Properties70"===r.name){Object.keys(r).forEach((function(e){t[e]=r[e]}))}else if("Properties70"===e&&"P"===r.name){let e=r.propertyList[0],n=r.propertyList[1];const o=r.propertyList[2],a=r.propertyList[3];let s;0===e.indexOf("Lcl ")&&(e=e.replace("Lcl ","Lcl_")),0===n.indexOf("Lcl ")&&(n=n.replace("Lcl ","Lcl_")),s="Color"===n||"ColorRGB"===n||"Vector"===n||"Vector3D"===n||0===n.indexOf("Lcl_")?[r.propertyList[4],r.propertyList[5],r.propertyList[6]]:r.propertyList[4],t[e]={type:n,type2:o,flag:a,value:s}}else void 0===t[r.name]?"number"==typeof r.id?(t[r.name]={},t[r.name][r.id]=r):t[r.name]=r:"PoseNode"===r.name?(Array.isArray(t[r.name])||(t[r.name]=[t[r.name]]),t[r.name].push(r)):void 0===t[r.name][r.id]&&(t[r.name][r.id]=r)}parseProperty(e){const r=e.getString(1);let n;switch(r){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return n=e.getUint32(),e.getArrayBuffer(n);case"S":return n=e.getUint32(),e.getString(n);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const o=e.getUint32(),a=e.getUint32(),s=e.getUint32();if(0===a)switch(r){case"b":case"c":return e.getBooleanArray(o);case"d":return e.getFloat64Array(o);case"f":return e.getFloat32Array(o);case"i":return e.getInt32Array(o);case"l":return e.getInt64Array(o)}const i=t.unzlibSync(new Uint8Array(e.getArrayBuffer(s))),l=new h(i.buffer);switch(r){case"b":case"c":return l.getBooleanArray(o);case"d":return l.getFloat64Array(o);case"f":return l.getFloat32Array(o);case"i":return l.getInt32Array(o);case"l":return l.getInt64Array(o)}default:throw new Error("THREE.FBXLoader: Unknown property type "+r)}}}class h{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=void 0===t||t}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return 1==(1&this.getUint8())}getBooleanArray(e){const t=[];for(let r=0;r<e;r++)t.push(this.getBoolean());return t}getUint8(){const e=this.dv.getUint8(this.offset);return this.offset+=1,e}getInt16(){const e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}getInt32(){const e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}getInt32Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getInt32());return t}getUint32(){const e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}getInt64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),2147483648&t?(t=4294967295&~t,e=4294967295&~e,4294967295===e&&(t=t+1&4294967295),e=e+1&4294967295,-(4294967296*t+e)):4294967296*t+e}getInt64Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getInt64());return t}getUint64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),4294967296*t+e}getFloat32(){const e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}getFloat32Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getFloat32());return t}getFloat64(){const e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}getFloat64Array(e){const t=[];for(let r=0;r<e;r++)t.push(this.getFloat64());return t}getArrayBuffer(e){const t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}getString(t){let r=[];for(let e=0;e<t;e++)r[e]=this.getUint8();const n=r.indexOf(0);return n>=0&&(r=r.slice(0,n)),e.LoaderUtils.decodeText(new Uint8Array(r))}}class d{add(e,t){this[e]=t}}function f(e){const t=e.match(/FBXVersion: (\d+)/);if(t){return parseInt(t[1])}throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function m(e){return e/46186158e3}const g=[];function v(e,t,r,n){let o;switch(n.mappingType){case"ByPolygonVertex":o=e;break;case"ByPolygon":o=t;break;case"ByVertice":o=r;break;case"AllSame":o=n.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+n.mappingType)}"IndexToDirect"===n.referenceType&&(o=n.indices[o]);const a=o*n.dataSize,s=a+n.dataSize;return function(e,t,r,n){for(let o=r,a=0;o<n;o++,a++)e[a]=t[o];return e}(g,n.buffer,a,s)}const y=new e.Euler,w=new e.Vector3;function I(t){const r=new e.Matrix4,n=new e.Matrix4,o=new e.Matrix4,a=new e.Matrix4,s=new e.Matrix4,i=new e.Matrix4,l=new e.Matrix4,c=new e.Matrix4,u=new e.Matrix4,p=new e.Matrix4,h=new e.Matrix4,d=new e.Matrix4,f=t.inheritType?t.inheritType:0;if(t.translation&&r.setPosition(w.fromArray(t.translation)),t.preRotation){const r=t.preRotation.map(e.MathUtils.degToRad);r.push(t.eulerOrder),n.makeRotationFromEuler(y.fromArray(r))}if(t.rotation){const r=t.rotation.map(e.MathUtils.degToRad);r.push(t.eulerOrder),o.makeRotationFromEuler(y.fromArray(r))}if(t.postRotation){const r=t.postRotation.map(e.MathUtils.degToRad);r.push(t.eulerOrder),a.makeRotationFromEuler(y.fromArray(r)),a.invert()}t.scale&&s.scale(w.fromArray(t.scale)),t.scalingOffset&&l.setPosition(w.fromArray(t.scalingOffset)),t.scalingPivot&&i.setPosition(w.fromArray(t.scalingPivot)),t.rotationOffset&&c.setPosition(w.fromArray(t.rotationOffset)),t.rotationPivot&&u.setPosition(w.fromArray(t.rotationPivot)),t.parentMatrixWorld&&(h.copy(t.parentMatrix),p.copy(t.parentMatrixWorld));const m=n.clone().multiply(o).multiply(a),g=new e.Matrix4;g.extractRotation(p);const v=new e.Matrix4;v.copyPosition(p);const I=v.clone().invert().multiply(p),x=g.clone().invert().multiply(I),b=s,T=new e.Matrix4;if(0===f)T.copy(g).multiply(m).multiply(x).multiply(b);else if(1===f)T.copy(g).multiply(x).multiply(m).multiply(b);else{const t=(new e.Matrix4).scale((new e.Vector3).setFromMatrixScale(h)).clone().invert(),r=x.clone().multiply(t);T.copy(g).multiply(m).multiply(r).multiply(b)}const M=u.clone().invert(),A=i.clone().invert();let E=r.clone().multiply(c).multiply(u).multiply(n).multiply(o).multiply(a).multiply(M).multiply(l).multiply(i).multiply(s).multiply(A);const D=(new e.Matrix4).copyPosition(E),P=p.clone().multiply(D);return d.copyPosition(P),E=d.clone().multiply(T),E.premultiply(p.invert()),E}function x(e){const t=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return 6===(e=e||0)?(console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),t[0]):t[e]}function b(e){return e.split(",").map((function(e){return parseFloat(e)}))}function T(t,r,n){return void 0===r&&(r=0),void 0===n&&(n=t.byteLength),e.LoaderUtils.decodeText(new Uint8Array(t,r,n))}function M(e,t,r){return e.slice(0,t).concat(r).concat(e.slice(t))}exports.FBXLoader=s;
|
package/loaders/FBXLoader.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Loader, LoaderUtils, FileLoader, TextureLoader, RepeatWrapping, ClampToEdgeWrapping, Texture, MeshPhongMaterial, MeshLambertMaterial, Color,
|
1
|
+
import { Loader, LoaderUtils, FileLoader, TextureLoader, RepeatWrapping, ClampToEdgeWrapping, Texture, MeshPhongMaterial, MeshLambertMaterial, Color, EquirectangularReflectionMapping, Matrix4, Group, Bone, PropertyBinding, Object3D, OrthographicCamera, PerspectiveCamera, PointLight, MathUtils, SpotLight, DirectionalLight, SkinnedMesh, Mesh, LineBasicMaterial, Line, Vector3, Skeleton, AmbientLight, BufferGeometry, Float32BufferAttribute, Uint16BufferAttribute, Matrix3, Vector4, AnimationClip, Quaternion, Euler, VectorKeyframeTrack, QuaternionKeyframeTrack, NumberKeyframeTrack } from 'three';
|
2
2
|
import { unzlibSync } from 'fflate';
|
3
3
|
import { NURBSCurve } from '../curves/NURBSCurve.js';
|
4
4
|
|
@@ -423,7 +423,7 @@ class FBXTreeParser {
|
|
423
423
|
parameters.map = scope.getTexture(textureMap, child.ID);
|
424
424
|
|
425
425
|
if (parameters.map !== undefined) {
|
426
|
-
parameters.map.encoding = sRGBEncoding
|
426
|
+
if ('colorSpace' in parameters.map) parameters.map.colorSpace = 'srgb';else parameters.map.encoding = 3001; // sRGBEncoding
|
427
427
|
}
|
428
428
|
|
429
429
|
break;
|
@@ -436,7 +436,7 @@ class FBXTreeParser {
|
|
436
436
|
parameters.emissiveMap = scope.getTexture(textureMap, child.ID);
|
437
437
|
|
438
438
|
if (parameters.emissiveMap !== undefined) {
|
439
|
-
parameters.emissiveMap.encoding = sRGBEncoding
|
439
|
+
if ('colorSpace' in parameters.emissiveMap) parameters.emissiveMap.colorSpace = 'srgb';else parameters.emissiveMap.encoding = 3001; // sRGBEncoding
|
440
440
|
}
|
441
441
|
|
442
442
|
break;
|
@@ -451,7 +451,7 @@ class FBXTreeParser {
|
|
451
451
|
|
452
452
|
if (parameters.envMap !== undefined) {
|
453
453
|
parameters.envMap.mapping = EquirectangularReflectionMapping;
|
454
|
-
parameters.envMap.encoding = sRGBEncoding
|
454
|
+
if ('colorSpace' in parameters.envMap) parameters.envMap.colorSpace = 'srgb';else parameters.envMap.encoding = 3001; // sRGBEncoding
|
455
455
|
}
|
456
456
|
|
457
457
|
break;
|
@@ -460,7 +460,7 @@ class FBXTreeParser {
|
|
460
460
|
parameters.specularMap = scope.getTexture(textureMap, child.ID);
|
461
461
|
|
462
462
|
if (parameters.specularMap !== undefined) {
|
463
|
-
parameters.specularMap.encoding = sRGBEncoding
|
463
|
+
if ('colorSpace' in parameters.specularMap) parameters.specularMap.colorSpace = 'srgb';else parameters.specularMap.encoding = 3001; // sRGBEncoding
|
464
464
|
}
|
465
465
|
|
466
466
|
break;
|