aframe-extras
Version:
Add-ons and examples for A-Frame VR.
2 lines • 167 kB
JavaScript
/*! For license information please see aframe-extras.min.js.LICENSE.txt */
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("THREE"));else if("function"==typeof define&&define.amd)define(["THREE"],t);else{var n="object"==typeof exports?t(require("THREE")):t(e.THREE);for(var o in n)("object"==typeof exports?exports:e)[o]=n[o]}}(self,e=>(()=>{var t={95:()=>{AFRAME.registerComponent("checkpoint",{schema:{offset:{default:{x:0,y:0,z:0},type:"vec3"}},init:function(){this.active=!1,this.targetEl=null,this.fire=this.fire.bind(this),this.offset=new THREE.Vector3},update:function(){this.offset.copy(this.data.offset)},play:function(){this.el.addEventListener("click",this.fire)},pause:function(){this.el.removeEventListener("click",this.fire)},remove:function(){this.pause()},fire:function(){const e=this.el.sceneEl.querySelector("[checkpoint-controls]");if(!e)throw new Error("No `checkpoint-controls` component found.");e.components["checkpoint-controls"].setCheckpoint(this.el)},getOffset:function(){return this.offset.copy(this.data.offset)}})},109:()=>{AFRAME.registerComponent("sphere-collider",{schema:{enabled:{default:!0},interval:{default:80},objects:{default:""},state:{default:"collided"},radius:{default:.05},watch:{default:!0}},init:function(){this.observer=null,this.els=[],this.collisions=[],this.prevCheckTime=void 0,this.eventDetail={},this.handleHit=this.handleHit.bind(this),this.handleHitEnd=this.handleHitEnd.bind(this)},play:function(){const e=this.el.sceneEl;this.data.watch&&(this.observer=new MutationObserver(this.update.bind(this,null)),this.observer.observe(e,{childList:!0,subtree:!0}))},pause:function(){this.observer&&(this.observer.disconnect(),this.observer=null)},update:function(){const e=this.data;let t;t=e.objects?this.el.sceneEl.querySelectorAll(e.objects):this.el.sceneEl.children,this.els=Array.prototype.slice.call(t)},tick:function(){const e=new THREE.Vector3,t=new THREE.Vector3,n=new THREE.Vector3,o=new THREE.Vector3,i=new THREE.Box3,s=[],r=new Map;return function(a){if(!this.data.enabled)return;const c=this.prevCheckTime;if(c&&a-c<this.data.interval)return;this.prevCheckTime=a;const l=this.el,d=this.data;let h;var u;l.getObject3D("mesh")&&(s.length=0,r.clear(),l.object3D.getWorldPosition(e),l.object3D.getWorldScale(n),h=d.radius*(u=n,Math.max(u.x,u.y,u.z)),this.els.forEach(function(n){let a,c,l,d;n.isEntity&&(c=n.getObject3D("mesh"),c&&(i.setFromObject(c).getSize(o),d=Math.max(o.x,o.y,o.z)/2,a=Math.sqrt(2*d*d),i.getCenter(t),a&&(l=e.distanceTo(t),l<a+h&&(s.push(n),r.set(n,l)))))}),s.sort((e,t)=>r.get(e)>r.get(t)?1:-1).forEach(this.handleHit),this.collisions.filter(e=>!r.has(e)).forEach(this.handleHitEnd),function(e,t){e.length=0;for(let n=0;n<t.length;n++)e[n]=t[n]}(this.collisions,s))}}(),handleHit:function(e){e.emit("hit"),e.addState(this.data.state),this.eventDetail.el=e,this.el.emit("hit",this.eventDetail)},handleHitEnd:function(e){e.emit("hitend"),e.removeState(this.data.state),this.eventDetail.el=e,this.el.emit("hitend",this.eventDetail)}})},144:()=>{AFRAME.registerComponent("object-model",{schema:{src:{type:"asset"},crossorigin:{default:""}},init:function(){this.model=null},update:function(){let e;const t=this.data;t.src&&(this.remove(),e=new THREE.ObjectLoader,t.crossorigin&&e.setCrossOrigin(t.crossorigin),e.load(t.src,e=>{e.traverse(e=>{e instanceof THREE.SkinnedMesh&&e.material&&(e.material.skinning=!!(e.geometry&&e.geometry.bones||[]).length)}),this.load(e)}))},load:function(e){this.model=e,this.el.setObject3D("mesh",e),this.el.emit("model-loaded",{format:"json",model:e})},remove:function(){this.model&&this.el.removeObject3D("mesh")}})},267:()=>{AFRAME.registerComponent("touch-controls",{schema:{enabled:{default:!0},reverseEnabled:{default:!0}},init:function(){this.dVelocity=new THREE.Vector3,this.bindMethods(),this.direction=0},play:function(){this.addEventListeners()},pause:function(){this.removeEventListeners(),this.dVelocity.set(0,0,0)},remove:function(){this.pause()},addEventListeners:function(){const e=this.el.sceneEl,t=e.canvas;if(!t)return void e.addEventListener("render-target-loaded",this.addEventListeners.bind(this));t.addEventListener("touchstart",this.onTouchStart,{passive:!0}),t.addEventListener("touchend",this.onTouchEnd,{passive:!0});const n=e.getAttribute("vr-mode-ui");n&&n.cardboardModeEnabled&&e.addEventListener("enter-vr",this.onEnterVR)},removeEventListeners:function(){const e=this.el.sceneEl&&this.el.sceneEl.canvas;e&&(e.removeEventListener("touchstart",this.onTouchStart),e.removeEventListener("touchend",this.onTouchEnd),this.el.sceneEl.removeEventListener("enter-vr",this.onEnterVR))},isVelocityActive:function(){return this.data.enabled&&!!this.direction},getVelocityDelta:function(){return this.dVelocity.z=this.direction,this.dVelocity.clone()},bindMethods:function(){this.onTouchStart=this.onTouchStart.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this),this.onEnterVR=this.onEnterVR.bind(this)},onTouchStart:function(e){this.direction=-1,this.data.reverseEnabled&&e.touches&&2===e.touches.length&&(this.direction=1),e.preventDefault()},onTouchEnd:function(e){this.direction=0,e.preventDefault()},onEnterVR:function(){const e=this.el.sceneEl.xrSession;e&&(e.addEventListener("selectstart",this.onTouchStart),e.addEventListener("selectend",this.onTouchEnd))}})},417:()=>{const e={once:THREE.LoopOnce,repeat:THREE.LoopRepeat,pingpong:THREE.LoopPingPong};function t(e){return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")}AFRAME.registerComponent("animation-mixer",{schema:{clip:{default:"*"},useRegExp:{default:!1},duration:{default:0},clampWhenFinished:{default:!1,type:"boolean"},crossFadeDuration:{default:0},loop:{default:"repeat",oneOf:Object.keys(e)},repetitions:{default:1/0,min:0},timeScale:{default:1},startAt:{default:0}},init:function(){this.model=null,this.mixer=null,this.activeActions=[];const e=this.el.getObject3D("mesh");e?this.load(e):this.el.addEventListener("model-loaded",e=>{this.load(e.detail.model)})},load:function(e){const t=this.el;this.model=e,this.mixer=new THREE.AnimationMixer(e),this.mixer.addEventListener("loop",e=>{t.emit("animation-loop",{action:e.action,loopDelta:e.loopDelta})}),this.mixer.addEventListener("finished",e=>{t.emit("animation-finished",{action:e.action,direction:e.direction})}),this.data.clip&&this.update({})},remove:function(){this.mixer&&this.mixer.stopAllAction()},update:function(t){if(!t)return;const n=this.data,o=AFRAME.utils.diff(n,t);if("clip"in o)return this.stopAction(),void(n.clip&&this.playAction());this.activeActions.forEach(t=>{"duration"in o&&n.duration&&t.setDuration(n.duration),"clampWhenFinished"in o&&(t.clampWhenFinished=n.clampWhenFinished),("loop"in o||"repetitions"in o)&&t.setLoop(e[n.loop],n.repetitions),"timeScale"in o&&t.setEffectiveTimeScale(n.timeScale)})},stopAction:function(){const e=this.data;for(let t=0;t<this.activeActions.length;t++)e.crossFadeDuration?this.activeActions[t].fadeOut(e.crossFadeDuration):this.activeActions[t].stop();this.activeActions.length=0},playAction:function(){if(!this.mixer)return;const n=this.model,o=this.data,i=n.animations||(n.geometry||{}).animations||[];if(!i.length)return;const s=o.useRegExp?o.clip:(r=o.clip,new RegExp("^"+r.split(/\*+/).map(t).join(".*")+"$"));var r;for(let t,r=0;t=i[r];r++)if(t.name.match(s)){const i=this.mixer.clipAction(t,n);i.enabled=!0,i.clampWhenFinished=o.clampWhenFinished,o.duration&&i.setDuration(o.duration),1!==o.timeScale&&i.setEffectiveTimeScale(o.timeScale),i.startAt(this.mixer.time-o.startAt/1e3),i.setLoop(e[o.loop],o.repetitions).fadeIn(o.crossFadeDuration).play(),this.activeActions.push(i)}},tick:function(e,t){this.mixer&&!isNaN(t)&&this.mixer.update(t/1e3)}})},449:(e,t,n)=>{"use strict";n(866),n(982);var o=n(612);class i{static roundNumber(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}static sample(e){return e[Math.floor(Math.random()*e.length)]}static distanceToSquared(e,t){var n=e.x-t.x,o=e.y-t.y,i=e.z-t.z;return n*n+o*o+i*i}static isPointInPoly(e,t){for(var n=!1,o=-1,i=e.length,s=i-1;++o<i;s=o)(e[o].z<=t.z&&t.z<e[s].z||e[s].z<=t.z&&t.z<e[o].z)&&t.x<(e[s].x-e[o].x)*(t.z-e[o].z)/(e[s].z-e[o].z)+e[o].x&&(n=!n);return n}static isVectorInPolygon(e,t,n){var o=1e5,i=-1e5,s=[];return t.vertexIds.forEach(e=>{o=Math.min(n[e].y,o),i=Math.max(n[e].y,i),s.push(n[e])}),!!(e.y<i+.5&&e.y>o-.5&&this.isPointInPoly(s,e))}static triarea2(e,t,n){return(n.x-e.x)*(t.z-e.z)-(t.x-e.x)*(n.z-e.z)}static vequal(e,t){return this.distanceToSquared(e,t)<1e-5}static mergeVertices(e,t=1e-4){t=Math.max(t,Number.EPSILON);for(var n={},i=e.getIndex(),s=e.getAttribute("position"),r=i?i.count:s.count,a=0,c=[],l=[],d=Math.log10(1/t),h=Math.pow(10,d),u=0;u<r;u++){var p=i?i.getX(u):u,f="";f+=~~(s.getX(p)*h)+",",f+=~~(s.getY(p)*h)+",",(f+=~~(s.getZ(p)*h)+",")in n?c.push(n[f]):(l.push(s.getX(p)),l.push(s.getY(p)),l.push(s.getZ(p)),n[f]=a,c.push(a),a++)}const m=new o.BufferAttribute(new Float32Array(l),s.itemSize,s.normalized),y=new o.BufferGeometry;return y.setAttribute("position",m),y.setIndex(c),y}}class s{constructor(e){this.content=[],this.scoreFunction=e}push(e){this.content.push(e),this.sinkDown(this.content.length-1)}pop(){const e=this.content[0],t=this.content.pop();return this.content.length>0&&(this.content[0]=t,this.bubbleUp(0)),e}remove(e){const t=this.content.indexOf(e),n=this.content.pop();t!==this.content.length-1&&(this.content[t]=n,this.scoreFunction(n)<this.scoreFunction(e)?this.sinkDown(t):this.bubbleUp(t))}size(){return this.content.length}rescoreElement(e){this.sinkDown(this.content.indexOf(e))}sinkDown(e){const t=this.content[e];for(;e>0;){const n=(e+1>>1)-1,o=this.content[n];if(!(this.scoreFunction(t)<this.scoreFunction(o)))break;this.content[n]=t,this.content[e]=o,e=n}}bubbleUp(e){const t=this.content.length,n=this.content[e],o=this.scoreFunction(n);for(;;){const i=e+1<<1,s=i-1;let r,a=null;if(s<t&&(r=this.scoreFunction(this.content[s]),r<o&&(a=s)),i<t&&this.scoreFunction(this.content[i])<(null===a?o:r)&&(a=i),null===a)break;this.content[e]=this.content[a],this.content[a]=n,e=a}}}class r{constructor(){this.portals=[]}push(e,t){void 0===t&&(t=e),this.portals.push({left:e,right:t})}stringPull(){const e=this.portals,t=[];let n,o,s,r=0,a=0,c=0;n=e[0].left,o=e[0].left,s=e[0].right,t.push(n);for(let l=1;l<e.length;l++){const d=e[l].left,h=e[l].right;if(i.triarea2(n,s,h)<=0){if(!(i.vequal(n,s)||i.triarea2(n,o,h)>0)){t.push(o),n=o,r=a,o=n,s=n,a=r,c=r,l=r;continue}s=h,c=l}if(i.triarea2(n,o,d)>=0){if(!(i.vequal(n,o)||i.triarea2(n,s,d)<0)){t.push(s),n=s,r=c,o=n,s=n,a=r,c=r,l=r;continue}o=d,a=l}}return 0!==t.length&&i.vequal(t[t.length-1],e[e.length-1].left)||t.push(e[e.length-1].left),this.path=t,t}}class a{constructor(){this.zones={}}static createZone(e,t=1e-4){return class{static buildZone(e,t){const n=this._buildNavigationMesh(e,t),s={};n.vertices.forEach(e=>{e.x=i.roundNumber(e.x,2),e.y=i.roundNumber(e.y,2),e.z=i.roundNumber(e.z,2)}),s.vertices=n.vertices;const r=this._buildPolygonGroups(n);return s.groups=new Array(r.length),r.forEach((e,t)=>{const n=new Map;e.forEach((e,t)=>{n.set(e,t)});const r=new Array(e.length);e.forEach((e,t)=>{const a=[];e.neighbours.forEach(e=>a.push(n.get(e)));const c=[];e.neighbours.forEach(t=>c.push(this._getSharedVerticesInOrder(e,t)));const l=new o.Vector3(0,0,0);l.add(s.vertices[e.vertexIds[0]]),l.add(s.vertices[e.vertexIds[1]]),l.add(s.vertices[e.vertexIds[2]]),l.divideScalar(3),l.x=i.roundNumber(l.x,2),l.y=i.roundNumber(l.y,2),l.z=i.roundNumber(l.z,2),r[t]={id:t,neighbours:a,vertexIds:e.vertexIds,centroid:l,portals:c}}),s.groups[t]=r}),s}static _buildNavigationMesh(e,t){return e=i.mergeVertices(e,t),this._buildPolygonsFromGeometry(e)}static _spreadGroupId(e){let t=new Set([e]);for(;t.size>0;){const n=t;t=new Set,n.forEach(n=>{n.group=e.group,n.neighbours.forEach(e=>{void 0===e.group&&t.add(e)})})}}static _buildPolygonGroups(e){const t=[];return e.polygons.forEach(e=>{void 0!==e.group?t[e.group].push(e):(e.group=t.length,this._spreadGroupId(e),t.push([e]))}),t}static _buildPolygonNeighbours(e,t){const n=new Set,o=t[e.vertexIds[1]],i=t[e.vertexIds[2]];return t[e.vertexIds[0]].forEach(t=>{t!==e&&(o.includes(t)||i.includes(t))&&n.add(t)}),o.forEach(t=>{t!==e&&i.includes(t)&&n.add(t)}),n}static _buildPolygonsFromGeometry(e){const t=[],n=[],i=e.attributes.position,s=e.index,r=[];for(let e=0;e<i.count;e++)n.push((new o.Vector3).fromBufferAttribute(i,e)),r[e]=[];for(let n=0;n<e.index.count;n+=3){const e=s.getX(n),o=s.getX(n+1),i=s.getX(n+2),a={vertexIds:[e,o,i],neighbours:null};t.push(a),r[e].push(a),r[o].push(a),r[i].push(a)}return t.forEach(e=>{e.neighbours=this._buildPolygonNeighbours(e,r)}),{polygons:t,vertices:n}}static _getSharedVerticesInOrder(e,t){const n=e.vertexIds,o=n[0],i=n[1],s=n[2],r=t.vertexIds,a=r.includes(o),c=r.includes(i),l=r.includes(s);return a&&c&&l?Array.from(n):a&&c?[o,i]:c&&l?[i,s]:a&&l?[s,o]:(console.warn("Error processing navigation mesh neighbors; neighbors with <2 shared vertices found."),[])}}.buildZone(e,t)}setZoneData(e,t){this.zones[e]=t}getRandomNode(e,t,n,s){if(!this.zones[e])return new o.Vector3;n=n||null,s=s||0;const r=[];return this.zones[e].groups[t].forEach(e=>{n&&s?i.distanceToSquared(n,e.centroid)<s*s&&r.push(e.centroid):r.push(e.centroid)}),i.sample(r)||new o.Vector3}getClosestNode(e,t,n,o=!1){const s=this.zones[t].vertices;let r=null,a=1/0;return this.zones[t].groups[n].forEach(t=>{const n=i.distanceToSquared(t.centroid,e);n<a&&(!o||i.isVectorInPolygon(e,t,s))&&(r=t,a=n)}),r}findPath(e,t,n,a){const c=this.zones[n].groups[a],l=this.zones[n].vertices,d=this.getClosestNode(e,n,a,!0),h=this.getClosestNode(t,n,a,!0);if(!d||!h)return null;const u=class{static init(e){for(let t=0;t<e.length;t++){const n=e[t];n.f=0,n.g=0,n.h=0,n.cost=1,n.visited=!1,n.closed=!1,n.parent=null}}static cleanUp(e){for(let t=0;t<e.length;t++){const n=e[t];delete n.f,delete n.g,delete n.h,delete n.cost,delete n.visited,delete n.closed,delete n.parent}}static heap(){return new s(function(e){return e.f})}static search(e,t,n){this.init(e);const o=this.heap();for(o.push(t);o.size()>0;){const t=o.pop();if(t===n){let e=t;const n=[];for(;e.parent;)n.push(e),e=e.parent;return this.cleanUp(n),n.reverse()}t.closed=!0;const i=this.neighbours(e,t);for(let e=0,s=i.length;e<s;e++){const s=i[e];if(s.closed)continue;const r=t.g+s.cost,a=s.visited;if(!a||r<s.g){if(s.visited=!0,s.parent=t,!s.centroid||!n.centroid)throw new Error("Unexpected state");s.h=s.h||this.heuristic(s.centroid,n.centroid),s.g=r,s.f=s.g+s.h,a?o.rescoreElement(s):o.push(s)}}}return[]}static heuristic(e,t){return i.distanceToSquared(e,t)}static neighbours(e,t){const n=[];for(let o=0;o<t.neighbours.length;o++)n.push(e[t.neighbours[o]]);return n}}.search(c,d,h),p=function(e,t){for(var n=0;n<e.neighbours.length;n++)if(e.neighbours[n]===t.id)return e.portals[n]},f=new r;f.push(e);for(let e=0;e<u.length;e++){const t=u[e],n=u[e+1];if(n){const e=p(t,n);f.push(l[e[0]],l[e[1]])}}f.push(t),f.stringPull();const m=f.path.map(e=>new o.Vector3(e.x,e.y,e.z));return m.shift(),m}}a.prototype.getGroup=function(){const e=new o.Plane;return function(t,n,o=!1){if(!this.zones[t])return null;let s=null,r=Math.pow(50,2);const a=this.zones[t];for(let t=0;t<a.groups.length;t++){const c=a.groups[t];for(const l of c){if(o&&(e.setFromCoplanarPoints(a.vertices[l.vertexIds[0]],a.vertices[l.vertexIds[1]],a.vertices[l.vertexIds[2]]),Math.abs(e.distanceToPoint(n))<.01)&&i.isPointInPoly([a.vertices[l.vertexIds[0]],a.vertices[l.vertexIds[1]],a.vertices[l.vertexIds[2]]],n))return t;const c=i.distanceToSquared(l.centroid,n);c<r&&(s=t,r=c)}}return s}}(),a.prototype.clampStep=function(){const e=new o.Vector3,t=new o.Plane,n=new o.Triangle,i=new o.Vector3;let s,r,a=new o.Vector3;return function(o,c,l,d,h,u){const p=this.zones[d].vertices,f=this.zones[d].groups[h],m=[l],y={};y[l.id]=0,s=void 0,a.set(0,0,0),r=1/0,t.setFromCoplanarPoints(p[l.vertexIds[0]],p[l.vertexIds[1]],p[l.vertexIds[2]]),t.projectPoint(c,e),i.copy(e);for(let t=m.pop();t;t=m.pop()){n.set(p[t.vertexIds[0]],p[t.vertexIds[1]],p[t.vertexIds[2]]),n.closestPointToPoint(i,e),e.distanceToSquared(i)<r&&(s=t,a.copy(e),r=e.distanceToSquared(i));const o=y[t.id];if(!(o>2))for(let e=0;e<t.neighbours.length;e++){const n=f[t.neighbours[e]];n.id in y||(m.push(n),y[n.id]=o+1)}}return u.copy(a),s}}(),o.Object3D;const c=new a,l="level";AFRAME.registerSystem("nav",{init:function(){this.navMesh=null,this.agents=new Set},setNavMeshGeometry:function(e){this.navMesh=new THREE.Mesh(e),c.setZoneData(l,a.createZone(e)),Array.from(this.agents).forEach(e=>e.updateNavLocation())},getNavMesh:function(){return this.navMesh},addAgent:function(e){this.agents.add(e)},removeAgent:function(e){this.agents.delete(e)},getPath:function(e,t,n){return this.navMesh?c.findPath(e,t,l,n):null},getGroup:function(e){return this.navMesh?c.getGroup(l,e):null},getNode:function(e,t){return this.navMesh?c.getClosestNode(e,l,t,!0):null},clampStep:function(e,t,n,o,i){return this.navMesh?o?c.clampStep(e,t,o,l,n,i):(i.copy(t),this.getNode(t,n)):(i.copy(t),null)}})},451:(e,t,n)=>{"use strict";n(417);var o=n(612);class i extends o.DataTextureLoader{constructor(e){super(e)}parse(e){if(e.length<19)throw new Error("THREE.TGALoader: Not enough data to contain header.");let t=0;const n=new Uint8Array(e),i={id_length:n[t++],colormap_type:n[t++],image_type:n[t++],colormap_index:n[t++]|n[t++]<<8,colormap_length:n[t++]|n[t++]<<8,colormap_size:n[t++],origin:[n[t++]|n[t++]<<8,n[t++]|n[t++]<<8],width:n[t++]|n[t++]<<8,height:n[t++]|n[t++]<<8,pixel_size:n[t++],flags:n[t++]};if(function(e){switch(e.image_type){case 1:case 9:if(e.colormap_length>256||24!==e.colormap_size||1!==e.colormap_type)throw new Error("THREE.TGALoader: Invalid type colormap data for indexed type.");break;case 2:case 3:case 10:case 11:if(e.colormap_type)throw new Error("THREE.TGALoader: Invalid type colormap data for colormap type.");break;case 0:throw new Error("THREE.TGALoader: No data.");default:throw new Error("THREE.TGALoader: Invalid type "+e.image_type)}if(e.width<=0||e.height<=0)throw new Error("THREE.TGALoader: Invalid image size.");if(8!==e.pixel_size&&16!==e.pixel_size&&24!==e.pixel_size&&32!==e.pixel_size)throw new Error("THREE.TGALoader: Invalid pixel size "+e.pixel_size)}(i),i.id_length+t>e.length)throw new Error("THREE.TGALoader: No data.");t+=i.id_length;let s=!1,r=!1,a=!1;switch(i.image_type){case 9:s=!0,r=!0;break;case 1:r=!0;break;case 10:s=!0;break;case 2:break;case 11:s=!0,a=!0;break;case 3:a=!0}const c=new Uint8Array(i.width*i.height*4),l=function(e,t,n,o,i){let s,r;const a=n.pixel_size>>3,c=n.width*n.height*a;if(t&&(r=i.subarray(o,o+=n.colormap_length*(n.colormap_size>>3))),e){let e,t,n;s=new Uint8Array(c);let r=0;const l=new Uint8Array(a);for(;r<c;)if(e=i[o++],t=1+(127&e),128&e){for(n=0;n<a;++n)l[n]=i[o++];for(n=0;n<t;++n)s.set(l,r+n*a);r+=a*t}else{for(t*=a,n=0;n<t;++n)s[r+n]=i[o++];r+=t}}else s=i.subarray(o,o+=t?n.width*n.height:c);return{pixel_data:s,palettes:r}}(s,r,i,t,n);return function(e,t,n,o,s){let r,c,l,d,h,u;switch((48&i.flags)>>4){default:case 2:r=0,l=1,h=t,c=0,d=1,u=n;break;case 0:r=0,l=1,h=t,c=n-1,d=-1,u=-1;break;case 3:r=t-1,l=-1,h=-1,c=0,d=1,u=n;break;case 1:r=t-1,l=-1,h=-1,c=n-1,d=-1,u=-1}if(a)switch(i.pixel_size){case 8:!function(e,t,n,o,s,r,a,c){let l,d,h,u=0;const p=i.width;for(h=t;h!==o;h+=n)for(d=s;d!==a;d+=r,u++)l=c[u],e[4*(d+p*h)+0]=l,e[4*(d+p*h)+1]=l,e[4*(d+p*h)+2]=l,e[4*(d+p*h)+3]=255}(e,c,d,u,r,l,h,o);break;case 16:!function(e,t,n,o,s,r,a,c){let l,d,h=0;const u=i.width;for(d=t;d!==o;d+=n)for(l=s;l!==a;l+=r,h+=2)e[4*(l+u*d)+0]=c[h+0],e[4*(l+u*d)+1]=c[h+0],e[4*(l+u*d)+2]=c[h+0],e[4*(l+u*d)+3]=c[h+1]}(e,c,d,u,r,l,h,o);break;default:throw new Error("THREE.TGALoader: Format not supported.")}else switch(i.pixel_size){case 8:!function(e,t,n,o,s,r,a,c,l){const d=l;let h,u,p,f=0;const m=i.width;for(p=t;p!==o;p+=n)for(u=s;u!==a;u+=r,f++)h=c[f],e[4*(u+m*p)+3]=255,e[4*(u+m*p)+2]=d[3*h+0],e[4*(u+m*p)+1]=d[3*h+1],e[4*(u+m*p)+0]=d[3*h+2]}(e,c,d,u,r,l,h,o,s);break;case 16:!function(e,t,n,o,s,r,a,c){let l,d,h,u=0;const p=i.width;for(h=t;h!==o;h+=n)for(d=s;d!==a;d+=r,u+=2)l=c[u+0]+(c[u+1]<<8),e[4*(d+p*h)+0]=(31744&l)>>7,e[4*(d+p*h)+1]=(992&l)>>2,e[4*(d+p*h)+2]=(31&l)<<3,e[4*(d+p*h)+3]=32768&l?0:255}(e,c,d,u,r,l,h,o);break;case 24:!function(e,t,n,o,s,r,a,c){let l,d,h=0;const u=i.width;for(d=t;d!==o;d+=n)for(l=s;l!==a;l+=r,h+=3)e[4*(l+u*d)+3]=255,e[4*(l+u*d)+2]=c[h+0],e[4*(l+u*d)+1]=c[h+1],e[4*(l+u*d)+0]=c[h+2]}(e,c,d,u,r,l,h,o);break;case 32:!function(e,t,n,o,s,r,a,c){let l,d,h=0;const u=i.width;for(d=t;d!==o;d+=n)for(l=s;l!==a;l+=r,h+=4)e[4*(l+u*d)+2]=c[h+0],e[4*(l+u*d)+1]=c[h+1],e[4*(l+u*d)+0]=c[h+2],e[4*(l+u*d)+3]=c[h+3]}(e,c,d,u,r,l,h,o);break;default:throw new Error("THREE.TGALoader: Format not supported.")}}(c,i.width,i.height,l.pixel_data,l.palettes),{data:c,width:i.width,height:i.height,flipY:!0,generateMipmaps:!0,minFilter:o.LinearMipmapLinearFilter}}}class s extends o.Loader{load(e,t,n,i){const s=this,r=""===s.path?o.LoaderUtils.extractUrlBase(e):s.path,a=new o.FileLoader(s.manager);a.setPath(s.path),a.setRequestHeader(s.requestHeader),a.setWithCredentials(s.withCredentials),a.load(e,function(n){try{t(s.parse(n,r))}catch(t){i?i(t):console.error(t),s.manager.itemError(e)}},n,i)}parse(e,t){function n(e,t){const n=[],o=e.childNodes;for(let e=0,i=o.length;e<i;e++){const i=o[e];i.nodeName===t&&n.push(i)}return n}function s(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,o=t.length;e<o;e++)n[e]=t[e];return n}function r(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,o=t.length;e<o;e++)n[e]=parseFloat(t[e]);return n}function a(e){if(0===e.length)return[];const t=e.trim().split(/\s+/),n=new Array(t.length);for(let e=0,o=t.length;e<o;e++)n[e]=parseInt(t[e]);return n}function c(e){return e.substring(1)}function l(){return"three_default_"+et++}function d(e){return 0===Object.keys(e).length}function h(e){return void 0!==e&&!0===e.hasAttribute("meter")?parseFloat(e.getAttribute("meter")):1}function u(e){return void 0!==e?e.textContent:"Y_UP"}function p(e,t,o,i){const s=n(e,t)[0];if(void 0!==s){const e=n(s,o);for(let t=0;t<e.length;t++)i(e[t])}}function f(e,t){for(const n in e)e[n].build=t(e[n])}function m(e,t){return void 0!==e.build||(e.build=t(e)),e.build}function y(e){const t={inputs:{}};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType&&"input"===o.nodeName){const e=c(o.getAttribute("source")),n=o.getAttribute("semantic");t.inputs[n]=e}}return t}function g(e){const t={};let n=e.getAttribute("target").split("/");const o=n.shift();let i=n.shift();const s=-1!==i.indexOf("("),r=-1!==i.indexOf(".");if(r)n=i.split("."),i=n.shift(),t.member=n.shift();else if(s){const e=i.split("(");i=e.shift();for(let t=0;t<e.length;t++)e[t]=parseInt(e[t].replace(/\)/,""));t.indices=e}return t.id=o,t.sid=i,t.arraySyntax=s,t.memberSyntax=r,t.sampler=c(e.getAttribute("source")),t}function v(e){const t=[],n=e.channels,o=e.samplers,i=e.sources;for(const e in n)if(n.hasOwnProperty(e)){const s=n[e],r=o[s.sampler],a=r.inputs.INPUT,c=r.inputs.OUTPUT;A(w(s,i[a],i[c]),t)}return t}function b(e){return m(tt.animations[e],v)}function w(e,t,n){const o=tt.nodes[e.id],i=Be(o.id),s=o.transforms[e.sid],r=o.matrix.clone().transpose();let a,c,l,d,h,u;const p={};switch(s){case"matrix":for(l=0,d=t.array.length;l<d;l++)if(a=t.array[l],c=l*n.stride,void 0===p[a]&&(p[a]={}),!0===e.arraySyntax){const t=n.array[c],o=e.indices[0]+4*e.indices[1];p[a][o]=t}else for(h=0,u=n.stride;h<u;h++)p[a][h]=n.array[c+h];break;case"translate":case"rotate":case"scale":console.warn('THREE.ColladaLoader: Animation transform type "%s" not yet implemented.',s)}const f=function(e,t){const n=[];for(const t in e)n.push({time:parseFloat(t),value:e[t]});n.sort(function(e,t){return e.time-t.time});for(let e=0;e<16;e++)T(n,e,t.elements[e]);return n}(p,r);return{name:i.uuid,keyframes:f}}const x=new o.Vector3,k=new o.Vector3,E=new o.Quaternion;function A(e,t){const n=e.keyframes,i=e.name,s=[],r=[],a=[],c=[];for(let e=0,t=n.length;e<t;e++){const t=n[e],o=t.time,i=t.value;De.fromArray(i).transpose(),De.decompose(x,E,k),s.push(o),r.push(x.x,x.y,x.z),a.push(E.x,E.y,E.z,E.w),c.push(k.x,k.y,k.z)}return r.length>0&&t.push(new o.VectorKeyframeTrack(i+".position",s,r)),a.length>0&&t.push(new o.QuaternionKeyframeTrack(i+".quaternion",s,a)),c.length>0&&t.push(new o.VectorKeyframeTrack(i+".scale",s,c)),t}function T(e,t,n){let o,i,s,r=!0;for(i=0,s=e.length;i<s;i++)o=e[i],void 0===o.value[t]?o.value[t]=null:r=!1;if(!0===r)for(i=0,s=e.length;i<s;i++)o=e[i],o.value[t]=n;else!function(e,t){let n,o;for(let i=0,s=e.length;i<s;i++){const s=e[i];if(null===s.value[t]){if(n=N(e,i,t),o=M(e,i,t),null===n){s.value[t]=o.value[t];continue}if(null===o){s.value[t]=n.value[t];continue}C(s,n,o,t)}}}(e,t)}function N(e,t,n){for(;t>=0;){const o=e[t];if(null!==o.value[n])return o;t--}return null}function M(e,t,n){for(;t<e.length;){const o=e[t];if(null!==o.value[n])return o;t++}return null}function C(e,t,n,o){n.time-t.time!==0?e.value[o]=(e.time-t.time)*(n.value[o]-t.value[o])/(n.time-t.time)+t.value[o]:e.value[o]=t.value[o]}function D(e){const t=[],n=e.name,i=e.end-e.start||-1,s=e.animations;for(let e=0,n=s.length;e<n;e++){const n=b(s[e]);for(let e=0,o=n.length;e<o;e++)t.push(n[e])}return new o.AnimationClip(n,i,t)}function L(e){return m(tt.clips[e],D)}function O(e){const t={sources:{}};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"bind_shape_matrix":t.bindShapeMatrix=r(o.textContent);break;case"source":const e=o.getAttribute("id");t.sources[e]=le(o);break;case"joints":t.joints=R(o);break;case"vertex_weights":t.vertexWeights=I(o)}}return t}function R(e){const t={inputs:{}};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType&&"input"===o.nodeName){const e=o.getAttribute("semantic"),n=c(o.getAttribute("source"));t.inputs[e]=n}}return t}function I(e){const t={inputs:{}};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"input":const e=o.getAttribute("semantic"),n=c(o.getAttribute("source")),i=parseInt(o.getAttribute("offset"));t.inputs[e]={id:n,offset:i};break;case"vcount":t.vcount=a(o.textContent);break;case"v":t.v=a(o.textContent)}}return t}function S(e){const t={id:e.id},n=tt.geometries[t.id];return void 0!==e.skin&&(t.skin=function(e){const t={joints:[],indices:{array:[],stride:4},weights:{array:[],stride:4}},n=e.sources,i=e.vertexWeights,s=i.vcount,r=i.v,a=i.inputs.JOINT.offset,c=i.inputs.WEIGHT.offset,l=e.sources[e.joints.inputs.JOINT],d=e.sources[e.joints.inputs.INV_BIND_MATRIX],h=n[i.inputs.WEIGHT.id].array;let u,p,f,m=0;for(u=0,f=s.length;u<f;u++){const e=s[u],n=[];for(p=0;p<e;p++){const e=r[m+a],t=h[r[m+c]];n.push({index:e,weight:t}),m+=2}for(n.sort(y),p=0;p<4;p++){const e=n[p];void 0!==e?(t.indices.array.push(e.index),t.weights.array.push(e.weight)):(t.indices.array.push(0),t.weights.array.push(0))}}for(e.bindShapeMatrix?t.bindMatrix=(new o.Matrix4).fromArray(e.bindShapeMatrix).transpose():t.bindMatrix=(new o.Matrix4).identity(),u=0,f=l.array.length;u<f;u++){const e=l.array[u],n=(new o.Matrix4).fromArray(d.array,u*d.stride).transpose();t.joints.push({name:e,boneInverse:n})}return t;function y(e,t){return t.weight-e.weight}}(e.skin),n.sources.skinIndices=t.skin.indices,n.sources.skinWeights=t.skin.weights),t}function P(e){return m(tt.controllers[e],S)}function _(e){return void 0!==e.build?e.build:e.init_from}function F(e){const t=tt.images[e];return void 0!==t?m(t,_):(console.warn("THREE.ColladaLoader: Couldn't find image with ID:",e),null)}function V(e){const t={surfaces:{},samplers:{}};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"newparam":j(o,t);break;case"technique":t.technique=z(o);break;case"extra":t.extra=W(o)}}return t}function j(e,t){const n=e.getAttribute("sid");for(let o=0,i=e.childNodes.length;o<i;o++){const i=e.childNodes[o];if(1===i.nodeType)switch(i.nodeName){case"surface":t.surfaces[n]=B(i);break;case"sampler2D":t.samplers[n]=K(i)}}}function B(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];1===o.nodeType&&"init_from"===o.nodeName&&(t.init_from=o.textContent)}return t}function K(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];1===o.nodeType&&"source"===o.nodeName&&(t.source=o.textContent)}return t}function z(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"constant":case"lambert":case"blinn":case"phong":t.type=o.nodeName,t.parameters=U(o);break;case"extra":t.extra=W(o)}}return t}function U(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"emission":case"diffuse":case"specular":case"bump":case"ambient":case"shininess":case"transparency":t[o.nodeName]=H(o);break;case"transparent":t[o.nodeName]={opaque:o.hasAttribute("opaque")?o.getAttribute("opaque"):"A_ONE",data:H(o)}}}return t}function H(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"color":t[o.nodeName]=r(o.textContent);break;case"float":t[o.nodeName]=parseFloat(o.textContent);break;case"texture":t[o.nodeName]={id:o.getAttribute("texture"),extra:G(o)}}}return t}function G(e){const t={technique:{}};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];1===o.nodeType&&"extra"===o.nodeName&&q(o,t)}return t}function q(e,t){for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];1===o.nodeType&&"technique"===o.nodeName&&X(o,t)}}function X(e,t){for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"repeatU":case"repeatV":case"offsetU":case"offsetV":t.technique[o.nodeName]=parseFloat(o.textContent);break;case"wrapU":case"wrapV":"TRUE"===o.textContent.toUpperCase()?t.technique[o.nodeName]=1:"FALSE"===o.textContent.toUpperCase()?t.technique[o.nodeName]=0:t.technique[o.nodeName]=parseInt(o.textContent);break;case"bump":t[o.nodeName]=Z(o)}}}function W(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];1===o.nodeType&&"technique"===o.nodeName&&(t.technique=J(o))}return t}function J(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"double_sided":t[o.nodeName]=parseInt(o.textContent);break;case"bump":t[o.nodeName]=Z(o)}}return t}function Z(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];1===o.nodeType&&"texture"===o.nodeName&&(t[o.nodeName]={id:o.getAttribute("texture"),texcoord:o.getAttribute("texcoord"),extra:G(o)})}return t}function Y(e){return e}function Q(e){const t=(n=e.url,m(tt.effects[n],Y));var n;const i=t.profile.technique;let s;switch(i.type){case"phong":case"blinn":s=new o.MeshPhongMaterial;break;case"lambert":s=new o.MeshLambertMaterial;break;default:s=new o.MeshBasicMaterial}function r(e,n=null){const i=t.profile.samplers[e.id];let s=null;if(void 0!==i?s=F(t.profile.surfaces[i.source].init_from):(console.warn("THREE.ColladaLoader: Undefined sampler. Access image directly (see #12530)."),s=F(e.id)),null!==s){const t=function(e){let t,n=e.slice((e.lastIndexOf(".")-1>>>0)+2);return n=n.toLowerCase(),t="tga"===n?Ze:Je,t}(s);if(void 0!==t){const i=t.load(s),r=e.extra;if(void 0!==r&&void 0!==r.technique&&!1===d(r.technique)){const e=r.technique;i.wrapS=e.wrapU?o.RepeatWrapping:o.ClampToEdgeWrapping,i.wrapT=e.wrapV?o.RepeatWrapping:o.ClampToEdgeWrapping,i.offset.set(e.offsetU||0,e.offsetV||0),i.repeat.set(e.repeatU||1,e.repeatV||1)}else i.wrapS=o.RepeatWrapping,i.wrapT=o.RepeatWrapping;return null!==n&&(i.colorSpace=n),i}return console.warn("THREE.ColladaLoader: Loader for texture %s not found.",s),null}return console.warn("THREE.ColladaLoader: Couldn't create texture with ID:",e.id),null}s.name=e.name||"";const a=i.parameters;for(const e in a){const t=a[e];switch(e){case"diffuse":t.color&&s.color.fromArray(t.color),t.texture&&(s.map=r(t.texture,o.SRGBColorSpace));break;case"specular":t.color&&s.specular&&s.specular.fromArray(t.color),t.texture&&(s.specularMap=r(t.texture));break;case"bump":t.texture&&(s.normalMap=r(t.texture));break;case"ambient":t.texture&&(s.lightMap=r(t.texture,o.SRGBColorSpace));break;case"shininess":t.float&&s.shininess&&(s.shininess=t.float);break;case"emission":t.color&&s.emissive&&s.emissive.fromArray(t.color),t.texture&&(s.emissiveMap=r(t.texture,o.SRGBColorSpace))}}s.color.convertSRGBToLinear(),s.specular&&s.specular.convertSRGBToLinear(),s.emissive&&s.emissive.convertSRGBToLinear();let c=a.transparent,l=a.transparency;if(void 0===l&&c&&(l={float:1}),void 0===c&&l&&(c={opaque:"A_ONE",data:{color:[1,1,1,1]}}),c&&l)if(c.data.texture)s.transparent=!0;else{const e=c.data.color;switch(c.opaque){case"A_ONE":s.opacity=e[3]*l.float;break;case"RGB_ZERO":s.opacity=1-e[0]*l.float;break;case"A_ZERO":s.opacity=1-e[3]*l.float;break;case"RGB_ONE":s.opacity=e[0]*l.float;break;default:console.warn('THREE.ColladaLoader: Invalid opaque type "%s" of transparent tag.',c.opaque)}s.opacity<1&&(s.transparent=!0)}if(void 0!==i.extra&&void 0!==i.extra.technique){const e=i.extra.technique;for(const t in e){const n=e[t];switch(t){case"double_sided":s.side=1===n?o.DoubleSide:o.FrontSide;break;case"bump":s.normalMap=r(n.texture),s.normalScale=new o.Vector2(1,1)}}}return s}function $(e){return m(tt.materials[e],Q)}function ee(e){for(let t=0;t<e.childNodes.length;t++){const n=e.childNodes[t];if("technique_common"===n.nodeName)return te(n)}return{}}function te(e){const t={};for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];switch(o.nodeName){case"perspective":case"orthographic":t.technique=o.nodeName,t.parameters=ne(o)}}return t}function ne(e){const t={};for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];switch(o.nodeName){case"xfov":case"yfov":case"xmag":case"ymag":case"znear":case"zfar":case"aspect_ratio":t[o.nodeName]=parseFloat(o.textContent)}}return t}function oe(e){let t;switch(e.optics.technique){case"perspective":t=new o.PerspectiveCamera(e.optics.parameters.yfov,e.optics.parameters.aspect_ratio,e.optics.parameters.znear,e.optics.parameters.zfar);break;case"orthographic":let n=e.optics.parameters.ymag,i=e.optics.parameters.xmag;const s=e.optics.parameters.aspect_ratio;i=void 0===i?n*s:i,n=void 0===n?i/s:n,i*=.5,n*=.5,t=new o.OrthographicCamera(-i,i,n,-n,e.optics.parameters.znear,e.optics.parameters.zfar);break;default:t=new o.PerspectiveCamera}return t.name=e.name||"",t}function ie(e){const t=tt.cameras[e];return void 0!==t?m(t,oe):(console.warn("THREE.ColladaLoader: Couldn't find camera with ID:",e),null)}function se(e){const t={};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"directional":case"point":case"spot":case"ambient":t.technique=o.nodeName,t.parameters=re(o)}}return t}function re(e){const t={};for(let n=0,i=e.childNodes.length;n<i;n++){const i=e.childNodes[n];if(1===i.nodeType)switch(i.nodeName){case"color":const e=r(i.textContent);t.color=(new o.Color).fromArray(e).convertSRGBToLinear();break;case"falloff_angle":t.falloffAngle=parseFloat(i.textContent);break;case"quadratic_attenuation":const n=parseFloat(i.textContent);t.distance=n?Math.sqrt(1/n):0}}return t}function ae(e){let t;switch(e.technique){case"directional":t=new o.DirectionalLight;break;case"point":t=new o.PointLight;break;case"spot":t=new o.SpotLight;break;case"ambient":t=new o.AmbientLight}return e.parameters.color&&t.color.copy(e.parameters.color),e.parameters.distance&&(t.distance=e.parameters.distance),t}function ce(e){const t=tt.lights[e];return void 0!==t?m(t,ae):(console.warn("THREE.ColladaLoader: Couldn't find light with ID:",e),null)}function le(e){const t={array:[],stride:3};for(let o=0;o<e.childNodes.length;o++){const i=e.childNodes[o];if(1===i.nodeType)switch(i.nodeName){case"float_array":t.array=r(i.textContent);break;case"Name_array":t.array=s(i.textContent);break;case"technique_common":const e=n(i,"accessor")[0];void 0!==e&&(t.stride=parseInt(e.getAttribute("stride")))}}return t}function de(e){const t={};for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];1===o.nodeType&&(t[o.getAttribute("semantic")]=c(o.getAttribute("source")))}return t}function he(e){const t={type:e.nodeName,material:e.getAttribute("material"),count:parseInt(e.getAttribute("count")),inputs:{},stride:0,hasUV:!1};for(let n=0,o=e.childNodes.length;n<o;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"input":const e=c(o.getAttribute("source")),n=o.getAttribute("semantic"),i=parseInt(o.getAttribute("offset")),s=parseInt(o.getAttribute("set")),r=s>0?n+s:n;t.inputs[r]={id:e,offset:i},t.stride=Math.max(t.stride,i+1),"TEXCOORD"===n&&(t.hasUV=!0);break;case"vcount":t.vcount=a(o.textContent);break;case"p":t.p=a(o.textContent)}}return t}function ue(e){let t=0;for(let n=0,o=e.length;n<o;n++)!0===e[n].hasUV&&t++;t>0&&t<e.length&&(e.uvsNeedsFix=!0)}function pe(e){const t={},n=e.sources,o=e.vertices,i=e.primitives;if(0===i.length)return{};const s=function(e){const t={};for(let n=0;n<e.length;n++){const o=e[n];void 0===t[o.type]&&(t[o.type]=[]),t[o.type].push(o)}return t}(i);for(const e in s){const i=s[e];ue(i),t[e]=fe(i,n,o)}return t}function fe(e,t,n){const i={},s={array:[],stride:0},r={array:[],stride:0},a={array:[],stride:0},c={array:[],stride:0},l={array:[],stride:0},d=[],h=[],u=new o.BufferGeometry,p=[];let f=0;for(let o=0;o<e.length;o++){const i=e[o],m=i.inputs;let y=0;switch(i.type){case"lines":case"linestrips":y=2*i.count;break;case"triangles":y=3*i.count;break;case"polylist":for(let e=0;e<i.count;e++){const t=i.vcount[e];switch(t){case 3:y+=3;break;case 4:y+=6;break;default:y+=3*(t-2)}}break;default:console.warn("THREE.ColladaLoader: Unknow primitive type:",i.type)}u.addGroup(f,y,o),f+=y,i.material&&p.push(i.material);for(const o in m){const u=m[o];switch(o){case"VERTEX":for(const o in n){const p=n[o];switch(o){case"POSITION":const n=s.array.length;if(me(i,t[p],u.offset,s.array),s.stride=t[p].stride,t.skinWeights&&t.skinIndices&&(me(i,t.skinIndices,u.offset,d),me(i,t.skinWeights,u.offset,h)),!1===i.hasUV&&!0===e.uvsNeedsFix){const e=(s.array.length-n)/s.stride;for(let t=0;t<e;t++)a.array.push(0,0)}break;case"NORMAL":me(i,t[p],u.offset,r.array),r.stride=t[p].stride;break;case"COLOR":me(i,t[p],u.offset,l.array),l.stride=t[p].stride;break;case"TEXCOORD":me(i,t[p],u.offset,a.array),a.stride=t[p].stride;break;case"TEXCOORD1":me(i,t[p],u.offset,c.array),a.stride=t[p].stride;break;default:console.warn('THREE.ColladaLoader: Semantic "%s" not handled in geometry build process.',o)}}break;case"NORMAL":me(i,t[u.id],u.offset,r.array),r.stride=t[u.id].stride;break;case"COLOR":me(i,t[u.id],u.offset,l.array,!0),l.stride=t[u.id].stride;break;case"TEXCOORD":me(i,t[u.id],u.offset,a.array),a.stride=t[u.id].stride;break;case"TEXCOORD1":me(i,t[u.id],u.offset,c.array),c.stride=t[u.id].stride}}}return s.array.length>0&&u.setAttribute("position",new o.Float32BufferAttribute(s.array,s.stride)),r.array.length>0&&u.setAttribute("normal",new o.Float32BufferAttribute(r.array,r.stride)),l.array.length>0&&u.setAttribute("color",new o.Float32BufferAttribute(l.array,l.stride)),a.array.length>0&&u.setAttribute("uv",new o.Float32BufferAttribute(a.array,a.stride)),c.array.length>0&&u.setAttribute("uv1",new o.Float32BufferAttribute(c.array,c.stride)),d.length>0&&u.setAttribute("skinIndex",new o.Float32BufferAttribute(d,4)),h.length>0&&u.setAttribute("skinWeight",new o.Float32BufferAttribute(h,4)),i.data=u,i.type=e[0].type,i.materialKeys=p,i}function me(e,t,n,o,i=!1){const s=e.p,r=e.stride,a=e.vcount;function c(e){let t=s[e+n]*d;const r=t+d;for(;t<r;t++)o.push(l[t]);if(i){const e=o.length-d-1;Ye.setRGB(o[e+0],o[e+1],o[e+2]).convertSRGBToLinear(),o[e+0]=Ye.r,o[e+1]=Ye.g,o[e+2]=Ye.b}}const l=t.array,d=t.stride;if(void 0!==e.vcount){let e=0;for(let t=0,n=a.length;t<n;t++){const n=a[t];if(4===n){const t=e+1*r,n=e+2*r,o=e+3*r;c(e+0*r),c(t),c(o),c(t),c(n),c(o)}else if(3===n){const t=e+1*r,n=e+2*r;c(e+0*r),c(t),c(n)}else if(n>4)for(let t=1,o=n-2;t<=o;t++){const n=e+r*t,o=e+r*(t+1);c(e+0*r),c(n),c(o)}e+=r*n}}else for(let e=0,t=s.length;e<t;e+=r)c(e)}function ye(e){return m(tt.geometries[e],pe)}function ge(e){return void 0!==e.build?e.build:e}function ve(e,t){for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"joint":t.joints[o.getAttribute("sid")]=be(o);break;case"link":t.links.push(xe(o))}}}function be(e){let t;for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"prismatic":case"revolute":t=we(o)}}return t}function we(e){const t={sid:e.getAttribute("sid"),name:e.getAttribute("name")||"",axis:new o.Vector3,limits:{min:0,max:0},type:e.nodeName,static:!1,zeroPosition:0,middlePosition:0};for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"axis":const e=r(o.textContent);t.axis.fromArray(e);break;case"limits":const n=o.getElementsByTagName("max")[0],i=o.getElementsByTagName("min")[0];t.limits.max=parseFloat(n.textContent),t.limits.min=parseFloat(i.textContent)}}return t.limits.min>=t.limits.max&&(t.static=!0),t.middlePosition=(t.limits.min+t.limits.max)/2,t}function xe(e){const t={sid:e.getAttribute("sid"),name:e.getAttribute("name")||"",attachments:[],transforms:[]};for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"attachment_full":t.attachments.push(ke(o));break;case"matrix":case"translate":case"rotate":t.transforms.push(Ee(o))}}return t}function ke(e){const t={joint:e.getAttribute("joint").split("/").pop(),transforms:[],links:[]};for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"link":t.links.push(xe(o));break;case"matrix":case"translate":case"rotate":t.transforms.push(Ee(o))}}return t}function Ee(e){const t={type:e.nodeName},n=r(e.textContent);switch(t.type){case"matrix":t.obj=new o.Matrix4,t.obj.fromArray(n).transpose();break;case"translate":t.obj=new o.Vector3,t.obj.fromArray(n);break;case"rotate":t.obj=new o.Vector3,t.obj.fromArray(n),t.angle=o.MathUtils.degToRad(n[3])}return t}function Ae(e,t){for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];1===o.nodeType&&"technique_common"===o.nodeName&&Te(o,t)}}function Te(e,t){for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];if(1===o.nodeType)switch(o.nodeName){case"inertia":t.inertia=r(o.textContent);break;case"mass":t.mass=r(o.textContent)[0]}}}function Ne(e){const t={target:e.getAttribute("target").split("/").pop()};for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];if(1===o.nodeType&&"axis"===o.nodeName){const e=o.getElementsByTagName("param")[0];t.axis=e.textContent;const n=t.axis.split("inst_").pop().split("axis")[0];t.jointIndex=n.substring(0,n.length-1)}}return t}function Me(e){return void 0!==e.build?e.build:e}function Ce(e){const t=[],n=Ge.querySelector('[id="'+e.id+'"]');for(let e=0;e<n.childNodes.length;e++){const i=n.childNodes[e];if(1!==i.nodeType)continue;let s,a;switch(i.nodeName){case"matrix":s=r(i.textContent);const e=(new o.Matrix4).fromArray(s).transpose();t.push({sid:i.getAttribute("sid"),type:i.nodeName,obj:e});break;case"translate":case"scale":s=r(i.textContent),a=(new o.Vector3).fromArray(s),t.push({sid:i.getAttribute("sid"),type:i.nodeName,obj:a});break;case"rotate":s=r(i.textContent),a=(new o.Vector3).fromArray(s);const n=o.MathUtils.degToRad(s[3]);t.push({sid:i.getAttribute("sid"),type:i.nodeName,obj:a,angle:n})}}return t}const De=new o.Matrix4,Le=new o.Vector3;function Oe(e){const t={name:e.getAttribute("name")||"",type:e.getAttribute("type"),id:e.getAttribute("id"),sid:e.getAttribute("sid"),matrix:new o.Matrix4,nodes:[],instanceCameras:[],instanceControllers:[],instanceLights:[],instanceGeometries:[],instanceNodes:[],transforms:{}};for(let n=0;n<e.childNodes.length;n++){const i=e.childNodes[n];if(1!==i.nodeType)continue;let s;switch(i.nodeName){case"node":t.nodes.push(i.getAttribute("id")),Oe(i);break;case"instance_camera":t.instanceCameras.push(c(i.getAttribute("url")));break;case"instance_controller":t.instanceControllers.push(Re(i));break;case"instance_light":t.instanceLights.push(c(i.getAttribute("url")));break;case"instance_geometry":t.instanceGeometries.push(Re(i));break;case"instance_node":t.instanceNodes.push(c(i.getAttribute("url")));break;case"matrix":s=r(i.textContent),t.matrix.multiply(De.fromArray(s).transpose()),t.transforms[i.getAttribute("sid")]=i.nodeName;break;case"translate":s=r(i.textContent),Le.fromArray(s),t.matrix.multiply(De.makeTranslation(Le.x,Le.y,Le.z)),t.transforms[i.getAttribute("sid")]=i.nodeName;break;case"rotate":s=r(i.textContent);const e=o.MathUtils.degToRad(s[3]);t.matrix.multiply(De.makeRotationAxis(Le.fromArray(s),e)),t.transforms[i.getAttribute("sid")]=i.nodeName;break;case"scale":s=r(i.textContent),t.matrix.scale(Le.fromArray(s)),t.transforms[i.getAttribute("sid")]=i.nodeName;break;case"extra":break;default:console.log(i)}}return je(t.id)?console.warn("THREE.ColladaLoader: There is already a node with ID %s. Exclude current node from further processing.",t.id):tt.nodes[t.id]=t,t}function Re(e){const t={id:c(e.getAttribute("url")),materials:{},skeletons:[]};for(let n=0;n<e.childNodes.length;n++){const o=e.childNodes[n];switch(o.nodeName){case"bind_material":const e=o.getElementsByTagName("instance_material");for(let n=0;n<e.length;n++){const o=e[n],i=o.getAttribute("symbol"),s=o.getAttribute("target");t.materials[i]=c(s)}break;case"skeleton":t.skeletons.push(c(o.textContent))}}return t}function Ie(e,t){const n=[],i=[];let s,r,a;for(s=0;s<e.length;s++){const o=e[s];let i;if(je(o))i=Be(o),Se(i,t,n);else if(ze(o)){const e=tt.visualScenes[o].children;for(let o=0;o<e.length;o++){const i=e[o];"JOINT"===i.type&&Se(Be(i.id),t,n)}}else console.error("THREE.ColladaLoader: Unable to find root bone of skeleton with ID:",o)}for(s=0;s<t.length;s++)for(r=0;r<n.length;r++)if(a=n[r],a.bone.name===t[s].name){i[s]=a,a.processed=!0;break}for(s=0;s<n.length;s++)a=n[s],!1===a.processed&&(i.push(a),a.processed=!0);const c=[],l=[];for(s=0;s<i.length;s++)a=i[s],c.push(a.bone),l.push(a.boneInverse);return new o.Skeleton(c,l)}function Se(e,t,n){e.traverse(function(e){if(!0===e.isBone){let i;for(let n=0;n<t.length;n++){const o=t[n];if(o.name===e.name){i=o.boneInverse;break}}void 0===i&&(i=new o.Matrix4),n.push({bone:e,boneInverse:i,processed:!1})}})}function Pe(e){const t=[],n=e.matrix,i=e.nodes,s=e.type,r=e.instanceCameras,a=e.instanceControllers,c=e.instanceLights,l=e.instanceGeometries,d=e.instanceNodes;for(let e=0,n=i.length;e<n;e++)t.push(Be(i[e]));for(let e=0,n=r.length;e<n;e++){const n=ie(r[e]);null!==n&&t.push(n.clone())}for(let e=0,n=a.length;e<n;e++){const n=a[e],o=P(n.id),i=Ve(ye(o.id),n.materials),s=Ie(n.skeletons,o.skin.joints);for(let e=0,n=i.length;e<n;e++){const n=i[e];n.isSkinnedMesh&&(n.bind(s,o.skin.bindMatrix),n.normalizeSkinWeights()),t.push(n)}}for(let e=0,n=c.length;e<n;e++){const n=ce(c[e]);null!==n&&t.push(n.clone())}for(let e=0,n=l.length;e<n;e++){const n=l[e],o=Ve(ye(n.id),n.materials);for(let e=0,n=o.length;e<n;e++)t.push(o[e])}for(let e=0,n=d.length;e<n;e++)t.push(Be(d[e]).clone());let h;if(0===i.length&&1===t.length)h=t[0];else{h="JOINT"===s?new o.Bone:new o.Group;for(let e=0;e<t.length;e++)h.add(t[e])}return h.name="JOINT"===s?e.sid:e.name,h.matrix.copy(n),h.matrix.decompose(h.position,h.quaternion,h.scale),h}const _e=new o.MeshBasicMaterial({name:o.Loader.DEFAULT_MATERIAL_NAME,color:16711935});function Fe(e,t){const n=[];for(let o=0,i=e.length;o<i;o++){const i=t[e[o]];void 0===i?(console.warn("THREE.ColladaLoader: Material with key %s not found. Apply fallback material.",e[o]),n.push(_e)):n.push($(i))}return n}function Ve(e,t){const n=[];for(const i in e){const s=e[i],r=Fe(s.materialKeys,t);if(0===r.length&&("lines"===i||"linestrips"===i?r.push(new o.LineBasicMaterial):r.push(new o.MeshPhongMaterial)),"lines"===i||"linestrips"===i)for(let e=0,t=r.length;e<t;e++){const t=r[e];if(!0===t.isMeshPhongMaterial||!0===t.isMeshLambertMaterial){const n=new o.LineBasicMaterial;n.color.copy(t.color),n.opacity=t.opacity,n.transparent=t.transparent,r[e]=n}}const a=void 0!==s.data.attributes.skinIndex,c=1===r.length?r[0]:r;let l;switch(i){case"lines":l=new o.LineSegments(s.data,c);break;case"linestrips":l=new o.Line(s.data,c);break;case"triangles":case"polylist":l=a?new o.SkinnedMesh(s.data,c):new o.Mesh(s.data,c)}n.push(l)}return n}function je(e){return void 0!==tt.nodes[e]}function Be(e){return m(tt.nodes[e],Pe)}function Ke(e){const t=new o.Group;t.name=e.name;const n=e.children;for(let e=0;e<n.length;e++){const o=n[e];t.add(Be(o.id))}return t}function ze(e){return void 0!==tt.visualScenes[e]}function Ue(e){return m(tt.visualScenes[e],Ke)}if(0===e.length)return{scene:new o.Scene};const He=(new DOMParser).parseFromString(e,"application/xml"),Ge=n(He,"COLLADA")[0],qe=He.getElementsByTagName("parsererror")[0];if(void 0!==qe){const e=n(qe,"div")[0];let t;return t=e?e.textContent:function(e){let t="";const n=[e];for(;n.length;){const e=n.shift();e.nodeType===Node.TEXT_NODE?t+=e.textContent:(t+="\n",n.push.apply(n,e.childNodes))}return t.trim()}(qe),console.error("THREE.ColladaLoader: Failed to parse collada file.\n",t),null}const Xe=Ge.getAttribute("version");console.debug("THREE.ColladaLoader: File version",Xe);const We=function(e){return{unit:h(n(e,"unit")[0]),upAxis:u(n(e,"up_axis")[0])}}(n(Ge,"asset")[0]),Je=new o.TextureLoader(this.manager);let Ze;Je.setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin),i&&(Ze=new i(this.manager),Ze.setPath(this.resourcePath||t));const Ye=new o.Color,Qe=[];let $e={},et=0;const tt={animations:{},clips:{},controllers:{},images:{},effects:{},materials:{},c