@pixiv/three-vrm 3.0.0-beta.2 → 3.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,15 +20,13 @@ Use [VRM](https://vrm.dev/) on [three.js](https://threejs.org/)
20
20
 
21
21
  You will need:
22
22
 
23
- - [Three.js build](https://github.com/mrdoob/three.js/blob/master/build/three.js)
24
- - [GLTFLoader](https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/GLTFLoader.js)
25
- - [A build of @pixiv/three-vrm](https://www.jsdelivr.com/package/npm/@pixiv/three-vrm?tab=files&path=lib)
23
+ - Three.js build
24
+ - GLTFLoader
25
+ - A build of @pixiv/three-vrm
26
26
  - `.module` ones are ESM, otherwise it's UMD and injects its modules into global `THREE`
27
27
  - `.min` ones are minified (for production), otherwise it's not minified and it comes with source maps
28
28
 
29
- You can import all of them via CDN. See the example below.
30
-
31
- Code like this:
29
+ You can import all the dependencies via CDN like [jsDelivr](https://www.jsdelivr.com/).
32
30
 
33
31
  ```html
34
32
  <script type="importmap">
@@ -36,7 +34,7 @@ Code like this:
36
34
  "imports": {
37
35
  "three": "https://cdn.jsdelivr.net/npm/three@0.167.0/build/three.module.js",
38
36
  "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.167.0/examples/jsm/",
39
- "@pixiv/three-vrm": "three-vrm.module.js"
37
+ "@pixiv/three-vrm": "https://cdn.jsdelivr.net/npm/@pixiv/three-vrm@3/lib/three-vrm.module.min.js"
40
38
  }
41
39
  }
42
40
  </script>
@@ -46,11 +44,12 @@ Code like this:
46
44
  import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
47
45
  import { VRMLoaderPlugin } from '@pixiv/three-vrm';
48
46
 
49
- const scene = new THREE.Scene();
47
+ // ... Setup renderer, camera, scene ...
50
48
 
49
+ // Create a GLTFLoader - The loader for loading VRM models
51
50
  const loader = new GLTFLoader();
52
51
 
53
- // Install GLTFLoader plugin
52
+ // Install a GLTFLoader plugin that enables VRM support
54
53
  loader.register((parser) => {
55
54
  return new VRMLoaderPlugin(parser);
56
55
  });
@@ -77,9 +76,15 @@ Code like this:
77
76
  // called when loading has errors
78
77
  (error) => console.error(error),
79
78
  );
79
+
80
+ // ... Perform the render loop ...
80
81
  </script>
81
82
  ```
82
83
 
84
+ See the Three.js document if you are not familiar with Three.js yet: https://threejs.org/docs/#manual/en/introduction/Creating-a-scene
85
+
86
+ See the example for the complete code: https://github.com/pixiv/three-vrm/blob/release/packages/three-vrm/examples/basic.html
87
+
83
88
  ### via npm
84
89
 
85
90
  Install [`three`](https://www.npmjs.com/package/three) and [`@pixiv/three-vrm`](https://www.npmjs.com/package/@pixiv/three-vrm) :
@@ -88,46 +93,6 @@ Install [`three`](https://www.npmjs.com/package/three) and [`@pixiv/three-vrm`](
88
93
  npm install three @pixiv/three-vrm
89
94
  ```
90
95
 
91
- Code like this:
92
-
93
- ```javascript
94
- import * as THREE from 'three';
95
- import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
96
- import { VRMLoaderPlugin } from '@pixiv/three-vrm';
97
-
98
- const scene = new THREE.Scene();
99
-
100
- const loader = new GLTFLoader();
101
-
102
- // Install GLTFLoader plugin
103
- loader.register((parser) => {
104
- return new VRMLoaderPlugin(parser);
105
- });
106
-
107
- loader.load(
108
- // URL of the VRM you want to load
109
- '/models/VRM1_Constraint_Twist_Sample.vrm',
110
-
111
- // called when the resource is loaded
112
- (gltf) => {
113
- // retrieve a VRM instance from gltf
114
- const vrm = gltf.userData.vrm;
115
-
116
- // add the loaded vrm to the scene
117
- scene.add(vrm.scene);
118
-
119
- // deal with vrm features
120
- console.log(vrm);
121
- },
122
-
123
- // called while loading is progressing
124
- (progress) => console.log('Loading model...', 100.0 * (progress.loaded / progress.total), '%'),
125
-
126
- // called when loading has errors
127
- (error) => console.error(error),
128
- );
129
- ```
130
-
131
96
  ### Use with WebGPURenderer
132
97
 
133
98
  Starting from v3, we provide [WebGPURenderer](https://github.com/mrdoob/three.js/blob/master/examples/jsm/renderers/webgpu/WebGPURenderer.js) compatibility.
@@ -137,10 +102,14 @@ To use three-vrm with WebGPURenderer, specify the WebGPU-compatible `MToonNodeMa
137
102
  The NodeMaterial system of Three.js is still under development, so we may break compatibility with older versions of Three.js more frequently than other parts of three-vrm.
138
103
 
139
104
  ```js
140
- import { VRMLoaderPlugin } from '@pixiv/three-vrm';
105
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
106
+ import { MToonMaterialLoaderPlugin, VRMLoaderPlugin } from '@pixiv/three-vrm';
141
107
  import { MToonNodeMaterial } from '@pixiv/three-vrm/nodes';
142
108
 
143
- // ...
109
+ // ... Setup renderer, camera, scene ...
110
+
111
+ // Create a GLTFLoader
112
+ const loader = new GLTFLoader();
144
113
 
145
114
  // Register a VRMLoaderPlugin
146
115
  loader.register((parser) => {
@@ -161,8 +130,12 @@ loader.register((parser) => {
161
130
  });
162
131
 
163
132
  });
133
+
134
+ // ... Load the VRM and perform the render loop ...
164
135
  ```
165
136
 
137
+ See the example for the complete code: https://github.com/pixiv/three-vrm/blob/release/packages/three-vrm/examples/webgpu-dnd.html
138
+
166
139
  ## Contributing
167
140
 
168
141
  See: [CONTRIBUTING.md](CONTRIBUTING.md)
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pixiv/three-vrm v3.0.0-beta.2
2
+ * @pixiv/three-vrm v3.1.0-beta.0
3
3
  * VRM file loader for three.js.
4
4
  *
5
5
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -505,7 +505,7 @@ var MToonNodeMaterial = class extends THREE7.NodeMaterial {
505
505
  }
506
506
  };
507
507
  /*!
508
- * @pixiv/three-vrm-materials-mtoon v3.0.0-beta.2
508
+ * @pixiv/three-vrm-materials-mtoon v3.1.0-beta.0
509
509
  * MToon (toon material) module for @pixiv/three-vrm
510
510
  *
511
511
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -1,7 +1,7 @@
1
1
  /*! (c) 2019-2024 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
2
2
  "use strict";var X=Object.create;var T=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var K=(t,e)=>{for(var o in e)T(t,o,{get:e[o],enumerable:!0})},A=(t,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of B(e))!q.call(t,n)&&n!==o&&T(t,n,{get:()=>e[n],enumerable:!(a=z(e,n))||a.enumerable});return t};var d=(t,e,o)=>(o=t!=null?X(j(t)):{},A(e||!t||!t.__esModule?T(o,"default",{value:t,enumerable:!0}):o,t)),Z=t=>A(T({},"__esModule",{value:!0}),t);var Ft={};K(Ft,{MToonAnimatedUVNode:()=>b,MToonLightingModel:()=>Y,MToonNodeMaterial:()=>St});module.exports=Z(Ft);var U=d(require("three"),1),s=d(require("three/webgpu"),1),r=d(require("three/webgpu"),1),l=d(require("three/webgpu"),1),m=d(require("three/webgpu"),1),i=d(require("three/webgpu"),1),h=d(require("three/webgpu"),1);var V=parseInt(U.REVISION,10);V<167&&console.warn(`MToonNodeMaterial requires Three.js r167 or higher (You are using r${V}). This would not work correctly.`);var $=r.materialReference("color","color"),G=r.materialReference("map","texture"),J=r.materialReference("normalMap","texture"),Q=r.materialReference("normalScale","vec2"),tt=r.materialReference("emissive","color"),et=r.materialReference("emissiveIntensity","float"),it=r.materialReference("emissiveMap","texture"),ot=r.materialReference("shadeColorFactor","color"),rt=r.materialReference("shadingShiftFactor","float"),W=r.materialReference("shadeMultiplyTexture","texture"),at=r.materialReference("shadeMultiplyTextureScale","float"),lt=r.materialReference("shadingToonyFactor","float"),nt=r.materialReference("rimLightingMixFactor","float"),st=r.materialReference("rimMultiplyTexture","texture"),mt=r.materialReference("matcapFactor","color"),ut=r.materialReference("matcapTexture","texture"),ht=r.materialReference("parametricRimColorFactor","color"),dt=r.materialReference("parametricRimLiftFactor","float"),ct=r.materialReference("parametricRimFresnelPowerFactor","float"),pt=r.materialReference("outlineWidthMultiplyTexture","texture"),Et=r.materialReference("outlineWidthFactor","float"),O=r.materialReference("outlineColorFactor","color"),ft=r.materialReference("outlineLightingMixFactor","float"),Rt=r.materialReference("uvAnimationMaskTexture","texture"),Tt=r.materialReference("uvAnimationScrollXOffset","float"),vt=r.materialReference("uvAnimationScrollYOffset","float"),Nt=r.materialReference("uvAnimationRotationPhase","float"),b=class extends s.TempNode{constructor(t){super("vec2"),this.hasMaskTexture=t}setup(){let t=1;this.hasMaskTexture&&(t=s.vec4(Rt).context({getUV:()=>s.uv()}).r);let e=s.uv(),o=Nt.mul(t),a=s.cos(o),n=s.sin(o);e=e.sub(s.vec2(.5,.5)),e=e.mul(s.mat2(a,n,n.negate(),a)),e=e.add(s.vec2(.5,.5));let u=s.vec2(Tt,vt).mul(t);return e=e.add(u),e.temp("AnimatedUV")}},I=m.nodeImmutable(m.PropertyNode,"vec3").temp("ShadeColor"),D=m.nodeImmutable(m.PropertyNode,"float").temp("ShadingShift"),k=m.nodeImmutable(m.PropertyNode,"float").temp("ShadingToony"),v=m.nodeImmutable(m.PropertyNode,"float").temp("RimLightingMix"),N=m.nodeImmutable(m.PropertyNode,"vec3").temp("RimMultiply"),g=m.nodeImmutable(m.PropertyNode,"vec3").temp("matcap"),H=m.nodeImmutable(m.PropertyNode,"vec3").temp("ParametricRim"),gt=l.tslFn(({a:t,b:e,t:o})=>{let a=o.sub(t),n=e.sub(t);return a.div(n).clamp()}),Ht=l.tslFn(({dotNL:t})=>{let o=l.float(1).sub(k),a=t.add(D);return a=gt({a:o.negate(),b:o,t:a}),a=a.mul(1),a}),Mt=l.tslFn(({shading:t,lightColor:e})=>{let o=l.mix(I,l.diffuseColor,t);return e.mul(l.BRDF_Lambert({diffuseColor:o}))}),Y=class extends l.LightingModel{constructor(){super()}direct({lightDirection:t,lightColor:e,reflectedLight:o}){let a=l.transformedNormalView.dot(t).clamp(-1,1),n=Ht({dotNL:a});o.directDiffuse.assign(o.directDiffuse.add(Mt({shading:n,lightColor:e}))),o.directSpecular.assign(o.directSpecular.add(H.add(g).mul(N).mul(l.mix(l.vec3(0),l.BRDF_Lambert({diffuseColor:e}),v))))}indirect(t){this.indirectDiffuse(t),this.indirectSpecular(t)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.assign(e.indirectDiffuse.add(t.mul(l.BRDF_Lambert({diffuseColor:l.diffuseColor}))))}indirectSpecular({reflectedLight:t}){t.indirectSpecular.assign(t.indirectSpecular.add(H.add(g).mul(N).mul(l.mix(l.vec3(1),l.vec3(0),v))))}},f={None:"none",WorldCoordinates:"worldCoordinates",ScreenCoordinates:"screenCoordinates"},xt=h.tslFn(({parametricRimLift:t,parametricRimFresnelPower:e,parametricRimColor:o})=>{let a=h.modelViewPosition.normalize(),n=h.transformedNormalView.dot(a.negate());return h.float(1).sub(n).add(t).clamp().pow(e).mul(o)}),St=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 Y}setup(t){var e;this._animatedUVNode=new b((e=this.uvAnimationMaskTexture&&this.uvAnimationMaskTexture.isTexture===!0)!=null?e:!1),super.setup(t)}setupDiffuseColor(t){let e=null;if(this.colorNode==null){if(e=$,this.map&&this.map.isTexture===!0){let o=G.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(){I.assign(this._setupShadeColorNode()),D.assign(this._setupShadingShiftNode()),k.assign(this._setupShadingToonyNode()),v.assign(this._setupRimLightingMixNode()),N.assign(this._setupRimMultiplyNode()),g.assign(this._setupMatcapNode()),H.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 o=J.context({getUV:()=>this._animatedUVNode});this.normalNode=o.normalMap(Q)}this.isOutline&&(this.normalNode=this.normalNode.negate())}super.setupNormal(t),this.normalNode=e}setupLighting(t){let e=null;if(this.emissiveNode==null){if(e=tt.mul(et),this.emissiveMap&&this.emissiveMap.isTexture===!0){let a=it.context({getUV:()=>this._animatedUVNode});e=e.mul(a)}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(O,e.xyz.mul(O),ft),e.w)),super.setupOutput(t,e)}setupPosition(t){var e,o;let a=this.positionNode;if(this.isOutline&&this.outlineWidthMode!==f.None){(e=this.positionNode)!=null||(this.positionNode=i.positionLocal);let u=i.normalLocal.normalize(),c=Et;if(this.outlineWidthMultiplyTexture&&this.outlineWidthMultiplyTexture.isTexture===!0){let p=pt.context({getUV:()=>this._animatedUVNode});c=c.mul(p)}let R=i.length(i.modelNormalMatrix.mul(u)),E=c.mul(R).mul(u);if(this.outlineWidthMode===f.WorldCoordinates)this.positionNode=this.positionNode.add(E);else if(this.outlineWidthMode===f.ScreenCoordinates){let p=i.cameraProjectionMatrix.element(1).element(1);this.positionNode=this.positionNode.add(E.div(p).mul(i.positionView.z.negate()))}(o=this.positionNode)!=null||(this.positionNode=i.positionLocal)}let n=super.setupPosition(t);return n.z.add(n.w.mul(1e-6)),this.positionNode=a,n}copy(t){var e,o,a,n,u,c,R,E,p,M,x,S,F,y,C,_,L,w,P;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=(a=t.normalMap)!=null?a:null,this.normalScale.copy(t.normalScale),this.shadeColorFactor.copy(t.shadeColorFactor),this.shadeMultiplyTexture=(n=t.shadeMultiplyTexture)!=null?n:null,this.shadingShiftFactor=t.shadingShiftFactor,this.shadingShiftTexture=(u=t.shadingShiftTexture)!=null?u:null,this.shadingShiftTextureScale=t.shadingShiftTextureScale,this.shadingToonyFactor=t.shadingToonyFactor,this.rimLightingMixFactor=t.rimLightingMixFactor,this.rimMultiplyTexture=(c=t.rimMultiplyTexture)!=null?c:null,this.matcapFactor.copy(t.matcapFactor),this.matcapTexture=(R=t.matcapTexture)!=null?R:null,this.parametricRimColorFactor.copy(t.parametricRimColorFactor),this.parametricRimLiftFactor=t.parametricRimLiftFactor,this.parametricRimFresnelPowerFactor=t.parametricRimFresnelPowerFactor,this.outlineWidthMode=t.outlineWidthMode,this.outlineWidthMultiplyTexture=(E=t.outlineWidthMultiplyTexture)!=null?E: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=(p=t.uvAnimationMaskTexture)!=null?p:null,this.shadeColorNode=(M=t.shadeColorNode)!=null?M:null,this.shadingShiftNode=(x=t.shadingShiftNode)!=null?x:null,this.shadingToonyNode=(S=t.shadingToonyNode)!=null?S:null,this.rimLightingMixNode=(F=t.rimLightingMixNode)!=null?F:null,this.rimMultiplyNode=(y=t.rimMultiplyNode)!=null?y:null,this.matcapNode=(C=t.matcapNode)!=null?C:null,this.parametricRimColorNode=(_=t.parametricRimColorNode)!=null?_:null,this.parametricRimLiftNode=(L=t.parametricRimLiftNode)!=null?L:null,this.parametricRimFresnelPowerNode=(w=t.parametricRimFresnelPowerNode)!=null?w:null,this.isOutline=(P=t.isOutline)!=null?P: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=ot;if(this.shadeMultiplyTexture&&this.shadeMultiplyTexture.isTexture===!0){let e=W.context({getUV:()=>this._animatedUVNode});t=t.mul(e)}return t}_setupShadingShiftNode(){if(this.shadingShiftNode!=null)return i.float(this.shadingShiftNode);let t=rt;if(this.shadingShiftTexture&&this.shadingShiftTexture.isTexture===!0){let e=W.context({getUV:()=>this._animatedUVNode});t=t.add(e.mul(at))}return t}_setupShadingToonyNode(){return this.shadingToonyNode!=null?i.float(this.shadingToonyNode):lt}_setupRimLightingMixNode(){return this.rimLightingMixNode!=null?i.float(this.rimLightingMixNode):nt}_setupRimMultiplyNode(){return this.rimMultiplyNode!=null?i.vec3(this.rimMultiplyNode):this.rimMultiplyTexture&&this.rimMultiplyTexture.isTexture===!0?st.context({getUV:()=>this._animatedUVNode}):i.vec3(1)}_setupMatcapNode(){return this.matcapNode!=null?i.vec3(this.matcapNode):this.matcapTexture&&this.matcapTexture.isTexture===!0?ut.context({getUV:()=>i.matcapUV.mul(1,-1).add(0,1)}).mul(mt):i.vec3(0)}_setupParametricRimNode(){let t=this.parametricRimColorNode!=null?i.vec3(this.parametricRimColorNode):ht,e=this.parametricRimLiftNode!=null?i.float(this.parametricRimLiftNode):dt,o=this.parametricRimFresnelPowerNode!=null?i.float(this.parametricRimFresnelPowerNode):ct;return xt({parametricRimLift:e,parametricRimFresnelPower:o,parametricRimColor:t})}};
3
3
  /*!
4
- * @pixiv/three-vrm-materials-mtoon v3.0.0-beta.2
4
+ * @pixiv/three-vrm-materials-mtoon v3.1.0-beta.0
5
5
  * MToon (toon material) module for @pixiv/three-vrm
6
6
  *
7
7
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pixiv/three-vrm v3.0.0-beta.2
2
+ * @pixiv/three-vrm v3.1.0-beta.0
3
3
  * VRM file loader for three.js.
4
4
  *
5
5
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -473,7 +473,7 @@ export {
473
473
  MToonNodeMaterial
474
474
  };
475
475
  /*!
476
- * @pixiv/three-vrm-materials-mtoon v3.0.0-beta.2
476
+ * @pixiv/three-vrm-materials-mtoon v3.1.0-beta.0
477
477
  * MToon (toon material) module for @pixiv/three-vrm
478
478
  *
479
479
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -1,7 +1,7 @@
1
1
  /*! (c) 2019-2024 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
2
2
  import*as V from"three";import*as n from"three/webgpu";import*as r from"three/webgpu";import*as a from"three/webgpu";import*as s from"three/webgpu";import*as i from"three/webgpu";import*as h from"three/webgpu";var w=parseInt(V.REVISION,10);w<167&&console.warn(`MToonNodeMaterial requires Three.js r167 or higher (You are using r${w}). This would not work correctly.`);var b=r.materialReference("color","color"),I=r.materialReference("map","texture"),D=r.materialReference("normalMap","texture"),k=r.materialReference("normalScale","vec2"),Y=r.materialReference("emissive","color"),X=r.materialReference("emissiveIntensity","float"),z=r.materialReference("emissiveMap","texture"),B=r.materialReference("shadeColorFactor","color"),j=r.materialReference("shadingShiftFactor","float"),P=r.materialReference("shadeMultiplyTexture","texture"),q=r.materialReference("shadeMultiplyTextureScale","float"),K=r.materialReference("shadingToonyFactor","float"),Z=r.materialReference("rimLightingMixFactor","float"),$=r.materialReference("rimMultiplyTexture","texture"),G=r.materialReference("matcapFactor","color"),J=r.materialReference("matcapTexture","texture"),Q=r.materialReference("parametricRimColorFactor","color"),tt=r.materialReference("parametricRimLiftFactor","float"),et=r.materialReference("parametricRimFresnelPowerFactor","float"),it=r.materialReference("outlineWidthMultiplyTexture","texture"),ot=r.materialReference("outlineWidthFactor","float"),A=r.materialReference("outlineColorFactor","color"),rt=r.materialReference("outlineLightingMixFactor","float"),at=r.materialReference("uvAnimationMaskTexture","texture"),lt=r.materialReference("uvAnimationScrollXOffset","float"),nt=r.materialReference("uvAnimationScrollYOffset","float"),st=r.materialReference("uvAnimationRotationPhase","float"),mt=class extends n.TempNode{constructor(t){super("vec2"),this.hasMaskTexture=t}setup(){let t=1;this.hasMaskTexture&&(t=n.vec4(at).context({getUV:()=>n.uv()}).r);let e=n.uv(),o=st.mul(t),l=n.cos(o),m=n.sin(o);e=e.sub(n.vec2(.5,.5)),e=e.mul(n.mat2(l,m,m.negate(),l)),e=e.add(n.vec2(.5,.5));let u=n.vec2(lt,nt).mul(t);return e=e.add(u),e.temp("AnimatedUV")}},W=s.nodeImmutable(s.PropertyNode,"vec3").temp("ShadeColor"),O=s.nodeImmutable(s.PropertyNode,"float").temp("ShadingShift"),U=s.nodeImmutable(s.PropertyNode,"float").temp("ShadingToony"),R=s.nodeImmutable(s.PropertyNode,"float").temp("RimLightingMix"),T=s.nodeImmutable(s.PropertyNode,"vec3").temp("RimMultiply"),v=s.nodeImmutable(s.PropertyNode,"vec3").temp("matcap"),N=s.nodeImmutable(s.PropertyNode,"vec3").temp("ParametricRim"),ut=a.tslFn(({a:t,b:e,t:o})=>{let l=o.sub(t),m=e.sub(t);return l.div(m).clamp()}),ht=a.tslFn(({dotNL:t})=>{let o=a.float(1).sub(U),l=t.add(O);return l=ut({a:o.negate(),b:o,t:l}),l=l.mul(1),l}),dt=a.tslFn(({shading:t,lightColor:e})=>{let o=a.mix(W,a.diffuseColor,t);return e.mul(a.BRDF_Lambert({diffuseColor:o}))}),ct=class extends a.LightingModel{constructor(){super()}direct({lightDirection:t,lightColor:e,reflectedLight:o}){let l=a.transformedNormalView.dot(t).clamp(-1,1),m=ht({dotNL:l});o.directDiffuse.assign(o.directDiffuse.add(dt({shading:m,lightColor:e}))),o.directSpecular.assign(o.directSpecular.add(N.add(v).mul(T).mul(a.mix(a.vec3(0),a.BRDF_Lambert({diffuseColor:e}),R))))}indirect(t){this.indirectDiffuse(t),this.indirectSpecular(t)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.assign(e.indirectDiffuse.add(t.mul(a.BRDF_Lambert({diffuseColor:a.diffuseColor}))))}indirectSpecular({reflectedLight:t}){t.indirectSpecular.assign(t.indirectSpecular.add(N.add(v).mul(T).mul(a.mix(a.vec3(1),a.vec3(0),R))))}},E={None:"none",WorldCoordinates:"worldCoordinates",ScreenCoordinates:"screenCoordinates"},pt=h.tslFn(({parametricRimLift:t,parametricRimFresnelPower:e,parametricRimColor:o})=>{let l=h.modelViewPosition.normalize(),m=h.transformedNormalView.dot(l.negate());return h.float(1).sub(m).add(t).clamp().pow(e).mul(o)}),Et=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=E.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 ct}setup(t){var e;this._animatedUVNode=new mt((e=this.uvAnimationMaskTexture&&this.uvAnimationMaskTexture.isTexture===!0)!=null?e:!1),super.setup(t)}setupDiffuseColor(t){let e=null;if(this.colorNode==null){if(e=b,this.map&&this.map.isTexture===!0){let o=I.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(){W.assign(this._setupShadeColorNode()),O.assign(this._setupShadingShiftNode()),U.assign(this._setupShadingToonyNode()),R.assign(this._setupRimLightingMixNode()),T.assign(this._setupRimMultiplyNode()),v.assign(this._setupMatcapNode()),N.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 o=D.context({getUV:()=>this._animatedUVNode});this.normalNode=o.normalMap(k)}this.isOutline&&(this.normalNode=this.normalNode.negate())}super.setupNormal(t),this.normalNode=e}setupLighting(t){let e=null;if(this.emissiveNode==null){if(e=Y.mul(X),this.emissiveMap&&this.emissiveMap.isTexture===!0){let l=z.context({getUV:()=>this._animatedUVNode});e=e.mul(l)}this.emissiveNode=e}let o=super.setupLighting(t);return this.emissiveNode===e&&(this.emissiveNode=null),o}setupOutput(t,e){return this.isOutline&&this.outlineWidthMode!==E.None&&(e=i.vec4(i.mix(A,e.xyz.mul(A),rt),e.w)),super.setupOutput(t,e)}setupPosition(t){var e,o;let l=this.positionNode;if(this.isOutline&&this.outlineWidthMode!==E.None){(e=this.positionNode)!=null||(this.positionNode=i.positionLocal);let u=i.normalLocal.normalize(),d=ot;if(this.outlineWidthMultiplyTexture&&this.outlineWidthMultiplyTexture.isTexture===!0){let c=it.context({getUV:()=>this._animatedUVNode});d=d.mul(c)}let f=i.length(i.modelNormalMatrix.mul(u)),p=d.mul(f).mul(u);if(this.outlineWidthMode===E.WorldCoordinates)this.positionNode=this.positionNode.add(p);else if(this.outlineWidthMode===E.ScreenCoordinates){let c=i.cameraProjectionMatrix.element(1).element(1);this.positionNode=this.positionNode.add(p.div(c).mul(i.positionView.z.negate()))}(o=this.positionNode)!=null||(this.positionNode=i.positionLocal)}let m=super.setupPosition(t);return m.z.add(m.w.mul(1e-6)),this.positionNode=l,m}copy(t){var e,o,l,m,u,d,f,p,c,g,H,M,x,S,F,y,C,_,L;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=(l=t.normalMap)!=null?l:null,this.normalScale.copy(t.normalScale),this.shadeColorFactor.copy(t.shadeColorFactor),this.shadeMultiplyTexture=(m=t.shadeMultiplyTexture)!=null?m:null,this.shadingShiftFactor=t.shadingShiftFactor,this.shadingShiftTexture=(u=t.shadingShiftTexture)!=null?u: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=(f=t.matcapTexture)!=null?f:null,this.parametricRimColorFactor.copy(t.parametricRimColorFactor),this.parametricRimLiftFactor=t.parametricRimLiftFactor,this.parametricRimFresnelPowerFactor=t.parametricRimFresnelPowerFactor,this.outlineWidthMode=t.outlineWidthMode,this.outlineWidthMultiplyTexture=(p=t.outlineWidthMultiplyTexture)!=null?p: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=(g=t.shadeColorNode)!=null?g:null,this.shadingShiftNode=(H=t.shadingShiftNode)!=null?H:null,this.shadingToonyNode=(M=t.shadingToonyNode)!=null?M:null,this.rimLightingMixNode=(x=t.rimLightingMixNode)!=null?x:null,this.rimMultiplyNode=(S=t.rimMultiplyNode)!=null?S:null,this.matcapNode=(F=t.matcapNode)!=null?F:null,this.parametricRimColorNode=(y=t.parametricRimColorNode)!=null?y:null,this.parametricRimLiftNode=(C=t.parametricRimLiftNode)!=null?C:null,this.parametricRimFresnelPowerNode=(_=t.parametricRimFresnelPowerNode)!=null?_:null,this.isOutline=(L=t.isOutline)!=null?L: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=B;if(this.shadeMultiplyTexture&&this.shadeMultiplyTexture.isTexture===!0){let e=P.context({getUV:()=>this._animatedUVNode});t=t.mul(e)}return t}_setupShadingShiftNode(){if(this.shadingShiftNode!=null)return i.float(this.shadingShiftNode);let t=j;if(this.shadingShiftTexture&&this.shadingShiftTexture.isTexture===!0){let e=P.context({getUV:()=>this._animatedUVNode});t=t.add(e.mul(q))}return t}_setupShadingToonyNode(){return this.shadingToonyNode!=null?i.float(this.shadingToonyNode):K}_setupRimLightingMixNode(){return this.rimLightingMixNode!=null?i.float(this.rimLightingMixNode):Z}_setupRimMultiplyNode(){return this.rimMultiplyNode!=null?i.vec3(this.rimMultiplyNode):this.rimMultiplyTexture&&this.rimMultiplyTexture.isTexture===!0?$.context({getUV:()=>this._animatedUVNode}):i.vec3(1)}_setupMatcapNode(){return this.matcapNode!=null?i.vec3(this.matcapNode):this.matcapTexture&&this.matcapTexture.isTexture===!0?J.context({getUV:()=>i.matcapUV.mul(1,-1).add(0,1)}).mul(G):i.vec3(0)}_setupParametricRimNode(){let t=this.parametricRimColorNode!=null?i.vec3(this.parametricRimColorNode):Q,e=this.parametricRimLiftNode!=null?i.float(this.parametricRimLiftNode):tt,o=this.parametricRimFresnelPowerNode!=null?i.float(this.parametricRimFresnelPowerNode):et;return pt({parametricRimLift:e,parametricRimFresnelPower:o,parametricRimColor:t})}};export{mt as MToonAnimatedUVNode,ct as MToonLightingModel,Et as MToonNodeMaterial};
3
3
  /*!
4
- * @pixiv/three-vrm-materials-mtoon v3.0.0-beta.2
4
+ * @pixiv/three-vrm-materials-mtoon v3.1.0-beta.0
5
5
  * MToon (toon material) module for @pixiv/three-vrm
6
6
  *
7
7
  * Copyright (c) 2019-2024 pixiv Inc.