-
Notifications
You must be signed in to change notification settings - Fork 11
/
loadRlLoadout.ts
63 lines (52 loc) · 2.22 KB
/
loadRlLoadout.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { createPaintConfig, RocketAssetManager, BodyModel, WheelsModel, Body, Wheel, Decal } from 'rl-loadout-lib'
import { ExtendedPlayer } from '../../models/ReplayMetadata'
import { Mesh, MeshPhongMaterial, MeshStandardMaterial } from 'three'
export async function loadRlLoadout(manager: RocketAssetManager, player: ExtendedPlayer, defaultLoadout?: boolean):
Promise<{ body: BodyModel; player: ExtendedPlayer }> {
let body: BodyModel
let wheels: WheelsModel
if (defaultLoadout) {
const paintConfig = createPaintConfig(player.isOrange)
body = new BodyModel(Body.DEFAULT, Decal.NONE, paintConfig, manager.config)
wheels = new WheelsModel(Wheel.DEFAULT, paintConfig, manager.config)
await Promise.all([body.load(), wheels.load()])
} else {
const paintConfig = createPaintConfig(
player.isOrange,
player.loadout.primaryColor,
player.loadout.accentColor,
player.loadout.carPaint,
player.loadout.skinPaint,
player.loadout.wheelsPaint,
player.loadout.topperPaint,
player.loadout.antennaPaint
)
const bodyTask = manager.loadBody(player.loadout.car, paintConfig, Body.DEFAULT)
// TODO use the default wheel for now, there aren't a lot of wheels in rocket-loadout yet, and not yet fully supported
wheels = new WheelsModel(Wheel.DEFAULT, paintConfig, manager.config)
await wheels.load()
body = await bodyTask
}
body.addWheelsModel(wheels)
body.scene.traverse(object => {
// @ts-ignore
if (object.isMesh) {
const mesh = object as Mesh
mesh.receiveShadow = true
mesh.castShadow = true
// Phong material is less physically accurate but has noticably better performance
const oldMaterial = mesh.material as MeshStandardMaterial
const phongMaterial = new MeshPhongMaterial()
phongMaterial.name = oldMaterial.name
phongMaterial.map = oldMaterial.map
phongMaterial.normalMap = oldMaterial.normalMap
phongMaterial.color = oldMaterial.color
phongMaterial.shininess = (1 - oldMaterial.roughness) * 100
phongMaterial.skinning = oldMaterial.skinning
mesh.material = phongMaterial
mesh.material.needsUpdate = true
oldMaterial.dispose()
}
})
return {player, body}
}