Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Marmoset viewer embedded code, as is
/*
(Built: Mon, Sep 24, 2018 4:38:25 PM)
Marmoset Viewer Code and Tools
Copyright (c) 2018 Marmoset LLC.
All rights reserved.
Redistribution and use of this software are permitted provided
that the software remains whole and unmodified and this copyright
notice remains attached. Use or inclusion of any portion of this
code in other software programs is prohibited, excepting simple
embedding of this file in web applications. This software, or any
derivatives thereof, may not be resold, rented, leased, or
distributed on any other for-charge basis.
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
marmoset={};(function(marmoset){'use strict';function AnimatedObject(a,b,c){this.name=b.partName;this.animatedProperties=[];this.sceneObjectType=b.sceneObjectType;this.skinningRigIndex=b.skinningRigIndex;this.id=c;this.mesh=this.skinningRig=0;this.materialIndex=this.lightIndex=this.meshIndex=-1;this.emissiveProperty=this.offsetVProperty=this.offsetUProperty=this.material=0;this.debugMe=b.debugMe;this.debugString="";this.hasTransform=!1;this.modelPartIndex=b.modelPartIndex;this.modelPartFPS=b.modelPartFPS;this.modelPartScale=b.modelPartScale;
this.parentIndex=b.parentIndex;this.startTime=b.startTime;this.endTime=b.endTime;this.animationLength=this.endTime-this.startTime;this.totalFrames=b.totalFrames;this.turnTableSpinOffset=this.turnTableSpin=this.spinProperty=this.dispersionProperty=this.lightIllumProperty=this.skyIllumProperty=this.opacityProperty=this.spotSharpnessProperty=this.spotAngleProperty=this.distanceProperty=this.brightnessProperty=this.blueProperty=this.greenProperty=this.redProperty=this.visibleProperty=0;if(b.animatedProperties){c=
b.animatedProperties.length;for(var d=0;d<c;++d){var e=b.animatedProperties[d],f=new AnimatedProperty;f.name=e.name;this.animatedProperties.push(f);"Red"!=f.name||this.redProperty||(this.redProperty=f);"Green"!=f.name||this.greenProperty||(this.greenProperty=f);"Blue"!=f.name||this.blueProperty||(this.blueProperty=f);"Brightness"!=f.name||this.brightnessProperty||(this.brightnessProperty=f);"Distance"!=f.name||this.distanceProperty||(this.distanceProperty=f);"Spot Angle"!=f.name||this.spotAngleProperty||
(this.spotAngleProperty=f);"Spot Sharpness"!=f.name||this.spotSharpnessProperty||(this.spotSharpnessProperty=f);"Opacity"!=f.name||this.opacityProperty||(this.opacityProperty=f);"Sky Illumination"!=f.name||this.skyIllumProperty||(this.skyIllumProperty=f);"Light Illumination"!=f.name||this.lightIllumProperty||(this.lightIllumProperty=f);"Dispersion"!=f.name||this.dispersionProperty||(this.dispersionProperty=f);"Visible"!=f.name||this.visibleProperty||(this.visibleProperty=f);"Spin Rate"==f.name&&(this.spinProperty=
f);"OffsetU"==f.name&&(this.offsetUProperty=f);"OffsetV"==f.name&&(this.offsetVProperty=f);"EmissiveIntensity"==f.name&&(this.emissiveProperty=f)}}this.keyframesSharedBufferUShorts=this.keyframesSharedBufferFloats=this.keyFramesByteStream=0;if(a=a.get(b.file))this.keyFramesByteStream=new ByteStream(a.data),this.unPackKeyFrames();this.animatedLocalTransform=new AnimatedTransform(this);this.hasTransform=this.animatedLocalTransform.hasTranslation||this.animatedLocalTransform.hasRotation||this.animatedLocalTransform.hasScale;
this.cachedWorldTransform0=Matrix.identity();this.cachedWorldTransform1=Matrix.identity();this.cachedWorldTransform2=Matrix.identity();this.cachedWorldTransform3=Matrix.identity();this.cachedFrame3=this.cachedFrame2=this.cachedFrame1=this.cachedFrame0=-10;this.cachedFrameUse3=this.cachedFrameUse2=this.cachedFrameUse1=this.cachedFrameUse0=0;this.useFixedLocalTransform=this.useFixedWorldTransform=!1}
AnimatedObject.prototype.setFixedWorldTransform=function(a){this.useFixedWorldTransform=!0;Matrix.copy(this.cachedWorldTransform0,a)};AnimatedObject.prototype.setFixedLocalTransform=function(a){this.useFixedLocalTransform=!0;this.animatedLocalTransform.lockTransform=!0;Matrix.copy(this.animatedLocalTransform.cachedmatrix0,a)};
AnimatedObject.prototype.getCachedWorldTransform=function(a){return this.useFixedWorldTransform?0:a==this.cachedFrame0?this.cachedmatrix0:a==this.cachedFrame1?this.cachedmatrix1:a==this.cachedFrame2?this.cachedmatrix2:a==this.cachedFrame3?this.cachedmatrix3:0};
AnimatedObject.prototype.getFreeCachedWorldTransform=function(a){if(this.useFixedWorldTransform)return 0;this.cachedFrameUse0--;this.cachedFrameUse1--;this.cachedFrameUse2--;this.cachedFrameUse3--;if(this.cachedFrameUse0<=this.cachedFrameUse1&&this.cachedFrameUse0<=this.cachedFrameUse2&&this.cachedFrameUse0<=this.cachedFrameUse3)return this.cachedFrame0=a,this.cachedFrameUse0=0,this.cachedWorldTransform0;if(this.cachedFrameUse1<=this.cachedFrameUse0&&this.cachedFrameUse1<=this.cachedFrameUse2&&this.cachedFrameUse1<=
this.cachedFrameUse3)return this.cachedFrame1=a,this.cachedFrameUse1=0,this.cachedWorldTransform1;if(this.cachedFrameUse2<=this.cachedFrameUse0&&this.cachedFrameUse2<=this.cachedFrameUse1&&this.cachedFrameUse2<=this.cachedFrameUse3)return this.cachedFrame2=a,this.cachedFrameUse2=0,this.cachedWorldTransform2;this.cachedFrame3=a;this.cachedFrameUse3=0;return this.cachedWorldTransform3};
AnimatedObject.prototype.unPackKeyFrames=function(){if(this.keyFramesByteStream){var a=new Float32Array(this.keyFramesByteStream.bytes.buffer),b=new Uint32Array(this.keyFramesByteStream.bytes.buffer),c=new Uint16Array(this.keyFramesByteStream.bytes.buffer),d=new Uint8Array(this.keyFramesByteStream.bytes.buffer);this.keyframesSharedBufferFloats=a;this.keyframesSharedBufferUShorts=b;for(var a=0,b=b[0],a=1+b,b=this.animatedProperties.length,e=0;e<b;e++){var f=this.animatedProperties[e],g=2+2*e,h=2*g;
f.keyframeBufferStartIndexFloat=a;f.numKeyframes=c[g];f.keyframePackingType=d[h+2];f.interpolationType=d[h+3];f.indexFloatSkip=0;f.indexUShortSkip=0;0<f.numKeyframes&&(0==f.keyframePackingType?(f.bytesPerKeyFrame=16,f.indexFloatSkip=4,f.indexUShortSkip=8,f.valueOffsetFloat=0,f.weighInOffsetFloat=1,f.weighOutOffsetFloat=2,f.frameIndexOffsetUShort=6,f.interpolationOffsetUShort=7):1==f.keyframePackingType?(f.bytesPerKeyFrame=8,f.indexFloatSkip=2,f.indexUShortSkip=4,f.valueOffsetFloat=0,f.weighInOffsetFloat=
0,f.weighOutOffsetFloat=0,f.frameIndexOffsetUShort=2,f.interpolationOffsetUShort=3):2==f.keyframePackingType&&(f.bytesPerKeyFrame=4,f.indexFloatSkip=1,f.indexUShortSkip=2,f.valueOffsetFloat=0,f.weighInOffsetFloat=0,f.weighOutOffsetFloat=0,f.frameIndexOffsetUShort=0,f.interpolationOffsetUShort=0));a+=f.numKeyframes*f.indexFloatSkip}}};
AnimatedObject.prototype.setupSkinningRig=function(a,b,c,d){var e=Matrix.identity(),f=Matrix.identity(),g=a.animatedObjects[b],h=c*g.modelPartFPS,h=h-Math.floor(h);c=Math.floor(a.getObjectAnimationFramePercent(g,c));var g=c+1,k=1-h,l=d.skinningClusters.length;if(0<l)for(var n=0;n<l;n++){var m=d.skinningClusters[n];m.solveClusterTransformAtFrame(a,b,c,e);m.solveClusterTransformAtFrame(a,b,g,f);for(var m=m.matrix,p=0;16>p;p++)m[p]=e[p]*k+f[p]*h}};
AnimatedObject.prototype.evaluateLocalTransformAtFramePercent=function(a,b,c,d){if(this.useFixedLocalTransform)Matrix.copy(b,this.animatedLocalTransform.cachedmatrix0);else{var e=0;d&&(e=this.animatedLocalTransform.getCachedTransform(a));e?Matrix.copy(b,e):((e=this.animatedLocalTransform.getFreeCachedTransform(a))?(this.animatedLocalTransform.evaluateMatrix(e,this.totalFrames,a,c),Matrix.copy(b,e)):this.animatedLocalTransform.evaluateMatrix(b,this.totalFrames,a,c),0!=this.turnTableSpin&&(a=Matrix.rotation(Matrix.empty(),
this.turnTableSpin,1),Matrix.mul(b,b,a)))}};AnimatedObject.prototype.hasAnimatedTransform=function(){var a=this.animatedLocalTransform;return a.TX&&1<a.TX.numKeyframes||a.TY&&1<a.TY.numKeyframes||a.TZ&&1<a.TZ.numKeyframes||a.RX&&1<a.RX.numKeyframes||a.RY&&1<a.RY.numKeyframes||a.RZ&&1<a.RZ.numKeyframes||a.SX&&1<a.SX.numKeyframes||a.SY&&1<a.SY.numKeyframes||a.SZ&&1<a.SZ.numKeyframes?!0:!1};function AnimatedProperty(){this.currentValue=0;this.keyframeBufferStartIndexFloat=-1;this.lastValue=this.interpolationOffsetUShort=this.frameIndexOffsetUShort=this.weighOutOffsetFloat=this.weighInOffsetFloat=this.valueOffsetFloat=this.indexUShortSkip=this.indexFloatSkip=this.interpolationType=this.bytesPerKeyFrame=this.keyframePackingType=0;this.lastFramePercent=-10;this.enable=!0;this.name="NONE";this.splineKF0=new KeyFrame(0,0);this.splineKF1=new KeyFrame(0,0);this.splineKF2=new KeyFrame(0,0);
this.splineKF3=new KeyFrame(0,0);this.debugMe=!0;this.debugString="";this.lastSearchIndex=1;this.savedSearchIndex=0;this.splineKF0.frameIndex=0;this.splineKF1.frameIndex=1;this.splineKF2.frameIndex=2;this.splineKF3.frameIndex=3;this.numKeyframes=0}
AnimatedProperty.prototype.evaluateCurve=function(a,b){var c=this.splineKF1.frameIndex,d=this.splineKF2.frameIndex,e=this.splineKF1.value,f=this.splineKF2.value,g=c-(this.splineKF2.frameIndex-this.splineKF0.frameIndex),h=d-(this.splineKF1.frameIndex-this.splineKF3.frameIndex),k=e-(this.splineKF2.value-this.splineKF0.value)*this.splineKF1.weighOut,l=f-(this.splineKF1.value-this.splineKF3.value)*this.splineKF2.weighIn;3==this.splineKF1.interpolation&&(g=c-(this.splineKF2.frameIndex-this.splineKF1.frameIndex),
k=e-this.splineKF1.weighOut);3==this.splineKF2.interpolation&&(h=d-(this.splineKF1.frameIndex-this.splineKF2.frameIndex),l=f+this.splineKF2.weighIn);g=(a-g)/(c-g);c=(a-c)/(d-c);d=(a-d)/(h-d);h=e*(1-c)+f*c;return((k*(1-g)+e*g)*(1-c)+h*c)*(1-c)+((f*(1-d)+l*d)*c+h*(1-c))*c};
AnimatedProperty.prototype.evaluate=function(a,b,c){if(!c)return b;if(0==this.numKeyframes)return this.lastValue=b;if(1==this.numKeyframes)return this.lastValue=2==this.keyframePackingType?c.keyframesSharedBufferFloats[this.keyframeBufferStartIndexFloat]:c.keyframesSharedBufferFloats[this.keyframeBufferStartIndexFloat+this.valueOffsetFloat];if(this.lastFramePercent==a)return this.lastValue;var d=this.keyframeBufferStartIndexFloat,e=2*this.keyframeBufferStartIndexFloat;this.lastValue=b;this.lastFramePercent=
a;if(2==this.keyframePackingType){b=Math.floor(a);var f=a-b;a>=this.numKeyframes&&(b-=Math.floor(a/this.numKeyframes)*this.numKeyframes);if(b>=this.numKeyframes-1)return this.lastValue=c.keyframesSharedBufferFloats[d+(this.numKeyframes-1)];if(0>b)return this.lastValue=c.keyframesSharedBufferFloats[d];if(0==f)return this.lastValue=c.keyframesSharedBufferFloats[d+b];a=e=c.keyframesSharedBufferFloats[d+b];b++;b>=this.numKeyframes&&(b-=this.numKeyframes);0<=b&&b<this.numKeyframes?a=e*(1-f)+c.keyframesSharedBufferFloats[d+
b]*f:c.debugString+="<br>bad lerp frame "+b+" of "+this.numKeyframes;return this.lastValue=a}var g=this.numKeyframes,f=c.keyframesSharedBufferUShorts[e+this.frameIndexOffsetUShort];if(a>=c.keyframesSharedBufferUShorts[e+(g-1)*this.indexUShortSkip+this.frameIndexOffsetUShort])return this.lastValue=c.keyframesSharedBufferFloats[d+(g-1)*this.indexFloatSkip+this.valueOffsetFloat];if(a<f)return this.lastValue=c.keyframesSharedBufferFloats[d+this.valueOffsetFloat];this.lastSearchIndex<this.numKeyframes&&
a>c.keyframesSharedBufferUShorts[e+this.lastSearchIndex*this.indexUShortSkip+this.frameIndexOffsetUShort]&&(this.lastSearchIndex=1);for(var h=this.lastSearchIndex;h<g;h++){var f=d+h*this.indexFloatSkip,k=d+(h-1)*this.indexFloatSkip,l=e+h*this.indexUShortSkip,n=e+(h-1)*this.indexUShortSkip;if(a>=c.keyframesSharedBufferUShorts[n+this.frameIndexOffsetUShort]&&a<=c.keyframesSharedBufferUShorts[l+this.frameIndexOffsetUShort]){this.lastSearchIndex=h;var m=c.keyframesSharedBufferUShorts[n+this.interpolationOffsetUShort];
if(2==m){this.lastValue=a=a>=c.keyframesSharedBufferUShorts[l+this.frameIndexOffsetUShort]?c.keyframesSharedBufferFloats[f+this.valueOffsetFloat]:c.keyframesSharedBufferFloats[k+this.valueOffsetFloat];break}if(0==m){d=c.keyframesSharedBufferUShorts[n+this.frameIndexOffsetUShort];b=c.keyframesSharedBufferFloats[k+this.valueOffsetFloat];e=c.keyframesSharedBufferFloats[f+this.valueOffsetFloat];f=(a-d)/(c.keyframesSharedBufferUShorts[l+this.frameIndexOffsetUShort]-d);this.lastValue=a=b*(1-f)+e*f;break}if(1==
m||3==m){var p=m=!1,r=0,s=c.keyframesSharedBufferFloats[k+this.valueOffsetFloat],u=c.keyframesSharedBufferFloats[f+this.valueOffsetFloat],q=0,x=0,n=c.keyframesSharedBufferUShorts[n+this.frameIndexOffsetUShort],l=c.keyframesSharedBufferUShorts[l+this.frameIndexOffsetUShort],w=0,v=1,t=1,y=1,E=1,F=1,A=1,B=1,z=1;0!=this.weighInOffsetFloat&&(t=c.keyframesSharedBufferFloats[k+this.weighInOffsetFloat],y=c.keyframesSharedBufferFloats[f+this.weighInOffsetFloat],A=c.keyframesSharedBufferFloats[k+this.weighOutOffsetFloat],
B=c.keyframesSharedBufferFloats[f+this.weighOutOffsetFloat]);1<h&&(m=!0,r=c.keyframesSharedBufferFloats[d+(h-2)*this.indexFloatSkip+this.valueOffsetFloat],x=c.keyframesSharedBufferUShorts[e+(h-2)*this.indexUShortSkip+this.frameIndexOffsetUShort],0!=this.weighInOffsetFloat&&(v=c.keyframesSharedBufferFloats[d+(h-2)*this.indexFloatSkip+this.weighInOffsetFloat],F=c.keyframesSharedBufferFloats[d+(h-2)*this.indexFloatSkip+this.weighOutOffsetFloat]));h<g-1&&(p=!0,q=c.keyframesSharedBufferFloats[d+(h+1)*
this.indexFloatSkip+this.valueOffsetFloat],w=c.keyframesSharedBufferUShorts[e+(h+1)*this.indexUShortSkip+this.frameIndexOffsetUShort],0!=this.weighInOffsetFloat&&(E=c.keyframesSharedBufferFloats[d+(h+1)*this.indexFloatSkip+this.weighInOffsetFloat],z=c.keyframesSharedBufferFloats[d+(h+1)*this.indexFloatSkip+this.weighOutOffsetFloat]));m&&p?(this.splineKF0.value=r,this.splineKF1.value=s,this.splineKF2.value=u,this.splineKF3.value=q,this.splineKF0.frameIndex=x,this.splineKF1.frameIndex=n,this.splineKF2.frameIndex=
l,this.splineKF3.frameIndex=w,this.splineKF0.weighIn=v,this.splineKF0.weighOut=F,this.splineKF1.weighIn=t,this.splineKF1.weighOut=A,this.splineKF2.weighIn=y,this.splineKF2.weighOut=B,this.splineKF3.weighIn=E,this.splineKF3.weighOut=z):(this.splineKF0.value=s,this.splineKF1.value=s,this.splineKF2.value=u,this.splineKF3.value=u,this.splineKF0.frameIndex=n,this.splineKF1.frameIndex=n,this.splineKF2.frameIndex=l,this.splineKF3.frameIndex=l,this.splineKF1.weighIn=t,this.splineKF2.weighIn=y,this.splineKF1.weighOut=
A,this.splineKF2.weighOut=B,p?(this.splineKF3.value=q,this.splineKF3.frameIndex=w,this.splineKF3.weighIn=E,this.splineKF3.weighOut=z):(this.splineKF3.frameIndex++,this.splineKF3.value=this.splineKF1.value,this.splineKF3.weighIn=1,this.splineKF3.weighOut=1),m?(this.splineKF0.value=r,this.splineKF0.frameIndex=x,this.splineKF0.weighIn=v,this.splineKF0.weighOut=F):(this.splineKF0.value=this.splineKF2.value,this.splineKF0.weighIn=1,this.splineKF0.weighOut=1,0<this.splineKF0.frameIndex?this.splineKF0.frameIndex--:
(this.splineKF1.frameIndex++,this.splineKF2.frameIndex++,this.splineKF3.frameIndex++,a++)));this.lastValue=a=this.evaluateCurve(a,b);break}}}return this.lastValue};function AnimatedTransform(a){var b=a.animatedProperties;this.TX=this.TY=this.TZ=this.RX=this.RY=this.RZ=this.SX=this.SY=this.SZ=0;this.hostObject=a;this.matrix=Matrix.identity();this.cachedmatrix0=Matrix.identity();this.cachedmatrix1=Matrix.identity();this.cachedmatrix2=Matrix.identity();this.cachedmatrix3=Matrix.identity();this.cachedFrame3=this.cachedFrame2=this.cachedFrame1=this.cachedFrame0=-1;this.cachedFrameUse3=this.cachedFrameUse2=this.cachedFrameUse1=this.cachedFrameUse0=0;this.debugString=
"";for(a=0;a<b.length;a++){var c=b[a];"Translation X"==c.name?this.TX=c:"Translation Y"==c.name?this.TY=c:"Translation Z"==c.name?this.TZ=c:"Rotation X"==c.name?this.RX=c:"Rotation Y"==c.name?this.RY=c:"Rotation Z"==c.name?this.RZ=c:"Scale X"==c.name?this.SX=c:"Scale Y"==c.name?this.SY=c:"Scale Z"==c.name&&(this.SZ=c)}this.hasTranslation=this.TX&&this.TY&&this.TZ;this.hasRotation=this.RX&&this.RY&&this.RZ;this.hasScale=this.SX&&this.SY&&this.SZ;this.lockTransform=!1}
AnimatedTransform.prototype.getTRSValue=function(a,b,c){if(!b)return c;b.evaluate(a,c,this.hostObject);""!=b.debugString&&(this.debugString+=b.debugString);return b.lastValue};
AnimatedTransform.prototype.evaluateMatrix=function(a,b,c,d){if(this.lockTransform)Matrix.copy(a,this.cachedmatrix0);else{var e=0,f=b=0,e=f=b=0,e=f=b=1;this.hasRotation?(e=this.getTRSValue(c,this.RX,0),b=this.getTRSValue(c,this.RY,0),f=this.getTRSValue(c,this.RZ,0),d?(this.matrix=Matrix.rotation(Matrix.empty(),f,2),d=Matrix.rotation(Matrix.empty(),e,0),Matrix.mul(d,d,this.matrix),this.matrix=Matrix.rotation(Matrix.empty(),b,1)):(this.matrix=Matrix.rotation(Matrix.empty(),e,0),d=Matrix.rotation(Matrix.empty(),
b,1),Matrix.mul(d,d,this.matrix),this.matrix=Matrix.rotation(Matrix.empty(),f,2)),Matrix.mul(this.matrix,this.matrix,d)):Matrix.copy(this.matrix,Matrix.identity());this.hasTranslation&&(b=this.getTRSValue(c,this.TX,0),f=this.getTRSValue(c,this.TY,0),e=this.getTRSValue(c,this.TZ,0),this.matrix[12]=b,this.matrix[13]=f,this.matrix[14]=e);this.hasScale&&(b=this.getTRSValue(c,this.SX,1),f=this.getTRSValue(c,this.SY,1),e=this.getTRSValue(c,this.SZ,1),this.matrix[0]*=b,this.matrix[4]*=f,this.matrix[8]*=
e,this.matrix[1]*=b,this.matrix[5]*=f,this.matrix[9]*=e,this.matrix[2]*=b,this.matrix[6]*=f,this.matrix[10]*=e,this.matrix[3]*=b,this.matrix[7]*=f,this.matrix[11]*=e);Matrix.copy(a,this.matrix)}};
AnimatedTransform.prototype.clearCachedTransforms=function(){this.cachedFrame3=this.cachedFrame2=this.cachedFrame1=this.cachedFrame0=-1;this.cachedFrameUse3=this.cachedFrameUse2=this.cachedFrameUse1=this.cachedFrameUse0=0;this.TX&&(this.TX.lastFramePercent=-10);this.TY&&(this.TY.lastFramePercent=-10);this.TZ&&(this.TZ.lastFramePercent=-10);this.RX&&(this.RX.lastFramePercent=-10);this.RY&&(this.RY.lastFramePercent=-10);this.RZ&&(this.RZ.lastFramePercent=-10);this.SX&&(this.SX.lastFramePercent=-10);
this.SY&&(this.SY.lastFramePercent=-10);this.SZ&&(this.SZ.lastFramePercent=-10);this.lockTransform=!1};AnimatedTransform.prototype.getCachedTransform=function(a){return this.lockTransform?0:this.cachedFrame0==a?this.cachedmatrix0:this.cachedFrame1==a?this.cachedmatrix1:this.cachedFrame2==a?this.cachedmatrix2:this.cachedFrame3==a?this.cachedmatrix3:0};
AnimatedTransform.prototype.getFreeCachedTransform=function(a){if(this.lockTransform)return 0;this.cachedFrameUse0--;this.cachedFrameUse1--;this.cachedFrameUse2--;this.cachedFrameUse3--;if(this.cachedFrameUse0<=this.cachedFrameUse1&&this.cachedFrameUse0<=this.cachedFrameUse2&&this.cachedFrameUse0<=this.cachedFrameUse3||this.cachedFrame0==a)return this.cachedFrame0=a,this.cachedFrameUse0=0,this.cachedmatrix0;if(this.cachedFrameUse1<=this.cachedFrameUse0&&this.cachedFrameUse1<=this.cachedFrameUse2&&
this.cachedFrameUse1<=this.cachedFrameUse3||this.cachedFrame1==a)return this.cachedFrame1=a,this.cachedFrameUse1=0,this.cachedmatrix1;if(this.cachedFrameUse2<=this.cachedFrameUse0&&this.cachedFrameUse2<=this.cachedFrameUse1&&this.cachedFrameUse2<=this.cachedFrameUse3||this.cachedFrame2==a)return this.cachedFrame2=a,this.cachedFrameUse2=0,this.cachedmatrix2;this.cachedFrame3=a;this.cachedFrameUse3=0;return this.cachedmatrix3};function Animation(a,b){this.originalFPS=1;this.name=b.name;this.totalSeconds=b.length;this.originalFPS=b.originalFPS;this.totalFrames=b.totalFrames;this.expectedNumAnimatedObjects=b.numAnimatedObjects;this.animatedObjects=[];this.sceneTransform=Matrix.identity();this.debugString="";if(b.animatedObjects)for(var c=b.animatedObjects.length,d=0;d<c;++d){var e=new AnimatedObject(a,b.animatedObjects[d],d);this.animatedObjects.push(e);this.debugString+=e.debugString}this.meshObjects=[];this.lightObjects=
[];this.materialObjects=[];this.turnTableObjects=[];this.cameraObjects=[]}
Animation.prototype.evaluateModelPartTransformAtFrame=function(a,b,c,d){Matrix.copy(c,Matrix.identity());for(var e=0;100>e;e++){var f=this.animatedObjects[a];if(a==f.parentIndex)break;if(f.useFixedWorldTransform){Matrix.mul(c,f.cachedWorldTransform0,c);break}else{var g=0;d&&(g=f.getCachedWorldTransform(b));if(g){Matrix.mul(c,g,c);break}else g=Matrix.identity(),f.evaluateLocalTransformAtFramePercent(b,g,!1,d),Matrix.mul(c,g,c),a==f.parentIndex&&(e=100),a=f.parentIndex}}};
Animation.prototype.lerpModelPartTransform=function(a,b,c,d){var e=this.animatedObjects[a];if(e.useFixedWorldTransform)Matrix.copy(c,e.cachedWorldTransform0);else{var f=b*e.modelPartFPS,f=f-Math.floor(f),g=Math.floor(this.getObjectAnimationFramePercent(e,b)),h=g+1,k=b=0;d&&(b=e.getCachedWorldTransform(g),k=e.getCachedWorldTransform(h));b||((b=e.getFreeCachedWorldTransform(g))||(b=Matrix.identity()),this.evaluateModelPartTransformAtFrame(a,g,b,d));k||((k=e.getFreeCachedWorldTransform(h))||(k=Matrix.identity()),
this.evaluateModelPartTransformAtFrame(a,h,k,d));a=1-f;for(d=0;16>d;d++)c[d]=b[d]*a+k[d]*f}};Animation.prototype.getModelPartTransform=function(a,b,c,d){this.lerpModelPartTransform(a,b,c,d)};
Animation.prototype.getAnimatedLocalTransform=function(a,b,c,d){a=this.animatedObjects[a];var e=this.animatedObjects[a.parentIndex],f=e.modelPartIndex!=e.id,g=Matrix.identity();this.getModelPartTransform(a.modelPartIndex,b,g,d);if(f){var f=Matrix.identity(),h=Matrix.identity();this.getModelPartTransform(e.modelPartIndex,b,f,d);Matrix.invert(h,f);Matrix.mul(c,h,g);c[12]*=a.modelPartScale;c[13]*=a.modelPartScale;c[14]*=a.modelPartScale}else Matrix.copy(c,g)};
Animation.prototype.isVisibleAtFramePercent=function(a,b){for(var c=a,d=0,e=0;100>e;e++){d=this.animatedObjects[c];if(d.visibleProperty){d.visibleProperty.evaluate(b,1,d);if(""!=d.debugString||""!=d.visibleProperty.debugString)return this.debugString+=d.debugString,this.debugString+=d.visibleProperty.debugString,!1;if(0==d.visibleProperty.lastValue)return!1}c==d.parentIndex&&(e=100);c=d.parentIndex}return!0};
Animation.prototype.getWorldTransform=function(a,b,c,d,e){a=this.animatedObjects[a];if(a.useFixedWorldTransform)Matrix.copy(c,a.cachedWorldTransform0);else{var f=this.getObjectAnimationFramePercent(a,b),g=Matrix.identity();a.evaluateLocalTransformAtFramePercent(f,g,!0,e);if(f=a.modelPartIndex!=a.id){var f=Matrix.identity(),h=Matrix.identity();Matrix.copy(h,g);this.getAnimatedLocalTransform(a.id,b,f);Matrix.mul(g,f,h)}Matrix.copy(c,g);if(a.parentIndex!=a.id)for(var k=a.parentIndex,l=0;100>l;l++)a=
this.animatedObjects[k],f=this.getObjectAnimationFramePercent(a,b),g=Matrix.identity(),a.evaluateLocalTransformAtFramePercent(f,g,!0,e),(f=a.modelPartIndex!=a.id)?(f=Matrix.identity(),this.getAnimatedLocalTransform(a.id,b,f),h=Matrix.identity(),Matrix.mul(h,g,c),Matrix.mul(c,f,h)):(h=Matrix.identity(),Matrix.copy(h,c),Matrix.mul(c,g,h)),k==a.parentIndex&&(l=100),k=a.parentIndex;c[12]*=d;c[13]*=d;c[14]*=d}};
Animation.prototype.hasParentInHierarchy=function(a,b){for(var c=a.parentIndex,d=0;100>d;d++){a=this.animatedObjects[c];if(a.id==b)return!0;c==a.parentIndex&&(d=100);c=a.parentIndex}return!1};Animation.prototype.hasParentTypeInHierarchy=function(a,b){for(var c=a.parentIndex,d=0;100>d;d++){a=this.animatedObjects[c];if(a.sceneObjectType==b)return!0;c==a.parentIndex&&(d=100);c=a.parentIndex}return!1};
Animation.prototype.searchAnimationUpHierarchy=function(a){for(var b=a.id,c=0;100>c;c++){a=this.animatedObjects[b];if(a.animatedLocalTransform&&(a.hasAnimatedTransform()||a.id!=a.modelPartIndex&&this.searchAnimationUpHierarchy(this.animatedObjects[a.modelPartIndex])))return!0;b==a.parentIndex&&(c=100);b=a.parentIndex}return!1};
Animation.prototype.hasAnimationInHierarchy=function(a){return this.searchAnimationUpHierarchy(a)||a.id!=a.modelPartIndex&&this.searchAnimationUpHierarchy(this.animatedObjects[a.modelPartIndex])||this.hasParentTypeInHierarchy(a,"TurnTableSO")||this.hasParentTypeInHierarchy(a,"CameraSO")||"CameraSO"==a.sceneObjectType?!0:!1};
Animation.prototype.getObjectAnimationFramePercent=function(a,b){if(0==this.totalFrames||0==a.animationLength)return 0;if(a.endTime==this.totalSeconds)return b*a.modelPartFPS;var c=b/a.animationLength,c=Math.floor(c);b-=a.animationLength*c;c=b*a.modelPartFPS;c>=a.totalFrames+1&&(c=a.totalFrames);return c};function Archive(a){this.files=[];for(a=new ByteStream(a);!a.empty();){var b={};b.name=a.readCString();b.type=a.readCString();var c=a.readUint32(),d=a.readUint32(),e=a.readUint32();b.data=a.readBytes(d);if(!(b.data.length<d)){if(c&1&&(b.data=this.decompress(b.data,e),null===b.data))continue;this.files[b.name]=b}}}Archive.prototype.get=function(a){return this.files[a]};Archive.prototype.extract=function(a){var b=this.files[a];delete this.files[a];return b};
Archive.prototype.checkSignature=function(a){if(!a)return!1;var b=this.get(a.name+".sig");if(!b)return!1;b=JSON.parse(String.fromCharCode.apply(null,b.data));if(!b)return!1;for(var c=5381,d=0;d<a.data.length;++d)c=33*c+a.data[d]&4294967295;a=new BigInt;a.setBytes([0,233,33,170,116,86,29,195,228,46,189,3,185,31,245,19,159,105,73,190,158,80,175,38,210,116,221,229,171,134,104,144,140,5,99,255,208,78,248,215,172,44,79,83,5,244,152,19,92,137,112,10,101,142,209,100,244,92,190,125,28,0,185,54,143,247,49,
37,15,254,142,180,185,232,50,219,11,186,106,116,78,212,10,105,53,26,14,181,80,47,87,213,182,19,126,151,86,109,182,224,37,135,80,59,22,93,125,68,214,106,209,152,235,157,249,245,48,76,203,0,0,95,200,246,243,229,85,79,169],!0);d=new BigInt;d.setBytes(b[0]);return d.powmod(65537,a).toInt32()!=c?!1:!0};
Archive.prototype.decompress=function(a,b){var c=new Uint8Array(b),d=0,e=new Uint32Array(4096),f=new Uint32Array(4096),g=256,h=a.length,k=0,l=1,n=0,m=1;c[d++]=a[0];for(var p=1;;p++){m=p+(p>>1);if(m+1>=h)break;var n=a[m+1],m=a[m],r=p&1?n<<4|m>>4:(n&15)<<8|m;if(r<g)if(256>r)n=d,m=1,c[d++]=r;else for(var n=d,m=f[r],r=e[r],s=r+m;r<s;)c[d++]=c[r++];else if(r==g){n=d;m=l+1;r=k;for(s=k+l;r<s;)c[d++]=c[r++];c[d++]=c[k]}else break;e[g]=k;f[g++]=l+1;k=n;l=m;g=4096<=g?256:g}return d==b?c:null};function BigInt(a){this.digits=new Uint16Array(a||0)}BigInt.prototype.setBytes=function(a,b){var c=(a.length+1)/2|0;this.digits=new Uint16Array(c);if(b)for(var d=0,c=a.length-1;0<=c;c-=2)this.digits[d++]=a[c]+(0<c?256*a[c-1]:0);else for(d=0;d<c;++d)this.digits[d]=a[2*d]+256*a[2*d+1];this.trim()};BigInt.prototype.toInt32=function(){var a=0;0<this.digits.length&&(a=this.digits[0],1<this.digits.length&&(a|=this.digits[1]<<16));return a};
BigInt.prototype.lessThan=function(a){if(this.digits.length==a.digits.length)for(var b=this.digits.length-1;0<=b;--b){var c=this.digits[b],d=a.digits[b];if(c!=d)return c<d}return this.digits.length<a.digits.length};BigInt.prototype.shiftRight=function(){for(var a=0,b=this.digits,c=b.length-1;0<=c;--c){var d=b[c];b[c]=d>>1|a<<15;a=d}this.trim()};
BigInt.prototype.shiftLeft=function(a){if(0<a){var b=a/16|0;a%=16;for(var c=16-a,d=this.digits.length+b+1,e=new BigInt(d),f=0;f<d;++f)e.digits[f]=((f<b||f>=this.digits.length+b?0:this.digits[f-b])<<a|(f<b+1?0:this.digits[f-b-1])>>>c)&65535;e.trim();return e}return new BigInt(this)};BigInt.prototype.bitCount=function(){var a=0;if(0<this.digits.length)for(var a=16*(this.digits.length-1),b=this.digits[this.digits.length-1];b;)b>>>=1,++a;return a};
BigInt.prototype.sub=function(a){var b=this.digits,c=a.digits,d=this.digits.length;a=a.digits.length;for(var e=0,f=0;f<d;++f){var g=b[f],h=f<a?c[f]:0,h=h+e,e=h>g?1:0,g=g+(e<<16);b[f]=g-h&65535}this.trim()};BigInt.prototype.mul=function(a){for(var b=new BigInt(this.digits.length+a.digits.length),c=b.digits,d=0;d<this.digits.length;++d)for(var e=this.digits[d],f=0;f<a.digits.length;++f)for(var g=e*a.digits[f],h=d+f;g;){var k=(g&65535)+c[h];c[h]=k&65535;g>>>=16;g+=k>>>16;++h}b.trim();return b};
BigInt.prototype.mod=function(a){if(0>=this.digits.length||0>=a.digits.length)return new BigInt(0);var b=new BigInt(this.digits);if(!this.lessThan(a)){for(var c=new BigInt(a.digits),c=c.shiftLeft(b.bitCount()-c.bitCount());!b.lessThan(a);)c.lessThan(b)&&b.sub(c),c.shiftRight();b.trim()}return b};BigInt.prototype.powmod=function(a,b){for(var c=new BigInt([1]),d=this.mod(b);a;)a&1&&(c=c.mul(d).mod(b)),a>>>=1,d=d.mul(d).mod(b);return c};
BigInt.prototype.trim=function(){for(var a=this.digits.length;0<a&&0==this.digits[a-1];)--a;a!=this.digits.length&&(this.digits=this.digits.subarray(0,a))};function Bounds(a){for(var b=0;b<a.length;++b){var c=a[b].bounds;if(void 0===this.min)this.min=[c.min[0],c.min[1],c.min[2]],this.max=[c.max[0],c.max[1],c.max[2]];else for(var d=0;3>d;++d)this.min[d]=Math.min(c.min[d],this.min[d]),this.max[d]=Math.max(c.max[d],this.max[d])}this.min=this.min?this.min:[0,0,0];this.max=this.max?this.max:[0,0,0];this.center=[0.5*(this.min[0]+this.max[0]),0.5*(this.min[1]+this.max[1]),0.5*(this.min[2]+this.max[2])];this.radius=[this.max[0]-this.center[0],this.max[1]-this.center[1],
this.max[2]-this.center[2]];this.radiusDiagonal=Math.sqrt(this.radius[0]*this.radius[0]+this.radius[1]*this.radius[1]+this.radius[2]*this.radius[2])};function Button(a){this.name="none";this.text="default text";this.title="none";this.debugString=this.imagePath="";this.controlRect=new ControlRect(a);this.defaultAlpha=0.5;this.focusAlpha=1;this.updateAlphas=!0;this.linkedBackground=this.backgroundOffsetY=this.backgroundOffsetX=this.edgePixelsY=this.edgePixelsX=this.backgroundBottomMiddle=this.backgroundBottomRight=this.backgroundBottomLeft=this.backgroundMiddleMiddle=this.backgroundMiddleRight=this.backgroundMiddleLeft=this.backgroundTopMiddle=this.backgroundTopRight=
this.backgroundTopLeft=this.backgroundMiddle=this.backgroundRight=this.backgroundLeft=0}Button.prototype.setBackground3x1=function(a,b,c,d,e,f,g){this.backgroundOffsetX=b;this.backgroundOffsetY=c;this.edgePixelsX=g;this.backgroundLeft=a.addImage(d);this.backgroundMiddle=a.addImage(e);this.backgroundRight=a.addImage(f);this.backgroundLeft.linkedControl.style.zIndex="0";this.backgroundMiddle.linkedControl.style.zIndex="0";this.backgroundRight.linkedControl.style.zIndex="0";this.setOpacity(this.defaultAlpha)};
Button.prototype.setBackground3x3=function(a,b,c,d,e,f,g,h,k,l,n,m,p,r){this.backgroundOffsetX=b;this.backgroundOffsetY=c;this.edgePixelsX=p;this.edgePixelsY=r;this.backgroundTopLeft=a.addImage(d);this.backgroundMiddleLeft=a.addImage(g);this.backgroundBottomLeft=a.addImage(l);this.backgroundTopMiddle=a.addImage(e);this.backgroundMiddleMiddle=a.addImage(h);this.backgroundBottomMiddle=a.addImage(n);this.backgroundTopRight=a.addImage(f);this.backgroundMiddleRight=a.addImage(k);this.backgroundBottomRight=
a.addImage(m);this.backgroundTopLeft.linkedControl.style.zIndex="0";this.backgroundTopRight.linkedControl.style.zIndex="0";this.backgroundTopMiddle.linkedControl.style.zIndex="0";this.backgroundMiddleLeft.linkedControl.style.zIndex="0";this.backgroundMiddleRight.linkedControl.style.zIndex="0";this.backgroundMiddleMiddle.linkedControl.style.zIndex="0";this.backgroundBottomLeft.linkedControl.style.zIndex="0";this.backgroundBottomRight.linkedControl.style.zIndex="0";this.backgroundBottomMiddle.linkedControl.style.zIndex=
"0";this.setOpacity(this.defaultAlpha)};
Button.prototype.alignBackground=function(){var a=this.controlRect,b=a.guiScreen,c=b.left*(1-a.getScreenXPercent()),d=b.bottom*(1-a.getScreenYPercent()),e=b.width*a.getScreenWidthPercent(),a=b.height*a.getScreenHeightPercent(),d=d+this.backgroundOffsetY,c=c+this.backgroundOffsetX;if(this.backgroundTopLeft&&this.backgroundTopRight&&this.backgroundTopMiddle&&this.backgroundMiddleLeft&&this.backgroundMiddleRight&&this.backgroundMiddleMiddle&&this.backgroundBottomLeft&&this.backgroundBottomRight&&this.backgroundBottomMiddle){var b=
e-2*this.edgePixelsX,f=a-2*this.edgePixelsY;this.backgroundTopLeft.linkedControl.style.height=this.edgePixelsY+"px";this.backgroundTopMiddle.linkedControl.style.height=this.edgePixelsY+"px";this.backgroundTopRight.linkedControl.style.height=this.edgePixelsY+"px";this.backgroundBottomLeft.linkedControl.style.height=this.edgePixelsY+"px";this.backgroundBottomMiddle.linkedControl.style.height=this.edgePixelsY+"px";this.backgroundBottomRight.linkedControl.style.height=this.edgePixelsY+"px";this.backgroundMiddleLeft.linkedControl.style.height=
f+"px";this.backgroundMiddleMiddle.linkedControl.style.height=f+"px";this.backgroundMiddleRight.linkedControl.style.height=f+"px";this.backgroundTopLeft.linkedControl.style.width=this.edgePixelsX+"px";this.backgroundBottomLeft.linkedControl.style.width=this.edgePixelsX+"px";this.backgroundMiddleLeft.linkedControl.style.width=this.edgePixelsX+"px";this.backgroundTopRight.linkedControl.style.width=this.edgePixelsX+"px";this.backgroundBottomRight.linkedControl.style.width=this.edgePixelsX+"px";this.backgroundMiddleRight.linkedControl.style.width=
this.edgePixelsX+"px";this.backgroundTopMiddle.linkedControl.style.width=b+"px";this.backgroundBottomMiddle.linkedControl.style.width=b+"px";this.backgroundMiddleMiddle.linkedControl.style.width=b+"px";this.backgroundTopLeft.linkedControl.style.left=c+"px";this.backgroundBottomLeft.linkedControl.style.left=c+"px";this.backgroundMiddleLeft.linkedControl.style.left=c+"px";c+=this.edgePixelsX;this.backgroundTopMiddle.linkedControl.style.left=c+"px";this.backgroundBottomMiddle.linkedControl.style.left=
c+"px";this.backgroundMiddleMiddle.linkedControl.style.left=c+"px";c+=b;this.backgroundTopRight.linkedControl.style.left=c+"px";this.backgroundBottomRight.linkedControl.style.left=c+"px";this.backgroundMiddleRight.linkedControl.style.left=c+"px";this.backgroundBottomLeft.linkedControl.style.bottom=d+"px";this.backgroundBottomMiddle.linkedControl.style.bottom=d+"px";this.backgroundBottomRight.linkedControl.style.bottom=d+"px";d+=this.edgePixelsY;this.backgroundMiddleLeft.linkedControl.style.bottom=
d+"px";this.backgroundMiddleRight.linkedControl.style.bottom=d+"px";this.backgroundMiddleMiddle.linkedControl.style.bottom=d+"px";d+=f;this.backgroundTopLeft.linkedControl.style.bottom=d+"px";this.backgroundTopMiddle.linkedControl.style.bottom=d+"px";this.backgroundTopRight.linkedControl.style.bottom=d+"px"}this.backgroundLeft&&this.backgroundRight&&this.backgroundMiddle&&(e-=2*this.edgePixelsX,this.backgroundLeft.linkedControl.style.bottom=d+"px",this.backgroundMiddle.linkedControl.style.bottom=
d+"px",this.backgroundRight.linkedControl.style.bottom=d+"px",this.backgroundLeft.linkedControl.style.height=a+"px",this.backgroundMiddle.linkedControl.style.height=a+"px",this.backgroundRight.linkedControl.style.height=a+"px",this.backgroundLeft.linkedControl.style.width=this.edgePixelsX+"px",this.backgroundMiddle.linkedControl.style.width=e+"px",this.backgroundRight.linkedControl.style.width=this.edgePixelsX+"px",this.backgroundLeft.linkedControl.style.left=c+"px",c+=this.edgePixelsX,this.backgroundMiddle.linkedControl.style.left=
c+"px",this.backgroundRight.linkedControl.style.left=c+e+"px")};
Button.prototype.setOpacity=function(a){this.controlRect.linkedControl.style.opacity=a;this.backgroundLeft&&(this.backgroundLeft.linkedControl.style.opacity=a);this.backgroundRight&&(this.backgroundRight.linkedControl.style.opacity=a);this.backgroundMiddle&&(this.backgroundMiddle.linkedControl.style.opacity=a);this.backgroundTopLeft&&(this.backgroundTopLeft.linkedControl.style.opacity=a);this.backgroundTopRight&&(this.backgroundTopRight.linkedControl.style.opacity=a);this.backgroundTopMiddle&&(this.backgroundTopMiddle.linkedControl.style.opacity=
a);this.backgroundMiddleLeft&&(this.backgroundMiddleLeft.linkedControl.style.opacity=a);this.backgroundMiddleRight&&(this.backgroundMiddleRight.linkedControl.style.opacity=a);this.backgroundMiddleMiddle&&(this.backgroundMiddleMiddle.linkedControl.style.opacity=a);this.backgroundBottomLeft&&(this.backgroundBottomLeft.linkedControl.style.opacity=a);this.backgroundBottomRight&&(this.backgroundBottomRight.linkedControl.style.opacity=a);this.backgroundBottomMiddle&&(this.backgroundBottomMiddle.linkedControl.style.opacity=
a)};
Button.prototype.setBackgroundVisible=function(a){this.backgroundLeft&&this.backgroundLeft.showControl(a);this.backgroundRight&&this.backgroundRight.showControl(a);this.backgroundMiddle&&this.backgroundMiddle.showControl(a);this.backgroundTopLeft&&this.backgroundTopLeft.showControl(a);this.backgroundTopRight&&this.backgroundTopRight.showControl(a);this.backgroundTopMiddle&&this.backgroundTopMiddle.showControl(a);this.backgroundMiddleLeft&&this.backgroundMiddleLeft.showControl(a);this.backgroundMiddleRight&&this.backgroundMiddleRight.showControl(a);
this.backgroundMiddleMiddle&&this.backgroundMiddleMiddle.showControl(a);this.backgroundBottomLeft&&this.backgroundBottomLeft.showControl(a);this.backgroundBottomRight&&this.backgroundBottomRight.showControl(a);this.backgroundBottomMiddle&&this.backgroundBottomMiddle.showControl(a)};Button.prototype.setVisible=function(a){this.controlRect.showControl(a);this.setBackgroundVisible(a)};
Button.prototype.linkControl=function(a){this.controlRect.linkedControl=a;a.onmouseover=function(){this.updateAlphas&&(this.setOpacity(this.focusAlpha),this.controlRect.mouseOver=!0,this.linkedBackground&&this.linkedBackground.setOpacity(this.focusAlpha))}.bind(this);a.onmouseout=function(){this.updateAlphas&&(this.setOpacity(this.defaultAlpha),this.controlRect.mouseOver=!1,this.linkedBackground&&this.linkedBackground.setOpacity(this.defaultAlpha))}.bind(this)};function ByteStream(a){this.bytes=new Uint8Array(a)}ByteStream.prototype.empty=function(){return 0>=this.bytes.length};ByteStream.prototype.readCString=function(){for(var a=this.bytes,b=a.length,c=0;c<b;++c)if(0==a[c])return a=String.fromCharCode.apply(null,this.bytes.subarray(0,c)),this.bytes=this.bytes.subarray(c+1),a;return null};ByteStream.prototype.asString=function(){for(var a="",b=0;b<this.bytes.length;++b)a+=String.fromCharCode(this.bytes[b]);return a};
ByteStream.prototype.readBytes=function(a){var b=this.bytes.subarray(0,a);this.bytes=this.bytes.subarray(a);return b};ByteStream.prototype.readUint32=function(){var a=this.bytes,b=a[0]|a[1]<<8|a[2]<<16|a[3]<<24;this.bytes=a.subarray(4);return b};ByteStream.prototype.readUint8=function(){var a=this.bytes,b=a[0];this.bytes=a.subarray(1);return b};ByteStream.prototype.readUint16=function(){var a=this.bytes,b=a[0]|a[1]<<8;this.bytes=a.subarray(2);return b};
ByteStream.prototype.readFloat32=function(){var a=new Uint8Array(this.bytes),a=new Float32Array(a.buffer);this.bytes=this.bytes.subarray(4);return a[0]};ByteStream.prototype.seekUint32=function(a){a=this.bytes.subarray(4*a);return a[0]|a[1]<<8|a[2]<<16|a[3]<<24};ByteStream.prototype.seekFloat32=function(a){a=new Uint8Array(this.bytes.subarray(4*a));return(new Float32Array(a.buffer))[0]};ByteStream.prototype.getMatrix=function(a){return new Float32Array(this.bytes.buffer,64*a,16)};function ControlRect(a){this.name="none";this.title="frame";this.yPercent=this.xPercent=0;this.heightPercent=this.widthPercent=1;this.debugString="";this.parentControlRect=0;this.childControlRects=[];this.clicked=this.mouseDown=this.mouseOver=!1;this.localMouseYPercent=this.localMouseXPercent=0;this.enabled=this.visible=!0;this.opacity=1;this.guiScreen=a;this.id=this.callBack=this.linkedControl=0}ControlRect.prototype.getScreenWidth=function(){if(this.linkedControl)return this.guiScreen.width*this.getScreenWidthPercent()};
ControlRect.prototype.getScreenHeight=function(){if(this.linkedControl)return this.guiScreen.height*this.getScreenHeightPercent()};
ControlRect.prototype.updateElement=function(){var a=this.linkedControl;if(a){var b=this.guiScreen.left*(1-this.getScreenXPercent()),c=this.guiScreen.bottom*(1-this.getScreenYPercent()),d=this.guiScreen.width*this.getScreenWidthPercent(),e=this.guiScreen.height*this.getScreenHeightPercent();a.style.left=b+"px";a.style.bottom=c+"px";a.style.width=d+"px";a.style.height=e+"px"}};
ControlRect.prototype.updateElement=function(){var a=this.linkedControl;if(a){var b=this.guiScreen.left*(1-this.getScreenXPercent()),c=this.guiScreen.bottom*(1-this.getScreenYPercent()),d=this.guiScreen.width*this.getScreenWidthPercent(),e=this.guiScreen.height*this.getScreenHeightPercent();a.style.left=b+"px";a.style.bottom=c+"px";a.style.width=d+"px";a.style.height=e+"px"}};ControlRect.prototype.updateChildElements=function(){this.updateElement();for(var a=0;a<this.childControlRects.length;a++)this.childControlRects[a].updateChildElements()};
ControlRect.prototype.set=function(a,b,c,d){this.xPercent=a;this.yPercent=b;this.widthPercent=c;this.heightPercent=d};ControlRect.prototype.linkControl=function(a){this.linkedControl=a;a.onmouseover=function(){this.mouseOver=!0}.bind(this);a.onmouseout=function(){this.mouseOver=!1}.bind(this);a.onmousedown=function(){this.mouseDown=!0}.bind(this);a.onmouseup=function(){this.mouseDown=!1}.bind(this);a.onclick=function(){this.callBack&&this.callBack(this);this.clicked=!0}.bind(this)};
ControlRect.prototype.showControl=function(a){this.visible=a;this.linkedControl&&(this.linkedControl.style.display=a?"block":"none")};ControlRect.prototype.setOpacity=function(a){this.opacity=a;this.linkedControl&&(this.linkedControl.style.opacity=a)};ControlRect.prototype.hasChildControlRect=function(a){for(var b=0;b<this.childControlRects.length;b++)if(this.childControlRects[b]==a)return!0;return!1};
ControlRect.prototype.registerChildControlRect=function(a){this.hasChildControlRect(a)||(this.childControlRects.push(a),a.parentControlRect=this)};ControlRect.prototype.getScreenWidthPercent=function(){var a=this.widthPercent;this.parentControlRect&&(a*=this.parentControlRect.getScreenWidthPercent());return a};ControlRect.prototype.getScreenHeightPercent=function(){var a=this.heightPercent;this.parentControlRect&&(a*=this.parentControlRect.getScreenHeightPercent());return a};
ControlRect.prototype.getScreenXPercent=function(){var a=this.xPercent;this.parentControlRect&&(a*=this.parentControlRect.getScreenWidthPercent(),a+=this.parentControlRect.getScreenXPercent());return a};ControlRect.prototype.getScreenYPercent=function(){var a=this.yPercent;this.parentControlRect&&(a*=this.parentControlRect.getScreenHeightPercent(),a+=this.parentControlRect.getScreenYPercent());return a};var prepareEmbedParams=function(a){a=a||{};if(document.location.search)for(var b=document.location.search.substring(1).split("&"),c=0;c<b.length;++c){var d=b[c].split("=");a[d[0]]=d[1]}b=function(a){if(a|0)return!0;for(var c="true True TRUE yes Yes YES".split(" "),b=0;b<c.length;++b)if(a===c[b])return!0;return!1};a.width=a.width||800;a.height=a.height||600;a.autoStart=b(a.autoStart);a.pagePreset=b(a.pagePreset);a.fullFrame=b(a.fullFrame)||b(a.bare);a.fullFrame=!a.pagePreset&&a.fullFrame;return a},
embed=function(a,b){var c;b=prepareEmbedParams(b);var d=b.thumbnailURL;if(b.pagePreset){c=new WebViewer(b.width,b.height,a,!!d);document.body.style.backgroundColor="#d7e4da";var e=document.createElement("div");e.style.position="relative";e.style.backgroundColor="#e4e7e4";e.style.width=b.width+12+"px";e.style.height=b.height+6+16+"px";e.style.margin="auto";e.style.boxShadow="3px 5px 12px 0px grey";document.body.appendChild(e);var f=document.createElement("div");f.style.position="relative";f.style.left=
"6px";f.style.top="6px";e.appendChild(f);f.appendChild(c.domRoot);if(!c.mobile){e.style.resize="both";e.style.overflow="hidden";var g=[e.style.width,e.style.height],h=function(){if(FullScreen.active())e.style.resize="none";else if(e.style.resize="both",g[0]!=e.style.width||g[1]!=e.style.height)g[0]=e.style.width,g[1]=e.style.height,c.resize(e.clientWidth-12,e.clientHeight-6-16);window.setTimeout(h,100)};h()}}else c=new WebViewer(b.fullFrame?window.innerWidth:b.width,b.fullFrame?window.innerHeight:
b.height,a,!!d),document.body.appendChild(c.domRoot),b.fullFrame&&(c.domRoot.style.position="absolute",c.domRoot.style.left=c.domRoot.style.top=0,window.addEventListener("resize",function(){FullScreen.active()||c.resize(window.innerWidth,window.innerHeight)}));c.ui.setThumbnailURL(d);b.autoStart&&c.loadScene();return c},fetchThumbnail=function(a,b,c,d){var e=!1,f=a+(-1==a.indexOf("?")?"?":"&")+"thumb=1",g=function(a){(a=(new Archive(a)).extract("thumbnail.jpg"))?TextureCache.parseFile(a,b,d):e?c&&
c():(e=!0,Network.fetchBinaryIncremental(f,g,c,394240));return 0};Network.fetchBinaryIncremental(f,g,c,65536)},marmoset="undefined"==typeof marmoset?{}:marmoset;marmoset.embed=embed;marmoset.fetchThumbnail=fetchThumbnail;function Fog(a,b){this.desc=b;this.gl=a;this.iblShader=a.shaderCache.fromURLs("fogvert.glsl","fogfrag.glsl",["#define FOG_IBL"]);var c=["#define FOG_DIR"];this.dirShader=a.shaderCache.fromURLs("fogvert.glsl","fogfrag.glsl",c);c.push("#define FOG_SHADOWS");this.dirShaderShadow=a.shaderCache.fromURLs("fogvert.glsl","fogfrag.glsl",c);c=["#define FOG_SPOT"];this.spotShader=a.shaderCache.fromURLs("fogvert.glsl","fogfrag.glsl",c);c.push("#define FOG_SHADOWS");this.spotShaderShadow=a.shaderCache.fromURLs("fogvert.glsl",
"fogfrag.glsl",c);c=["#define FOG_OMNI"];this.omniShaderShadow=this.omniShader=a.shaderCache.fromURLs("fogvert.glsl","fogfrag.glsl",c);this.fullscreenTriangle=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,this.fullscreenTriangle);c=new Float32Array([0,0,2,0,0,2]);a.bufferData(a.ARRAY_BUFFER,c,a.STATIC_DRAW);a.bindBuffer(a.ARRAY_BUFFER,null)}
Fog.prototype.draw=function(a,b){var c=this.gl,d=a.view,e=d.projectionMatrix,f=Matrix.empty();Matrix.mul(f,d.viewMatrix,d.projectionMatrix);Matrix.invert(f,d.viewProjectionMatrix);f=[e[10]+e[11],-e[14],-2*e[11]];e=[-2/e[0],-2/e[5],(1-e[8])/e[0],(1-e[9])/e[5]];c.enable(c.BLEND);c.blendFunc(c.ONE,c.ONE_MINUS_SRC_ALPHA);for(var g=0;g<a.lights.count+1;++g){var h=g-1,k=h<a.lights.shadowCount,l;l=0==g?this.iblShader:0<a.lights.spot[3*h]?k?this.spotShaderShadow:this.spotShader:0<a.lights.getLightPos(h)[3]?
this.omniShader:k?this.dirShaderShadow:this.dirShader;l.bind();var n=l.params;c.uniform3fv(n.uDepthToZ,f);c.uniform4fv(n.uUnproject,e);c.uniformMatrix4fv(n.uInvViewMatrix,!1,d.transform);c.uniform1f(n.uFogInvDistance,1/this.desc.distance);c.uniform1f(n.uFogOpacity,this.desc.opacity*(1-a.stripData.activeFade()));c.uniform1f(n.uFogDispersion,1-this.desc.dispersion);var m=[0,0,0];m[this.desc.type]=1;c.uniform3fv(n.uFogType,m);c.uniform3fv(n.uFogColor,this.desc.color);c.uniform1f(n.uFogIllum,0==g?this.desc.skyIllum:
this.desc.lightIllum);c.uniformMatrix4fv(n.uLightMatrix,!1,a.lights.invMatrix);if(0==g){h=new Float32Array(a.sky.diffuseCoefficients);for(k=4;16>k;++k)h[k]*=1-this.desc.dispersion;for(k=16;36>k;++k)h[k]*=1-this.desc.dispersion*this.desc.dispersion;c.uniform4fv(n.uFogLightSphere,h)}else{var p=a.lights.getLightPos(h),p=Matrix.mul4(Vect.empty(),a.lights.invMatrix,p[0],p[1],p[2],p[3]),m=a.lights.getLightDir(h),m=Matrix.mulVec(Vect.empty(),a.lights.invMatrix,m[0],m[1],m[2]);c.uniform4fv(n.uLightPosition,
p);c.uniform3fv(n.uLightColor,a.lights.getColor(h));var p=0.01745329251*a.lights.spot[3*h],r=Math.cos(0.5*p);c.uniform4fv(n.uSpotParams,[-m[0],-m[1],-m[2],0<p?r*r:0]);c.uniform4fv(n.uLightAttenuation,[a.lights.parameters[3*h+0],a.lights.parameters[3*h+1],a.lights.parameters[3*h+2],r]);k&&(k=Matrix.mul(Matrix.empty(),a.lights.finalTransformBuffer.subarray(16*h),a.lights.matrix),c.uniformMatrix4fv(n.uShadowProj,!1,k),a.shadow.depthTextures[h].bind(l.samplers.uShadowMap),h=0,1<a.postRender.sampleCount&&
(h=a.postRender.currentSample()/a.postRender.sampleCount),c.uniform1f(n.uDitherOffset,h),c.uniform3fv(n.uAABBMin,a.bounds.min),c.uniform3fv(n.uAABBMax,a.bounds.max),h=Vect.lerp(Vect.empty(),a.bounds.min,a.bounds.max,0.5),k=Vect.distance(h,a.bounds.min),c.uniform4f(n.uCylinder,h[0],h[1],h[2],k*k))}b.bind(l.samplers.tDepth);l=l.attribs.vCoord;c.bindBuffer(c.ARRAY_BUFFER,this.fullscreenTriangle);c.enableVertexAttribArray(l);c.vertexAttribPointer(l,2,c.FLOAT,!1,0,0);c.drawArrays(c.TRIANGLES,0,3);c.disableVertexAttribArray(l);
c.bindBuffer(c.ARRAY_BUFFER,null)}c.disable(c.BLEND)};Fog.prototype.complete=function(){return this.iblShader.complete()&&this.dirShader.complete()&&this.dirShaderShadow.complete()&&this.spotShader.complete()&&this.spotShaderShadow.complete()&&this.omniShader.complete()&&this.omniShaderShadow.complete()};function Framebuffer(a,b){this.gl=a;this.fbo=a.createFramebuffer();a.bindFramebuffer(a.FRAMEBUFFER,this.fbo);b&&(this.width=b.width,this.height=b.height,b.color0&&(this.color0=b.color0,a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,this.color0.id,0),this.width=b.color0.desc.width,this.height=b.color0.desc.height),b.depth?(this.depth=b.depth,a.framebufferTexture2D(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.TEXTURE_2D,this.depth.id,0)):(this.depthBuffer=b.depthBuffer,b.createDepth&&!this.depthBuffer&&
(this.depthBuffer=Framebuffer.createDepthBuffer(a,this.width,this.height)),this.depthBuffer&&(a.bindRenderbuffer(a.RENDERBUFFER,this.depthBuffer),a.framebufferRenderbuffer(a.FRAMEBUFFER,a.DEPTH_ATTACHMENT,a.RENDERBUFFER,this.depthBuffer),a.bindRenderbuffer(a.RENDERBUFFER,null))));this.valid=b&&b.ignoreStatus||a.checkFramebufferStatus(a.FRAMEBUFFER)==a.FRAMEBUFFER_COMPLETE;a.bindFramebuffer(a.FRAMEBUFFER,null)}
Framebuffer.createDepthBuffer=function(a,b,c){var d=a.createRenderbuffer();a.bindRenderbuffer(a.RENDERBUFFER,d);a.renderbufferStorage(a.RENDERBUFFER,a.DEPTH_COMPONENT16,b,c);a.bindRenderbuffer(a.RENDERBUFFER,null);return d};Framebuffer.prototype.bind=function(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,this.fbo);this.gl.viewport(0,0,this.width,this.height)};Framebuffer.bindNone=function(a){a.bindFramebuffer(a.FRAMEBUFFER,null)};var FullScreen={support:function(){return!!(document.fullscreenEnabled||document.webkitFullscreenEnabled||document.mozFullScreenEnabled||document.msFullscreenEnabled)},begin:function(a,b){var c=a.requestFullscreen||a.webkitRequestFullScreen||a.mozRequestFullScreen||a.msRequestFullscreen;if(c){var d=function(){FullScreen.active()||(document.removeEventListener("fullscreenchange",d),document.removeEventListener("webkitfullscreenchange",d),document.removeEventListener("mozfullscreenchange",d),document.removeEventListener("MSFullscreenChange",
d));b&&b()};document.addEventListener("fullscreenchange",d);document.addEventListener("webkitfullscreenchange",d);document.addEventListener("mozfullscreenchange",d);document.addEventListener("MSFullscreenChange",d);c.bind(a)()}},end:function(){var a=document.exitFullscreen||document.webkitExitFullscreen||document.mozCancelFullScreen||document.msExitFullscreen;a&&a.bind(document)()},active:function(){return!!(document.fullscreenElement||document.webkitIsFullScreen||document.mozFullScreenElement||document.msFullscreenElement)}};function GUIManager(a){this.init=!1;this.ui=a;this.bottom=this.left=this.height=this.width=0;this.clicked=this.mouseDown=!1;this.playbackControls=0;a=1;window.devicePixelRatio&&(2<window.devicePixelRatio?a=4:1<window.devicePixelRatio&&(a=2));this.imageSetNumber=a}GUIManager.prototype.setSize=function(a,b){this.width=a;this.height=b;this.left=-a;this.bottom=-b;this.playbackControls&&this.playbackControls.resize(this)};
GUIManager.prototype.setupActiveView=function(a){this.init||(this.init=!0,this.ui=a,a.viewer.scene.sceneAnimator&&(this.playbackControls=new PlaybackControls(this),this.playbackControls.resize(this)))};
GUIManager.prototype.updateElement=function(a){var b=a.linkedControl;if(b){var c=this.left*(1-a.getScreenXPercent()),d=this.bottom*(1-a.getScreenYPercent()),e=this.width*a.getScreenWidthPercent();a=this.height*a.getScreenHeightPercent();b.style.left=c+"px";b.style.bottom=d+"px";b.style.width=e+"px";b.style.height=a+"px"}};function GUIRegion(a){this.debugString="GUIRegion";this.name="Default";this.controlRect=new ControlRect(a);this.yPercent=this.xPercent=0;this.heightPercent=this.widthPercent=1;this.guiScreen=a}
GUIRegion.prototype.addImageElement=function(a,b){var c=this.guiScreen.ui.menuCluster.contents,d=document.createElement("input");a.linkControl(d);this.guiScreen.updateElement(a);d.type="image";d.src=marmoset.dataLocale+b;d.style.position="absolute";d.style.border="none";d.style.outline="0px";d.style.zIndex="1";d.title=b;d.style.opacity=a.opacity;var e=new XMLHttpRequest;e.open("HEAD",d.src,!0);e.onload=function(a){a.appendChild(this)}.bind(d,c);e.send();return d};
GUIRegion.prototype.addImage=function(a){var b=new ControlRect(this.guiScreen);this.addImageElement(b,a);return b};
GUIRegion.prototype.addTextButton=function(a,b,c,d,e,f){var g=new Button(this.guiScreen);g.name="none";g.text=a;g.controlRect.set(b,c,d,e);g.controlRect.opacity=f;this.controlRect.registerChildControlRect(g.controlRect);b=this.guiScreen.ui.menuCluster.contents;c=document.createElement("text");c.style.color="white";c.style.fontFamily="Arial";c.style.fontSize=marmoset.largeUI?"14px":"12px";c.style.textShadow="2px 2px 3px #000000";b.appendChild(c);g.controlRect.linkControl(c);this.guiScreen.updateElement(g.controlRect);
c.type="text";c.name="text";c.style.position="absolute";c.style.border="none";c.style.outline="0px";c.style.zIndex="2";c.innerHTML=a;c.style.opacity=g.controlRect.opacity;g.linkControl(c);return g};function GUIScreen(a){this.init=!1;this.ui=a;this.bottom=this.left=this.height=this.width=0;this.clicked=this.mouseDown=!1;this.playbackControls=0;a=1;window.devicePixelRatio&&(2<window.devicePixelRatio?a=4:1<window.devicePixelRatio&&(a=2));this.imageSetNumber=a}GUIScreen.prototype.setSize=function(a,b){this.width=a;this.height=b;this.left=-a;this.bottom=-b;this.playbackControls&&this.playbackControls.resize(this)};
GUIScreen.prototype.setupActiveView=function(a){this.init||(this.init=!0,this.ui=a,a.viewer.scene.sceneAnimator&&(this.playbackControls=new PlaybackControls(this),this.playbackControls.resize(this)))};
GUIScreen.prototype.updateElement=function(a){var b=a.linkedControl;if(b){var c=this.left*(1-a.getScreenXPercent()),d=this.bottom*(1-a.getScreenYPercent()),e=this.width*a.getScreenWidthPercent();a=this.height*a.getScreenHeightPercent();b.style.left=c+"px";b.style.bottom=d+"px";b.style.width=e+"px";b.style.height=a+"px"}};function Input(a){this.onTap=[];this.onSingleTap=[];this.onDoubleTap=[];this.onDrag=[];this.onZoom=[];this.onPan=[];this.onPan2=[];this.onAnything=[];this.mouseDownCount=0;this.macHax=0<=navigator.platform.toUpperCase().indexOf("MAC");a&&this.attach(a)}
Input.prototype.attach=function(a){this.element=a;var b=function(a){for(var b=0;b<this.onAnything.length;++b)this.onAnything[b]();a.preventDefault()}.bind(this);this.mouseStates=[{pressed:!1,position:[0,0],downPosition:[0,0]},{pressed:!1,position:[0,0],downPosition:[0,0]},{pressed:!1,position:[0,0],downPosition:[0,0]}];this.lastTapPos=[0,0];a=function(a){if(a.target===this.element){this.mouseDownCount++;var d=this.mouseStates[a.button];if(d){d.pressed=!0;var e=this.element.getBoundingClientRect();
d.position[0]=d.downPosition[0]=a.clientX-e.left;d.position[1]=d.downPosition[1]=a.clientY-e.top;b(a)}}}.bind(this);this.element.addEventListener("mousedown",a);a=function(a){var d=this.mouseStates[a.button];if(d){var e=this.element.getBoundingClientRect(),f=a.clientX-e.left,e=a.clientY-e.top;d.pressed=!1;d.position[0]=f;d.position[1]=e;if(0==a.button&&a.target==this.element&&10>Math.abs(d.position[0]-d.downPosition[0])+Math.abs(d.position[1]-d.downPosition[1])){for(var g=0;g<this.onTap.length;++g)this.onTap[g](f,
e);this.needSingleClick=!0;window.setTimeout(function(a,c){if(this.needSingleClick){for(var b=0;b<this.onSingleTap.length;++b)this.onSingleTap[b](a,c);this.needSingleClick=!1}}.bind(this,f,e),301);d=!1;if(void 0!==this.doubleClickTimer&&(g=8>Math.abs(f-this.lastTapPos[0])+Math.abs(e-this.lastTapPos[1]),300>Date.now()-this.doubleClickTimer&&g))for(d=!0,this.needSingleClick=!1,g=0;g<this.onDoubleTap.length;++g)this.onDoubleTap[g](f,e);this.doubleClickTimer=Date.now();d&&(this.doubleClickTimer=-1E9);
this.lastTapPos[0]=f;this.lastTapPos[1]=e}}b(a)}.bind(this);this.element.addEventListener("mouseup",a);a=function(a){for(var d=!1,e=this.element.getBoundingClientRect(),f=0;3>f;++f){var g=this.mouseStates[f];if(g.pressed){var d=a.clientX-e.left,h=a.clientY-e.top,k=d-g.position[0],l=h-g.position[1];g.position[0]=d;g.position[1]=h;if(2==f&&a.altKey)for(g=0;g<this.onZoom.length;++g)this.onZoom[g](2*l);else if(1<=f||a.ctrlKey)for(g=0;g<this.onPan.length;++g)this.onPan[g](k,l);else if(0==f)if(a.shiftKey)for(g=
0;g<this.onPan2.length;++g)this.onPan2[g](k,l);else for(g=0;g<this.onDrag.length;++g)this.onDrag[g](d,h,k,l);d=!0}}d&&b(a)}.bind(this);this.element.addEventListener("mousemove",a);a=function(a){var d=0;a.deltaY?(d=-0.4*a.deltaY,1==a.deltaMode?d*=16:2==a.deltaMode&&(d*=this.element.clientHeight)):a.wheelDelta?d=this.macHax&&120==Math.abs(a.wheelDelta)?0.08*a.wheelDelta:0.4*a.wheelDelta:a.detail&&(d=-10*a.detail);for(var e=0;e<this.onZoom.length;++e)this.onZoom[e](d);b(a)}.bind(this);this.element.addEventListener("mousewheel",
a);this.element.addEventListener("DOMMouseScroll",a);this.element.addEventListener("wheel",a);a=function(a){for(var b=0;b<this.mouseStates.length;++b)this.mouseStates[b].pressed=!1;a.preventDefault()}.bind(this);this.element.addEventListener("mouseleave",a);this.element.addEventListener("contextmenu",function(a){a.preventDefault()});this.touches={};this.tapPossible=!1;this.touchCountFloor=0;a=function(a){for(var d=this.element.getBoundingClientRect(),e=!1,f=0;f<a.changedTouches.length;++f)if(a.target===
this.element){var g=a.changedTouches[f],e={x:g.clientX-d.left,y:g.clientY-d.top};e.startX=e.x;e.startY=e.y;this.touches[g.identifier]=e;e=!0}this.tapPossible=1==a.touches.length;for(g=d=0;g<this.touches.length;++g)d++;d>this.touchCountFloor&&(this.touchCountFloor=d);e&&b(a)}.bind(this);this.element.addEventListener("touchstart",a);a=function(a){for(var d=!1,e=0;e<a.changedTouches.length;++e){var f=a.changedTouches[e],g=this.touches[f.identifier];if(g){if(this.tapPossible){var h=this.element.getBoundingClientRect(),
d=f.clientX-h.left,h=f.clientY-h.top;if(24>Math.max(Math.abs(d-g.startX),Math.abs(h-g.startY))){for(e=0;e<this.onTap.length;++e)this.onTap[e](d,h);this.needSingleTap=!0;window.setTimeout(function(a,b){if(this.needSingleTap){for(var c=0;c<this.onSingleTap.length;++c)this.onSingleTap[c](a,b);this.needSingleTap=!1}}.bind(this,d,h),501);g=!1;if(void 0!==this.doubleTapTimer){var k=24>Math.max(Math.abs(d-this.lastTapPos[0]),Math.abs(h-this.lastTapPos[1])),l=500>Date.now()-this.doubleTapTimer;if(k&&l)for(g=
!0,e=0;e<this.onDoubleTap.length;++e)this.onDoubleTap[e](d,h)}this.doubleTapTimer=Date.now();g&&(this.doubleTapTimer=-1E9);this.lastTapPos[0]=d;this.lastTapPos[1]=h}this.tapPossible=!1}delete this.touches[f.identifier];d=!0}}for(f=e=0;f<this.touches.length;++f)e++;0>=e&&(this.touchCountFloor=0);d&&b(a)}.bind(this);this.element.addEventListener("touchend",a);this.element.addEventListener("touchcancel",a);this.element.addEventListener("touchleave",a);a=function(a){for(var d=[],e=0;e<a.touches.length;++e)a.touches[e].target===
this.element&&d.push(a.touches[e]);var f=this.element.getBoundingClientRect();if(1==d.length&&1>=this.touchCountFloor){var g=d[0],h=this.touches[g.identifier];if(h){var k=g.clientX-f.left,g=g.clientY-f.top,f=k-h.x,l=g-h.y;h.x=k;h.y=g;for(e=0;e<this.onDrag.length;++e)this.onDrag[e](k,g,f,l,a.shiftKey)}}else if(2==d.length&&2>=this.touchCountFloor){if(l=d[0],e=this.touches[l.identifier],g=d[1],h=this.touches[g.identifier],e&&h){var k=l.clientX-f.left,l=l.clientY-f.top,n=g.clientX-f.left,m=g.clientY-
f.top,p=Math.sqrt((k-n)*(k-n)+(l-m)*(l-m)),r=Math.sqrt((e.x-h.x)*(e.x-h.x)+(e.y-h.y)*(e.y-h.y)),s=Math.abs(p-r),f=(k-e.x+n-h.x)/2,g=(l-e.y+m-h.y)/2,u=Math.sqrt(f*f+g*g);e.x=k;e.y=l;h.x=n;h.y=m;if(0<s)for(h=s/(s+u),e=0;e<this.onZoom.length;++e)this.onZoom[e](2*(p-r)*h);if(0<u)for(h=u/(s+u),e=0;e<this.onDrag.length;++e)this.onPan[e](f*h,g*h)}}else if(3<=d.length){for(e=r=p=n=l=0;e<d.length;++e)g=d[e],h=this.touches[g.identifier],k=g.clientX-f.left,g=g.clientY-f.top,p+=k,r+=g,h&&(l+=h.x,n+=h.y,h.x=k,
h.y=g);l/=d.length;n/=d.length;p/=d.length;r/=d.length;for(e=0;e<this.onPan2.length;++e)this.onPan2[e](p-l,r-n)}0<d.length&&b(a)}.bind(this);this.element.addEventListener("touchmove",a)};function KeyFrame(a,b){a&&b?(this.frameIndex=b.frameIndex,this.value=b.value,this.interpolation=b.interpolation,this.weighIn=b.weighIn,this.weighOut=b.weighOut):(this.interpolation=this.value=this.frameIndex=0,this.weighOut=this.weighIn=1)};function Lights(a,b){this.rotation=this.shadowCount=this.count=0;this.positions=[];this.directions=[];this.matrixWeights=[];this.matrix=Matrix.identity();this.invMatrix=Matrix.identity();this.defaultmatrix=Matrix.identity();this.defaultviewmatrix=Matrix.identity();for(var c in a)this[c]=a[c];this.count=this.positions.length/4;this.count=Math.min(6,this.count);this.shadowCount=Math.min(3,this.shadowCount);this.positions=new Float32Array(this.positions);this.positionBuffer=new Float32Array(this.positions);
this.directions=new Float32Array(this.directions);this.directionBuffer=new Float32Array(this.directions);this.colors=new Float32Array(this.colors);this.colorsBuffer=new Float32Array(this.colors);this.modelViewBuffer=new Float32Array(16*this.shadowCount);this.projectionBuffer=new Float32Array(16*this.shadowCount);this.finalTransformBuffer=new Float32Array(16*this.shadowCount);this.inverseTransformBuffer=new Float32Array(16*this.shadowCount);this.shadowTexelPadProjections=new Float32Array(4*this.shadowCount);
this.shadowsNeedUpdate=new Uint8Array(this.shadowCount);for(var d=0;d<this.shadowsNeedUpdate.length;++d)this.shadowsNeedUpdate[d]=1;Matrix.rotation(this.matrix,this.rotation,1);Matrix.transpose(this.invMatrix,this.matrix);Matrix.copy(this.defaultmatrix,this.matrix);Matrix.copy(this.defaultviewmatrix,b.viewMatrix);for(d=0;d<this.count;++d){c=this.positions.subarray(4*d,4*d+4);var e=this.directions.subarray(3*d,3*d+3);1==this.matrixWeights[d]?(Matrix.mul4(c,this.matrix,c[0],c[1],c[2],c[3]),Matrix.mulVec(e,
this.matrix,e[0],e[1],e[2])):2==this.matrixWeights[d]&&(Matrix.mul4(c,b.viewMatrix,c[0],c[1],c[2],c[3]),Matrix.mulVec(e,b.viewMatrix,e[0],e[1],e[2]))}}Lights.prototype.getLightPos=function(a){return this.positionBuffer.subarray(4*a,4*a+4)};Lights.prototype.setLightDistance=function(a,b){0>=b&&(b=1E-5);this.parameters[3*a+2]=1/b};Lights.prototype.setLightSpotAngle=function(a,b){0>=b&&(b=1E-6);this.spot[3*a]=b;var c=Math.sin(3.1415926/180*b/2);this.spot[3*a+2]=1/(c*c)*this.spot[3*a+1]};
Lights.prototype.setLightSpotSharpness=function(a,b){this.spot[3*a+1]=b;this.setLightSpotAngle(this.spot[3*a])};Lights.prototype.setLightPos=function(a,b){this.positions[4*a+0]=b[0];this.positions[4*a+1]=b[1];this.positions[4*a+2]=b[2];var c=this.positions.subarray(4*a,4*a+4);1==this.matrixWeights[a]?Matrix.mul4(c,this.defaultmatrix,b[0],b[1],b[2],c[3]):2==this.matrixWeights[a]&&Matrix.mul4(c,this.defaultviewmatrix,b[0],b[1],b[2],c[3])};
Lights.prototype.setLightDir=function(a,b){this.directions[3*a+0]=b[0];this.directions[3*a+1]=b[1];this.directions[3*a+2]=b[2];var c=this.directions.subarray(3*a,3*a+3);1==this.matrixWeights[a]?Matrix.mulVec(c,this.defaultmatrix,b[0],b[1],b[2]):2==this.matrixWeights[a]&&Matrix.mulVec(c,this.defaultviewmatrix,b[0],b[1],b[2])};Lights.prototype.getLightColor=function(a){return this.colors.subarray(3*a,3*a+3)};
Lights.prototype.setLightColor=function(a,b){this.colors[3*a+0]=b[0];this.colors[3*a+1]=b[1];this.colors[3*a+2]=b[2]};Lights.prototype.getLightDir=function(a){return this.directionBuffer.subarray(3*a,3*a+3)};Lights.prototype.getColor=function(a){a*=3;return[this.colors[a],this.colors[a+1],this.colors[a+2]]};
Lights.prototype.update=function(a,b){var c=new Matrix.type(this.matrix);Matrix.rotation(this.matrix,this.rotation,1);Matrix.transpose(this.invMatrix,this.matrix);for(var d=0;d<this.count;++d){var e=this.positions.subarray(4*d,4*d+4),f=this.directions.subarray(3*d,3*d+3),g=this.getLightPos(d),h=this.getLightDir(d);1==this.matrixWeights[d]?(g[0]=e[0],g[1]=e[1],g[2]=e[2],g[3]=e[3],h[0]=f[0],h[1]=f[1],h[2]=f[2]):2==this.matrixWeights[d]?(Matrix.mul4(g,a.transform,e[0],e[1],e[2],e[3]),Matrix.mulVec(h,
a.transform,f[0],f[1],f[2]),Matrix.mul4(g,this.matrix,g[0],g[1],g[2],g[3]),Matrix.mulVec(h,this.matrix,h[0],h[1],h[2])):(Matrix.mul4(g,this.matrix,e[0],e[1],e[2],e[3]),Matrix.mulVec(h,this.matrix,f[0],f[1],f[2]));Vect.normalize(h,h)}for(var f=new Float32Array(this.finalTransformBuffer),g=Matrix.empty(),h=Matrix.empty(),k=Matrix.empty(),l=Vect.empty(),n=Vect.empty(),m=Vect.empty(),p=Vect.empty(),e=Vect.empty(),r=[],s=[],u=Matrix.create(0.5,0,0,0.5,0,0.5,0,0.5,0,0,0.5,0.5,0,0,0,1),d=0;d<this.count;++d){l=
this.getLightPos(d);n=this.getLightDir(d);0.99<Math.abs(n[1])?Vect.set(m,1,0,0):Vect.set(m,0,1,0);Vect.cross(p,m,n);Vect.normalize(p,p);Vect.cross(m,n,p);Vect.normalize(m,m);Matrix.set(g,p[0],p[1],p[2],-Vect.dot(p,l),m[0],m[1],m[2],-Vect.dot(m,l),n[0],n[1],n[2],-Vect.dot(n,l),0,0,0,1);for(l=0;8>l;++l)e[0]=l&1?b.max[0]:b.min[0],e[1]=l&2?b.max[1]:b.min[1],e[2]=l&4?b.max[2]:b.min[2],Matrix.mulPoint(e,this.matrix,1.005*e[0],1.005*e[1],1.005*e[2]),Matrix.mulPoint(e,g,e[0],e[1],e[2]),0==l?(r[0]=s[0]=e[0],
r[1]=s[1]=e[1],r[2]=s[2]=e[2]):(r[0]=Math.min(r[0],e[0]),r[1]=Math.min(r[1],e[1]),r[2]=Math.min(r[2],e[2]),s[0]=Math.max(s[0],e[0]),s[1]=Math.max(s[1],e[1]),s[2]=Math.max(s[2],e[2]));var l=-r[2],n=-s[2],q=this.spot[3*d];0<q?(l=Math.min(l,1/this.parameters[3*d+2]),n=Math.max(0.04*l,n),Matrix.perspective(h,q,1,n,l),d<this.shadowCount&&(l=2*-Math.tan(0.00872664625*q),this.shadowTexelPadProjections[4*d+0]=this.modelViewBuffer[16*d+2]*l,this.shadowTexelPadProjections[4*d+1]=this.modelViewBuffer[16*d+6]*
l,this.shadowTexelPadProjections[4*d+2]=this.modelViewBuffer[16*d+10]*l,this.shadowTexelPadProjections[4*d+3]=this.modelViewBuffer[16*d+14]*l)):(Matrix.ortho(h,r[0],s[0],r[1],s[1],n,l),d<this.shadowCount&&(this.shadowTexelPadProjections[4*d+0]=this.shadowTexelPadProjections[4*d+1]=this.shadowTexelPadProjections[4*d+2]=0,this.shadowTexelPadProjections[4*d+3]=Math.max(s[0]-r[0],s[1]-r[1])));Matrix.mul(k,h,g);Matrix.mul(k,u,k);Matrix.copyToBuffer(this.modelViewBuffer,16*d,g);Matrix.copyToBuffer(this.projectionBuffer,
16*d,h);Matrix.copyToBuffer(this.finalTransformBuffer,16*d,k);Matrix.invert(k,k);Matrix.copyToBuffer(this.inverseTransformBuffer,16*d,k)}e=!1;for(d=0;d<c.length;++d)if(c[d]!=this.matrix[d]){e=!0;break}for(d=0;d<this.shadowCount;d++)if(e&&1==this.matrixWeights[d])this.shadowsNeedUpdate[d]=1;else for(c=16*d;c<16*d+16;++c)if(f[c]!=this.finalTransformBuffer[c]){this.shadowsNeedUpdate[d]=1;break}};
Lights.prototype.flagUpdateAnimatedLighting=function(){for(var a=0;a<this.shadowCount;a++)this.shadowsNeedUpdate[a]=1};function ListBox(a){this.name="none";this.text="default text";this.title="none";this.debugString=this.imagePath="";this.controlRect=new ControlRect(a);this.textEntries=[];this.textOffsetsX=[];this.textOffsetsY=[];this.buttons=[];this.listBoxEntryHeight=20;this.selectedItemText="";this.selectedIndex=-1;this.localPixelsY=0;this.localPixelsX=100;this.labelPixelDrop=0;this.labelPixelInset=10;this.labelTextHeight=16;this.closed=!1;this.defaultButtonText=this.spacerMiddle=this.spacerRight=this.spacerLeft=
this.spacerControl=0;this.listBoxButtons=[];this.listBoxRegion=new GUIRegion(a);this.guiScreen=a;this.lastMouseOverIndex=-1;this.selectionChangedCallback=0;this.debugString=""}ListBox.prototype.linkControl=function(a){this.controlRect.linkControl(a)};
ListBox.prototype.spawnControl=function(a,b,c,d,e,f){var g=this.guiScreen.imageSetNumber,h="backgroundTopLE"+g+"x.png",k="backgroundTopM"+g+"x.png",l="backgroundTopRE"+g+"x.png",n="backgroundMiddleLE"+g+"x.png",m="backgroundMiddleM"+g+"x.png",p="backgroundMiddleRE"+g+"x.png",r="backgroundBottomLE"+g+"x.png",s="backgroundBottomM"+g+"x.png",u="backgroundBottomRE"+g+"x.png",q=3*g,x="backgroundLE"+g+"x.png",w="backgroundM"+g+"x.png",v="backgroundRE"+g+"x.png",t=2*g,y="spacerLE"+g+"x.png",E="spacerM"+
g+"x.png",F="spacerRE"+g+"x.png",g=2*g,A=this.controlRect.guiScreen.width,B=this.controlRect.guiScreen.height;if(e){e=this.textEntries.length;var z=c;for(c=0;c<e;c++){var C=8*(this.textEntries[c]?this.textEntries[c].length:0);z<C&&(z=C)}c=z+f}e=this.textEntries.length+1;f=1/e;this.localPixelsX=c;this.listBoxEntryHeight=d;this.localPixelsY=(this.textEntries.length+1)*this.listBoxEntryHeight;c=8/this.localPixelsY;d=6/this.localPixelsX;z=4/this.localPixelsX;C=f-c/4;this.labelTextHeight=marmoset.largeUI?
20:16;this.labelPixelDrop=(this.listBoxEntryHeight-this.labelTextHeight)/2;this.listBoxRegion.controlRect.widthPercent=this.localPixelsX/A;this.listBoxRegion.controlRect.heightPercent=this.localPixelsY/B;this.listBoxRegion.controlRect.xPercent=a/A;this.listBoxRegion.controlRect.yPercent=b/B;this.openBackground=this.listBoxRegion.addTextButton("",0,0,1,1+c,1);this.openBackground.setBackground3x3(this.listBoxRegion,0,0,h,k,l,n,m,p,r,s,u,q,q);this.closedBackground=this.listBoxRegion.addTextButton("",
0,0,1,f,1);this.closedBackground.setBackground3x1(this.listBoxRegion,0,0,x,w,v,t);a=this.labelPixelInset+this.textOffsetsX[0];b=this.labelPixelDrop+this.textOffsetsY[0];b/=this.localPixelsY;a/=this.localPixelsX;this.defaultButton=this.listBoxRegion.addTextButton("Selected",a,-b,1,f,0.5);this.selectedIndex=0;this.defaultButton.controlRect.linkedControl.innerHTML=this.textEntries[this.selectedIndex];this.defaultButton.linkedBackground=this.closedBackground;this.spacerControl=this.listBoxRegion.addTextButton("",
d,C,1-(d+z),c,1);this.spacerControl.defaultAlpha=1;this.spacerControl.setBackground3x1(this.listBoxRegion,0,0,y,E,F,g);this.spacerControl.setVisible(!1);this.spacerControl.linkedBackground=this.openBackground;for(c=1;c<e;c++)a=this.labelPixelInset+this.textOffsetsX[c-1],b=this.labelPixelDrop+this.textOffsetsY[c-1]-4,a/=this.localPixelsX,b/=this.localPixelsY,y=this.listBoxRegion.addTextButton(this.textEntries[c-1],a,f*c-b,1-a,f,0.5),this.listBoxButtons.push(y),y.linkedBackground=this.openBackground;
this.showList(!1);this.setupCallbacks()};
ListBox.prototype.setControl=function(a,b,c,d,e,f){var g=this.controlRect.guiScreen.width,h=this.controlRect.guiScreen.height;if(e){e=this.textEntries.length;for(var k=0;k<e;k++){var l=8*(this.textEntries[k]?this.textEntries[k].length:0);c<l&&(c=l)}c+=f}this.localPixelsX=c;this.listBoxEntryHeight=d;this.localPixelsY=(this.textEntries.length+1)*this.listBoxEntryHeight;this.listBoxRegion.controlRect.widthPercent=this.localPixelsX/g;this.listBoxRegion.controlRect.heightPercent=this.localPixelsY/h;this.listBoxRegion.controlRect.xPercent=
a/g;this.listBoxRegion.controlRect.yPercent=b/h;this.listBoxRegion.controlRect.updateChildElements();this.spacerControl.alignBackground();this.openBackground.alignBackground();this.closedBackground.alignBackground()};ListBox.prototype.addItem=function(a,b,c){this.textEntries.push(a);this.textOffsetsX.push(b);this.textOffsetsY.push(c)};
ListBox.prototype.showList=function(a){for(var b=this.listBoxButtons.length,c=0;c<b;c++)this.listBoxButtons[c].setVisible(a);this.closed=!a;this.spacerControl&&this.spacerControl.setVisible(a);this.openBackground&&this.openBackground.setVisible(a);this.closedBackground&&this.closedBackground.setVisible(!a);a?(this.defaultButton.linkedBackground=this.openBackground,this.openBackground.setOpacity(1),this.closedBackground.setOpacity(0.5)):this.defaultButton.linkedBackground=this.closedBackground};
ListBox.prototype.selectItem=function(a){this.selectedItemText=this.textEntries[a];this.selectedIndex=a;this.defaultButton.controlRect.linkedControl.innerHTML=this.textEntries[this.selectedIndex];a=(this.labelTextHeight-this.listBoxEntryHeight+3)/this.localPixelsY;this.defaultButton.controlRect.xPercent=(this.labelPixelInset+this.textOffsetsX[this.selectedIndex])/this.localPixelsX;this.defaultButton.controlRect.yPercent=a;this.defaultButton.controlRect.updateElement()};
ListBox.prototype.setupCallbacks=function(){var a=function(a){if(this.closed){var b=this.closedBackground.controlRect.linkedControl,b=b.getBoundingClientRect(),c=a.clientX-b.left;a=a.clientY-b.top;c/=b.width;b=a/b.height;0<=c&&1>=c&&0<=b&&1>=b?this.closedBackground.setOpacity(1):this.closedBackground.setOpacity(0.5)}else b=this.openBackground.controlRect.linkedControl,b=b.getBoundingClientRect(),c=a.clientX-b.left,a=a.clientY-b.top,c/=b.width,b=a/b.height,0<=c&&1>=c&&0<=b&&1>=b?this.openBackground.setOpacity(1):
this.openBackground.setOpacity(0.5)}.bind(this);this.defaultButton.controlRect.linkedControl.onclick=function(){this.closed?this.showList(!0):(this.showList(this.closed),this.closedBackground.setOpacity(1),this.defaultButton.setOpacity(1))}.bind(this);for(var b=function(a){this.selectItem(a.id);this.showList(!1);this.defaultButton.setOpacity(0.5);this.selectionChangedCallback&&this.selectionChangedCallback(this)}.bind(this),c=function(a){a=this.listBoxButtons.length;for(var b=0;b<a;b++)this.listBoxButtons[b].controlRect.mouseOver&&
(this.selectItem(b),b=a,this.selectionChangedCallback&&this.selectionChangedCallback(this));this.showList(!1)}.bind(this),d=this.listBoxButtons.length,e=0;e<d;e++)this.listBoxButtons[e].controlRect.callBack=b,this.listBoxButtons[e].controlRect.id=e,this.listBoxButtons[e].controlRect.linkedControl.addEventListener("mousemove",a);this.guiScreen.ui.viewer.input.element.addEventListener("mousemove",a);this.openBackground.controlRect.linkedControl.addEventListener("mousemove",a);this.closedBackground.controlRect.linkedControl.addEventListener("mousemove",
a);this.guiScreen.ui.viewer.input.element.addEventListener("mousedown",c)};function Material(a,b,c){this.gl=a;this.name=c.name;var d={mipmap:!0,aniso:a.hints.mobile?0:4,clamp:!!c.textureWrapClamp,mirror:!!c.textureWrapMirror},e={mipmap:d.mipmap,clamp:d.clamp,mirror:d.mirror,nofilter:c.textureFilterNearest||!1};e.nofilter||(e.aniso=a.hints.mobile?2:4);this.textures={albedo:a.textureCache.fromFilesMergeAlpha(b.get(c.albedoTex),b.get(c.alphaTex),e),reflectivity:a.textureCache.fromFilesMergeAlpha(b.get(c.reflectivityTex),b.get(c.glossTex),d),normal:a.textureCache.fromFile(b.get(c.normalTex),
d),extras:a.textureCache.fromFilesMergeAlpha(b.get(c.extrasTex),b.get(c.extrasTexA),d)};this.extrasTexCoordRanges={};if(c.extrasTexCoordRanges)for(var f in c.extrasTexCoordRanges)this.extrasTexCoordRanges[f]=new Float32Array(c.extrasTexCoordRanges[f].scaleBias);this.textures.extras||(b=new Texture(a,{width:1,height:1}),b.loadArray(new Uint8Array([255,255,255,255])),this.textures.extras=b);var g=c.blendTint||[1,1,1];b={none:function(){a.disable(a.BLEND)},alpha:function(){a.enable(a.BLEND);a.blendFuncSeparate(a.SRC_ALPHA,
a.ONE_MINUS_SRC_ALPHA,a.ONE_MINUS_DST_ALPHA,a.ONE)},add:function(){a.enable(a.BLEND);a.blendColor(g[0],g[1],g[2],1);a.blendFunc(a.ONE,a.CONSTANT_COLOR)}};this.blend=b[c.blend]||b.none;this.alphaTest=c.alphaTest||0;this.usesBlending=this.blend!==b.none;this.usesRefraction=!!c.refraction;this.shadowAlphaTest=this.alphaTest;0>=this.shadowAlphaTest&&this.blend===b.alpha&&(this.shadowAlphaTest=0.5);this.castShadows=this.blend!==b.add;this.horizonOcclude=c.horizonOcclude||0;this.fresnel=new Float32Array(c.fresnel?
c.fresnel:[1,1,1]);this.emissiveIntensity=c.emissiveIntensity||1;d=[];e=!1;0<c.lightCount&&d.push("#define LIGHT_COUNT "+c.lightCount);0<c.shadowCount&&(f=Math.min(c.lightCount,c.shadowCount),this.usesRefraction&&8>=a.limits.textureCount&&(f=2<f?2:f),d.push("#define SHADOW_COUNT "+f));0<c.alphaTest&&d.push("#define ALPHA_TEST");this.blend===b.alpha?d.push("#define TRANSPARENCY_DITHER"):this.blend===b.none&&d.push("#define NOBLEND");a.hints.mobile&&d.push("#define MOBILE");a.ext.textureDepth&&d.push("#define SHADOW_NATIVE_DEPTH");
f=function(a){return 1/(2/3*3.1415962*(a*a+a+1))};c.useSkin&&(d.push("#define SKIN"),this.skinParams=c.skinParams||{subdermisColor:[1,1,1],transColor:[1,0,0,1],fresnelColor:[0.2,0.2,0.2,0.5],fresnelOcc:1,fresnelGlossMask:1,transSky:0.5,shadowBlur:0.5,normalSmooth:0.5,transScatter:0,transDepth:0,millimeterScale:1},this.extrasTexCoordRanges.subdermisTex||d.push("#define SKIN_NO_SUBDERMIS_TEX"),this.extrasTexCoordRanges.translucencyTex||d.push("#define SKIN_NO_TRANSLUCENCY_TEX"),this.extrasTexCoordRanges.fuzzTex||
d.push("#define SKIN_NO_FUZZ_TEX"),void 0===this.skinParams.version&&(this.skinParams.version=1),2==this.skinParams.version?(d.push("#define SKIN_VERSION_2"),this.skinParams.shadowBlur*=4,this.skinParams.shadowBlur=Math.min(this.skinParams.shadowBlur,40),this.skinParams.transIntegral=f(0.5*this.skinParams.transScatter),this.skinParams.fresnelIntegral=1/3.14159*(1-0.5*this.skinParams.fresnelColor[3]),this.skinParams.transSky=0):(d.push("#define SKIN_VERSION_1"),this.skinParams.shadowBlur=8*Math.min(this.skinParams.shadowBlur,
1),this.skinParams.transDepth=0,this.skinParams.transScatter=this.skinParams.transColor[3],this.skinParams.transIntegral=1/3.14159*(1-0.5*this.skinParams.transScatter),this.skinParams.fresnelIntegral=1/3.14159*(1-0.5*this.skinParams.fresnelColor[3]),this.skinParams.transSky*=1.25,this.skinParams.transIntegral*=1.25));c.aniso&&(d.push("#define ANISO"),this.anisoParams=c.anisoParams||{strength:1,tangent:[1,0,0],integral:0.5},this.extrasTexCoordRanges.anisoTex||d.push("#define ANISO_NO_DIR_TEX"));c.microfiber&&
(d.push("#define MICROFIBER"),this.microfiberParams=c.microfiberParams||{fresnelColor:[0.2,0.2,0.2,0.5],fresnelOcc:1,fresnelGlossMask:1},this.microfiberParams.fresnelIntegral=1/3.14159*(1-0.5*this.microfiberParams.fresnelColor[3]),this.extrasTexCoordRanges.fuzzTex||d.push("#define MICROFIBER_NO_FUZZ_TEX"));c.refraction&&(d.push("#define REFRACTION"),this.refractionParams=c.refractionParams||{distantBackground:!1,tint:[1,1,1],useAlbedoTint:!1,IOR:1.5},this.extrasTexCoordRanges.refractionMaskTex||d.push("#define REFRACTION_NO_MASK_TEX"));
c.vertexColor&&(d.push("#define VERTEX_COLOR"),c.vertexColorsRGB&&d.push("#define VERTEX_COLOR_SRGB"),c.vertexColorAlpha&&d.push("#define VERTEX_COLOR_ALPHA"));this.horizonSmoothing=c.horizonSmoothing||0;0<this.horizonSmoothing&&d.push("#define HORIZON_SMOOTHING");c.unlitDiffuse&&d.push("#define DIFFUSE_UNLIT");this.extrasTexCoordRanges.emissiveTex&&(d.push("#define EMISSIVE"),c.emissiveSecondaryUV&&(d.push("#define EMISSIVE_SECONDARY_UV"),e=!0));this.extrasTexCoordRanges.aoTex&&(d.push("#define AMBIENT_OCCLUSION"),
c.aoSecondaryUV&&(d.push("#define AMBIENT_OCCLUSION_SECONDARY_UV"),e=!0));c.tangentOrthogonalize&&d.push("#define TSPACE_ORTHOGONALIZE");c.tangentNormalize&&d.push("#define TSPACE_RENORMALIZE");c.tangentGenerateBitangent&&d.push("#define TSPACE_COMPUTE_BITANGENT");e&&d.push("#define TEXCOORD_SECONDARY");this.vOffset=this.uOffset=0;d.push("#define UV_OFFSET ");this.shader=a.shaderCache.fromURLs("matvert.glsl","matfrag.glsl",d);d.push("#define STRIPVIEW");this.stripShader=a.shaderCache.fromURLs("matvert.glsl",
"matfrag.glsl",d);this.wireShader=a.shaderCache.fromURLs("wirevert.glsl","wirefrag.glsl");this.blend===b.alpha&&(this.prepassShader=a.shaderCache.fromURLs("alphaprepassvert.glsl","alphaprepassfrag.glsl"))}
Material.prototype.bind=function(a,b){if(!this.complete())return!1;var c=a.view,d=a.lights,e=a.sky,f=a.shadow,g=a.stripData.active()?this.stripShader:this.shader,h=this.skinParams,k=this.anisoParams,l=this.microfiberParams,n,m=this.gl,p=g.params,r=this.textures,s=g.samplers;g.bind();this.blend();var u=b.mesh.displayMatrix,q=Matrix.mul(Matrix.empty(),c.viewMatrix,u),x=Matrix.mul(Matrix.empty(),c.projectionMatrix,c.viewMatrix),q=Matrix.mul(Matrix.empty(),c.projectionMatrix,q),u=Matrix.mul(Matrix.empty(),
d.matrix,u);m.uniformMatrix4fv(p.uModelViewProjectionMatrix,!1,q);m.uniformMatrix4fv(p.uSkyMatrix,!1,u);u=Matrix.mulPoint(Vect.empty(),d.matrix,c.transform[12],c.transform[13],c.transform[14]);m.uniform3f(p.uCameraPosition,u[0],u[1],u[2]);m.uniform3fv(p.uFresnel,this.fresnel);m.uniform1f(p.uAlphaTest,this.alphaTest);m.uniform1f(p.uHorizonOcclude,this.horizonOcclude);m.uniform1f(p.uHorizonSmoothing,this.horizonSmoothing);m.uniform4fv(p.uDiffuseCoefficients,e.diffuseCoefficients);0<d.count&&(m.uniform4fv(p.uLightPositions,
d.positionBuffer),m.uniform3fv(p.uLightDirections,d.directionBuffer),m.uniform3fv(p.uLightColors,d.colors),m.uniform3fv(p.uLightParams,d.parameters),m.uniform3fv(p.uLightSpot,d.spot),u=0.392699*a.postRender.currentSample(),m.uniform2f(p.uShadowKernelRotation,0.5*Math.cos(u),0.5*Math.sin(u)),0<d.shadowCount&&(u=f.depthTextures[0].desc.width,m.uniform2f(p.uShadowMapSize,u,1/u),m.uniformMatrix4fv(p.uShadowMatrices,!1,d.finalTransformBuffer),m.uniformMatrix4fv(p.uInvShadowMatrices,!1,d.inverseTransformBuffer),
m.uniform4fv(p.uShadowTexelPadProjections,d.shadowTexelPadProjections),f.bindDepthTexture(s.tDepth0,0),f.bindDepthTexture(s.tDepth1,1),f.bindDepthTexture(s.tDepth2,2)));h&&(m.uniform3fv(p.uSubdermisColor,h.subdermisColor),m.uniform4fv(p.uTransColor,h.transColor),m.uniform1f(p.uTransScatter,h.transScatter),m.uniform4fv(p.uFresnelColor,h.fresnelColor),m.uniform1f(p.uFresnelOcc,h.fresnelOcc),m.uniform1f(p.uFresnelGlossMask,h.fresnelGlossMask),m.uniform1f(p.uFresnelIntegral,h.fresnelIntegral),m.uniform1f(p.uTransIntegral,
h.transIntegral),m.uniform1f(p.uSkinTransDepth,h.transDepth),m.uniform1f(p.uTransSky,h.transSky),m.uniform1f(p.uSkinShadowBlur,h.shadowBlur),m.uniform1f(p.uNormalSmooth,h.normalSmooth),(n=this.extrasTexCoordRanges.subdermisTex)&&m.uniform4fv(p.uTexRangeSubdermis,n),(n=this.extrasTexCoordRanges.translucencyTex)&&m.uniform4fv(p.uTexRangeTranslucency,n),(n=this.extrasTexCoordRanges.fuzzTex)&&m.uniform4fv(p.uTexRangeFuzz,n));l&&(m.uniform4fv(p.uFresnelColor,l.fresnelColor),m.uniform1f(p.uFresnelOcc,l.fresnelOcc),
m.uniform1f(p.uFresnelGlossMask,l.fresnelGlossMask),m.uniform1f(p.uFresnelIntegral,l.fresnelIntegral),(n=this.extrasTexCoordRanges.fuzzTex)&&m.uniform4fv(p.uTexRangeFuzz,n));k&&(m.uniform3fv(p.uAnisoTangent,k.tangent),m.uniform1f(p.uAnisoStrength,k.strength),m.uniform1f(p.uAnisoIntegral,k.integral),(n=this.extrasTexCoordRanges.anisoTex)&&m.uniform4fv(p.uTexRangeAniso,n));this.usesRefraction&&(a.refractionSurface&&a.refractionSurface.bind(s.tRefraction),d=Matrix.mul(Matrix.empty(),x,d.invMatrix),m.uniformMatrix4fv(p.uRefractionViewProjection,
!1,d),m.uniform1f(p.uRefractionRayDistance,this.refractionParams.distantBackground?1E10:4*b.mesh.bounds.maxExtent),m.uniform3fv(p.uRefractionTint,this.refractionParams.tint),m.uniform1f(p.uRefractionAlbedoTint,this.refractionParams.useAlbedoTint?1:0),m.uniform1f(p.uRefractionIOREntry,1/this.refractionParams.IOR),(n=this.extrasTexCoordRanges.refractionMaskTex)&&m.uniform4fv(p.uTexRangeRefraction,n));if(n=this.extrasTexCoordRanges.emissiveTex)m.uniform4fv(p.uTexRangeEmissive,n),m.uniform1f(p.uEmissiveScale,
this.emissiveIntensity);(n=this.extrasTexCoordRanges.aoTex)&&m.uniform4fv(p.uTexRangeAO,n);r.albedo.bind(s.tAlbedo);r.reflectivity.bind(s.tReflectivity);r.normal.bind(s.tNormal);r.extras.bind(s.tExtras);e.specularTexture.bind(s.tSkySpecular);g===this.stripShader&&(m.uniform1fv(p.uStrips,a.stripData.strips),m.uniform2f(p.uStripRes,2/c.size[0],2/c.size[1]));m.uniform2f(p.uUVOffset,this.uOffset,this.vOffset);return!0};
Material.prototype.bindAlphaPrepass=function(a,b){if(!this.complete()||!this.prepassShader)return!1;var c=this.gl,d=this.prepassShader.params,e=this.prepassShader.samplers;this.prepassShader.bind();var f=Matrix.mul(Matrix.empty(),a.view.viewMatrix,b.mesh.displayMatrix),f=Matrix.mul(Matrix.empty(),a.view.projectionMatrix,f);c.uniformMatrix4fv(d.uModelViewProjectionMatrix,!1,f);c.uniform2f(d.uUVOffset,this.uOffset,this.vOffset);this.textures.albedo.bind(e.tAlbedo);return!0};
Material.prototype.bindWire=function(a,b){if(!this.complete())return!1;var c=this.gl,d=this.wireShader.params,e=a.view;c.enable(c.BLEND);c.blendFunc(c.SRC_ALPHA,c.ONE_MINUS_SRC_ALPHA);c.depthMask(!1);this.wireShader.bind();var f=Matrix.mul(Matrix.empty(),a.view.viewMatrix,b.mesh.displayMatrix),f=Matrix.mul(Matrix.empty(),a.view.projectionMatrix,f);c.uniformMatrix4fv(d.uModelViewProjectionMatrix,!1,f);c.uniform4f(d.uStripParams,2/e.size[0],2/e.size[1],a.stripData.strips[3],a.stripData.strips[4]);return!0};
Material.prototype.complete=function(){return this.wireShader.complete()&&this.shader.complete()&&this.stripShader.complete()&&(!this.prepassShader||this.prepassShader.complete())&&(!this.refractionShader||this.refractionShader.complete())&&this.textures.albedo.complete()&&this.textures.reflectivity.complete()&&this.textures.normal.complete()};var Matrix={type:Float32Array,create:function(a,b,c,d,e,f,g,h,k,l,n,m,p,r,s,u){var q=new Matrix.type(16);q[0]=a;q[4]=b;q[8]=c;q[12]=d;q[1]=e;q[5]=f;q[9]=g;q[13]=h;q[2]=k;q[6]=l;q[10]=n;q[14]=m;q[3]=p;q[7]=r;q[11]=s;q[15]=u;return q},empty:function(){return new Matrix.type(16)},identity:function(){var a=new Matrix.type(16);a[0]=1;a[4]=0;a[8]=0;a[12]=0;a[1]=0;a[5]=1;a[9]=0;a[13]=0;a[2]=0;a[6]=0;a[10]=1;a[14]=0;a[3]=0;a[7]=0;a[11]=0;a[15]=1;return a},set:function(a,b,c,d,e,f,g,h,k,l,n,m,p,r,s,u,q){a[0]=
b;a[4]=c;a[8]=d;a[12]=e;a[1]=f;a[5]=g;a[9]=h;a[13]=k;a[2]=l;a[6]=n;a[10]=m;a[14]=p;a[3]=r;a[7]=s;a[11]=u;a[15]=q},translation:function(a,b,c,d){Matrix.set(a,1,0,0,b,0,1,0,c,0,0,1,d,0,0,0,1);return a},rotation:function(a,b,c){a[0]=1;a[4]=0;a[8]=0;a[12]=0;a[1]=0;a[5]=1;a[9]=0;a[13]=0;a[2]=0;a[6]=0;a[10]=1;a[14]=0;a[3]=0;a[7]=0;a[11]=0;a[15]=1;var d=0.0174532925*b;b=Math.sin(d);d=Math.cos(d);switch(c){case 0:a[5]=d;a[9]=-b;a[6]=b;a[10]=d;break;case 1:a[0]=d;a[8]=b;a[2]=-b;a[10]=d;break;case 2:a[0]=d,
a[4]=-b,a[1]=b,a[5]=d}return a},mul:function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=b[4],k=b[5],l=b[6],n=b[7],m=b[8],p=b[9],r=b[10],s=b[11],u=b[12],q=b[13],x=b[14];b=b[15];var w=c[0],v=c[1],t=c[2],y=c[3];a[0]=w*d+v*h+t*m+y*u;a[1]=w*e+v*k+t*p+y*q;a[2]=w*f+v*l+t*r+y*x;a[3]=w*g+v*n+t*s+y*b;w=c[4];v=c[5];t=c[6];y=c[7];a[4]=w*d+v*h+t*m+y*u;a[5]=w*e+v*k+t*p+y*q;a[6]=w*f+v*l+t*r+y*x;a[7]=w*g+v*n+t*s+y*b;w=c[8];v=c[9];t=c[10];y=c[11];a[8]=w*d+v*h+t*m+y*u;a[9]=w*e+v*k+t*p+y*q;a[10]=w*f+v*l+t*r+y*x;a[11]=
w*g+v*n+t*s+y*b;w=c[12];v=c[13];t=c[14];y=c[15];a[12]=w*d+v*h+t*m+y*u;a[13]=w*e+v*k+t*p+y*q;a[14]=w*f+v*l+t*r+y*x;a[15]=w*g+v*n+t*s+y*b;return a},invert:function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=b[4],h=b[5],k=b[6],l=b[7],n=b[8],m=b[9],p=b[10],r=b[11],s=b[12],u=b[13],q=b[14],x=b[15],w=c*h-d*g,v=c*k-e*g,t=c*l-f*g,y=d*k-e*h,E=d*l-f*h,F=e*l-f*k,A=n*u-m*s,B=n*q-p*s,z=n*x-r*s,C=m*q-p*u,G=m*x-r*u,H=p*x-r*q,D=w*H-v*G+t*C+y*z-E*B+F*A;if(!D)return null;D=1/D;a[0]=(h*H-k*G+l*C)*D;a[1]=(e*G-d*H-f*C)*D;
a[2]=(u*F-q*E+x*y)*D;a[3]=(p*E-m*F-r*y)*D;a[4]=(k*z-g*H-l*B)*D;a[5]=(c*H-e*z+f*B)*D;a[6]=(q*t-s*F-x*v)*D;a[7]=(n*F-p*t+r*v)*D;a[8]=(g*G-h*z+l*A)*D;a[9]=(d*z-c*G-f*A)*D;a[10]=(s*E-u*t+x*w)*D;a[11]=(m*t-n*E-r*w)*D;a[12]=(h*B-g*C-k*A)*D;a[13]=(c*C-d*B+e*A)*D;a[14]=(u*v-s*y-q*w)*D;a[15]=(n*y-m*v+p*w)*D;return a},transpose:function(a,b){a[0]=b[0];a[4]=b[1];a[8]=b[2];a[12]=b[3];a[1]=b[4];a[5]=b[5];a[9]=b[6];a[13]=b[7];a[2]=b[8];a[6]=b[9];a[10]=b[10];a[14]=b[11];a[3]=b[12];a[7]=b[13];a[11]=b[14];a[15]=b[15];
return a},mul4:function(a,b,c,d,e,f){a[0]=b[0]*c+b[4]*d+b[8]*e+b[12]*f;a[1]=b[1]*c+b[5]*d+b[9]*e+b[13]*f;a[2]=b[2]*c+b[6]*d+b[10]*e+b[14]*f;a[3]=b[3]*c+b[7]*d+b[11]*e+b[15]*f;return a},mulPoint:function(a,b,c,d,e){a[0]=b[0]*c+b[4]*d+b[8]*e+b[12];a[1]=b[1]*c+b[5]*d+b[9]*e+b[13];a[2]=b[2]*c+b[6]*d+b[10]*e+b[14];return a},mulVec:function(a,b,c,d,e){a[0]=b[0]*c+b[4]*d+b[8]*e;a[1]=b[1]*c+b[5]*d+b[9]*e;a[2]=b[2]*c+b[6]*d+b[10]*e;return a},perspective:function(a,b,c,d,e,f){f=f||0;b=1/Math.tan(0.00872664625*
b);a[0]=b/c;a[1]=a[2]=a[3]=0;a[5]=b;a[4]=a[6]=a[7]=0;a[8]=a[9]=0;a[10]=(e+d)/(d-e)-3.0518044E-5*f;a[11]=-1;a[14]=2*e*d/(d-e);a[12]=a[13]=a[15]=0;return a},perspectiveInfinite:function(a,b,c,d,e){e=e||0;b=1/Math.tan(0.00872664625*b);a[0]=b/c;a[1]=a[2]=a[3]=0;a[5]=b;a[4]=a[6]=a[7]=0;a[8]=a[9]=0;a[10]=a[11]=-1-3.0518044E-5*e;a[14]=-2*d;a[12]=a[13]=a[15]=0;return a},ortho:function(a,b,c,d,e,f,g,h){var k=1/(c-b),l=1/(e-d),n=1/(g-f);a[0]=k+k;a[1]=a[2]=a[3]=0;a[5]=l+l;a[4]=a[6]=a[7]=0;a[12]=-(c+b)*k;a[13]=
-(e+d)*l;a[10]=-(n+n)-3.0518044E-5*(h||0);a[14]=-(g+f)*n;a[8]=a[9]=a[11]=0;a[15]=1;return a},lookAt:function(a,b,c,d){var e=a.subarray(0,3),f=a.subarray(4,7),g=a.subarray(8,11);Vect.sub(g,b,c);Vect.cross(e,d,g);Vect.normalize(g,g);Vect.normalize(e,e);Vect.cross(f,g,e);Matrix.set(a,e[0],e[1],e[2],-Vect.dot(e,b),f[0],f[1],f[2],-Vect.dot(f,b),g[0],g[1],g[2],-Vect.dot(g,b),0,0,0,1)},copy:function(a,b){for(var c=0;16>c;++c)a[c]=b[c]},copyToBuffer:function(a,b,c){for(var d=0;16>d;++d)a[b+d]=c[d]}};function Mesh(a,b,c){this.gl=a;this.desc=b;var d=b.isDynamicMesh;this.numSubMeshes=this.dynamicVertexData=0;this.displayMatrix=Matrix.identity();this.name=b.name;this.modelMatrix=Matrix.identity();this.origin=b.transform?Vect.create(b.transform[12],b.transform[13],b.transform[14],1):Vect.create(0,5,0,1);this.stride=32;if(this.vertexColor=b.vertexColor)this.stride+=4;if(this.secondaryTexCoord=b.secondaryTexCoord)this.stride+=8;c=new ByteStream(c.data);this.indexCount=b.indexCount;this.indexTypeSize=
b.indexTypeSize;this.indexType=4==this.indexTypeSize?a.UNSIGNED_INT:a.UNSIGNED_SHORT;this.indexBuffer=a.createBuffer();a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.indexBuffer);var e=c.readBytes(this.indexCount*this.indexTypeSize);a.bufferData(a.ELEMENT_ARRAY_BUFFER,e,a.STATIC_DRAW);this.wireCount=b.wireCount;this.wireBuffer=a.createBuffer();a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.wireBuffer);e=c.readBytes(this.wireCount*this.indexTypeSize);a.bufferData(a.ELEMENT_ARRAY_BUFFER,e,a.STATIC_DRAW);a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,
null);this.vertexCount=b.vertexCount;this.vertexBuffer=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffer);c=c.readBytes(this.vertexCount*this.stride);d?(this.dynamicVertexData=new Uint8Array(c),a.bufferData(a.ARRAY_BUFFER,c,a.DYNAMIC_DRAW)):a.bufferData(a.ARRAY_BUFFER,c,a.STATIC_DRAW);a.bindBuffer(a.ARRAY_BUFFER,null);this.bounds=void 0===b.minBound||void 0===b.maxBound?{min:Vect.create(-10,-10,-10,1),max:Vect.create(10,10,-0,1)}:{min:Vect.create(b.minBound[0],b.minBound[1],b.minBound[2],
1),max:Vect.create(b.maxBound[0],b.maxBound[1],b.maxBound[2],1)};this.bounds.maxExtent=Math.max(Math.max(b.maxBound[0]-b.minBound[0],b.maxBound[1]-b.minBound[1]),b.maxBound[2]-b.minBound[2]);this.bounds.averageExtent=(b.maxBound[0]-b.minBound[0]+(b.maxBound[1]-b.minBound[1])+(b.maxBound[2]-b.minBound[2]))/3};function MeshRenderable(a,b,c){this.mesh=a;this.gl=this.mesh.gl;this.indexOffset=b.firstIndex*a.indexTypeSize;this.indexCount=b.indexCount;this.wireIndexOffset=b.firstWireIndex*a.indexTypeSize;this.wireIndexCount=b.wireIndexCount;this.material=c;this.visible=!0}
MeshRenderable.prototype.draw=function(a){var b=this.gl;if(this.material.bind(a,this)){a=this.material.shader.attribs;var c=this.mesh.stride;this.mesh.desc.cullBackFaces?(b.enable(b.CULL_FACE),b.cullFace(b.BACK)):b.disable(b.CULL_FACE);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.mesh.indexBuffer);b.bindBuffer(b.ARRAY_BUFFER,this.mesh.vertexBuffer);b.enableVertexAttribArray(a.vPosition);b.enableVertexAttribArray(a.vTexCoord);b.enableVertexAttribArray(a.vTangent);b.enableVertexAttribArray(a.vBitangent);
b.enableVertexAttribArray(a.vNormal);var d=this.mesh.vertexColor&&void 0!==a.vColor;d&&b.enableVertexAttribArray(a.vColor);var e=this.mesh.secondaryTexCoord&&void 0!==a.vTexCoord2;e&&b.enableVertexAttribArray(a.vTexCoord2);var f=0;b.vertexAttribPointer(a.vPosition,3,b.FLOAT,!1,c,f);f+=12;b.vertexAttribPointer(a.vTexCoord,2,b.FLOAT,!1,c,f);f+=8;this.mesh.secondaryTexCoord&&(e&&b.vertexAttribPointer(a.vTexCoord2,2,b.FLOAT,!1,c,f),f+=8);b.vertexAttribPointer(a.vTangent,2,b.UNSIGNED_SHORT,!0,c,f);f+=
4;b.vertexAttribPointer(a.vBitangent,2,b.UNSIGNED_SHORT,!0,c,f);f+=4;b.vertexAttribPointer(a.vNormal,2,b.UNSIGNED_SHORT,!0,c,f);d&&b.vertexAttribPointer(a.vColor,4,b.UNSIGNED_BYTE,!0,c,f+4);b.drawElements(b.TRIANGLES,this.indexCount,this.mesh.indexType,this.indexOffset);b.disableVertexAttribArray(a.vPosition);b.disableVertexAttribArray(a.vTexCoord);b.disableVertexAttribArray(a.vTangent);b.disableVertexAttribArray(a.vBitangent);b.disableVertexAttribArray(a.vNormal);d&&b.disableVertexAttribArray(a.vColor);
e&&b.disableVertexAttribArray(a.vTexCoord2)}};MeshRenderable.prototype.drawShadow=function(a){var b=this.gl;this.mesh.desc.cullBackFaces?(b.enable(b.CULL_FACE),b.cullFace(b.BACK)):b.disable(b.CULL_FACE);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.mesh.indexBuffer);b.bindBuffer(b.ARRAY_BUFFER,this.mesh.vertexBuffer);b.enableVertexAttribArray(a);b.vertexAttribPointer(a,3,b.FLOAT,!1,this.mesh.stride,0);b.drawElements(b.TRIANGLES,this.indexCount,this.mesh.indexType,this.indexOffset);b.disableVertexAttribArray(a)};
MeshRenderable.prototype.drawAlphaShadow=function(a,b){var c=this.gl;this.mesh.desc.cullBackFaces?(c.enable(c.CULL_FACE),c.cullFace(c.BACK)):c.disable(c.CULL_FACE);c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,this.mesh.indexBuffer);c.bindBuffer(c.ARRAY_BUFFER,this.mesh.vertexBuffer);c.enableVertexAttribArray(a);c.enableVertexAttribArray(b);c.vertexAttribPointer(a,3,c.FLOAT,!1,this.mesh.stride,0);c.vertexAttribPointer(b,2,c.FLOAT,!1,this.mesh.stride,12);c.drawElements(c.TRIANGLES,this.indexCount,this.mesh.indexType,
this.indexOffset);c.disableVertexAttribArray(a);c.disableVertexAttribArray(b)};
MeshRenderable.prototype.drawAlphaPrepass=function(a){var b=this.gl;if(this.material.bindAlphaPrepass(a,this)){a=this.material.prepassShader.attribs;var c=this.mesh.stride;this.mesh.desc.cullBackFaces?(b.enable(b.CULL_FACE),b.cullFace(b.BACK)):b.disable(b.CULL_FACE);b.bindBuffer(b.ELEMENT_ARRAY_BUFFER,this.mesh.indexBuffer);b.bindBuffer(b.ARRAY_BUFFER,this.mesh.vertexBuffer);b.enableVertexAttribArray(a.vPosition);b.enableVertexAttribArray(a.vTexCoord);b.vertexAttribPointer(a.vPosition,3,b.FLOAT,!1,
c,0);b.vertexAttribPointer(a.vTexCoord,2,b.FLOAT,!1,c,12);b.drawElements(b.TRIANGLES,this.indexCount,this.mesh.indexType,this.indexOffset);b.disableVertexAttribArray(a.vPosition);b.disableVertexAttribArray(a.vTexCoord)}};
MeshRenderable.prototype.drawWire=function(a){var b=this.material.wireShader.attribs,c=this.gl;this.material.bindWire(a,this)&&(c.enableVertexAttribArray(b.vPosition),c.bindBuffer(c.ELEMENT_ARRAY_BUFFER,this.mesh.wireBuffer),c.bindBuffer(c.ARRAY_BUFFER,this.mesh.vertexBuffer),c.vertexAttribPointer(b.vPosition,3,c.FLOAT,!1,this.mesh.stride,0),c.drawElements(c.LINES,this.wireIndexCount,this.mesh.indexType,this.wireIndexOffset),c.disableVertexAttribArray(b.vPosition))};
MeshRenderable.prototype.complete=function(){return this.material.complete()};var Network={fetchImage:function(a,b,c){var d=new Image;d.crossOrigin="Anonymous";d.onload=function(){0<d.width&&0<d.height?b(d):c&&c()};c&&(req.onerror=function(){c()});d.src=a},fetchText:function(a,b,c,d){var e=new XMLHttpRequest;e.open("GET",a,!0);e.onload=function(){200==e.status?b(e.responseText):c&&c()};c&&(e.onerror=function(){c()});d&&(e.onprogress=function(a){d(a.loaded,a.total)});e.send()},fetchBinary:function(a,b,c,d){var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";
e.onload=function(){200==e.status?b(e.response):c&&c()};c&&(e.onerror=function(){c()});d&&(e.onprogress=function(a){d(a.loaded,a.total)});e.send()},fetchBinaryIncremental:function(a,b,c,d){var e=new XMLHttpRequest;e.open("HEAD",a,!0);e.onload=function(){if(200==e.status){var f=e.getResponseHeader("Accept-Ranges");if(f&&"none"!=f){var g=e.getResponseHeader("Content-Length")|0,h=function(c,e){var f=new XMLHttpRequest;f.open("GET",a,!0);f.setRequestHeader("Range","bytes="+c+"-"+e);f.responseType="arraybuffer";
f.onload=function(){(206==f.status||200==f.status)&&b(f.response)&&e<g&&(c+=d,e+=d,e=e<g-1?e:g-1,h(c,e))};f.send()};h(0,d-1)}else c&&c()}else c&&c()};c&&(e.onerror=function(){c()});e.send()}};function PlaybackControls(a){this.debugString="";this.init=!1;this.speedList=this.cameraList=this.animationList=this.playButton=this.timelineSlider=this.playbackRegion=this.previousFrameButton=this.nextFrameButton=this.pauseButton=this.playButton=0;this.visible=!1;this.backgroundRegion=this.screenButton=0;this.guiScreen=a;this.playbackRegion=new GUIRegion(a);this.idealSliderWidth=650;this.totalListBoxPixelsX=0;this.minWidth=500;this.compactMode=!1;this.ui=a.ui;var b="animationpause"+a.imageSetNumber+
"x.png",c="animationplay"+a.imageSetNumber+"x.png",d="timelineLE"+a.imageSetNumber+"x.png",e="timelineM"+a.imageSetNumber+"x.png",f="timelineRE"+a.imageSetNumber+"x.png",g=a.ui.viewer.scene.sceneAnimator.animations.length;if(0!=g){var h=this.idealSliderWidth;this.bottomOffset=85;this.centerOffset=60;var k=a.width/2+this.centerOffset,l=k-h/2,k=k+h/2,n=l-14-32,m=k-n,p=32/a.height,r=this.bottomOffset/a.height,s=this.playbackRegion;s.controlRect.widthPercent=m/a.width;s.controlRect.heightPercent=p;s.controlRect.xPercent=
n/a.width;s.controlRect.yPercent=r;p=32/m;this.pauseButton=new Button(this.guiScreen);this.pauseButton.controlRect.set(0,0.125,p,0.75);this.pauseButton.controlRect.opacity=0.5;s.controlRect.registerChildControlRect(this.pauseButton.controlRect);this.pauseButton.linkControl(s.addImageElement(this.pauseButton.controlRect,b));this.playButton=new Button(this.guiScreen);this.playButton.controlRect.set(0,0.125,p,0.75);this.playButton.controlRect.opacity=0.5;s.controlRect.registerChildControlRect(this.playButton.controlRect);
this.playButton.linkControl(s.addImageElement(this.playButton.controlRect,c));b=h/m;m=(l-n)/m;this.timelineSlider=new TimelineSlider(this.guiScreen,s);this.timelineSlider.controlRect.set(m,0.03125,b,1);s.controlRect.registerChildControlRect(this.timelineSlider.controlRect);this.timelineSlider.setBackground3x1(s,d,e