@@ -49,18 +49,19 @@ export const getSettingSafe = async (key: string) => {
4949
5050export function traverseAddShader (
5151 model : THREE . Group < THREE . Object3DEventMap > ,
52- mii : Mii
52+ shaderType : ShaderType
5353) {
5454 // Traverse the model to access its meshes
5555 model . traverse ( ( n ) => {
5656 const node = n as THREE . Mesh ;
5757 if ( node . isMesh ) {
58- traverseMesh ( node , mii ) ;
58+ traverseMesh ( node , shaderType ) ;
5959 }
6060 } ) ;
6161}
62- export async function traverseMesh ( node : THREE . Mesh , mpCharInfo : Mii ) {
63- const shaderSetting = ( await getSettingSafe ( "shaderType" ) ) as ShaderType ;
62+ export async function traverseMesh ( node : THREE . Mesh , shaderType : ShaderType ) {
63+ const shaderSetting =
64+ shaderType || ( ( await getSettingSafe ( "shaderType" ) ) as ShaderType ) ;
6465 const originalMaterial = node . material as THREE . MeshBasicMaterial ;
6566
6667 // Access userData from geometry
@@ -133,75 +134,76 @@ export async function traverseMesh(node: THREE.Mesh, mpCharInfo: Mii) {
133134
134135 let finalMat : THREE . Material ;
135136
136- const overrides = await getMaterialOverridesFromShaderType ( ) ;
137+ const isUsingShader = await isShaderMaterial ( ) ;
138+
139+ let modulate = isUsingShader
140+ ? {
141+ modulateMode,
142+ modulateType : modulateType ,
143+ lightEnable : shaderSetting === ShaderType . LightDisabled ? false : true
144+ }
145+ : { } ;
137146
138147 const params = {
139148 color : new THREE . Color ( ...modulateColor ) ,
140- modulateMode,
141- modulateType : modulateType ,
149+ ...modulate ,
142150 map : originalMaterial . map || undefined ,
143- side,
144- lightEnable : shaderSetting === ShaderType . LightDisabled ? false : true
151+ side
145152 } ;
146153
147- switch ( shaderSetting ) {
148- case ShaderType . WiiU :
149- finalMat = new FFLShaderMaterial ( params ) as any ;
150- break ;
151- case ShaderType . Switch :
152- throw new Error ( "This shader isn't supported yet" ) ;
153- case ShaderType . LightDisabled :
154- finalMat = new FFLShaderLightDisabledMaterial ( params ) as any ;
155- break ;
156- case ShaderType . Miitomo :
157- finalMat = new LUTShaderMaterial ( params ) as any ;
158- break ;
159- case ShaderType . MiitomoBasic :
160- finalMat = new LUTShaderPretendoMaterial ( params ) as any ;
161- break ;
162- case ShaderType . WiiUBlinn :
163- finalMat = new FFLShaderBlinnMaterial ( params ) as any ;
164- break ;
165- case ShaderType . WiiUFFLIconWithBody :
166- finalMat = new FFLShaderBrightMaterial ( params ) as any ;
167- break ;
168- case ShaderType . WiiUToon :
169- finalMat = new FFLShaderToonMaterial ( params ) as any ;
170- break ;
171- default :
172- throw new Error ( "This shader doesn't exist" ) ;
173- }
154+ let shaderMaterial = await getShaderMaterialFromShaderType ( shaderSetting ) ;
155+
156+ finalMat = new shaderMaterial ( params ) as any ;
157+ // switch (shaderSetting) {
158+ // case ShaderType.WiiU:
159+ // finalMat = new FFLShaderMaterial(params) as any;
160+ // break;
161+ // case ShaderType.Switch:
162+ // throw new Error("This shader isn't supported yet");
163+ // case ShaderType.LightDisabled:
164+ // finalMat = new FFLShaderLightDisabledMaterial(params) as any;
165+ // break;
166+ // case ShaderType.Miitomo:
167+ // finalMat = new LUTShaderMaterial(params) as any;
168+ // break;
169+ // case ShaderType.MiitomoBasic:
170+ // finalMat = new LUTShaderPretendoMaterial(params) as any;
171+ // break;
172+ // case ShaderType.WiiUBlinn:
173+ // finalMat = new FFLShaderBlinnMaterial(params) as any;
174+ // break;
175+ // case ShaderType.WiiUFFLIconWithBody:
176+ // finalMat = new FFLShaderBrightMaterial(params) as any;
177+ // break;
178+ // case ShaderType.WiiUToon:
179+ // finalMat = new FFLShaderToonMaterial(params) as any;
180+ // break;
181+ // default:
182+ // throw new Error("This shader doesn't exist");
183+ // }
174184
175185 // Assign the custom material to the mesh
176186 node . material = finalMat ;
177187}
178188
179- export async function getMaterialOverridesFromShaderType (
189+ export async function isShaderMaterial (
180190 shader : string | undefined = undefined
181- ) : Promise < Partial < any > | null > {
191+ ) : Promise < boolean > {
182192 let shaderType = ( shader ||
183193 ( await getSettingSafe ( "shaderType" ) ) ) as ShaderType ;
184194 switch ( shaderType ) {
185195 case ShaderType . WiiU :
186- return null ;
187196 case ShaderType . WiiUBlinn :
188- return { customMaterial : FFLBlinnMaterial } ;
189197 case ShaderType . WiiUFFLIconWithBody :
190- return {
191- lightAmbient : cLightAmbientFFLIconWithBody ,
192- lightDiffuse : cLightDiffuseFFLIconWithBody ,
193- lightSpecular : cLightSpecularFFLIconWithBody ,
194- lightDirection : cLightDirFFLIconWithBody
195- } ;
196198 case ShaderType . WiiUToon :
197- return { customMaterial : FFLToonMaterial } ;
198- case ShaderType . LightDisabled :
199- return { lightEnable : false } ;
200199 case ShaderType . Switch :
201- return null ;
202200 case ShaderType . Miitomo :
203201 case ShaderType . MiitomoBasic :
204- return null ;
202+ return true ;
203+ case ShaderType . LightDisabled :
204+ case ShaderType . ThreeToon :
205+ case ShaderType . ThreePhong :
206+ return false ;
205207 }
206208}
207209export async function getShaderMaterialFromShaderType ( type ?: string ) {
@@ -211,7 +213,7 @@ export async function getShaderMaterialFromShaderType(type?: string) {
211213 case ShaderType . WiiU :
212214 return FFLShaderMaterial ;
213215 case ShaderType . LightDisabled :
214- return FFLShaderLightDisabledMaterial ;
216+ return THREE . MeshBasicMaterial ;
215217 case ShaderType . WiiUBlinn :
216218 return FFLShaderBlinnMaterial ;
217219 case ShaderType . WiiUFFLIconWithBody :
@@ -226,5 +228,73 @@ export async function getShaderMaterialFromShaderType(type?: string) {
226228 return LUTShaderMaterial ;
227229 case ShaderType . MiitomoBasic :
228230 return LUTShaderPretendoMaterial ;
231+ case ShaderType . ThreeToon :
232+ return THREE . MeshToonMaterial ;
233+ case ShaderType . ThreePhong :
234+ return THREE . MeshPhongMaterial ;
235+ }
236+ }
237+
238+ const ThreeMaterialStandardLights = ( scene : THREE . Scene ) => {
239+ const intensity = Number ( THREE . REVISION ) >= 155 ? Math . PI : 1 ;
240+ const ambientLight = new THREE . AmbientLight (
241+ new THREE . Color ( 0.73 , 0.73 , 0.73 ) ,
242+ intensity
243+ ) ;
244+ const directionalLight = new THREE . DirectionalLight (
245+ new THREE . Color ( 0.6 , 0.6 , 0.6 ) ,
246+ intensity
247+ ) ;
248+ directionalLight . position . set ( - 0.455 , 0.348 , 0.5 ) ;
249+
250+ ambientLight . name = "ambientLight" ;
251+ directionalLight . name = "directionalLight" ;
252+
253+ scene . add ( ambientLight , directionalLight ) ;
254+ } ;
255+ const ThreeMaterialToonLights = ( scene : THREE . Scene ) => {
256+ const intensity = 2.5 ;
257+ const ambientLight = new THREE . AmbientLight (
258+ new THREE . Color ( 0.73 , 0.73 , 0.73 ) ,
259+ intensity
260+ ) ;
261+ const directionalLight = new THREE . DirectionalLight (
262+ new THREE . Color ( 0.6 , 0.6 , 0.6 ) ,
263+ intensity
264+ ) ;
265+ directionalLight . position . set ( - 0.255 , 0.348 , 0.5 ) ;
266+
267+ ambientLight . name = "ambientLight" ;
268+ directionalLight . name = "directionalLight" ;
269+
270+ scene . add ( ambientLight , directionalLight ) ;
271+ } ;
272+
273+ export async function getSimpleMaterialAddLights (
274+ type ?: string
275+ ) : Promise < ( ( scene : THREE . Scene ) => any ) | undefined > {
276+ const shaderType = ( type ||
277+ ( await getSettingSafe ( "shaderType" ) ) ) as ShaderType ;
278+ switch ( shaderType ) {
279+ case ShaderType . WiiU :
280+ case ShaderType . WiiUBlinn :
281+ case ShaderType . WiiUFFLIconWithBody :
282+ case ShaderType . WiiUToon :
283+ case ShaderType . Switch :
284+ case ShaderType . Miitomo :
285+ case ShaderType . MiitomoBasic :
286+ return ;
287+ case ShaderType . LightDisabled :
288+ case ShaderType . ThreePhong :
289+ return ThreeMaterialStandardLights ;
290+ case ShaderType . ThreeToon :
291+ return ThreeMaterialToonLights ;
229292 }
230293}
294+ export function cleanupLights ( scene : THREE . Scene ) {
295+ let amb = scene . getObjectByName ( "ambientLight" ) ;
296+ let dir = scene . getObjectByName ( "directionalLight" ) ;
297+
298+ if ( amb ) scene . remove ( amb ) ;
299+ if ( dir ) scene . remove ( dir ) ;
300+ }
0 commit comments