-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
67 lines (53 loc) · 2.07 KB
/
index.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
64
65
66
67
import * as THREE from 'three'
import { Main } from './main'
import { Marionette } from './marionette'
import { ModelLoader } from './model_loader'
import { Theater } from './theater'
const DEFAULT_POSE_BASE = 'J0000000000000000K000300K000500000f0I0006000g4j010000000000000000000000550000000000000000000ZL00Z'
const DEFAULT_POSE_FLYER = 'l0Z000000701B0C000000f000000f000006fG0000000gIi000000000000000000000000000000000000000000000Z2U0Z'
const DEFAULT_CAM_POS = 'oqDHai320'
const MODEL_PATH = './xbot.fbx'
// const MODEL_PATH = './ybot.fbx'
// const MODEL_PATH = './mannequin.fbx'
const BONES_PREFIX = 'mixamorig'
// const BONES_PREFIX = 'mixamorig1'
const params = new URLSearchParams(window.location.search.substring(1))
const base = new Marionette('base' , params.get('_base' ) || DEFAULT_POSE_BASE)
const flyer = new Marionette('flyer', params.get('_flyer') || DEFAULT_POSE_FLYER)
const cam_pos = params.get('cam') || DEFAULT_CAM_POS
const mat = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.03, 2),
new THREE.MeshPhongMaterial({ color: 0xc399c8 })
)
const model_loader = new ModelLoader(MODEL_PATH, model => {
model.scale.setScalar(0.01)
model.children.find(child => child instanceof THREE.Bone)?.traverse(bone => {
bone.name = bone.name.substring(BONES_PREFIX.length)
})
console.info('Loaded model:', model)
})
const theater = new Theater('cv1', [ base, flyer ], () => {
const params: string[] = []
params.push('cam=' + theater.camera_pos)
Object.values(theater.marionettes).map(marionette => {
params.push('_' + marionette.name + '=' + marionette.toString())
})
const new_url = window.location.pathname + '?' + params.join('&')
window.history.pushState({}, '', new_url)
})
theater.camera_pos = cam_pos
theater.scene.add(mat)
const main = new Main(model_loader, [ theater ])
main.init()
const animate = () => main.animate(animate)
animate()
document.addEventListener('keydown', event => {
if (event.ctrlKey) {
theater.axe_modifier_id = 1
} else if (event.shiftKey) {
theater.axe_modifier_id = 2
}
})
document.addEventListener('keyup', () => {
theater.axe_modifier_id = 0
})