16 | function t(e,t,n,i){return new(n||(n=Promise))((function(r,o){function s(e){try{l(i.next(e))}catch(e){o(e)}}function a(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((i=i.apply(e,t||[])).next())}))}function n(e){Object.keys(e).forEach((t=>{const n=e[t];if(null==n?void 0:n.isTexture){n.dispose()}})),e.dispose()}function i(e){const t=e.geometry;t&&t.dispose();const i=e.material;i&&(Array.isArray(i)?i.forEach((e=>n(e))):i&&n(i))}var r;!function(e){e[e.NUMBER=0]="NUMBER",e[e.VECTOR2=1]="VECTOR2",e[e.VECTOR3=2]="VECTOR3",e[e.VECTOR4=3]="VECTOR4",e[e.COLOR=4]="COLOR"}(r||(r={}));const o=new e.Vector2,s=new e.Vector3,a=new e.Vector4,l=new e.Color;class d extends e.Object3D{constructor(e){super(),this.weight=0,this.isBinary=!1,this._binds=[],this._materialValues=[],this.name=`BlendShapeController_${e}`,this.type="BlendShapeController",this.visible=!1}addBind(e){const t=e.weight/100;this._binds.push({meshes:e.meshes,morphTargetIndex:e.morphTargetIndex,weight:t})}addMaterialValue(t){const n=t.material,i=t.propertyName;let o,s,a,l,d=n[i];d&&(d=t.defaultValue||d,d.isVector2?(o=r.VECTOR2,s=d.clone(),a=(new e.Vector2).fromArray(t.targetValue),l=a.clone().sub(s)):d.isVector3?(o=r.VECTOR3,s=d.clone(),a=(new e.Vector3).fromArray(t.targetValue),l=a.clone().sub(s)):d.isVector4?(o=r.VECTOR4,s=d.clone(),a=(new e.Vector4).fromArray([t.targetValue[2],t.targetValue[3],t.targetValue[0],t.targetValue[1]]),l=a.clone().sub(s)):d.isColor?(o=r.COLOR,s=d.clone(),a=(new e.Color).fromArray(t.targetValue),l=a.clone().sub(s)):(o=r.NUMBER,s=d,a=t.targetValue[0],l=a-s),this._materialValues.push({material:n,propertyName:i,defaultValue:s,targetValue:a,deltaValue:l,type:o}))}applyWeight(){const e=this.isBinary?this.weight<.5?0:1:this.weight;this._binds.forEach((t=>{t.meshes.forEach((n=>{n.morphTargetInfluences&&(n.morphTargetInfluences[t.morphTargetIndex]+=e*t.weight)}))})),this._materialValues.forEach((t=>{if(void 0!==t.material[t.propertyName]){if(t.type===r.NUMBER){const n=t.deltaValue;t.material[t.propertyName]+=n*e}else if(t.type===r.VECTOR2){const n=t.deltaValue;t.material[t.propertyName].add(o.copy(n).multiplyScalar(e))}else if(t.type===r.VECTOR3){const n=t.deltaValue;t.material[t.propertyName].add(s.copy(n).multiplyScalar(e))}else if(t.type===r.VECTOR4){const n=t.deltaValue;t.material[t.propertyName].add(a.copy(n).multiplyScalar(e))}else if(t.type===r.COLOR){const n=t.deltaValue;t.material[t.propertyName].add(l.copy(n).multiplyScalar(e))}"boolean"==typeof t.material.shouldApplyUniforms&&(t.material.shouldApplyUniforms=!0)}}))}clearAppliedWeight(){this._binds.forEach((e=>{e.meshes.forEach((t=>{t.morphTargetInfluences&&(t.morphTargetInfluences[e.morphTargetIndex]=0)}))})),this._materialValues.forEach((e=>{if(void 0!==e.material[e.propertyName]){if(e.type===r.NUMBER){const t=e.defaultValue;e.material[e.propertyName]=t}else if(e.type===r.VECTOR2){const t=e.defaultValue;e.material[e.propertyName].copy(t)}else if(e.type===r.VECTOR3){const t=e.defaultValue;e.material[e.propertyName].copy(t)}else if(e.type===r.VECTOR4){const t=e.defaultValue;e.material[e.propertyName].copy(t)}else if(e.type===r.COLOR){const t=e.defaultValue;e.material[e.propertyName].copy(t)}"boolean"==typeof e.material.shouldApplyUniforms&&(e.material.shouldApplyUniforms=!0)}}))}}var h;function u(e,t,n){const i=e.parser.json.nodes[t].mesh;if(null==i)return null;const r=e.parser.json.meshes[i].primitives.length,o=[];return n.traverse((e=>{o.length<r&&e.isMesh&&o.push(e)})),o}function c(e){return t(this,void 0,void 0,(function*(){const t=yield e.parser.getDependencies("node"),n=new Map;return t.forEach(((t,i)=>{const r=u(e,i,t);null!=r&&n.set(i,r)})),n}))}function p(e){return"_"!==e[0]?(console.warn(`renameMaterialProperty: Given property name "${e}" might be invalid`),e):(e=e.substring(1),/[A-Z]/.test(e[0])?e[0].toLowerCase()+e.substring(1):(console.warn(`renameMaterialProperty: Given property name "${e}" might be invalid`),e))}!function(e){var t,n,i,r,o,s;(t=e.BlendShapePresetName||(e.BlendShapePresetName={})).A="a",t.Angry="angry",t.Blink="blink",t.BlinkL="blink_l",t.BlinkR="blink_r",t.E="e",t.Fun="fun",t.I="i",t.Joy="joy",t.Lookdown="lookdown",t.Lookleft="lookleft",t.Lookright="lookright",t.Lookup="lookup",t.Neutral="neutral",t.O="o",t.Sorrow="sorrow",t.U="u",t.Unknown="unknown",(n=e.FirstPersonLookAtTypeName||(e.FirstPersonLookAtTypeName={})).BlendShape="BlendShape",n.Bone="Bone",(i=e.HumanoidBoneName||(e.HumanoidBoneName={})).Chest="chest",i.Head="head",i.Hips="hips",i.Jaw="jaw",i.LeftEye="leftEye",i.LeftFoot="leftFoot",i.LeftHand="leftHand",i.LeftIndexDistal="leftIndexDistal",i.LeftIndexIntermediate="leftIndexIntermediate",i.LeftIndexProximal="leftIndexProximal",i.LeftLittleDistal="leftLittleDistal",i.LeftLittleIntermediate="leftLittleIntermediate",i.LeftLittleProximal="leftLittleProximal",i.LeftLowerArm="leftLowerArm",i.LeftLowerLeg="leftLowerLeg",i.LeftMiddleDistal="leftMiddleDistal",i.LeftMiddleIntermediate="leftMiddleIntermediate",i.LeftMiddleProximal="leftMiddleProximal",i.LeftRingDistal="leftRingDistal",i.LeftRingIntermediate="leftRingIntermediate",i.LeftRingProximal="leftRingProximal",i.LeftShoulder="leftShoulder",i.LeftThumbDistal="leftThumbDistal",i.LeftThumbIntermediate="leftThumbIntermediate",i.LeftThumbProximal="leftThumbProximal",i.LeftToes="leftToes",i.LeftUpperArm="leftUpperArm",i.LeftUpperLeg="leftUpperLeg",i.Neck="neck",i.RightEye="rightEye",i.RightFoot="rightFoot",i.RightHand="rightHand",i.RightIndexDistal="rightIndexDistal",i.RightIndexIntermediate="rightIndexIntermediate",i.RightIndexProximal="rightIndexProximal",i.RightLittleDistal="rightLittleDistal",i.RightLittleIntermediate="rightLittleIntermediate",i.RightLittleProximal="rightLittleProximal",i.RightLowerArm="rightLowerArm",i.RightLowerLeg="rightLowerLeg",i.RightMiddleDistal="rightMiddleDistal",i.RightMiddleIntermediate="rightMiddleIntermediate",i.RightMiddleProximal="rightMiddleProximal",i.RightRingDistal="rightRingDistal",i.RightRingIntermediate="rightRingIntermediate",i.RightRingProximal="rightRingProximal",i.RightShoulder="rightShoulder",i.RightThumbDistal="rightThumbDistal",i.RightThumbIntermediate="rightThumbIntermediate",i.RightThumbProximal="rightThumbProximal",i.RightToes="rightToes",i.RightUpperArm="rightUpperArm",i.RightUpperLeg="rightUpperLeg",i.Spine="spine",i.UpperChest="upperChest",(r=e.MetaAllowedUserName||(e.MetaAllowedUserName={})).Everyone="Everyone",r.ExplicitlyLicensedPerson="ExplicitlyLicensedPerson",r.OnlyAuthor="OnlyAuthor",(o=e.MetaUssageName||(e.MetaUssageName={})).Allow="Allow",o.Disallow="Disallow",(s=e.MetaLicenseName||(e.MetaLicenseName={})).Cc0="CC0",s.CcBy="CC_BY",s.CcByNc="CC_BY_NC",s.CcByNcNd="CC_BY_NC_ND",s.CcByNcSa="CC_BY_NC_SA",s.CcByNd="CC_BY_ND",s.CcBySa="CC_BY_SA",s.Other="Other",s.RedistributionProhibited="Redistribution_Prohibited"}(h||(h={}));const m=new e.Vector3,f=new e.Vector3;function g(e,t){return e.matrixWorld.decompose(m,t,f),t}new e.Quaternion;class _{constructor(){this._blendShapeGroups={},this._blendShapePresetMap={},this._unknownGroupNames=[]}get expressions(){return Object.keys(this._blendShapeGroups)}get blendShapePresetMap(){return this._blendShapePresetMap}get unknownGroupNames(){return this._unknownGroupNames}getBlendShapeGroup(e){const t=this._blendShapePresetMap[e],n=t?this._blendShapeGroups[t]:this._blendShapeGroups[e];if(n)return n;console.warn(`no blend shape found by ${e}`)}registerBlendShapeGroup(e,t,n){this._blendShapeGroups[e]=n,t?this._blendShapePresetMap[t]=e:this._unknownGroupNames.push(e)}getValue(e){var t;const n=this.getBlendShapeGroup(e);return null!==(t=null==n?void 0:n.weight)&&void 0!==t?t:null}setValue(e,t){const n=this.getBlendShapeGroup(e);var i;n&&(n.weight=(i=t,Math.max(Math.min(i,1),0)))}getBlendShapeTrackName(e){const t=this.getBlendShapeGroup(e);return t?`${t.name}.weight`:null}update(){Object.keys(this._blendShapeGroups).forEach((e=>{this._blendShapeGroups[e].clearAppliedWeight()})),Object.keys(this._blendShapeGroups).forEach((e=>{this._blendShapeGroups[e].applyWeight()}))}}class v{import(e){var n;return t(this,void 0,void 0,(function*(){const i=null===(n=e.parser.json.extensions)||void 0===n?void 0:n.VRM;if(!i)return null;const r=i.blendShapeMaster;if(!r)return null;const o=new _,s=r.blendShapeGroups;if(!s)return o;const a={};return yield Promise.all(s.map((n=>t(this,void 0,void 0,(function*(){const i=n.name;if(void 0===i)return void console.warn("VRMBlendShapeImporter: One of blendShapeGroups has no name");let r;n.presetName&&n.presetName!==h.BlendShapePresetName.Unknown&&!a[n.presetName]&&(r=n.presetName,a[n.presetName]=i);const s=new d(i);e.scene.add(s),s.isBinary=n.isBinary||!1,n.binds&&n.binds.forEach((i=>t(this,void 0,void 0,(function*(){if(void 0===i.mesh||void 0===i.index)return;const r=[];e.parser.json.nodes.forEach(((e,t)=>{e.mesh===i.mesh&&r.push(t)}));const o=i.index;yield Promise.all(r.map((r=>t(this,void 0,void 0,(function*(){var a;const l=yield function(e,n){return t(this,void 0,void 0,(function*(){const t=yield e.parser.getDependency("node",n);return u(e,n,t)}))}(e,r);l.every((e=>Array.isArray(e.morphTargetInfluences)&&o<e.morphTargetInfluences.length))?s.addBind({meshes:l,morphTargetIndex:o,weight:null!==(a=i.weight)&&void 0!==a?a:100}):console.warn(`VRMBlendShapeImporter: ${n.name} attempts to index ${o}th morph but not found.`)})))))}))));const l=n.materialValues;l&&l.forEach((t=>{if(void 0===t.materialName||void 0===t.propertyName||void 0===t.targetValue)return;const n=[];e.scene.traverse((e=>{if(e.material){const i=e.material;Array.isArray(i)?n.push(...i.filter((e=>e.name===t.materialName&&-1===n.indexOf(e)))):i.name===t.materialName&&-1===n.indexOf(i)&&n.push(i)}})),n.forEach((e=>{s.addMaterialValue({material:e,propertyName:p(t.propertyName),targetValue:t.targetValue})}))})),o.registerBlendShapeGroup(i,r,s)}))))),o}))}}const y=Object.freeze(new e.Vector3(0,0,-1)),T=new e.Quaternion;var x;!function(e){e[e.Auto=0]="Auto",e[e.Both=1]="Both",e[e.ThirdPersonOnly=2]="ThirdPersonOnly",e[e.FirstPersonOnly=3]="FirstPersonOnly"}(x||(x={}));class S{constructor(e,t){this.firstPersonFlag=S._parseFirstPersonFlag(e),this.primitives=t}static _parseFirstPersonFlag(e){switch(e){case"Both":return x.Both;case"ThirdPersonOnly":return x.ThirdPersonOnly;case"FirstPersonOnly":return x.FirstPersonOnly;default:return x.Auto}}}class M{constructor(e,t,n){this._meshAnnotations=[],this._firstPersonOnlyLayer=M._DEFAULT_FIRSTPERSON_ONLY_LAYER,this._thirdPersonOnlyLayer=M._DEFAULT_THIRDPERSON_ONLY_LAYER,this._initialized=!1,this._firstPersonBone=e,this._firstPersonBoneOffset=t,this._meshAnnotations=n}get firstPersonBone(){return this._firstPersonBone}get meshAnnotations(){return this._meshAnnotations}getFirstPersonWorldDirection(e){return e.copy(y).applyQuaternion(g(this._firstPersonBone,T))}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}getFirstPersonBoneOffset(e){return e.copy(this._firstPersonBoneOffset)}getFirstPersonWorldPosition(t){const n=this._firstPersonBoneOffset,i=new e.Vector4(n.x,n.y,n.z,1);return i.applyMatrix4(this._firstPersonBone.matrixWorld),t.set(i.x,i.y,i.z)}setup({firstPersonOnlyLayer:e=M._DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:t=M._DEFAULT_THIRDPERSON_ONLY_LAYER}={}){this._initialized||(this._initialized=!0,this._firstPersonOnlyLayer=e,this._thirdPersonOnlyLayer=t,this._meshAnnotations.forEach((e=>{e.firstPersonFlag===x.FirstPersonOnly?e.primitives.forEach((e=>{e.layers.set(this._firstPersonOnlyLayer)})):e.firstPersonFlag===x.ThirdPersonOnly?e.primitives.forEach((e=>{e.layers.set(this._thirdPersonOnlyLayer)})):e.firstPersonFlag===x.Auto&&this._createHeadlessModel(e.primitives)})))}_excludeTriangles(e,t,n,i){let r=0;if(null!=t&&t.length>0)for(let o=0;o<e.length;o+=3){const s=e[o],a=e[o+1],l=e[o+2],d=t[s],h=n[s];if(d[0]>0&&i.includes(h[0]))continue;if(d[1]>0&&i.includes(h[1]))continue;if(d[2]>0&&i.includes(h[2]))continue;if(d[3]>0&&i.includes(h[3]))continue;const u=t[a],c=n[a];if(u[0]>0&&i.includes(c[0]))continue;if(u[1]>0&&i.includes(c[1]))continue;if(u[2]>0&&i.includes(c[2]))continue;if(u[3]>0&&i.includes(c[3]))continue;const p=t[l],m=n[l];p[0]>0&&i.includes(m[0])||(p[1]>0&&i.includes(m[1])||p[2]>0&&i.includes(m[2])||p[3]>0&&i.includes(m[3])||(e[r++]=s,e[r++]=a,e[r++]=l))}return r}_createErasedMesh(t,n){const i=new e.SkinnedMesh(t.geometry.clone(),t.material);i.name=`${t.name}(erase)`,i.frustumCulled=t.frustumCulled,i.layers.set(this._firstPersonOnlyLayer);const r=i.geometry,o=r.getAttribute("skinIndex").array,s=[];for(let e=0;e<o.length;e+=4)s.push([o[e],o[e+1],o[e+2],o[e+3]]);const a=r.getAttribute("skinWeight").array,l=[];for(let e=0;e<a.length;e+=4)l.push([a[e],a[e+1],a[e+2],a[e+3]]);const d=r.getIndex();if(!d)throw new Error("The geometry doesn't have an index buffer");const h=Array.from(d.array),u=this._excludeTriangles(h,l,s,n),c=[];for(let e=0;e<u;e++)c[e]=h[e];return r.setIndex(c),t.onBeforeRender&&(i.onBeforeRender=t.onBeforeRender),i.bind(new e.Skeleton(t.skeleton.bones,t.skeleton.boneInverses),new e.Matrix4),i}_createHeadlessModelForSkinnedMesh(e,t){const n=[];if(t.skeleton.bones.forEach(((e,t)=>{this._isEraseTarget(e)&&n.push(t)})),!n.length)return t.layers.enable(this._thirdPersonOnlyLayer),void t.layers.enable(this._firstPersonOnlyLayer);t.layers.set(this._thirdPersonOnlyLayer);const i=this._createErasedMesh(t,n);e.add(i)}_createHeadlessModel(e){e.forEach((e=>{if("SkinnedMesh"===e.type){const t=e;this._createHeadlessModelForSkinnedMesh(t.parent,t)}else this._isEraseTarget(e)&&e.layers.set(this._thirdPersonOnlyLayer)}))}_isEraseTarget(e){return e===this._firstPersonBone||!!e.parent&&this._isEraseTarget(e.parent)}}M._DEFAULT_FIRSTPERSON_ONLY_LAYER=9,M._DEFAULT_THIRDPERSON_ONLY_LAYER=10;class E{import(n,i){var r;return t(this,void 0,void 0,(function*(){const t=null===(r=n.parser.json.extensions)||void 0===r?void 0:r.VRM;if(!t)return null;const o=t.firstPerson;if(!o)return null;const s=o.firstPersonBone;let a;if(a=void 0===s||-1===s?i.getBoneNode(h.HumanoidBoneName.Head):yield n.parser.getDependency("node",s),!a)return console.warn("VRMFirstPersonImporter: Could not find firstPersonBone of the VRM"),null;const l=o.firstPersonBoneOffset?new e.Vector3(o.firstPersonBoneOffset.x,o.firstPersonBoneOffset.y,-o.firstPersonBoneOffset.z):new e.Vector3(0,.06,0),d=[],u=yield c(n);return Array.from(u.entries()).forEach((([e,t])=>{const i=n.parser.json.nodes[e],r=o.meshAnnotations?o.meshAnnotations.find((e=>e.mesh===i.mesh)):void 0;d.push(new S(null==r?void 0:r.firstPersonFlag,t))})),new M(a,l,d)}))}}class L{constructor(e,t){this.node=e,this.humanLimit=t}}function w(e){return e.invert?e.invert():e.inverse(),e}const R=new e.Vector3,P=new e.Quaternion;class A{constructor(e,t){this.restPose={},this.humanBones=this._createHumanBones(e),this.humanDescription=t,this.restPose=this.getPose()}getPose(){const e={};return Object.keys(this.humanBones).forEach((t=>{const n=this.getBoneNode(t);if(!n)return;if(e[t])return;R.set(0,0,0),P.identity();const i=this.restPose[t];(null==i?void 0:i.position)&&R.fromArray(i.position).negate(),(null==i?void 0:i.rotation)&&w(P.fromArray(i.rotation)),R.add(n.position),P.premultiply(n.quaternion),e[t]={position:R.toArray(),rotation:P.toArray()}}),{}),e}setPose(e){Object.keys(e).forEach((t=>{const n=e[t],i=this.getBoneNode(t);if(!i)return;const r=this.restPose[t];r&&(n.position&&(i.position.fromArray(n.position),r.position&&i.position.add(R.fromArray(r.position))),n.rotation&&(i.quaternion.fromArray(n.rotation),r.rotation&&i.quaternion.multiply(P.fromArray(r.rotation))))}))}resetPose(){Object.entries(this.restPose).forEach((([e,t])=>{const n=this.getBoneNode(e);n&&((null==t?void 0:t.position)&&n.position.fromArray(t.position),(null==t?void 0:t.rotation)&&n.quaternion.fromArray(t.rotation))}))}getBone(e){var t;return null!==(t=this.humanBones[e][0])&&void 0!==t?t:void 0}getBones(e){var t;return null!==(t=this.humanBones[e])&&void 0!==t?t:[]}getBoneNode(e){var t,n;return null!==(n=null===(t=this.humanBones[e][0])||void 0===t?void 0:t.node)&&void 0!==n?n:null}getBoneNodes(e){var t,n;return null!==(n=null===(t=this.humanBones[e])||void 0===t?void 0:t.map((e=>e.node)))&&void 0!==n?n:[]}_createHumanBones(e){const t=Object.values(h.HumanoidBoneName).reduce(((e,t)=>(e[t]=[],e)),{});return e.forEach((e=>{t[e.name].push(e.bone)})),t}}class C{import(n){var i;return t(this,void 0,void 0,(function*(){const r=null===(i=n.parser.json.extensions)||void 0===i?void 0:i.VRM;if(!r)return null;const o=r.humanoid;if(!o)return null;const s=[];o.humanBones&&(yield Promise.all(o.humanBones.map((i=>t(this,void 0,void 0,(function*(){if(!i.bone||null==i.node)return;const t=yield n.parser.getDependency("node",i.node);s.push({name:i.bone,bone:new L(t,{axisLength:i.axisLength,center:i.center&&new e.Vector3(i.center.x,i.center.y,i.center.z),max:i.max&&new e.Vector3(i.max.x,i.max.y,i.max.z),min:i.min&&new e.Vector3(i.min.x,i.min.y,i.min.z),useDefaultValues:i.useDefaultValues})})}))))));const a={armStretch:o.armStretch,legStretch:o.legStretch,upperArmTwist:o.upperArmTwist,lowerArmTwist:o.lowerArmTwist,upperLegTwist:o.upperLegTwist,lowerLegTwist:o.lowerLegTwist,feetSpacing:o.feetSpacing,hasTranslationDoF:o.hasTranslationDoF};return new A(s,a)}))}}class O{constructor(e,t,n){this.curve=[0,0,0,1,1,1,1,0],this.curveXRangeDegree=90,this.curveYRangeDegree=10,void 0!==e&&(this.curveXRangeDegree=e),void 0!==t&&(this.curveYRangeDegree=t),void 0!==n&&(this.curve=n)}map(e){const t=Math.min(Math.max(e,0),this.curveXRangeDegree)/this.curveXRangeDegree;return this.curveYRangeDegree*((e,t)=>{if(e.length<8)throw new Error("evaluateCurve: Invalid curve detected! (Array length must be 8 at least)");if(e.length%4!=0)throw new Error("evaluateCurve: Invalid curve detected! (Array length must be multiples of 4");let n;for(n=0;;n++){if(e.length<=4*n)return e[4*n-3];if(t<=e[4*n])break}const i=n-1;if(i<0)return e[4*i+5];const r=e[4*i],o=(t-r)/(e[4*n]-r);return((e,t,n,i,r)=>{const o=r*r*r,s=r*r;return e+(t-e)*(-2*o+3*s)+n*(o-2*s+r)+i*(o-s)})(e[4*i+1],e[4*n+1],e[4*i+3],e[4*n+2],o)})(this.curve,t)}}class b{}class I extends b{constructor(e,t,n,i){super(),this.type=h.FirstPersonLookAtTypeName.BlendShape,this._curveHorizontal=t,this._curveVerticalDown=n,this._curveVerticalUp=i,this._blendShapeProxy=e}name(){return h.FirstPersonLookAtTypeName.BlendShape}lookAt(e){const t=e.x,n=e.y;t<0?(this._blendShapeProxy.setValue(h.BlendShapePresetName.Lookup,0),this._blendShapeProxy.setValue(h.BlendShapePresetName.Lookdown,this._curveVerticalDown.map(-t))):(this._blendShapeProxy.setValue(h.BlendShapePresetName.Lookdown,0),this._blendShapeProxy.setValue(h.BlendShapePresetName.Lookup,this._curveVerticalUp.map(t))),n<0?(this._blendShapeProxy.setValue(h.BlendShapePresetName.Lookleft,0),this._blendShapeProxy.setValue(h.BlendShapePresetName.Lookright,this._curveHorizontal.map(-n))):(this._blendShapeProxy.setValue(h.BlendShapePresetName.Lookright,0),this._blendShapeProxy.setValue(h.BlendShapePresetName.Lookleft,this._curveHorizontal.map(n)))}}const N=Object.freeze(new e.Vector3(0,0,-1)),D=new e.Vector3,U=new e.Vector3,B=new e.Vector3,V=new e.Quaternion;class G{constructor(t,n){this.autoUpdate=!0,this._euler=new e.Euler(0,0,0,G.EULER_ORDER),this.firstPerson=t,this.applyer=n}getLookAtWorldDirection(e){const t=g(this.firstPerson.firstPersonBone,V);return e.copy(N).applyEuler(this._euler).applyQuaternion(t)}lookAt(e){this._calcEuler(this._euler,e),this.applyer&&this.applyer.lookAt(this._euler)}update(e){this.target&&this.autoUpdate&&(this.lookAt(this.target.getWorldPosition(D)),this.applyer&&this.applyer.lookAt(this._euler))}_calcEuler(e,t){const n=this.firstPerson.getFirstPersonWorldPosition(U),i=B.copy(t).sub(n).normalize();return i.applyQuaternion(w(g(this.firstPerson.firstPersonBone,V))),e.x=Math.atan2(i.y,Math.sqrt(i.x*i.x+i.z*i.z)),e.y=Math.atan2(-i.x,-i.z),e}}G.EULER_ORDER="YXZ";const F=new e.Euler(0,0,0,G.EULER_ORDER);class k extends b{constructor(e,t,n,i,r){super(),this.type=h.FirstPersonLookAtTypeName.Bone,this._curveHorizontalInner=t,this._curveHorizontalOuter=n,this._curveVerticalDown=i,this._curveVerticalUp=r,this._leftEye=e.getBoneNode(h.HumanoidBoneName.LeftEye),this._rightEye=e.getBoneNode(h.HumanoidBoneName.RightEye)}lookAt(e){const t=e.x,n=e.y;this._leftEye&&(F.x=t<0?-this._curveVerticalDown.map(-t):this._curveVerticalUp.map(t),F.y=n<0?-this._curveHorizontalInner.map(-n):this._curveHorizontalOuter.map(n),this._leftEye.quaternion.setFromEuler(F)),this._rightEye&&(F.x=t<0?-this._curveVerticalDown.map(-t):this._curveVerticalUp.map(t),F.y=n<0?-this._curveHorizontalOuter.map(-n):this._curveHorizontalInner.map(n),this._rightEye.quaternion.setFromEuler(F))}}const H=Math.PI/180;class W{import(e,t,n,i){var r;const o=null===(r=e.parser.json.extensions)||void 0===r?void 0:r.VRM;if(!o)return null;const s=o.firstPerson;if(!s)return null;const a=this._importApplyer(s,n,i);return new G(t,a||void 0)}_importApplyer(e,t,n){const i=e.lookAtHorizontalInner,r=e.lookAtHorizontalOuter,o=e.lookAtVerticalDown,s=e.lookAtVerticalUp;switch(e.lookAtTypeName){case h.FirstPersonLookAtTypeName.Bone:return void 0===i||void 0===r||void 0===o||void 0===s?null:new k(n,this._importCurveMapperBone(i),this._importCurveMapperBone(r),this._importCurveMapperBone(o),this._importCurveMapperBone(s));case h.FirstPersonLookAtTypeName.BlendShape:return void 0===r||void 0===o||void 0===s?null:new I(t,this._importCurveMapperBlendShape(r),this._importCurveMapperBlendShape(o),this._importCurveMapperBlendShape(s));default:return null}}_importCurveMapperBone(e){return new O("number"==typeof e.xRange?H*e.xRange:void 0,"number"==typeof e.yRange?H*e.yRange:void 0,e.curve)}_importCurveMapperBlendShape(e){return new O("number"==typeof e.xRange?H*e.xRange:void 0,e.yRange,e.curve)}}const z=(t,n)=>{const i=(t=>{switch(t){case e.LinearEncoding:return["Linear","( value )"];case e.sRGBEncoding:return["sRGB","( value )"];case e.RGBEEncoding:return["RGBE","( value )"];case e.RGBM7Encoding:return["RGBM","( value, 7.0 )"];case e.RGBM16Encoding:return["RGBM","( value, 16.0 )"];case e.RGBDEncoding:return["RGBD","( value, 256.0 )"];case e.GammaEncoding:return["Gamma","( value, float( GAMMA_FACTOR ) )"];default:throw new Error("unsupported encoding: "+t)}})(n);return"vec4 "+t+"( vec4 value ) { return "+i[0]+"ToLinear"+i[1]+"; }"};const j=2*Math.PI;var Y,X,q,Q,Z;!function(e){e[e.Off=0]="Off",e[e.Front=1]="Front",e[e.Back=2]="Back"}(Y||(Y={})),function(e){e[e.None=0]="None",e[e.Normal=1]="Normal",e[e.LitShadeRate=2]="LitShadeRate",e[e.UV=3]="UV"}(X||(X={})),function(e){e[e.FixedColor=0]="FixedColor",e[e.MixedLighting=1]="MixedLighting"}(q||(q={})),function(e){e[e.None=0]="None",e[e.WorldCoordinates=1]="WorldCoordinates",e[e.ScreenCoordinates=2]="ScreenCoordinates"}(Q||(Q={})),function(e){e[e.Opaque=0]="Opaque",e[e.Cutout=1]="Cutout",e[e.Transparent=2]="Transparent",e[e.TransparentWithZWrite=3]="TransparentWithZWrite"}(Z||(Z={}));class $ extends e.ShaderMaterial{constructor(t={}){super(),this.isMToonMaterial=!0,this.cutoff=.5,this.color=new e.Vector4(1,1,1,1),this.shadeColor=new e.Vector4(.97,.81,.86,1),this.map=null,this.mainTex_ST=new e.Vector4(0,0,1,1),this.shadeTexture=null,this.normalMap=null,this.normalMapType=e.TangentSpaceNormalMap,this.normalScale=new e.Vector2(1,1),this.receiveShadowRate=1,this.receiveShadowTexture=null,this.shadingGradeRate=1,this.shadingGradeTexture=null,this.shadeShift=0,this.shadeToony=.9,this.lightColorAttenuation=0,this.indirectLightIntensity=.1,this.rimTexture=null,this.rimColor=new e.Vector4(0,0,0,1),this.rimLightingMix=0,this.rimFresnelPower=1,this.rimLift=0,this.sphereAdd=null,this.emissionColor=new e.Vector4(0,0,0,1),this.emissiveMap=null,this.outlineWidthTexture=null,this.outlineWidth=.5,this.outlineScaledMaxDistance=1,this.outlineColor=new e.Vector4(0,0,0,1),this.outlineLightingMix=1,this.uvAnimMaskTexture=null,this.uvAnimScrollX=0,this.uvAnimScrollY=0,this.uvAnimRotation=0,this.shouldApplyUniforms=!0,this._debugMode=X.None,this._blendMode=Z.Opaque,this._outlineWidthMode=Q.None,this._outlineColorMode=q.FixedColor,this._cullMode=Y.Back,this._outlineCullMode=Y.Front,this._isOutline=!1,this._uvAnimOffsetX=0,this._uvAnimOffsetY=0,this._uvAnimPhase=0,this.encoding=t.encoding||e.LinearEncoding,this.encoding!==e.LinearEncoding&&this.encoding!==e.sRGBEncoding&&console.warn("The specified color encoding does not work properly with MToonMaterial. You might want to use THREE.sRGBEncoding instead."),["mToonVersion","shadeTexture_ST","bumpMap_ST","receiveShadowTexture_ST","shadingGradeTexture_ST","rimTexture_ST","sphereAdd_ST","emissionMap_ST","outlineWidthTexture_ST","uvAnimMaskTexture_ST","srcBlend","dstBlend"].forEach((e=>{void 0!==t[e]&&delete t[e]})),t.fog=!0,t.lights=!0,t.clipping=!0,parseInt(e.REVISION,10)<129&&(t.skinning=t.skinning||!1),parseInt(e.REVISION,10)<131&&(t.morphTargets=t.morphTargets||!1,t.morphNormals=t.morphNormals||!1),t.uniforms=e.UniformsUtils.merge([e.UniformsLib.common,e.UniformsLib.normalmap,e.UniformsLib.emissivemap,e.UniformsLib.fog,e.UniformsLib.lights,{cutoff:{value:.5},color:{value:new e.Color(1,1,1)},colorAlpha:{value:1},shadeColor:{value:new e.Color(.97,.81,.86)},mainTex_ST:{value:new e.Vector4(0,0,1,1)},shadeTexture:{value:null},receiveShadowRate:{value:1},receiveShadowTexture:{value:null},shadingGradeRate:{value:1},shadingGradeTexture:{value:null},shadeShift:{value:0},shadeToony:{value:.9},lightColorAttenuation:{value:0},indirectLightIntensity:{value:.1},rimTexture:{value:null},rimColor:{value:new e.Color(0,0,0)},rimLightingMix:{value:0},rimFresnelPower:{value:1},rimLift:{value:0},sphereAdd:{value:null},emissionColor:{value:new e.Color(0,0,0)},outlineWidthTexture:{value:null},outlineWidth:{value:.5},outlineScaledMaxDistance:{value:1},outlineColor:{value:new e.Color(0,0,0)},outlineLightingMix:{value:1},uvAnimMaskTexture:{value:null},uvAnimOffsetX:{value:0},uvAnimOffsetY:{value:0},uvAnimTheta:{value:0}}]),this.setValues(t),this._updateShaderCode(),this._applyUniforms()}get mainTex(){return this.map}set mainTex(e){this.map=e}get bumpMap(){return this.normalMap}set bumpMap(e){this.normalMap=e}get bumpScale(){return this.normalScale.x}set bumpScale(e){this.normalScale.set(e,e)}get emissionMap(){return this.emissiveMap}set emissionMap(e){this.emissiveMap=e}get blendMode(){return this._blendMode}set blendMode(e){this._blendMode=e,this.depthWrite=this._blendMode!==Z.Transparent,this.transparent=this._blendMode===Z.Transparent||this._blendMode===Z.TransparentWithZWrite,this._updateShaderCode()}get debugMode(){return this._debugMode}set debugMode(e){this._debugMode=e,this._updateShaderCode()}get outlineWidthMode(){return this._outlineWidthMode}set outlineWidthMode(e){this._outlineWidthMode=e,this._updateShaderCode()}get outlineColorMode(){return this._outlineColorMode}set outlineColorMode(e){this._outlineColorMode=e,this._updateShaderCode()}get cullMode(){return this._cullMode}set cullMode(e){this._cullMode=e,this._updateCullFace()}get outlineCullMode(){return this._outlineCullMode}set outlineCullMode(e){this._outlineCullMode=e,this._updateCullFace()}get zWrite(){return this.depthWrite?1:0}set zWrite(e){this.depthWrite=.5<=e}get isOutline(){return this._isOutline}set isOutline(e){this._isOutline=e,this._updateShaderCode(),this._updateCullFace()}updateVRMMaterials(e){this._uvAnimOffsetX=this._uvAnimOffsetX+e*this.uvAnimScrollX,this._uvAnimOffsetY=this._uvAnimOffsetY-e*this.uvAnimScrollY,this._uvAnimPhase=this._uvAnimPhase+e*this.uvAnimRotation,this._applyUniforms()}copy(e){return super.copy(e),this.cutoff=e.cutoff,this.color.copy(e.color),this.shadeColor.copy(e.shadeColor),this.map=e.map,this.mainTex_ST.copy(e.mainTex_ST),this.shadeTexture=e.shadeTexture,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(this.normalScale),this.receiveShadowRate=e.receiveShadowRate,this.receiveShadowTexture=e.receiveShadowTexture,this.shadingGradeRate=e.shadingGradeRate,this.shadingGradeTexture=e.shadingGradeTexture,this.shadeShift=e.shadeShift,this.shadeToony=e.shadeToony,this.lightColorAttenuation=e.lightColorAttenuation,this.indirectLightIntensity=e.indirectLightIntensity,this.rimTexture=e.rimTexture,this.rimColor.copy(e.rimColor),this.rimLightingMix=e.rimLightingMix,this.rimFresnelPower=e.rimFresnelPower,this.rimLift=e.rimLift,this.sphereAdd=e.sphereAdd,this.emissionColor.copy(e.emissionColor),this.emissiveMap=e.emissiveMap,this.outlineWidthTexture=e.outlineWidthTexture,this.outlineWidth=e.outlineWidth,this.outlineScaledMaxDistance=e.outlineScaledMaxDistance,this.outlineColor.copy(e.outlineColor),this.outlineLightingMix=e.outlineLightingMix,this.uvAnimMaskTexture=e.uvAnimMaskTexture,this.uvAnimScrollX=e.uvAnimScrollX,this.uvAnimScrollY=e.uvAnimScrollY,this.uvAnimRotation=e.uvAnimRotation,this.debugMode=e.debugMode,this.blendMode=e.blendMode,this.outlineWidthMode=e.outlineWidthMode,this.outlineColorMode=e.outlineColorMode,this.cullMode=e.cullMode,this.outlineCullMode=e.outlineCullMode,this.isOutline=e.isOutline,this}_applyUniforms(){this.uniforms.uvAnimOffsetX.value=this._uvAnimOffsetX,this.uniforms.uvAnimOffsetY.value=this._uvAnimOffsetY,this.uniforms.uvAnimTheta.value=j*this._uvAnimPhase,this.shouldApplyUniforms&&(this.shouldApplyUniforms=!1,this.uniforms.cutoff.value=this.cutoff,this.uniforms.color.value.setRGB(this.color.x,this.color.y,this.color.z),this.uniforms.colorAlpha.value=this.color.w,this.uniforms.shadeColor.value.setRGB(this.shadeColor.x,this.shadeColor.y,this.shadeColor.z),this.uniforms.map.value=this.map,this.uniforms.mainTex_ST.value.copy(this.mainTex_ST),this.uniforms.shadeTexture.value=this.shadeTexture,this.uniforms.normalMap.value=this.normalMap,this.uniforms.normalScale.value.copy(this.normalScale),this.uniforms.receiveShadowRate.value=this.receiveShadowRate,this.uniforms.receiveShadowTexture.value=this.receiveShadowTexture,this.uniforms.shadingGradeRate.value=this.shadingGradeRate,this.uniforms.shadingGradeTexture.value=this.shadingGradeTexture,this.uniforms.shadeShift.value=this.shadeShift,this.uniforms.shadeToony.value=this.shadeToony,this.uniforms.lightColorAttenuation.value=this.lightColorAttenuation,this.uniforms.indirectLightIntensity.value=this.indirectLightIntensity,this.uniforms.rimTexture.value=this.rimTexture,this.uniforms.rimColor.value.setRGB(this.rimColor.x,this.rimColor.y,this.rimColor.z),this.uniforms.rimLightingMix.value=this.rimLightingMix,this.uniforms.rimFresnelPower.value=this.rimFresnelPower,this.uniforms.rimLift.value=this.rimLift,this.uniforms.sphereAdd.value=this.sphereAdd,this.uniforms.emissionColor.value.setRGB(this.emissionColor.x,this.emissionColor.y,this.emissionColor.z),this.uniforms.emissiveMap.value=this.emissiveMap,this.uniforms.outlineWidthTexture.value=this.outlineWidthTexture,this.uniforms.outlineWidth.value=this.outlineWidth,this.uniforms.outlineScaledMaxDistance.value=this.outlineScaledMaxDistance,this.uniforms.outlineColor.value.setRGB(this.outlineColor.x,this.outlineColor.y,this.outlineColor.z),this.uniforms.outlineLightingMix.value=this.outlineLightingMix,this.uniforms.uvAnimMaskTexture.value=this.uvAnimMaskTexture,this.encoding===e.sRGBEncoding&&(this.uniforms.color.value.convertSRGBToLinear(),this.uniforms.shadeColor.value.convertSRGBToLinear(),this.uniforms.rimColor.value.convertSRGBToLinear(),this.uniforms.emissionColor.value.convertSRGBToLinear(),this.uniforms.outlineColor.value.convertSRGBToLinear()),this._updateCullFace())}_updateShaderCode(){const t=null!==this.outlineWidthTexture,n=null!==this.map||null!==this.shadeTexture||null!==this.receiveShadowTexture||null!==this.shadingGradeTexture||null!==this.rimTexture||null!==this.uvAnimMaskTexture;this.defines={THREE_VRM_THREE_REVISION:parseInt(e.REVISION,10),OUTLINE:this._isOutline,BLENDMODE_OPAQUE:this._blendMode===Z.Opaque,BLENDMODE_CUTOUT:this._blendMode===Z.Cutout,BLENDMODE_TRANSPARENT:this._blendMode===Z.Transparent||this._blendMode===Z.TransparentWithZWrite,MTOON_USE_UV:t||n,MTOON_UVS_VERTEX_ONLY:t&&!n,USE_SHADETEXTURE:null!==this.shadeTexture,USE_RECEIVESHADOWTEXTURE:null!==this.receiveShadowTexture,USE_SHADINGGRADETEXTURE:null!==this.shadingGradeTexture,USE_RIMTEXTURE:null!==this.rimTexture,USE_SPHEREADD:null!==this.sphereAdd,USE_OUTLINEWIDTHTEXTURE:null!==this.outlineWidthTexture,USE_UVANIMMASKTEXTURE:null!==this.uvAnimMaskTexture,DEBUG_NORMAL:this._debugMode===X.Normal,DEBUG_LITSHADERATE:this._debugMode===X.LitShadeRate,DEBUG_UV:this._debugMode===X.UV,OUTLINE_WIDTH_WORLD:this._outlineWidthMode===Q.WorldCoordinates,OUTLINE_WIDTH_SCREEN:this._outlineWidthMode===Q.ScreenCoordinates,OUTLINE_COLOR_FIXED:this._outlineColorMode===q.FixedColor,OUTLINE_COLOR_MIXED:this._outlineColorMode===q.MixedLighting};const i=(null!==this.shadeTexture?z("shadeTextureTexelToLinear",this.shadeTexture.encoding)+"\n":"")+(null!==this.sphereAdd?z("sphereAddTexelToLinear",this.sphereAdd.encoding)+"\n":"")+(null!==this.rimTexture?z("rimTextureTexelToLinear",this.rimTexture.encoding)+"\n":"");this.vertexShader="// #define PHONG\n\nvarying vec3 vViewPosition;\n\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n\n#include <common>\n\n// #include <uv_pars_vertex>\n#ifdef MTOON_USE_UV\n #ifdef MTOON_UVS_VERTEX_ONLY\n vec2 vUv;\n #else\n varying vec2 vUv;\n #endif\n\n uniform vec4 mainTex_ST;\n#endif\n\n#include <uv2_pars_vertex>\n// #include <displacementmap_pars_vertex>\n// #include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\n#ifdef USE_OUTLINEWIDTHTEXTURE\n uniform sampler2D outlineWidthTexture;\n#endif\n\nuniform float outlineWidth;\nuniform float outlineScaledMaxDistance;\n\nvoid main() {\n\n // #include <uv_vertex>\n #ifdef MTOON_USE_UV\n vUv = uv;\n vUv.y = 1.0 - vUv.y; // uv.y is opposite from UniVRM's\n vUv = mainTex_ST.st + mainTex_ST.pq * vUv;\n vUv.y = 1.0 - vUv.y; // reverting the previous flip\n #endif\n\n #include <uv2_vertex>\n #include <color_vertex>\n\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n\n // we need this to compute the outline properly\n objectNormal = normalize( objectNormal );\n\n #include <defaultnormal_vertex>\n\n #ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\n vNormal = normalize( transformedNormal );\n #endif\n\n #include <begin_vertex>\n\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n // #include <displacementmap_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n\n vViewPosition = - mvPosition.xyz;\n\n float outlineTex = 1.0;\n\n #ifdef OUTLINE\n #ifdef USE_OUTLINEWIDTHTEXTURE\n outlineTex = texture2D( outlineWidthTexture, vUv ).r;\n #endif\n\n #ifdef OUTLINE_WIDTH_WORLD\n float worldNormalLength = length( transformedNormal );\n vec3 outlineOffset = 0.01 * outlineWidth * outlineTex * worldNormalLength * objectNormal;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( outlineOffset + transformed, 1.0 );\n #endif\n\n #ifdef OUTLINE_WIDTH_SCREEN\n vec3 clipNormal = ( projectionMatrix * modelViewMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n vec2 projectedNormal = normalize( clipNormal.xy );\n projectedNormal *= min( gl_Position.w, outlineScaledMaxDistance );\n projectedNormal.x *= projectionMatrix[ 0 ].x / projectionMatrix[ 1 ].y;\n gl_Position.xy += 0.01 * outlineWidth * outlineTex * projectedNormal.xy;\n #endif\n\n gl_Position.z += 1E-6 * gl_Position.w; // anti-artifact magic\n #endif\n\n #include <worldpos_vertex>\n // #include <envmap_vertex>\n #include <shadowmap_vertex>\n #include <fog_vertex>\n\n}",this.fragmentShader=i+'// #define PHONG\n\n#ifdef BLENDMODE_CUTOUT\n uniform float cutoff;\n#endif\n\nuniform vec3 color;\nuniform float colorAlpha;\nuniform vec3 shadeColor;\n#ifdef USE_SHADETEXTURE\n uniform sampler2D shadeTexture;\n#endif\n\nuniform float receiveShadowRate;\n#ifdef USE_RECEIVESHADOWTEXTURE\n uniform sampler2D receiveShadowTexture;\n#endif\n\nuniform float shadingGradeRate;\n#ifdef USE_SHADINGGRADETEXTURE\n uniform sampler2D shadingGradeTexture;\n#endif\n\nuniform float shadeShift;\nuniform float shadeToony;\nuniform float lightColorAttenuation;\nuniform float indirectLightIntensity;\n\n#ifdef USE_RIMTEXTURE\n uniform sampler2D rimTexture;\n#endif\nuniform vec3 rimColor;\nuniform float rimLightingMix;\nuniform float rimFresnelPower;\nuniform float rimLift;\n\n#ifdef USE_SPHEREADD\n uniform sampler2D sphereAdd;\n#endif\n\nuniform vec3 emissionColor;\n\nuniform vec3 outlineColor;\nuniform float outlineLightingMix;\n\n#ifdef USE_UVANIMMASKTEXTURE\n uniform sampler2D uvAnimMaskTexture;\n#endif\n\nuniform float uvAnimOffsetX;\nuniform float uvAnimOffsetY;\nuniform float uvAnimTheta;\n\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n\n// #include <uv_pars_fragment>\n#if ( defined( MTOON_USE_UV ) && !defined( MTOON_UVS_VERTEX_ONLY ) )\n varying vec2 vUv;\n#endif\n\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n// #include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n// #include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n// #include <envmap_common_pars_fragment>\n// #include <envmap_pars_fragment>\n// #include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n\n// #include <bsdfs>\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n}\n\n#include <lights_pars_begin>\n\n// #include <lights_phong_pars_fragment>\nvarying vec3 vViewPosition;\n\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n\nstruct MToonMaterial {\n vec3 diffuseColor;\n vec3 shadeColor;\n float shadingGrade;\n float receiveShadow;\n};\n\n#define Material_LightProbeLOD( material ) (0)\n\n#include <shadowmap_pars_fragment>\n// #include <bumpmap_pars_fragment>\n\n// #include <normalmap_pars_fragment>\n#ifdef USE_NORMALMAP\n\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n\n#endif\n\n#ifdef OBJECTSPACE_NORMALMAP\n\n uniform mat3 normalMatrix;\n\n#endif\n\n#if ! defined ( USE_TANGENT ) && defined ( TANGENTSPACE_NORMALMAP )\n\n // Per-Pixel Tangent Space Normal Mapping\n // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html\n\n // three-vrm specific change: it requires `uv` as an input in order to support uv scrolls\n\n // Temporary compat against shader change @ Three.js r126\n // See: #21205, #21307, #21299\n #if THREE_VRM_THREE_REVISION >= 126\n\n vec3 perturbNormal2Arb( vec2 uv, vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\n vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n vec2 st0 = dFdx( uv.st );\n vec2 st1 = dFdy( uv.st );\n\n vec3 N = normalize( surf_norm );\n\n vec3 q1perp = cross( q1, N );\n vec3 q0perp = cross( N, q0 );\n\n vec3 T = q1perp * st0.x + q0perp * st1.x;\n vec3 B = q1perp * st0.y + q0perp * st1.y;\n\n // three-vrm specific change: Workaround for the issue that happens when delta of uv = 0.0\n // TODO: Is this still required? Or shall I make a PR about it?\n if ( length( T ) == 0.0 || length( B ) == 0.0 ) {\n return surf_norm;\n }\n\n float det = max( dot( T, T ), dot( B, B ) );\n float scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det );\n\n return normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );\n\n }\n\n #else\n\n vec3 perturbNormal2Arb( vec2 uv, vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {\n\n // Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988\n\n vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n vec2 st0 = dFdx( uv.st );\n vec2 st1 = dFdy( uv.st );\n\n float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude\n\n vec3 S = ( q0 * st1.t - q1 * st0.t ) * scale;\n vec3 T = ( - q0 * st1.s + q1 * st0.s ) * scale;\n\n // three-vrm specific change: Workaround for the issue that happens when delta of uv = 0.0\n // TODO: Is this still required? Or shall I make a PR about it?\n\n if ( length( S ) == 0.0 || length( T ) == 0.0 ) {\n return surf_norm;\n }\n\n S = normalize( S );\n T = normalize( T );\n vec3 N = normalize( surf_norm );\n\n #ifdef DOUBLE_SIDED\n\n // Workaround for Adreno GPUs gl_FrontFacing bug. See #15850 and #10331\n\n bool frontFacing = dot( cross( S, T ), N ) > 0.0;\n\n mapN.xy *= ( float( frontFacing ) * 2.0 - 1.0 );\n\n #else\n\n mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\n #endif\n\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n\n }\n\n #endif\n\n#endif\n\n// #include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\n// == lighting stuff ===========================================================\nfloat getLightIntensity(\n const in IncidentLight directLight,\n const in GeometricContext geometry,\n const in float shadow,\n const in float shadingGrade\n) {\n float lightIntensity = dot( geometry.normal, directLight.direction );\n lightIntensity = 0.5 + 0.5 * lightIntensity;\n lightIntensity = lightIntensity * shadow;\n lightIntensity = lightIntensity * shadingGrade;\n lightIntensity = lightIntensity * 2.0 - 1.0;\n return shadeToony == 1.0\n ? step( shadeShift, lightIntensity )\n : smoothstep( shadeShift, shadeShift + ( 1.0 - shadeToony ), lightIntensity );\n}\n\nvec3 getLighting( const in vec3 lightColor ) {\n vec3 lighting = lightColor;\n lighting = mix(\n lighting,\n vec3( max( 0.001, max( lighting.x, max( lighting.y, lighting.z ) ) ) ),\n lightColorAttenuation\n );\n\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n lighting *= PI;\n #endif\n\n return lighting;\n}\n\nvec3 getDiffuse(\n const in MToonMaterial material,\n const in float lightIntensity,\n const in vec3 lighting\n) {\n #ifdef DEBUG_LITSHADERATE\n return vec3( BRDF_Lambert( lightIntensity * lighting ) );\n #endif\n\n return lighting * BRDF_Lambert( mix( material.shadeColor, material.diffuseColor, lightIntensity ) );\n}\n\n// == post correction ==========================================================\nvoid postCorrection() {\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n #include <premultiplied_alpha_fragment>\n #include <dithering_fragment>\n}\n\n// == main procedure ===========================================================\nvoid main() {\n #include <clipping_planes_fragment>\n\n vec2 uv = vec2(0.5, 0.5);\n\n #if ( defined( MTOON_USE_UV ) && !defined( MTOON_UVS_VERTEX_ONLY ) )\n uv = vUv;\n\n float uvAnimMask = 1.0;\n #ifdef USE_UVANIMMASKTEXTURE\n uvAnimMask = texture2D( uvAnimMaskTexture, uv ).x;\n #endif\n\n uv = uv + vec2( uvAnimOffsetX, uvAnimOffsetY ) * uvAnimMask;\n float uvRotCos = cos( uvAnimTheta * uvAnimMask );\n float uvRotSin = sin( uvAnimTheta * uvAnimMask );\n uv = mat2( uvRotCos, uvRotSin, -uvRotSin, uvRotCos ) * ( uv - 0.5 ) + 0.5;\n #endif\n\n #ifdef DEBUG_UV\n gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n #if ( defined( MTOON_USE_UV ) && !defined( MTOON_UVS_VERTEX_ONLY ) )\n gl_FragColor = vec4( uv, 0.0, 1.0 );\n #endif\n return;\n #endif\n\n vec4 diffuseColor = vec4( color, colorAlpha );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissionColor;\n\n #include <logdepthbuf_fragment>\n\n // #include <map_fragment>\n #ifdef USE_MAP\n diffuseColor *= mapTexelToLinear( texture2D( map, uv ) );\n #endif\n\n #include <color_fragment>\n // #include <alphamap_fragment>\n\n // -- MToon: alpha -----------------------------------------------------------\n // #include <alphatest_fragment>\n #ifdef BLENDMODE_CUTOUT\n if ( diffuseColor.a <= cutoff ) { discard; }\n diffuseColor.a = 1.0;\n #endif\n\n #ifdef BLENDMODE_OPAQUE\n diffuseColor.a = 1.0;\n #endif\n\n #if defined( OUTLINE ) && defined( OUTLINE_COLOR_FIXED ) // omitting DebugMode\n gl_FragColor = vec4( outlineColor, diffuseColor.a );\n postCorrection();\n return;\n #endif\n\n // #include <specularmap_fragment>\n #include <normal_fragment_begin>\n\n #ifdef OUTLINE\n normal *= -1.0;\n #endif\n\n // #include <normal_fragment_maps>\n\n #ifdef OBJECTSPACE_NORMALMAP\n\n normal = texture2D( normalMap, uv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals\n\n #ifdef FLIP_SIDED\n\n normal = - normal;\n\n #endif\n\n #ifdef DOUBLE_SIDED\n\n // Temporary compat against shader change @ Three.js r126\n // See: #21205, #21307, #21299\n #if THREE_VRM_THREE_REVISION >= 126\n\n normal = normal * faceDirection;\n\n #else\n\n normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\n #endif\n\n #endif\n\n normal = normalize( normalMatrix * normal );\n\n #elif defined( TANGENTSPACE_NORMALMAP )\n\n vec3 mapN = texture2D( normalMap, uv ).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n\n #ifdef USE_TANGENT\n\n normal = normalize( vTBN * mapN );\n\n #else\n\n // Temporary compat against shader change @ Three.js r126\n // See: #21205, #21307, #21299\n #if THREE_VRM_THREE_REVISION >= 126\n\n normal = perturbNormal2Arb( uv, -vViewPosition, normal, mapN, faceDirection );\n\n #else\n\n normal = perturbNormal2Arb( uv, -vViewPosition, normal, mapN );\n\n #endif\n\n #endif\n\n #endif\n\n // #include <emissivemap_fragment>\n #ifdef USE_EMISSIVEMAP\n totalEmissiveRadiance *= emissiveMapTexelToLinear( texture2D( emissiveMap, uv ) ).rgb;\n #endif\n\n #ifdef DEBUG_NORMAL\n gl_FragColor = vec4( 0.5 + 0.5 * normal, 1.0 );\n return;\n #endif\n\n // -- MToon: lighting --------------------------------------------------------\n // accumulation\n // #include <lights_phong_fragment>\n MToonMaterial material;\n\n material.diffuseColor = diffuseColor.rgb;\n\n material.shadeColor = shadeColor;\n #ifdef USE_SHADETEXTURE\n material.shadeColor *= shadeTextureTexelToLinear( texture2D( shadeTexture, uv ) ).rgb;\n #endif\n\n material.shadingGrade = 1.0;\n #ifdef USE_SHADINGGRADETEXTURE\n material.shadingGrade = 1.0 - shadingGradeRate * ( 1.0 - texture2D( shadingGradeTexture, uv ).r );\n #endif\n\n material.receiveShadow = receiveShadowRate;\n #ifdef USE_RECEIVESHADOWTEXTURE\n material.receiveShadow *= texture2D( receiveShadowTexture, uv ).a;\n #endif\n\n // #include <lights_fragment_begin>\n GeometricContext geometry;\n\n geometry.position = - vViewPosition;\n geometry.normal = normal;\n geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n\n IncidentLight directLight;\n vec3 lightingSum = vec3( 0.0 );\n\n // since these variables will be used in unrolled loop, we have to define in prior\n float atten, shadow, lightIntensity;\n vec3 lighting;\n\n #if ( NUM_POINT_LIGHTS > 0 )\n PointLight pointLight;\n\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n\n #if THREE_VRM_THREE_REVISION >= 132\n getPointLightInfo( pointLight, geometry, directLight );\n #else\n getPointDirectLightIrradiance( pointLight, geometry, directLight );\n #endif\n\n atten = 1.0;\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n atten = all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n\n shadow = 1.0 - material.receiveShadow * ( 1.0 - ( 0.5 + 0.5 * atten ) );\n lightIntensity = getLightIntensity( directLight, geometry, shadow, material.shadingGrade );\n lighting = getLighting( directLight.color );\n reflectedLight.directDiffuse += getDiffuse( material, lightIntensity, lighting );\n lightingSum += lighting;\n }\n #pragma unroll_loop_end\n #endif\n\n #if ( NUM_SPOT_LIGHTS > 0 )\n SpotLight spotLight;\n\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n\n #if THREE_VRM_THREE_REVISION >= 132\n getSpotLightInfo( spotLight, geometry, directLight );\n #else\n getSpotDirectLightIrradiance( spotLight, geometry, directLight );\n #endif\n\n atten = 1.0;\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n atten = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n\n shadow = 1.0 - material.receiveShadow * ( 1.0 - ( 0.5 + 0.5 * atten ) );\n lightIntensity = getLightIntensity( directLight, geometry, shadow, material.shadingGrade );\n lighting = getLighting( directLight.color );\n reflectedLight.directDiffuse += getDiffuse( material, lightIntensity, lighting );\n lightingSum += lighting;\n }\n #pragma unroll_loop_end\n #endif\n\n #if ( NUM_DIR_LIGHTS > 0 )\n DirectionalLight directionalLight;\n\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n\n #if THREE_VRM_THREE_REVISION >= 132\n getDirectionalLightInfo( directionalLight, geometry, directLight );\n #else\n getDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n #endif\n\n atten = 1.0;\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n atten = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n\n shadow = 1.0 - material.receiveShadow * ( 1.0 - ( 0.5 + 0.5 * atten ) );\n lightIntensity = getLightIntensity( directLight, geometry, shadow, material.shadingGrade );\n lighting = getLighting( directLight.color );\n reflectedLight.directDiffuse += getDiffuse( material, lightIntensity, lighting );\n lightingSum += lighting;\n }\n #pragma unroll_loop_end\n #endif\n\n // #if defined( RE_IndirectDiffuse )\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #if THREE_VRM_THREE_REVISION >= 133\n irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n #else\n irradiance += getLightProbeIrradiance( lightProbe, geometry );\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n }\n #pragma unroll_loop_end\n #endif\n // #endif\n\n // #include <lights_fragment_maps>\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vUv2 );\n vec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n #ifndef PHYSICALLY_CORRECT_LIGHTS\n lightMapIrradiance *= PI;\n #endif\n irradiance += lightMapIrradiance;\n #endif\n\n // #include <lights_fragment_end>\n // RE_IndirectDiffuse here\n reflectedLight.indirectDiffuse += indirectLightIntensity * irradiance * BRDF_Lambert( material.diffuseColor );\n\n // modulation\n #include <aomap_fragment>\n\n vec3 col = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\n // The "comment out if you want to PBR absolutely" line\n #ifndef DEBUG_LITSHADERATE\n col = min(col, material.diffuseColor);\n #endif\n\n #if defined( OUTLINE ) && defined( OUTLINE_COLOR_MIXED )\n gl_FragColor = vec4(\n outlineColor.rgb * mix( vec3( 1.0 ), col, outlineLightingMix ),\n diffuseColor.a\n );\n postCorrection();\n return;\n #endif\n\n #ifdef DEBUG_LITSHADERATE\n gl_FragColor = vec4( col, diffuseColor.a );\n postCorrection();\n return;\n #endif\n\n // -- MToon: parametric rim lighting -----------------------------------------\n vec3 viewDir = normalize( vViewPosition );\n vec3 rimMix = mix( vec3( 1.0 ), lightingSum + indirectLightIntensity * irradiance, rimLightingMix );\n vec3 rim = rimColor * pow( saturate( 1.0 - dot( viewDir, normal ) + rimLift ), rimFresnelPower );\n #ifdef USE_RIMTEXTURE\n rim *= rimTextureTexelToLinear( texture2D( rimTexture, uv ) ).rgb;\n #endif\n col += rim;\n\n // -- MToon: additive matcap -------------------------------------------------\n #ifdef USE_SPHEREADD\n {\n vec3 x = normalize( vec3( viewDir.z, 0.0, -viewDir.x ) );\n vec3 y = cross( viewDir, x ); // guaranteed to be normalized\n vec2 sphereUv = 0.5 + 0.5 * vec2( dot( x, normal ), -dot( y, normal ) );\n vec3 matcap = sphereAddTexelToLinear( texture2D( sphereAdd, sphereUv ) ).xyz;\n col += matcap;\n }\n #endif\n\n // -- MToon: Emission --------------------------------------------------------\n col += totalEmissiveRadiance;\n\n // #include <envmap_fragment>\n\n // -- Almost done! -----------------------------------------------------------\n gl_FragColor = vec4( col, diffuseColor.a );\n postCorrection();\n}',this.needsUpdate=!0}_updateCullFace(){this.isOutline?this.outlineCullMode===Y.Off?this.side=e.DoubleSide:this.outlineCullMode===Y.Front?this.side=e.BackSide:this.outlineCullMode===Y.Back&&(this.side=e.FrontSide):this.cullMode===Y.Off?this.side=e.DoubleSide:this.cullMode===Y.Front?this.side=e.BackSide:this.cullMode===Y.Back&&(this.side=e.FrontSide)}}var J;!function(e){e[e.Opaque=0]="Opaque",e[e.Cutout=1]="Cutout",e[e.Transparent=2]="Transparent",e[e.TransparentWithZWrite=3]="TransparentWithZWrite"}(J||(J={}));class K extends e.ShaderMaterial{constructor(t){super(),this.isVRMUnlitMaterial=!0,this.cutoff=.5,this.map=null,this.mainTex_ST=new e.Vector4(0,0,1,1),this._renderType=J.Opaque,this.shouldApplyUniforms=!0,void 0===t&&(t={}),t.fog=!0,t.clipping=!0,parseInt(e.REVISION,10)<129&&(t.skinning=t.skinning||!1),parseInt(e.REVISION,10)<131&&(t.morphTargets=t.morphTargets||!1,t.morphNormals=t.morphNormals||!1),t.uniforms=e.UniformsUtils.merge([e.UniformsLib.common,e.UniformsLib.fog,{cutoff:{value:.5},mainTex_ST:{value:new e.Vector4(0,0,1,1)}}]),this.setValues(t),this._updateShaderCode(),this._applyUniforms()}get mainTex(){return this.map}set mainTex(e){this.map=e}get renderType(){return this._renderType}set renderType(e){this._renderType=e,this.depthWrite=this._renderType!==J.Transparent,this.transparent=this._renderType===J.Transparent||this._renderType===J.TransparentWithZWrite,this._updateShaderCode()}updateVRMMaterials(e){this._applyUniforms()}copy(e){return super.copy(e),this.cutoff=e.cutoff,this.map=e.map,this.mainTex_ST.copy(e.mainTex_ST),this.renderType=e.renderType,this}_applyUniforms(){this.shouldApplyUniforms&&(this.shouldApplyUniforms=!1,this.uniforms.cutoff.value=this.cutoff,this.uniforms.map.value=this.map,this.uniforms.mainTex_ST.value.copy(this.mainTex_ST))}_updateShaderCode(){this.defines={RENDERTYPE_OPAQUE:this._renderType===J.Opaque,RENDERTYPE_CUTOUT:this._renderType===J.Cutout,RENDERTYPE_TRANSPARENT:this._renderType===J.Transparent||this._renderType===J.TransparentWithZWrite},this.vertexShader="#include <common>\n\n// #include <uv_pars_vertex>\n#ifdef USE_MAP\n varying vec2 vUv;\n uniform vec4 mainTex_ST;\n#endif\n\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\nvoid main() {\n\n // #include <uv_vertex>\n #ifdef USE_MAP\n vUv = vec2( mainTex_ST.p * uv.x + mainTex_ST.s, mainTex_ST.q * uv.y + mainTex_ST.t );\n #endif\n\n #include <uv2_vertex>\n #include <color_vertex>\n #include <skinbase_vertex>\n\n #ifdef USE_ENVMAP\n\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n\n #endif\n\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n\n #include <worldpos_vertex>\n #include <clipping_planes_vertex>\n #include <envmap_vertex>\n #include <fog_vertex>\n\n}",this.fragmentShader="#ifdef RENDERTYPE_CUTOUT\n uniform float cutoff;\n#endif\n\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n// #include <alphamap_pars_fragment>\n// #include <aomap_pars_fragment>\n// #include <lightmap_pars_fragment>\n// #include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n// #include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\n// == main procedure ===========================================================\nvoid main() {\n #include <clipping_planes_fragment>\n\n vec4 diffuseColor = vec4( 1.0 );\n\n #include <logdepthbuf_fragment>\n\n // #include <map_fragment>\n #ifdef USE_MAP\n diffuseColor *= mapTexelToLinear( texture2D( map, vUv ) );\n #endif\n\n #include <color_fragment>\n // #include <alphamap_fragment>\n\n // MToon: alpha\n // #include <alphatest_fragment>\n #ifdef RENDERTYPE_CUTOUT\n if ( diffuseColor.a <= cutoff ) { discard; }\n diffuseColor.a = 1.0;\n #endif\n\n #ifdef RENDERTYPE_OPAQUE\n diffuseColor.a = 1.0;\n #endif\n\n // #include <specularmap_fragment>\n\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\n // accumulation (baked indirect lighting only)\n #ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n #else\n reflectedLight.indirectDiffuse += vec3( 1.0 );\n #endif\n\n // modulation\n // #include <aomap_fragment>\n\n reflectedLight.indirectDiffuse *= diffuseColor.rgb;\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n\n // #include <envmap_fragment>\n\n gl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\n #include <premultiplied_alpha_fragment>\n #include <tonemapping_fragment>\n #include <encodings_fragment>\n #include <fog_fragment>\n}",this.needsUpdate=!0}}class ee{constructor(t={}){this._encoding=t.encoding||e.LinearEncoding,this._encoding!==e.LinearEncoding&&this._encoding!==e.sRGBEncoding&&console.warn("The specified color encoding might not work properly with VRMMaterialImporter. You might want to use THREE.sRGBEncoding instead."),this._requestEnvMap=t.requestEnvMap}convertGLTFMaterials(e){var n;return t(this,void 0,void 0,(function*(){const i=null===(n=e.parser.json.extensions)||void 0===n?void 0:n.VRM;if(!i)return null;const r=i.materialProperties;if(!r)return null;const o=yield c(e),s={},a=[];return yield Promise.all(Array.from(o.entries()).map((([n,i])=>t(this,void 0,void 0,(function*(){const o=e.parser.json.nodes[n],l=e.parser.json.meshes[o.mesh];yield Promise.all(i.map(((n,i)=>t(this,void 0,void 0,(function*(){const t=l.primitives[i];if(!t)return;const o=n.geometry,d=o.index?o.index.count:o.attributes.position.count/3;Array.isArray(n.material)||(n.material=[n.material],o.addGroup(0,d,0));const h=t.material;let u,c=r[h];c||(console.warn(`VRMMaterialImporter: There are no material definition for material #${h} on VRM extension.`),c={shader:"VRM_USE_GLTFSHADER"}),s[h]?u=s[h]:(u=yield this.createVRMMaterials(n.material[0],c,e),s[h]=u,a.push(u.surface),u.outline&&a.push(u.outline)),n.material[0]=u.surface,this._requestEnvMap&&u.surface.isMeshStandardMaterial&&this._requestEnvMap().then((e=>{u.surface.envMap=e,u.surface.needsUpdate=!0})),n.renderOrder=c.renderQueue||2e3,u.outline&&(n.material[1]=u.outline,o.addGroup(0,d,1))})))))}))))),a}))}createVRMMaterials(e,n,i){return t(this,void 0,void 0,(function*(){let t,r;if("VRM/MToon"===n.shader){const o=yield this._extractMaterialProperties(e,n,i);["srcBlend","dstBlend","isFirstSetup"].forEach((e=>{void 0!==o[e]&&delete o[e]})),["mainTex","shadeTexture","emissionMap","sphereAdd","rimTexture"].forEach((e=>{void 0!==o[e]&&(o[e].encoding=this._encoding)})),o.encoding=this._encoding,t=new $(o),o.outlineWidthMode!==Q.None&&(o.isOutline=!0,r=new $(o))}else if("VRM/UnlitTexture"===n.shader){const r=yield this._extractMaterialProperties(e,n,i);r.renderType=J.Opaque,t=new K(r)}else if("VRM/UnlitCutout"===n.shader){const r=yield this._extractMaterialProperties(e,n,i);r.renderType=J.Cutout,t=new K(r)}else if("VRM/UnlitTransparent"===n.shader){const r=yield this._extractMaterialProperties(e,n,i);r.renderType=J.Transparent,t=new K(r)}else if("VRM/UnlitTransparentZWrite"===n.shader){const r=yield this._extractMaterialProperties(e,n,i);r.renderType=J.TransparentWithZWrite,t=new K(r)}else"VRM_USE_GLTFSHADER"!==n.shader&&console.warn(`Unknown shader detected: "${n.shader}"`),t=this._convertGLTFMaterial(e.clone());return t.name=e.name,t.userData=JSON.parse(JSON.stringify(e.userData)),t.userData.vrmMaterialProperties=n,r&&(r.name=e.name+" (Outline)",r.userData=JSON.parse(JSON.stringify(e.userData)),r.userData.vrmMaterialProperties=n),{surface:t,outline:r}}))}_renameMaterialProperty(e){return"_"!==e[0]?(console.warn(`VRMMaterials: Given property name "${e}" might be invalid`),e):(e=e.substring(1),/[A-Z]/.test(e[0])?e[0].toLowerCase()+e.substring(1):(console.warn(`VRMMaterials: Given property name "${e}" might be invalid`),e))}_convertGLTFMaterial(t){if(t.isMeshStandardMaterial){const n=t;n.map&&(n.map.encoding=this._encoding),n.emissiveMap&&(n.emissiveMap.encoding=this._encoding),this._encoding===e.LinearEncoding&&(n.color.convertLinearToSRGB(),n.emissive.convertLinearToSRGB())}if(t.isMeshBasicMaterial){const n=t;n.map&&(n.map.encoding=this._encoding),this._encoding===e.LinearEncoding&&n.color.convertLinearToSRGB()}return t}_extractMaterialProperties(t,n,i){const r=[],o={};if(n.textureProperties)for(const e of Object.keys(n.textureProperties)){const t=this._renameMaterialProperty(e),s=n.textureProperties[e];r.push(i.parser.getDependency("texture",s).then((e=>{o[t]=e})))}if(n.floatProperties)for(const e of Object.keys(n.floatProperties)){const t=this._renameMaterialProperty(e);o[t]=n.floatProperties[e]}if(n.vectorProperties)for(const t of Object.keys(n.vectorProperties)){let i=this._renameMaterialProperty(t);["_MainTex","_ShadeTexture","_BumpMap","_ReceiveShadowTexture","_ShadingGradeTexture","_RimTexture","_SphereAdd","_EmissionMap","_OutlineWidthTexture","_UvAnimMaskTexture"].some((e=>t===e))&&(i+="_ST"),o[i]=new e.Vector4(...n.vectorProperties[t])}return parseInt(e.REVISION,10)<129&&(o.skinning=t.skinning||!1),parseInt(e.REVISION,10)<131&&(o.morphTargets=t.morphTargets||!1,o.morphNormals=t.morphNormals||!1),Promise.all(r).then((()=>o))}}class te{constructor(e){var t;this.ignoreTexture=null!==(t=null==e?void 0:e.ignoreTexture)&&void 0!==t&&t}import(e){var n;return t(this,void 0,void 0,(function*(){const t=null===(n=e.parser.json.extensions)||void 0===n?void 0:n.VRM;if(!t)return null;const i=t.meta;if(!i)return null;let r;return this.ignoreTexture||null==i.texture||-1===i.texture||(r=yield e.parser.getDependency("texture",i.texture)),{allowedUserName:i.allowedUserName,author:i.author,commercialUssageName:i.commercialUssageName,contactInformation:i.contactInformation,licenseName:i.licenseName,otherLicenseUrl:i.otherLicenseUrl,otherPermissionUrl:i.otherPermissionUrl,reference:i.reference,sexualUssageName:i.sexualUssageName,texture:null!=r?r:void 0,title:i.title,version:i.version,violentUssageName:i.violentUssageName}}))}}const ne=new e.Matrix4;function ie(e){return e.invert?e.invert():e.getInverse(ne.copy(e)),e}class re{constructor(t){this._inverseCache=new e.Matrix4,this._shouldUpdateInverse=!0,this.matrix=t;const n={set:(e,t,n)=>(this._shouldUpdateInverse=!0,e[t]=n,!0)};this._originalElements=t.elements,t.elements=new Proxy(t.elements,n)}get inverse(){return this._shouldUpdateInverse&&(ie(this._inverseCache.copy(this.matrix)),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}}const oe=Object.freeze(new e.Matrix4),se=Object.freeze(new e.Quaternion),ae=new e.Vector3,le=new e.Vector3,de=new e.Vector3,he=new e.Quaternion,ue=new e.Matrix4,ce=new e.Matrix4;class pe{constructor(t,n={}){var i,r,o,s,a,l;if(this._currentTail=new e.Vector3,this._prevTail=new e.Vector3,this._nextTail=new e.Vector3,this._boneAxis=new e.Vector3,this._centerSpacePosition=new e.Vector3,this._center=null,this._parentWorldRotation=new e.Quaternion,this._initialLocalMatrix=new e.Matrix4,this._initialLocalRotation=new e.Quaternion,this._initialLocalChildPosition=new e.Vector3,this.bone=t,this.bone.matrixAutoUpdate=!1,this.radius=null!==(i=n.radius)&&void 0!==i?i:.02,this.stiffnessForce=null!==(r=n.stiffnessForce)&&void 0!==r?r:1,this.gravityDir=n.gravityDir?(new e.Vector3).copy(n.gravityDir):(new e.Vector3).set(0,-1,0),this.gravityPower=null!==(o=n.gravityPower)&&void 0!==o?o:0,this.dragForce=null!==(s=n.dragForce)&&void 0!==s?s:.4,this.colliders=null!==(a=n.colliders)&&void 0!==a?a:[],this._centerSpacePosition.setFromMatrixPosition(this.bone.matrixWorld),this._initialLocalMatrix.copy(this.bone.matrix),this._initialLocalRotation.copy(this.bone.quaternion),0===this.bone.children.length)this._initialLocalChildPosition.copy(this.bone.position).normalize().multiplyScalar(.07);else{const e=this.bone.children[0];this._initialLocalChildPosition.copy(e.position)}this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)),this._prevTail.copy(this._currentTail),this._nextTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize(),this._centerSpaceBoneLength=ae.copy(this._initialLocalChildPosition).applyMatrix4(this.bone.matrixWorld).sub(this._centerSpacePosition).length(),this.center=null!==(l=n.center)&&void 0!==l?l:null}get center(){return this._center}set center(e){var t;this._getMatrixCenterToWorld(ue),this._currentTail.applyMatrix4(ue),this._prevTail.applyMatrix4(ue),this._nextTail.applyMatrix4(ue),(null===(t=this._center)||void 0===t?void 0:t.userData.inverseCacheProxy)&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=e,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new re(this._center.matrixWorld))),this._getMatrixWorldToCenter(ue),this._currentTail.applyMatrix4(ue),this._prevTail.applyMatrix4(ue),this._nextTail.applyMatrix4(ue),ue.multiply(this.bone.matrixWorld),this._centerSpacePosition.setFromMatrixPosition(ue),this._centerSpaceBoneLength=ae.copy(this._initialLocalChildPosition).applyMatrix4(ue).sub(this._centerSpacePosition).length()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._getParentMatrixWorld(),this.bone.matrix),this._centerSpacePosition.setFromMatrixPosition(this.bone.matrixWorld),this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)),this._prevTail.copy(this._currentTail),this._nextTail.copy(this._currentTail)}update(e){if(e<=0)return;this.bone.matrixWorld.multiplyMatrices(this._getParentMatrixWorld(),this.bone.matrix),this.bone.parent?g(this.bone.parent,this._parentWorldRotation):this._parentWorldRotation.copy(se),this._getMatrixWorldToCenter(ue),ue.multiply(this.bone.matrixWorld),this._centerSpacePosition.setFromMatrixPosition(ue),this._getMatrixWorldToCenter(ce),ce.multiply(this._getParentMatrixWorld());const t=this.stiffnessForce*e,n=le.copy(this.gravityDir).multiplyScalar(this.gravityPower*e);this._nextTail.copy(this._currentTail).add(ae.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.dragForce)).add(ae.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(ce).sub(this._centerSpacePosition).normalize().multiplyScalar(t)).add(n),this._nextTail.sub(this._centerSpacePosition).normalize().multiplyScalar(this._centerSpaceBoneLength).add(this._centerSpacePosition),this._collision(this._nextTail),this._prevTail.copy(this._currentTail),this._currentTail.copy(this._nextTail);const i=ie(ue.copy(ce.multiply(this._initialLocalMatrix))),r=he.setFromUnitVectors(this._boneAxis,ae.copy(this._nextTail).applyMatrix4(i).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(r),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._getParentMatrixWorld(),this.bone.matrix)}_collision(e){this.colliders.forEach((t=>{this._getMatrixWorldToCenter(ue),ue.multiply(t.matrixWorld);const n=ae.setFromMatrixPosition(ue),i=t.geometry.boundingSphere.radius,r=this.radius+i;if(e.distanceToSquared(n)<=r*r){const t=le.subVectors(e,n).normalize(),i=de.addVectors(n,t.multiplyScalar(r));e.copy(i.sub(this._centerSpacePosition).normalize().multiplyScalar(this._centerSpaceBoneLength).add(this._centerSpacePosition))}}))}_getMatrixCenterToWorld(e){return this._center?e.copy(this._center.matrixWorld):e.identity(),e}_getMatrixWorldToCenter(e){return this._center?e.copy(this._center.userData.inverseCacheProxy.inverse):e.identity(),e}_getParentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:oe}}class me{constructor(e,t){this.colliderGroups=[],this.springBoneGroupList=[],this.colliderGroups=e,this.springBoneGroupList=t}setCenter(e){this.springBoneGroupList.forEach((t=>{t.forEach((t=>{t.center=e}))}))}lateUpdate(e){this.springBoneGroupList.forEach((t=>{t.forEach((t=>{t.update(e)}))}))}reset(){this.springBoneGroupList.forEach((e=>{e.forEach((e=>{e.reset()}))}))}}const fe=new e.Vector3,ge=new e.MeshBasicMaterial({visible:!1});class _e{import(e){var n;return t(this,void 0,void 0,(function*(){const t=null===(n=e.parser.json.extensions)||void 0===n?void 0:n.VRM;if(!t)return null;const i=t.secondaryAnimation;if(!i)return null;const r=yield this._importColliderMeshGroups(e,i),o=yield this._importSpringBoneGroupList(e,i,r);return new me(r,o)}))}_createSpringBone(e,t={}){return new pe(e,t)}_importSpringBoneGroupList(n,i,r){return t(this,void 0,void 0,(function*(){const o=i.boneGroups||[],s=[];return yield Promise.all(o.map((i=>t(this,void 0,void 0,(function*(){if(void 0===i.stiffiness||void 0===i.gravityDir||void 0===i.gravityDir.x||void 0===i.gravityDir.y||void 0===i.gravityDir.z||void 0===i.gravityPower||void 0===i.dragForce||void 0===i.hitRadius||void 0===i.colliderGroups||void 0===i.bones||void 0===i.center)return;const o=i.stiffiness,a=new e.Vector3(i.gravityDir.x,i.gravityDir.y,-i.gravityDir.z),l=i.gravityPower,d=i.dragForce,h=i.hitRadius,u=[];i.colliderGroups.forEach((e=>{u.push(...r[e].colliders)}));const c=[];yield Promise.all(i.bones.map((e=>t(this,void 0,void 0,(function*(){const t=yield n.parser.getDependency("node",e),r=-1!==i.center?yield n.parser.getDependency("node",i.center):null;t&&t.traverse((e=>{const t=this._createSpringBone(e,{radius:h,stiffnessForce:o,gravityDir:a,gravityPower:l,dragForce:d,colliders:u,center:r});c.push(t)}))}))))),s.push(c)}))))),s}))}_importColliderMeshGroups(e,n){return t(this,void 0,void 0,(function*(){const i=n.colliderGroups;if(void 0===i)return[];const r=[];return i.forEach((n=>t(this,void 0,void 0,(function*(){if(void 0===n.node||void 0===n.colliders)return;const t=yield e.parser.getDependency("node",n.node),i=[];n.colliders.forEach((e=>{if(void 0===e.offset||void 0===e.offset.x||void 0===e.offset.y||void 0===e.offset.z||void 0===e.radius)return;const n=fe.set(e.offset.x,e.offset.y,-e.offset.z),r=this._createColliderMesh(e.radius,n);t.add(r),i.push(r)}));const o={node:n.node,colliders:i};r.push(o)})))),r}))}_createColliderMesh(t,n){const i=new e.Mesh(new e.SphereBufferGeometry(t,8,4),ge);return i.position.copy(n),i.name="vrmColliderSphere",i.geometry.computeBoundingSphere(),i}}class ve{constructor(e={}){this._metaImporter=e.metaImporter||new te,this._blendShapeImporter=e.blendShapeImporter||new v,this._lookAtImporter=e.lookAtImporter||new W,this._humanoidImporter=e.humanoidImporter||new C,this._firstPersonImporter=e.firstPersonImporter||new E,this._materialImporter=e.materialImporter||new ee,this._springBoneImporter=e.springBoneImporter||new _e}import(e){return t(this,void 0,void 0,(function*(){if(void 0===e.parser.json.extensions||void 0===e.parser.json.extensions.VRM)throw new Error("Could not find VRM extension on the GLTF");const t=e.scene;t.updateMatrixWorld(!1),t.traverse((e=>{e.isMesh&&(e.frustumCulled=!1)}));const n=(yield this._metaImporter.import(e))||void 0,i=(yield this._materialImporter.convertGLTFMaterials(e))||void 0,r=(yield this._humanoidImporter.import(e))||void 0,o=r&&(yield this._firstPersonImporter.import(e,r))||void 0,s=(yield this._blendShapeImporter.import(e))||void 0,a=o&&s&&r&&(yield this._lookAtImporter.import(e,o,s,r))||void 0,l=(yield this._springBoneImporter.import(e))||void 0;return new ye({scene:e.scene,meta:n,materials:i,humanoid:r,firstPerson:o,blendShapeProxy:s,lookAt:a,springBoneManager:l})}))}}class ye{constructor(e){this.scene=e.scene,this.humanoid=e.humanoid,this.blendShapeProxy=e.blendShapeProxy,this.firstPerson=e.firstPerson,this.lookAt=e.lookAt,this.materials=e.materials,this.springBoneManager=e.springBoneManager,this.meta=e.meta}static from(e,n={}){return t(this,void 0,void 0,(function*(){const t=new ve(n);return yield t.import(e)}))}update(e){this.lookAt&&this.lookAt.update(e),this.blendShapeProxy&&this.blendShapeProxy.update(),this.springBoneManager&&this.springBoneManager.lateUpdate(e),this.materials&&this.materials.forEach((t=>{t.updateVRMMaterials&&t.updateVRMMaterials(e)}))}dispose(){var e,t;const n=this.scene;n&&n.traverse(i),null===(t=null===(e=this.meta)||void 0===e?void 0:e.texture)||void 0===t||t.dispose()}}const Te=new e.Vector2,xe=new e.OrthographicCamera(-1,1,-1,1,-1,1),Se=new e.MeshBasicMaterial({color:16777215,side:e.DoubleSide}),Me=new e.Mesh(new e.PlaneBufferGeometry(2,2),Se),Ee=new e.Scene;Ee.add(Me);class Le{constructor(){}}Le.extractThumbnailBlob=function(e,t,n=512){var i;const r=null===(i=t.meta)||void 0===i?void 0:i.texture;if(!r)throw new Error("extractThumbnailBlob: This VRM does not have a thumbnail");const o=e.getContext().canvas;e.getSize(Te);const s=Te.x,a=Te.y;return e.setSize(n,n,!1),Se.map=r,e.render(Ee,xe),Se.map=null,o instanceof OffscreenCanvas?o.convertToBlob().finally((()=>{e.setSize(s,a,!1)})):new Promise(((t,n)=>{o.toBlob((i=>{e.setSize(s,a,!1),null==i?n("extractThumbnailBlob: Failed to create a blob"):t(i)}))}))},Le.removeUnnecessaryJoints=function(t){const n=new Map;t.traverse((t=>{if("SkinnedMesh"!==t.type)return;const i=t,r=i.geometry.getAttribute("skinIndex");let o=n.get(r);if(!o){const t=[],s=[],a={},l=r.array;for(let e=0;e<l.length;e++){const n=l[e];void 0===a[n]&&(a[n]=t.length,t.push(i.skeleton.bones[n]),s.push(i.skeleton.boneInverses[n])),l[e]=a[n]}r.copyArray(l),r.needsUpdate=!0,o=new e.Skeleton(t,s),n.set(r,o)}i.bind(o,new e.Matrix4)}))};const we=new e.Vector3;class Re extends G{setupHelper(t,n){n.disableFaceDirectionHelper||(this._faceDirectionHelper=new e.ArrowHelper(new e.Vector3(0,0,-1),new e.Vector3(0,0,0),.5,16711935),t.add(this._faceDirectionHelper))}update(e){super.update(e),this._faceDirectionHelper&&(this.firstPerson.getFirstPersonWorldPosition(this._faceDirectionHelper.position),this._faceDirectionHelper.setDirection(this.getLookAtWorldDirection(we)))}}class Pe extends W{import(e,t,n,i){var r;const o=null===(r=e.parser.json.extensions)||void 0===r?void 0:r.VRM;if(!o)return null;const s=o.firstPerson;if(!s)return null;const a=this._importApplyer(s,n,i);return new Re(t,a||void 0)}}const Ae=new e.MeshBasicMaterial({color:16711935,wireframe:!0,transparent:!0,depthTest:!1});class Ce extends me{setupHelper(e,t){t.disableSpringBoneHelper||(this.springBoneGroupList.forEach((t=>{t.forEach((t=>{if(t.getGizmo){const n=t.getGizmo();e.add(n)}}))})),this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{e.material=Ae,e.renderOrder=De}))})))}}const Oe=new e.Vector3;class be extends pe{constructor(e,t){super(e,t)}getGizmo(){if(this._gizmo)return this._gizmo;const t=Oe.copy(this._nextTail).sub(this._centerSpacePosition),n=t.length();return this._gizmo=new e.ArrowHelper(t.normalize(),this._centerSpacePosition,n,16776960,this.radius,this.radius),this._gizmo.line.renderOrder=De,this._gizmo.cone.renderOrder=De,this._gizmo.line.material.depthTest=!1,this._gizmo.line.material.transparent=!0,this._gizmo.cone.material.depthTest=!1,this._gizmo.cone.material.transparent=!0,this._gizmo}update(e){super.update(e),this._updateGizmo()}_updateGizmo(){if(!this._gizmo)return;const e=Oe.copy(this._currentTail).sub(this._centerSpacePosition),t=e.length();this._gizmo.setDirection(e.normalize()),this._gizmo.setLength(t,this.radius,this.radius),this._gizmo.position.copy(this._centerSpacePosition)}}class Ie extends _e{import(e){var n;return t(this,void 0,void 0,(function*(){const t=null===(n=e.parser.json.extensions)||void 0===n?void 0:n.VRM;if(!t)return null;const i=t.secondaryAnimation;if(!i)return null;const r=yield this._importColliderMeshGroups(e,i),o=yield this._importSpringBoneGroupList(e,i,r);return new Ce(r,o)}))}_createSpringBone(e,t){return new be(e,t)}}class Ne extends ve{constructor(e={}){e.lookAtImporter=e.lookAtImporter||new Pe,e.springBoneImporter=e.springBoneImporter||new Ie,super(e)}import(e,n={}){return t(this,void 0,void 0,(function*(){if(void 0===e.parser.json.extensions||void 0===e.parser.json.extensions.VRM)throw new Error("Could not find VRM extension on the GLTF");const t=e.scene;t.updateMatrixWorld(!1),t.traverse((e=>{e.isMesh&&(e.frustumCulled=!1)}));const i=(yield this._metaImporter.import(e))||void 0,r=(yield this._materialImporter.convertGLTFMaterials(e))||void 0,o=(yield this._humanoidImporter.import(e))||void 0,s=o&&(yield this._firstPersonImporter.import(e,o))||void 0,a=(yield this._blendShapeImporter.import(e))||void 0,l=s&&a&&o&&(yield this._lookAtImporter.import(e,s,a,o))||void 0;l.setupHelper&&l.setupHelper(t,n);const d=(yield this._springBoneImporter.import(e))||void 0;return d.setupHelper&&d.setupHelper(t,n),new Ue({scene:e.scene,meta:i,materials:r,humanoid:o,firstPerson:s,blendShapeProxy:a,lookAt:l,springBoneManager:d},n)}))}}const De=1e4;class Ue extends ye{static from(e,n={},i={}){return t(this,void 0,void 0,(function*(){const t=new Ne(n);return yield t.import(e,i)}))}constructor(t,n={}){super(t),n.disableBoxHelper||this.scene.add(new e.BoxHelper(this.scene)),n.disableSkeletonHelper||this.scene.add(new e.SkeletonHelper(this.scene))}update(e){super.update(e)}}export{$ as MToonMaterial,Y as MToonMaterialCullMode,X as MToonMaterialDebugMode,q as MToonMaterialOutlineColorMode,Q as MToonMaterialOutlineWidthMode,Z as MToonMaterialRenderMode,ye as VRM,d as VRMBlendShapeGroup,v as VRMBlendShapeImporter,_ as VRMBlendShapeProxy,O as VRMCurveMapper,Ue as VRMDebug,M as VRMFirstPerson,E as VRMFirstPersonImporter,L as VRMHumanBone,A as VRMHumanoid,C as VRMHumanoidImporter,ve as VRMImporter,b as VRMLookAtApplyer,I as VRMLookAtBlendShapeApplyer,k as VRMLookAtBoneApplyer,G as VRMLookAtHead,W as VRMLookAtImporter,ee as VRMMaterialImporter,te as VRMMetaImporter,S as VRMRendererFirstPersonFlags,h as VRMSchema,pe as VRMSpringBone,be as VRMSpringBoneDebug,_e as VRMSpringBoneImporter,Ie as VRMSpringBoneImporterDebug,me as VRMSpringBoneManager,K as VRMUnlitMaterial,J as VRMUnlitMaterialRenderType,Le as VRMUtils,De as VRM_GIZMO_RENDER_ORDER};
|