Skip to content

Commit 84205bb

Browse files
datkat21ariankordi
authored andcommitted
Update ffl.js (2fc67ca), add Three.js materials, update selector.js, update builds
From "Archive 2.zip", Apr 07 3:49 pm
1 parent f88f241 commit 84205bb

22 files changed

Lines changed: 3180 additions & 14380 deletions

bun.lockb

100755100644
12.7 KB
Binary file not shown.

diff.diff

Lines changed: 0 additions & 12495 deletions
This file was deleted.
9.81 KB
Binary file not shown.

public/dist/ffl-emscripten.wasm

100644100755
35.7 KB
Binary file not shown.

public/dist/helper.js

Lines changed: 552 additions & 453 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/dist/main.js

Lines changed: 534 additions & 431 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/dist/worker.js

Lines changed: 508 additions & 414 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/class/3DScene.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ import {
3535
HatTypeList
3636
} from "../constants/Extensions";
3737
import {
38+
cleanupLights,
3839
getShaderMaterialFromShaderType,
40+
getSimpleMaterialAddLights,
3941
traverseAddShader,
4042
traverseMesh
4143
} from "./3d/shader/ShaderUtils";
@@ -130,13 +132,20 @@ export class Mii3DScene {
130132
// this.stats = new Stats();
131133
// document.body.appendChild(this.stats.dom);
132134

135+
// To fix default materials colors looking washed out,
136+
// shouldn't affect shader colors
137+
this.#renderer.outputColorSpace = THREE.LinearSRGBColorSpace;
138+
133139
this.getRendererElement().classList.add("scene");
134140
this.setupType = setupType;
135141

136142
getSetting("bodyModel").then((type) => {
137143
this.bodyModel = type;
138144
});
139145

146+
// THREE.ColorManagement.enabled = false;
147+
window.THREE = THREE;
148+
140149
getSetting("shaderType").then((type) => {
141150
this.shaderType = type;
142151
getSetting("simpleShaderLegacyColors").then((val) => {
@@ -207,13 +216,17 @@ export class Mii3DScene {
207216
this.#controls.enabled = true;
208217
this.#controls.minDistance = 10;
209218
this.#controls.maxDistance = 35;
219+
this.#controls.minAzimuthAngle = -Math.PI;
220+
this.#controls.maxAzimuthAngle = Math.PI;
210221
this.#controls.zoomTo(1);
211222
this.cameraPan = true;
212223
} else {
213224
console.log("canPan is True:", canPan);
214225
this.#controls.enabled = false;
215226
this.#controls.minDistance = 60;
216227
this.#controls.maxDistance = 140;
228+
this.#controls.minAzimuthAngle = -Math.PI;
229+
this.#controls.maxAzimuthAngle = Math.PI;
217230
this.#controls.dollyTo(380 / 10);
218231
this.#controls.zoomTo(2.5);
219232
this.cameraPan = false;
@@ -231,10 +244,6 @@ export class Mii3DScene {
231244
this.#controls.minDistance = 8;
232245
this.#controls.maxDistance = 300;
233246
} else {
234-
this.#controls.minPolarAngle = 0.8;
235-
this.#controls.maxPolarAngle = 1.8;
236-
this.#controls.minAzimuthAngle = -1.4;
237-
this.#controls.maxAzimuthAngle = 1.4;
238247
setTimeout(() => {
239248
this.focusCamera(CameraPosition.MiiHead, true);
240249
}, 200);
@@ -626,7 +635,7 @@ export class Mii3DScene {
626635
color: MiiFavoriteColorLookupTable[this.mii.favoriteColor]
627636
});
628637
// adds shader material
629-
else traverseMesh(gBodyMesh, this.mii);
638+
else traverseMesh(gBodyMesh, this.shaderType);
630639

631640
const gHandsMesh = glb.scene.getObjectByName(
632641
`hands_${type}`
@@ -646,7 +655,7 @@ export class Mii3DScene {
646655
});
647656
// adds shader material
648657
else {
649-
traverseMesh(gHandsMesh, this.mii);
658+
traverseMesh(gHandsMesh, this.shaderType);
650659
}
651660
}
652661

@@ -670,7 +679,7 @@ export class Mii3DScene {
670679
)
671680
});
672681
// adds shader material
673-
else traverseMesh(gLegsMesh, this.mii);
682+
else traverseMesh(gLegsMesh, this.shaderType);
674683

675684
if (this.#scene.getObjectByName("m"))
676685
this.#scene.getObjectByName("m")!.visible = false;
@@ -1233,7 +1242,14 @@ export class Mii3DScene {
12331242
this.#scene.add(GLB.scene);
12341243

12351244
if (Config.renderer.useRendererServer)
1236-
traverseAddShader(GLB.scene, this.mii);
1245+
traverseAddShader(GLB.scene, this.shaderType);
1246+
1247+
let lights = await getSimpleMaterialAddLights(this.shaderType);
1248+
cleanupLights(this.#scene);
1249+
if (lights) {
1250+
lights(this.#scene);
1251+
}
1252+
12371253
// else {
12381254
// this.#pastCharModel = (GLB as any).CharModel;
12391255
// }
@@ -1370,7 +1386,7 @@ export class Mii3DScene {
13701386
if (Config.renderer.useRendererServer === false) {
13711387
// apply shader material!
13721388
// var mc = m.geometry.userData["modulateColor"];
1373-
traverseMesh(m, this.mii);
1389+
traverseMesh(m, this.shaderType);
13741390
// m.material = new LUTShaderMaterial({
13751391
// modulateMode: 0,
13761392
// modulateType: 5,

src/class/3d/shader/ShaderUtils.ts

Lines changed: 122 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,19 @@ export const getSettingSafe = async (key: string) => {
4949

5050
export 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
}
207209
export 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

Comments
 (0)