-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathindex.js
78 lines (72 loc) · 2.06 KB
/
index.js
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
68
69
70
71
72
73
74
75
76
77
78
import {WowModelViewer} from './wow_model_viewer.js'
import {
findRaceGenderOptions,
optionsFromModel,
getDisplaySlot,
findItemsInEquipments,
modelingType
} from "./character_modeling.js"
import "./setup.js"
/**
*
* @param aspect {number}: Size of the character
* @param containerSelector {string}: jQuery selector on the container
* @param model {{}|{id: number, type: number}}: A json representation of a character
* @param env {('classic'|'live')}: select game enve
* @returns {Promise<WowModelViewer>}
*/
async function generateModels(aspect, containerSelector, model, env=`live`) {
let modelOptions
let fullOptions
if (model.id && model.type) {
const {id, type} = model
modelOptions = {models: {id, type}}
} else {
const {race, gender} = model
// CHARACTER OPTIONS
// This is how we describe a character properties
fullOptions = await findRaceGenderOptions(
race,
gender
)
modelOptions = optionsFromModel(model, fullOptions)
}
if(env === `classic`) {
modelOptions = {
dataEnv: `classic`,
env: `classic`,
gameDataEnv: `classic`,
hd: false,
...modelOptions
}
} else {
modelOptions = {
hd: true,
...modelOptions
}
}
const models = {
type: 2,
contentPath: window.CONTENT_PATH,
// eslint-disable-next-line no-undef
container: jQuery(containerSelector),
aspect: aspect,
...modelOptions
}
console.log(`Creating viewer with options`, models)
// eslint-disable-next-line no-undef
const wowModelViewer = await new WowModelViewer(models)
if(fullOptions) {
wowModelViewer.currentCharacterOptions = fullOptions
wowModelViewer.characterGender = model.gender
wowModelViewer.characterRace = model.race
}
return wowModelViewer
}
export {
findRaceGenderOptions,
generateModels,
getDisplaySlot,
findItemsInEquipments,
modelingType
}