-
Notifications
You must be signed in to change notification settings - Fork 34
/
wow_model_viewer.js
149 lines (131 loc) · 4.09 KB
/
wow_model_viewer.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import {getCharacterOptions} from "./character_modeling.js"
// eslint-disable-next-line no-undef
class WowModelViewer extends ZamModelViewer {
/**
* Returns the list of animation names
* @returns {Array.<string>}
*/
getListAnimations() {
console.log(`getListAnimations`)
return [...new Set(this.renderer.models[0].aq.map(e => e.l))]
}
/**
* Change character distance
* @param {number} val
*/
setDistance(val) {
this.renderer.distance = val
}
/**
* Change the animation
* @param {string} val
*/
setAnimation(val) {
if (!this.getListAnimations().includes(val)) {
console.warn(`${this.constructor.name}: Animation ${val} not found`)
}
this.renderer.models[0].setAnimation(val)
}
/**
* Play / Pause the animation
* @param {boolean} val
*/
setAnimPaused(val) {
this.renderer.models[0].setAnimPaused(val)
}
/**
* Set azimuth value this value is the angle to the azimuth based on PI
* @param {number} val
*/
setAzimuth(val) {
this.renderer.azimuth = val
}
/**
* Set zenith value this value is the angle to the azimuth based on PI
* @param {number} val
*/
setZenith(val) {
this.renderer.zenith = val
}
/**
* Returns azimuth value this value is the angle to the azimuth based on PI
* @return {number}
*/
getAzimuth() {
return this.renderer.azimuth
}
/**
* Returns zenith value this value is the angle to the azimuth based on PI
* @return {number}
*/
getZenith() {
return this.renderer.zenith
}
/**
* This methode is based on `updateViewer` from Paperdoll.js (https://wow.zamimg.com/js/Paperdoll.js?3ee7ec5121)
*
* @param slot {number}: Item slot number
* @param displayId {number}: Item display id
* @param enchant {number}: Enchant (experimental not tested)
*/
updateItemViewer(slot, displayId, enchant) {
const s = window.WH.Wow.Item
if (slot === s.INVENTORY_TYPE_SHOULDERS) {
// this.method(`setShouldersOverride`, [this.getShouldersOverrideData()]);
}
const a = (slot === s.INVENTORY_TYPE_ROBE) ? s.INVENTORY_TYPE_CHEST : slot
window.WH.debug(`Clearing model viewer slot:`, a.toString())
this.method(`clearSlots`, slot.toString())
if (displayId) {
window.WH.debug(`Attaching to model viewer slot:`, slot.toString(), `Display ID:`, displayId, `Enchant Visual:`, enchant)
this.method(`setItems`, [[{
slot: slot,
display: displayId,
visual: enchant || 0
}]])
}
}
setNewAppearance(options) {
if(!this.currentCharacterOptions) {
throw Error(`Character options are not set`)
}
const characterOptions = getCharacterOptions(options, this.currentCharacterOptions)
const race = this.characterRace
const gender = this.characterGender
this.method(`setAppearance`, {race: race, gender: gender, options: characterOptions})
}
}
// Instance variables
WowModelViewer.prototype._currentCharacterOptions = 0
WowModelViewer.prototype._characterGender = null
WowModelViewer.prototype._characterRace = null
// Getter and Setter for currentCharacterOptions
Object.defineProperty(WowModelViewer.prototype, `currentCharacterOptions`, {
get: function() {
return this._currentCharacterOptions
},
set: function(value) {
this._currentCharacterOptions = value
}
})
// Getter and Setter for characterGender
Object.defineProperty(WowModelViewer.prototype, `characterGender`, {
get: function() {
return this._characterGender
},
set: function(value) {
this._characterGender = value
}
})
// Getter and Setter for characterRace
Object.defineProperty(WowModelViewer.prototype, `characterRace`, {
get: function() {
return this._characterRace
},
set: function(value) {
this._characterRace = value
}
})
export {
WowModelViewer,
}