@pixiv/three-vrm
Version:
VRM file loader for three.js.
11 lines (10 loc) • 13.4 kB
JavaScript
/*! (c) 2019-2025 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
"use strict";var B=Object.create;var v=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var o in e)v(t,o,{get:e[o],enumerable:!0})},O=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of K(e))!Z.call(t,l)&&l!==o&&v(t,l,{get:()=>e[l],enumerable:!(r=q(e,l))||r.enumerable});return t};var h=(t,e,o)=>(o=t!=null?B(j(t)):{},O(e||!t||!t.__esModule?v(o,"default",{value:t,enumerable:!0}):o,t)),G=t=>O(v({},"__esModule",{value:!0}),t);var Ct={};$(Ct,{MToonAnimatedUVNode:()=>D,MToonLightingModel:()=>z,MToonNodeMaterial:()=>yt});module.exports=G(Ct);var b=h(require("three"),1),s=h(require("three/webgpu"),1),a=h(require("three/webgpu"),1),n=h(require("three/webgpu"),1),u=h(require("three/webgpu"),1),E=h(require("three/webgpu"),1),i=h(require("three/webgpu"),1),p=h(require("three/webgpu"),1);var W=parseInt(b.REVISION,10);W<167&&console.warn(`MToonNodeMaterial requires Three.js r167 or higher (You are using r${W}). This would not work correctly.`);var J=a.materialReference("color","color"),Q=a.materialReference("map","texture"),tt=a.materialReference("normalMap","texture"),et=a.materialReference("normalScale","vec2"),it=a.materialReference("emissive","color"),ot=a.materialReference("emissiveIntensity","float"),rt=a.materialReference("emissiveMap","texture"),at=a.materialReference("shadeColorFactor","color"),lt=a.materialReference("shadingShiftFactor","float"),U=a.materialReference("shadeMultiplyTexture","texture"),nt=a.materialReference("shadeMultiplyTextureScale","float"),st=a.materialReference("shadingToonyFactor","float"),ut=a.materialReference("rimLightingMixFactor","float"),mt=a.materialReference("rimMultiplyTexture","texture"),ht=a.materialReference("matcapFactor","color"),dt=a.materialReference("matcapTexture","texture"),ct=a.materialReference("parametricRimColorFactor","color"),Et=a.materialReference("parametricRimLiftFactor","float"),pt=a.materialReference("parametricRimFresnelPowerFactor","float"),Rt=a.materialReference("outlineWidthMultiplyTexture","texture"),ft=a.materialReference("outlineWidthFactor","float"),I=a.materialReference("outlineColorFactor","color"),Tt=a.materialReference("outlineLightingMixFactor","float"),vt=a.materialReference("uvAnimationMaskTexture","texture"),Nt=a.materialReference("uvAnimationScrollXOffset","float"),gt=a.materialReference("uvAnimationScrollYOffset","float"),Ht=a.materialReference("uvAnimationRotationPhase","float"),D=class extends s.TempNode{constructor(t){super("vec2"),this.hasMaskTexture=t}setup(){let t=1;this.hasMaskTexture&&(t=s.vec4(vt).context({getUV:()=>s.uv()}).r);let e=s.uv(),o=Ht.mul(t),r=s.cos(o),l=s.sin(o);e=e.sub(s.vec2(.5,.5)),e=e.mul(s.mat2(r,l,l.negate(),r)),e=e.add(s.vec2(.5,.5));let m=s.vec2(Nt,gt).mul(t);return e=e.add(m),e.toVar("AnimatedUV")}},k=u.nodeImmutable(u.PropertyNode,"vec3").toVar("ShadeColor"),Y=u.nodeImmutable(u.PropertyNode,"float").toVar("ShadingShift"),X=u.nodeImmutable(u.PropertyNode,"float").toVar("ShadingToony"),g=u.nodeImmutable(u.PropertyNode,"float").toVar("RimLightingMix"),H=u.nodeImmutable(u.PropertyNode,"vec3").toVar("RimMultiply"),M=u.nodeImmutable(u.PropertyNode,"vec3").toVar("matcap"),x=u.nodeImmutable(u.PropertyNode,"vec3").toVar("ParametricRim"),N=t=>parseInt(E.REVISION,10)>=168?E.Fn(t):E.tslFn(t),Mt=N(({a:t,b:e,t:o})=>{let r=o.sub(t),l=e.sub(t);return r.div(l).clamp()}),xt=N(({dotNL:t})=>{let o=n.float(1).sub(X),r=t.add(Y);return r=Mt({a:o.negate(),b:o,t:r}),r=r.mul(1),r}),St=N(({shading:t,lightColor:e})=>{let o=n.mix(k,n.diffuseColor,t);return e.mul(n.BRDF_Lambert({diffuseColor:o}))}),z=class extends n.LightingModel{constructor(){super()}direct({lightDirection:t,lightColor:e,reflectedLight:o}){let r=n.transformedNormalView.dot(t).clamp(-1,1),l=xt({dotNL:r});o.directDiffuse.assign(o.directDiffuse.add(St({shading:l,lightColor:e}))),o.directSpecular.assign(o.directSpecular.add(x.add(M).mul(H).mul(n.mix(n.vec3(0),n.BRDF_Lambert({diffuseColor:e}),g))))}indirect(t){this.indirectDiffuse(t),this.indirectSpecular(t)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.assign(e.indirectDiffuse.add(t.mul(n.BRDF_Lambert({diffuseColor:n.diffuseColor}))))}indirectSpecular({reflectedLight:t}){t.indirectSpecular.assign(t.indirectSpecular.add(x.add(M).mul(H).mul(n.mix(n.vec3(1),n.vec3(0),g))))}},f={None:"none",WorldCoordinates:"worldCoordinates",ScreenCoordinates:"screenCoordinates"},Ft=N(({parametricRimLift:t,parametricRimFresnelPower:e,parametricRimColor:o})=>{let r=p.modelViewPosition.normalize(),l=p.transformedNormalView.dot(r.negate());return p.float(1).sub(l).add(t).clamp().pow(e).mul(o)}),yt=class extends i.NodeMaterial{customProgramCacheKey(){let t=super.customProgramCacheKey();return t+=`isOutline:${this.isOutline},`,t}get isMToonNodeMaterial(){return!0}constructor(t={}){super(),t.transparentWithZWrite&&(t.depthWrite=!0),delete t.transparentWithZWrite,delete t.giEqualizationFactor,delete t.v0CompatShade,delete t.debugMode,this.emissiveNode=null,this.lights=!0,this.color=new i.Color(1,1,1),this.map=null,this.emissive=new i.Color(0,0,0),this.emissiveIntensity=1,this.emissiveMap=null,this.normalMap=null,this.normalScale=new i.Vector2(1,1),this.shadeColorFactor=new i.Color(0,0,0),this.shadeMultiplyTexture=null,this.shadingShiftFactor=0,this.shadingShiftTexture=null,this.shadingShiftTextureScale=1,this.shadingToonyFactor=.9,this.rimLightingMixFactor=1,this.rimMultiplyTexture=null,this.matcapFactor=new i.Color(1,1,1),this.matcapTexture=null,this.parametricRimColorFactor=new i.Color(0,0,0),this.parametricRimLiftFactor=0,this.parametricRimFresnelPowerFactor=5,this.outlineWidthMode=f.None,this.outlineWidthMultiplyTexture=null,this.outlineWidthFactor=0,this.outlineColorFactor=new i.Color(0,0,0),this.outlineLightingMixFactor=1,this.uvAnimationScrollXSpeedFactor=0,this.uvAnimationScrollYSpeedFactor=0,this.uvAnimationRotationSpeedFactor=0,this.uvAnimationMaskTexture=null,this.shadeColorNode=null,this.shadingShiftNode=null,this.shadingToonyNode=null,this.rimLightingMixNode=null,this.rimMultiplyNode=null,this.matcapNode=null,this.parametricRimColorNode=null,this.parametricRimLiftNode=null,this.parametricRimFresnelPowerNode=null,this.uvAnimationScrollXOffset=0,this.uvAnimationScrollYOffset=0,this.uvAnimationRotationPhase=0,this.isOutline=!1,this._animatedUVNode=null,this.setValues(t)}setupLightingModel(){return new z}setup(t){var e;this._animatedUVNode=new D((e=this.uvAnimationMaskTexture&&this.uvAnimationMaskTexture.isTexture===!0)!=null?e:!1),super.setup(t)}setupDiffuseColor(t){let e=null;if(this.colorNode==null){if(e=J,this.map&&this.map.isTexture===!0){let o=Q.context({getUV:()=>this._animatedUVNode});e=e.mul(o)}this.colorNode=e}this.vertexColors===!0&&t.geometry.hasAttribute("color")&&(console.warn("MToonNodeMaterial: MToon ignores vertex colors. Consider using a model without vertex colors instead."),this.vertexColors=!1),super.setupDiffuseColor(t),parseInt(i.REVISION,10)<166&&this.transparent===!1&&this.blending===i.NormalBlending&&this.alphaToCoverage===!1&&i.diffuseColor.a.assign(1),this.colorNode===e&&(this.colorNode=null)}setupVariants(){k.assign(this._setupShadeColorNode()),Y.assign(this._setupShadingShiftNode()),X.assign(this._setupShadingToonyNode()),g.assign(this._setupRimLightingMixNode()),H.assign(this._setupRimMultiplyNode()),M.assign(this._setupMatcapNode()),x.assign(this._setupParametricRimNode())}setupNormal(t){let e=this.normalNode;if(this.normalNode==null){if(this.normalNode=i.materialNormal,this.normalMap&&this.normalMap.isTexture===!0){let r=tt.context({getUV:()=>this._animatedUVNode});this.normalNode=i.normalMap(r,et)}this.isOutline&&(this.normalNode=this.normalNode.negate())}if(parseInt(i.REVISION,10)>=168){let r=this.normalNode;return this.normalNode=e,r}else{super.setupNormal(t),this.normalNode=e;return}}setupLighting(t){let e=null;if(this.emissiveNode==null){if(e=it.mul(ot),this.emissiveMap&&this.emissiveMap.isTexture===!0){let r=rt.context({getUV:()=>this._animatedUVNode});e=e.mul(r)}this.emissiveNode=e}let o=super.setupLighting(t);return this.emissiveNode===e&&(this.emissiveNode=null),o}setupOutput(t,e){return this.isOutline&&this.outlineWidthMode!==f.None&&(e=i.vec4(i.mix(I,e.xyz.mul(I),Tt),e.w)),super.setupOutput(t,e)}setupPosition(t){var e,o;let r=this.positionNode;if(this.isOutline&&this.outlineWidthMode!==f.None){(e=this.positionNode)!=null||(this.positionNode=i.positionLocal);let m=i.normalLocal.normalize(),d=ft;if(this.outlineWidthMultiplyTexture&&this.outlineWidthMultiplyTexture.isTexture===!0){let c=Rt.context({getUV:()=>this._animatedUVNode});d=d.mul(c)}let T=i.length(i.modelNormalMatrix.mul(m)),R=d.mul(T).mul(m);if(this.outlineWidthMode===f.WorldCoordinates)this.positionNode=this.positionNode.add(R);else if(this.outlineWidthMode===f.ScreenCoordinates){let c=i.cameraProjectionMatrix.element(1).element(1);this.positionNode=this.positionNode.add(R.div(c).mul(i.positionView.z.negate()))}(o=this.positionNode)!=null||(this.positionNode=i.positionLocal)}let l=super.setupPosition(t);return l.z.add(l.w.mul(1e-6)),this.positionNode=r,l}copy(t){var e,o,r,l,m,d,T,R,c,S,F,y,C,_,V,L,w,P,A;return this.color.copy(t.color),this.map=(e=t.map)!=null?e:null,this.emissive.copy(t.emissive),this.emissiveIntensity=t.emissiveIntensity,this.emissiveMap=(o=t.emissiveMap)!=null?o:null,this.normalMap=(r=t.normalMap)!=null?r:null,this.normalScale.copy(t.normalScale),this.shadeColorFactor.copy(t.shadeColorFactor),this.shadeMultiplyTexture=(l=t.shadeMultiplyTexture)!=null?l:null,this.shadingShiftFactor=t.shadingShiftFactor,this.shadingShiftTexture=(m=t.shadingShiftTexture)!=null?m:null,this.shadingShiftTextureScale=t.shadingShiftTextureScale,this.shadingToonyFactor=t.shadingToonyFactor,this.rimLightingMixFactor=t.rimLightingMixFactor,this.rimMultiplyTexture=(d=t.rimMultiplyTexture)!=null?d:null,this.matcapFactor.copy(t.matcapFactor),this.matcapTexture=(T=t.matcapTexture)!=null?T:null,this.parametricRimColorFactor.copy(t.parametricRimColorFactor),this.parametricRimLiftFactor=t.parametricRimLiftFactor,this.parametricRimFresnelPowerFactor=t.parametricRimFresnelPowerFactor,this.outlineWidthMode=t.outlineWidthMode,this.outlineWidthMultiplyTexture=(R=t.outlineWidthMultiplyTexture)!=null?R:null,this.outlineWidthFactor=t.outlineWidthFactor,this.outlineColorFactor.copy(t.outlineColorFactor),this.outlineLightingMixFactor=t.outlineLightingMixFactor,this.uvAnimationScrollXSpeedFactor=t.uvAnimationScrollXSpeedFactor,this.uvAnimationScrollYSpeedFactor=t.uvAnimationScrollYSpeedFactor,this.uvAnimationRotationSpeedFactor=t.uvAnimationRotationSpeedFactor,this.uvAnimationMaskTexture=(c=t.uvAnimationMaskTexture)!=null?c:null,this.shadeColorNode=(S=t.shadeColorNode)!=null?S:null,this.shadingShiftNode=(F=t.shadingShiftNode)!=null?F:null,this.shadingToonyNode=(y=t.shadingToonyNode)!=null?y:null,this.rimLightingMixNode=(C=t.rimLightingMixNode)!=null?C:null,this.rimMultiplyNode=(_=t.rimMultiplyNode)!=null?_:null,this.matcapNode=(V=t.matcapNode)!=null?V:null,this.parametricRimColorNode=(L=t.parametricRimColorNode)!=null?L:null,this.parametricRimLiftNode=(w=t.parametricRimLiftNode)!=null?w:null,this.parametricRimFresnelPowerNode=(P=t.parametricRimFresnelPowerNode)!=null?P:null,this.isOutline=(A=t.isOutline)!=null?A:null,super.copy(t)}update(t){this.uvAnimationScrollXOffset+=t*this.uvAnimationScrollXSpeedFactor,this.uvAnimationScrollYOffset+=t*this.uvAnimationScrollYSpeedFactor,this.uvAnimationRotationPhase+=t*this.uvAnimationRotationSpeedFactor}_setupShadeColorNode(){if(this.shadeColorNode!=null)return i.vec3(this.shadeColorNode);let t=at;if(this.shadeMultiplyTexture&&this.shadeMultiplyTexture.isTexture===!0){let e=U.context({getUV:()=>this._animatedUVNode});t=t.mul(e)}return t}_setupShadingShiftNode(){if(this.shadingShiftNode!=null)return i.float(this.shadingShiftNode);let t=lt;if(this.shadingShiftTexture&&this.shadingShiftTexture.isTexture===!0){let e=U.context({getUV:()=>this._animatedUVNode});t=t.add(e.mul(nt))}return t}_setupShadingToonyNode(){return this.shadingToonyNode!=null?i.float(this.shadingToonyNode):st}_setupRimLightingMixNode(){return this.rimLightingMixNode!=null?i.float(this.rimLightingMixNode):ut}_setupRimMultiplyNode(){return this.rimMultiplyNode!=null?i.vec3(this.rimMultiplyNode):this.rimMultiplyTexture&&this.rimMultiplyTexture.isTexture===!0?mt.context({getUV:()=>this._animatedUVNode}):i.vec3(1)}_setupMatcapNode(){return this.matcapNode!=null?i.vec3(this.matcapNode):this.matcapTexture&&this.matcapTexture.isTexture===!0?dt.context({getUV:()=>i.matcapUV.mul(1,-1).add(0,1)}).mul(ht):i.vec3(0)}_setupParametricRimNode(){let t=this.parametricRimColorNode!=null?i.vec3(this.parametricRimColorNode):ct,e=this.parametricRimLiftNode!=null?i.float(this.parametricRimLiftNode):Et,o=this.parametricRimFresnelPowerNode!=null?i.float(this.parametricRimFresnelPowerNode):pt;return Ft({parametricRimLift:e,parametricRimFresnelPower:o,parametricRimColor:t})}};
/*!
* @pixiv/three-vrm-materials-mtoon v3.3.6
* MToon (toon material) module for @pixiv/three-vrm
*
* Copyright (c) 2019-2025 pixiv Inc.
* @pixiv/three-vrm-materials-mtoon is distributed under MIT License
* https://github.com/pixiv/three-vrm/blob/release/LICENSE
*/