Repository navigation
Expand file tree
/
Copy pathcompress-utils.js
More file actions
75 lines (59 loc) · 2 KB
/
Copy pathcompress-utils.js
File metadata and controls
75 lines (59 loc) · 2 KB
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
var CompressUtils = {
/**
* @private
* @function
* @name CompressUtils#setCompressedPRS
* @description Set position, rotation and scale of an entity using compressed
* scene format.
* @param {Entity} entity - The entity.
* @param {object} data - Json entity data from a compressed scene.
* @param {object} compressed - Compression metadata.
*/
setCompressedPRS: function (entity, data, compressed) {
var a = compressed.singleVecs;
var b, i;
var v = data.___1;
if (!v) {
b = compressed.tripleVecs;
i = data.___2;
}
var n = v ? v[0] : b[i];
entity.setLocalPosition(a[n], a[n + 1], a[n + 2]);
n = v ? v[1] : b[i + 1];
entity.setLocalEulerAngles(a[n], a[n + 1], a[n + 2]);
n = v ? v[2] : b[i + 2];
entity.setLocalScale(a[n], a[n + 1], a[n + 2]);
},
/**
* @private
* @function
* @name CompressUtils#oneCharToKey
* @description Retrieve the original field name (key) for a single character key
* from a compressed entity.
* @param {string} s - The compressed key string.
* @param {object} data - Compression metadata.
* @returns {string} The original key.
*/
oneCharToKey: function (s, data) {
var i = s.charCodeAt(0) - data.fieldFirstCode;
return data.fieldArray[i];
},
/**
* @private
* @function
* @name CompressUtils#multCharToKey
* @description Retrieve the original field name (key) for a multi-character key
* from a compressed entity.
* @param {string} s - The compressed key string.
* @param {object} data - Compression metadata.
* @returns {string} The original key.
*/
multCharToKey: function (s, data) {
var ind = 0;
for (var i = 0; i < s.length; i++) {
ind = ind * data.fieldCodeBase + s.charCodeAt(i) - data.fieldFirstCode;
}
return data.fieldArray[ind];
}
};
export { CompressUtils };