@that-sky-project/that-sky-level 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +504 -0
- package/README.md +34 -0
- package/dist/cli.js +22 -0
- package/docs/img/blender_edit_obj_model.png +0 -0
- package/docs/materials.md +37 -0
- package/level_example/HTNH_Test/HTNH_Test.Objects.level.json +258 -0
- package/level_example/HTNH_Test/HTNH_Test.obj +46 -0
- package/level_example/HTNH_Test/Makefile +11 -0
- package/main.js +218 -0
- package/package.json +23 -0
- package/src/formats/triangleMesh.js +82 -0
- package/src/formats/wavefront.js +148 -0
- package/src/level/adjacency.js +466 -0
- package/src/level/enums/kFieldType.js +8 -0
- package/src/level/enums/kMaterial.js +39 -0
- package/src/level/meshes/levelGeo.js +283 -0
- package/src/level/meshes/levelLod.js +15 -0
- package/src/level/meshes/levelMeshes.js +141 -0
- package/src/level/meshes/levelToc.js +69 -0
- package/src/level/objects/levelObjects.js +683 -0
- package/src/level/objects/levelObjectsJson.js +256 -0
- package/src/meshopt/LICENSE +21 -0
- package/src/meshopt/meshopt_decoder.js +199 -0
- package/src/meshopt/meshopt_encoder.js +221 -0
- package/src/utils/binaryStream.js +806 -0
- package/src/utils/helperClasses.js +110 -0
- package/src/utils/logger.js +14 -0
- package/src/utils/normVec.js +67 -0
- package/src/utils/vector.js +232 -0
- package/webpack.config.js +31 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const NBT = require("parsenbt-js");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Helper class for creating singletons.
|
|
5
|
+
*/
|
|
6
|
+
class ISingleton {
|
|
7
|
+
/**
|
|
8
|
+
* Stores the singleton instance.
|
|
9
|
+
*/
|
|
10
|
+
static instance = null;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Get the singleton instance.
|
|
14
|
+
*/
|
|
15
|
+
static singleton() {
|
|
16
|
+
if (!this.instance)
|
|
17
|
+
this.instance = new this();
|
|
18
|
+
return this.instance;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Helper class for objects needs to be converted to JSON.
|
|
24
|
+
*
|
|
25
|
+
* Subclasses must implement serialize() and deserialize() methods.
|
|
26
|
+
*/
|
|
27
|
+
class IJsonable {
|
|
28
|
+
/**
|
|
29
|
+
* Convert from JSON to an instance.
|
|
30
|
+
*/
|
|
31
|
+
static deserialize(obj) {
|
|
32
|
+
return new IJsonable();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Convert the object to JSON.
|
|
37
|
+
*/
|
|
38
|
+
serialize() {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Default JSON.stringify function.
|
|
44
|
+
*/
|
|
45
|
+
toJSON() {
|
|
46
|
+
return this.serialize();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Helper class for objects needs to be converted to NBT and JSON.
|
|
52
|
+
*
|
|
53
|
+
* Subclasses must implement serialize() and deserialize() methods.
|
|
54
|
+
*/
|
|
55
|
+
class INbtify {
|
|
56
|
+
/**
|
|
57
|
+
* Convert from NBT to an instance.
|
|
58
|
+
*/
|
|
59
|
+
static deserialize(obj) {
|
|
60
|
+
return new INbtify();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Convert from JSON to an instance.
|
|
65
|
+
*/
|
|
66
|
+
static fromJSON(obj) {
|
|
67
|
+
return new INbtify();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Convert the object to an NBT object.
|
|
72
|
+
*/
|
|
73
|
+
serialize() {
|
|
74
|
+
return NBT.create(false);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Default JSON.stringify function.
|
|
79
|
+
*/
|
|
80
|
+
toJSON() {
|
|
81
|
+
return {};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Helper class for objects needs to be converted to BinaryStream.
|
|
87
|
+
*
|
|
88
|
+
* Subclasses must implement toStream() and fromStream() methods.
|
|
89
|
+
*/
|
|
90
|
+
class IBinarying {
|
|
91
|
+
static deserialize(stream) {
|
|
92
|
+
var result = new this();
|
|
93
|
+
result.fromStream(stream);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param {WritableBinaryStream} stream
|
|
100
|
+
*/
|
|
101
|
+
toStream(stream) { }
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
* @param {ReadOnlyBinaryStream} stream
|
|
106
|
+
*/
|
|
107
|
+
fromStream(stream) { }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = { ISingleton, IJsonable, INbtify, IBinarying };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { printF: printf } = require("@htmonkeyg/tformat");
|
|
2
|
+
|
|
3
|
+
var silence = false;
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
printf: function (format, ...args) {
|
|
7
|
+
if (silence)
|
|
8
|
+
return;
|
|
9
|
+
printf(format, args);
|
|
10
|
+
},
|
|
11
|
+
silence: function (enable) {
|
|
12
|
+
silence = !!enable;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { Vec4 } = require("./vector.js");
|
|
2
|
+
|
|
3
|
+
function clamp(x, a, b) { return x < a ? a : x > b ? b : x; }
|
|
4
|
+
function map(x) { return (x + 1) / 2; }
|
|
5
|
+
|
|
6
|
+
class R8G8B8A8_UNORM extends Vec4 {
|
|
7
|
+
constructor(x = 0, y = 0, z = 0, w = 0) {
|
|
8
|
+
super(x, y, z, w);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
fromStream(stream) {
|
|
12
|
+
var v = stream.readUint32();
|
|
13
|
+
|
|
14
|
+
this.x = (v & 0xFF) / 255;
|
|
15
|
+
this.y = ((v >> 8) & 0xFF) / 255;
|
|
16
|
+
this.z = ((v >> 16) & 0xFF) / 255;
|
|
17
|
+
this.w = ((v >> 24) & 0xFF) / 255;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toStream(stream) {
|
|
21
|
+
var x = (255 * clamp(this.x, 0, 1)) | 0
|
|
22
|
+
, y = (255 * clamp(this.y, 0, 1)) | 0
|
|
23
|
+
, z = (255 * clamp(this.z, 0, 1)) | 0
|
|
24
|
+
, w = (255 * clamp(this.w, 0, 1)) | 0;
|
|
25
|
+
|
|
26
|
+
stream.writeUint32(((w << 24) | (z << 16) | (y << 8) | x) >>> 0);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
class R8G8B8A8_SNORM extends Vec4 {
|
|
31
|
+
constructor(x = 0, y = 0, z = 0, w = 0) {
|
|
32
|
+
super(x, y, z, w);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fromStream(stream) {
|
|
36
|
+
var v = stream.readUint32();
|
|
37
|
+
|
|
38
|
+
var x = (v & 0xFF) << 24 >> 24
|
|
39
|
+
, y = ((v >> 8) & 0xFF) << 24 >> 24
|
|
40
|
+
, z = ((v >> 16) & 0xFF) << 24 >> 24
|
|
41
|
+
, w = ((v >> 24) & 0xFF) << 24 >> 24;
|
|
42
|
+
|
|
43
|
+
this.x = Math.max(x / 127.0, -1.0);
|
|
44
|
+
this.y = Math.max(y / 127.0, -1.0);
|
|
45
|
+
this.z = Math.max(z / 127.0, -1.0);
|
|
46
|
+
this.w = Math.max(w / 127.0, -1.0);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toStream(stream) {
|
|
50
|
+
var x = Math.round(clamp(this.x, -1, 1) * 127)
|
|
51
|
+
, y = Math.round(clamp(this.y, -1, 1) * 127)
|
|
52
|
+
, z = Math.round(clamp(this.z, -1, 1) * 127)
|
|
53
|
+
, w = Math.round(clamp(this.w, -1, 1) * 127);
|
|
54
|
+
|
|
55
|
+
x = clamp(x, -128, 127) & 0xFF;
|
|
56
|
+
y = clamp(y, -128, 127) & 0xFF;
|
|
57
|
+
z = clamp(z, -128, 127) & 0xFF;
|
|
58
|
+
w = clamp(w, -128, 127) & 0xFF;
|
|
59
|
+
|
|
60
|
+
stream.writeUint32(((w << 24) | (z << 16) | (y << 8) | x) >>> 0);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
R8G8B8A8_SNORM,
|
|
66
|
+
R8G8B8A8_UNORM
|
|
67
|
+
};
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
const { IBinarying } = require("./helperClasses.js");
|
|
2
|
+
|
|
3
|
+
class Vec3 extends IBinarying {
|
|
4
|
+
static get ZERO() {
|
|
5
|
+
return new Vec3();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static equal(a, b) {
|
|
9
|
+
return a.x == b.x && a.y == b.y && a.z == b.z;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static broadcast(a) {
|
|
13
|
+
return new Vec3(a, a, a);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
constructor(x = 0, y = 0, z = 0) {
|
|
17
|
+
super();
|
|
18
|
+
|
|
19
|
+
this.x = x;
|
|
20
|
+
this.y = y;
|
|
21
|
+
this.z = z;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {Vec3} v
|
|
26
|
+
* @returns {Vec3}
|
|
27
|
+
*/
|
|
28
|
+
add(v) {
|
|
29
|
+
return new Vec3(this.x + v.x, this.y + v.y, this.z + v.z);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {Vec3} v
|
|
34
|
+
* @returns {Vec3}
|
|
35
|
+
*/
|
|
36
|
+
sub(v) {
|
|
37
|
+
return new Vec3(this.x - v.x, this.y - v.y, this.z - v.z);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {Vec3} v
|
|
42
|
+
* @returns {Vec3}
|
|
43
|
+
*/
|
|
44
|
+
mul(v) {
|
|
45
|
+
return new Vec3(this.x * v.x, this.y * v.y, this.z * v.z);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {Vec3} v
|
|
50
|
+
* @returns {Vec3}
|
|
51
|
+
*/
|
|
52
|
+
div(v) {
|
|
53
|
+
return new Vec3(this.x / v.x, this.y / v.y, this.z / v.z);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {number} a
|
|
58
|
+
* @returns {Vec3}
|
|
59
|
+
*/
|
|
60
|
+
scale(a) {
|
|
61
|
+
return new Vec3(this.x * a, this.y * a, this.z * a);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {Vec3} v
|
|
66
|
+
* @returns {number}
|
|
67
|
+
*/
|
|
68
|
+
dot(v) {
|
|
69
|
+
return this.x * v.x + this.y * v.y + this.z * v.z;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @returns {number}
|
|
74
|
+
*/
|
|
75
|
+
length() {
|
|
76
|
+
return Math.hypot(this.x, this.y, this.z);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {Vec3} v
|
|
81
|
+
* @returns {number}
|
|
82
|
+
*/
|
|
83
|
+
dist(v) {
|
|
84
|
+
return this.sub(v).length();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fromStream(stream) {
|
|
88
|
+
this.x = stream.readFloat();
|
|
89
|
+
this.y = stream.readFloat();
|
|
90
|
+
this.z = stream.readFloat();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
toStream(stream) {
|
|
94
|
+
stream.writeFloat(this.x);
|
|
95
|
+
stream.writeFloat(this.y);
|
|
96
|
+
stream.writeFloat(this.z);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
toString() {
|
|
100
|
+
return "(" + this.x + "," + this.y + "," + this.z + ")";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
class Vec4 extends IBinarying {
|
|
105
|
+
static get ZERO() {
|
|
106
|
+
return new Vec4();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static equal(a, b) {
|
|
110
|
+
return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
constructor(x = 0, y = 0, z = 0, w = 0) {
|
|
114
|
+
super();
|
|
115
|
+
|
|
116
|
+
this.x = x;
|
|
117
|
+
this.y = y;
|
|
118
|
+
this.z = z;
|
|
119
|
+
this.w = w;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @param {Vec4} v
|
|
124
|
+
* @returns {Vec4}
|
|
125
|
+
*/
|
|
126
|
+
add(v) {
|
|
127
|
+
return new Vec4(
|
|
128
|
+
this.x + v.x,
|
|
129
|
+
this.y + v.y,
|
|
130
|
+
this.z + v.z,
|
|
131
|
+
this.w + v.w
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {Vec4} v
|
|
137
|
+
* @returns {Vec4}
|
|
138
|
+
*/
|
|
139
|
+
sub(v) {
|
|
140
|
+
return new Vec4(
|
|
141
|
+
this.x - v.x,
|
|
142
|
+
this.y - v.y,
|
|
143
|
+
this.z - v.z,
|
|
144
|
+
this.w - v.w
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {Vec4} v
|
|
150
|
+
* @returns {Vec4}
|
|
151
|
+
*/
|
|
152
|
+
mul(v) {
|
|
153
|
+
return new Vec4(
|
|
154
|
+
this.x * v.x,
|
|
155
|
+
this.y * v.y,
|
|
156
|
+
this.z * v.z,
|
|
157
|
+
this.w * v.w
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {Vec4} v
|
|
163
|
+
* @returns {Vec4}
|
|
164
|
+
*/
|
|
165
|
+
div(v) {
|
|
166
|
+
return new Vec4(
|
|
167
|
+
this.x / v.x,
|
|
168
|
+
this.y / v.y,
|
|
169
|
+
this.z / v.z,
|
|
170
|
+
this.w / v.w
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {number} a
|
|
176
|
+
* @returns {Vec4}
|
|
177
|
+
*/
|
|
178
|
+
scale(a) {
|
|
179
|
+
return new Vec4(
|
|
180
|
+
this.x * a,
|
|
181
|
+
this.y * a,
|
|
182
|
+
this.z * a,
|
|
183
|
+
this.w * a
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param {Vec4} v
|
|
189
|
+
* @returns {number}
|
|
190
|
+
*/
|
|
191
|
+
dot(v) {
|
|
192
|
+
return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @returns {number}
|
|
197
|
+
*/
|
|
198
|
+
length() {
|
|
199
|
+
return Math.hypot(this.x, this.y, this.z, this.w);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @param {Vec4} v
|
|
204
|
+
* @returns {number}
|
|
205
|
+
*/
|
|
206
|
+
dist(v) {
|
|
207
|
+
return this.sub(v).length();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
fromStream(stream) {
|
|
211
|
+
this.x = stream.readFloat();
|
|
212
|
+
this.y = stream.readFloat();
|
|
213
|
+
this.z = stream.readFloat();
|
|
214
|
+
this.w = stream.readFloat();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
toStream(stream) {
|
|
218
|
+
stream.writeFloat(this.x);
|
|
219
|
+
stream.writeFloat(this.y);
|
|
220
|
+
stream.writeFloat(this.z);
|
|
221
|
+
stream.writeFloat(this.w);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
toString() {
|
|
225
|
+
return "(" + this.x + "," + this.y + "," + this.z + ")";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
module.exports = {
|
|
230
|
+
Vec3,
|
|
231
|
+
Vec4
|
|
232
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const webpack = require("webpack");
|
|
3
|
+
const TerserPlugin = require("terser-webpack-plugin");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
entry: "./main.js",
|
|
7
|
+
target: "node",
|
|
8
|
+
output: {
|
|
9
|
+
filename: "cli.js",
|
|
10
|
+
path: path.resolve(__dirname, "dist"),
|
|
11
|
+
clean: true,
|
|
12
|
+
},
|
|
13
|
+
plugins: [
|
|
14
|
+
new webpack.BannerPlugin({
|
|
15
|
+
banner: '#!/usr/bin/env node',
|
|
16
|
+
raw: true,
|
|
17
|
+
entryOnly: true,
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
mode: "production",
|
|
21
|
+
optimization: {
|
|
22
|
+
minimize: true,
|
|
23
|
+
minimizer: [
|
|
24
|
+
new TerserPlugin({
|
|
25
|
+
extractComments: false
|
|
26
|
+
}),
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
externals: {},
|
|
30
|
+
externalsPresets: { node: true },
|
|
31
|
+
};
|