/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/maybe","../../../chunks/mat4f64","./DefaultErrorContext","./LoaderResult","./internal/Resource","../../webgl/enums"],(function(e,t,o,r,n,s,i,a){"use strict";let l=0;function u(e,t){return c.apply(this,arguments)}function c(){return c=t._asyncToGenerator((function*(e,n,s={},u=!0){const c=yield i.Resource.load(e,x,n,s),p="gltf_"+l++,f={lods:[],materials:new Map,textures:new Map,meta:d(c)},h=!(!c.json.asset.extras||"symbolResource"!==c.json.asset.extras.ESRI_type),S=new Map;yield m(c,function(){var e=t._asyncToGenerator((function*(e,t,n,i){var l;const d=null!=(l=S.get(n))?l:0;S.set(n,d+1);const m=void 0!==e.mode?e.mode:a.PrimitiveType.TRIANGLES,h=m===a.PrimitiveType.TRIANGLES||m===a.PrimitiveType.TRIANGLE_STRIP||m===a.PrimitiveType.TRIANGLE_FAN?m:null;if(o.isNone(h))return void x.warnUnsupported("Unsupported primitive mode ("+y[m]+"). Skipping primitive.");if(!c.hasPositions(e))return void x.warn("Skipping primitive without POSITION vertex attribute.");const _=c.getPositionData(e,s),I=c.getMaterial(e,s,u),R=c.hasNormals(e)?c.getNormalData(e,s):null,g=c.hasTangents(e)?c.getTangentData(e,s):null,v=c.hasTextureCoordinates(e)?c.getTextureCoordinates(e,s):null,E=c.hasVertexColors(e)?c.getVertexColors(e,s):null,M=c.getIndexData(e,s),N={transform:r.clone(t),attributes:{position:yield _,normal:R?yield R:null,texCoord0:v?yield v:null,color:E?yield E:null,tangent:g?yield g:null},indices:yield M,primitiveType:h,material:T(f,yield I,p)};let P=null;o.isSome(f.meta)&&o.isSome(f.meta.ESRI_lod)&&"screenSpaceRadius"===f.meta.ESRI_lod.metric&&(P=f.meta.ESRI_lod.thresholds[n]),f.lods[n]=f.lods[n]||{parts:[],name:i,lodThreshold:P},f.lods[n].parts[d]=N}));return function(t,o,r,n){return e.apply(this,arguments)}}());for(const t of f.lods)t.parts=t.parts.filter((e=>!!e));return{model:f,meta:{isEsriSymbolResource:h,uri:c.uri},customMeta:{}}})),c.apply(this,arguments)}function d(e){const t=e.json;let r=null;return t.nodes.forEach((e=>{const t=e.extras;o.isSome(t)&&(t.ESRI_proxyEllipsoid||t.ESRI_lod)&&(r=t)})),r}function m(e,t){return p.apply(this,arguments)}function p(){return p=t._asyncToGenerator((function*(e,o){const r=e.json,n=r.scenes[r.scene||0].nodes,s=n.length>1,i=[];for(const t of n){const e=r.nodes[t];if(i.push(a(t,0)),f(e)&&!s){e.extensions.MSFT_lod.ids.forEach(((e,t)=>a(e,t+1)))}}function a(e,t){return l.apply(this,arguments)}function l(){return(l=t._asyncToGenerator((function*(t,n){const s=r.nodes[t],l=e.getNodeTransform(t);if(x.warnUnsupportedIf(null!=s.weights,"Morph targets are not supported."),null!=s.mesh){const e=r.meshes[s.mesh];for(const t of e.primitives)i.push(o(t,l,n,e.name))}for(const e of s.children||[])i.push(a(e,n))}))).apply(this,arguments)}yield Promise.all(i)})),p.apply(this,arguments)}function f(e){return e.extensions&&e.extensions.MSFT_lod&&Array.isArray(e.extensions.MSFT_lod.ids)}function T(e,t,o){const r=t=>{const r=`${o}_tex_${t&&t.id}${t&&t.name?"_"+t.name:""}`;if(t&&!e.textures.has(r)){const o=s.makeTextureSource(t.data,{wrap:{s:t.wrapS,t:t.wrapT},mipmap:h.includes(t.minFilter),noUnpackFlip:!0});e.textures.set(r,o)}return r},n=`${o}_mat_${t.id}_${t.name}`;if(!e.materials.has(n)){const o=s.makeMaterialParameters({color:[t.color[0],t.color[1],t.color[2]],opacity:t.color[3],alphaMode:t.alphaMode,alphaCutoff:t.alphaCutoff,doubleSided:t.doubleSided,colorMixMode:t.ESRI_externalColorMixMode,textureColor:t.colorTexture?r(t.colorTexture):void 0,textureNormal:t.normalTexture?r(t.normalTexture):void 0,textureOcclusion:t.occlusionTexture?r(t.occlusionTexture):void 0,textureEmissive:t.emissiveTexture?r(t.emissiveTexture):void 0,textureMetallicRoughness:t.metallicRoughnessTexture?r(t.metallicRoughnessTexture):void 0,emissiveFactor:[t.emissiveFactor[0],t.emissiveFactor[1],t.emissiveFactor[2]],metallicFactor:t.metallicFactor,roughnessFactor:t.roughnessFactor});e.materials.set(n,o)}return n}const x=new n.DefaultErrorContext,h=[a.TextureSamplingMode.LINEAR_MIPMAP_LINEAR,a.TextureSamplingMode.LINEAR_MIPMAP_NEAREST],y=["POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLES","TRIANGLE_STRIP","TRIANGLE_FAN"];e.load=u,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
