@woosh/meep-engine 2.34.2 → 2.34.6
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/core/geom/3d/topology/TopoVertex.spec.js +6 -0
- package/core/model/object/objectDeepEquals.spec.js +1 -1
- package/editor/Editor.js +2 -2
- package/engine/EngineHarness.js +0 -1
- package/engine/asset/loaders/image/ImageDecoderWorker.js +1 -1
- package/engine/asset/loaders/image/ImageRGBADataLoader.js +10 -4
- package/engine/asset/loaders/image/codec/NativeImageDecoder.js +3 -1
- package/engine/asset/loaders/image/codec/ThreadedImageDecoder.js +2 -1
- package/engine/asset/loaders/image/png/PNG.js +10 -4
- package/engine/ecs/storage/BinaryBufferSerializer.js +2 -2
- package/engine/ecs/terrain/ecs/layers/TerrainLayers.js +9 -0
- package/engine/ecs/terrain/ecs/splat/SplatMapping.js +33 -0
- package/engine/graphics/micron/format/MicronGeometry.js +31 -4
- package/engine/graphics/micron/plugin/MicronRenderPlugin.js +3 -3
- package/package.json +1 -1
- package/samples/terrain/editor.js +347 -0
- package/view/controller/controls/NativeListController.js +6 -3
- package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +0 -32
|
@@ -88,9 +88,15 @@ test('replaceAnotherVertex', () => {
|
|
|
88
88
|
v_b.addEdge(e_b);
|
|
89
89
|
|
|
90
90
|
f_a.setVertexAt(0, v_a);
|
|
91
|
+
f_a.setVertexAt(1, new TopoVertex());
|
|
92
|
+
f_a.setVertexAt(2, new TopoVertex());
|
|
93
|
+
|
|
91
94
|
e_a.v0 = v_a;
|
|
92
95
|
|
|
93
96
|
f_b.setVertexAt(0, v_b);
|
|
97
|
+
f_b.setVertexAt(1, new TopoVertex());
|
|
98
|
+
f_b.setVertexAt(2, new TopoVertex());
|
|
99
|
+
|
|
94
100
|
e_b.v0 = v_b;
|
|
95
101
|
|
|
96
102
|
// verify assumptions about topology
|
package/editor/Editor.js
CHANGED
|
@@ -25,7 +25,7 @@ import TopDownCameraController from "../engine/graphics/ecs/camera/topdown/TopDo
|
|
|
25
25
|
import { Transform } from "../engine/ecs/transform/Transform.js";
|
|
26
26
|
import TopDownCameraControllerSystem, { setCameraControllerFromTransform } from "../engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
|
|
27
27
|
import { downloadAsFile } from "../core/binary/ByteArrayTools.js";
|
|
28
|
-
import
|
|
28
|
+
import BinaryBufferSerializer from "../engine/ecs/storage/BinaryBufferSerializer.js";
|
|
29
29
|
import { EncodingBinaryBuffer } from "../core/binary/EncodingBinaryBuffer.js";
|
|
30
30
|
import { EntityComponentDataset } from "../engine/ecs/EntityComponentDataset.js";
|
|
31
31
|
import InputControllerSystem from "../engine/input/ecs/systems/InputControllerSystem.js";
|
|
@@ -383,7 +383,7 @@ function Editor() {
|
|
|
383
383
|
// Set music tracks back to time=0
|
|
384
384
|
resetSoundEmitterTracks(dataset);
|
|
385
385
|
|
|
386
|
-
const serializer = new
|
|
386
|
+
const serializer = new BinaryBufferSerializer();
|
|
387
387
|
serializer.registry = engine.binarySerializationRegistry;
|
|
388
388
|
|
|
389
389
|
const state = new EncodingBinaryBuffer();
|
package/engine/EngineHarness.js
CHANGED
|
@@ -41,6 +41,12 @@ export class ImageRGBADataLoader extends AssetLoader {
|
|
|
41
41
|
return await this.decoder.decode(new Uint8Array(array_buffer));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {String} path
|
|
47
|
+
* @return {Promise<ImageRGBADataAsset>}
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
44
50
|
async __standard(path) {
|
|
45
51
|
|
|
46
52
|
const bitmap = await this.__decode_via_worker(path);
|
|
@@ -48,19 +54,19 @@ export class ImageRGBADataLoader extends AssetLoader {
|
|
|
48
54
|
|
|
49
55
|
let data;
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
case 8:
|
|
57
|
+
const bitDepth = bitmap.bitDepth;
|
|
53
58
|
|
|
59
|
+
switch (bitDepth) {
|
|
60
|
+
case 8:
|
|
54
61
|
data = new Uint8Array(bitmap.data);
|
|
55
62
|
break
|
|
56
63
|
case 16:
|
|
57
64
|
data = new Uint16Array(bitmap.data);
|
|
58
65
|
break;
|
|
59
66
|
default:
|
|
60
|
-
throw new Error(`Unsupported bit depth '${
|
|
67
|
+
throw new Error(`Unsupported bit depth '${bitDepth}'. path='${path}'`);
|
|
61
68
|
}
|
|
62
69
|
|
|
63
|
-
|
|
64
70
|
return new ImageRGBADataAsset(data, bitmap.width, bitmap.height, bitmap.itemSize);
|
|
65
71
|
}
|
|
66
72
|
|
|
@@ -2,7 +2,7 @@ import { Codec } from "./Codec.js";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
|
-
* @param {Image|ImageBitmap} img
|
|
5
|
+
* @param {Image|ImageBitmap|HTMLImageElement} img
|
|
6
6
|
* @returns {Uint8Array}
|
|
7
7
|
*/
|
|
8
8
|
function decode(img) {
|
|
@@ -28,10 +28,12 @@ export class NativeImageDecoder extends Codec {
|
|
|
28
28
|
async decode(data) {
|
|
29
29
|
const image = new Image();
|
|
30
30
|
|
|
31
|
+
// convert binary data to image URL that we can load
|
|
31
32
|
const url = URL.createObjectURL(new Blob([data]));
|
|
32
33
|
|
|
33
34
|
image.src = url;
|
|
34
35
|
|
|
36
|
+
// give browser a chance to decode image in async
|
|
35
37
|
await image.decode();
|
|
36
38
|
|
|
37
39
|
const rgba_data = decode(image);
|
|
@@ -343,7 +343,9 @@ PNG.prototype.getUint8Data_case3 = function () {
|
|
|
343
343
|
for (let i = 0; i < pixel_count; i++) {
|
|
344
344
|
const destination_address = i * itemSize;
|
|
345
345
|
|
|
346
|
-
const
|
|
346
|
+
const lookup_index = pixels[i * d];
|
|
347
|
+
|
|
348
|
+
const lookup_value = lookup_index * 3;
|
|
347
349
|
|
|
348
350
|
result_data[destination_address] = palette[lookup_value];
|
|
349
351
|
result_data[destination_address + 1] = palette[lookup_value + 1];
|
|
@@ -381,7 +383,12 @@ PNG.prototype.getUint8Data = function () {
|
|
|
381
383
|
break;
|
|
382
384
|
case 3:
|
|
383
385
|
// palette
|
|
384
|
-
|
|
386
|
+
const c3 = this.getUint8Data_case3();
|
|
387
|
+
|
|
388
|
+
data = c3.data;
|
|
389
|
+
itemSize = c3.itemSize;
|
|
390
|
+
|
|
391
|
+
break;
|
|
385
392
|
case 4:
|
|
386
393
|
// grayscale with alpha
|
|
387
394
|
data = this.pixels;
|
|
@@ -397,7 +404,6 @@ PNG.prototype.getUint8Data = function () {
|
|
|
397
404
|
|
|
398
405
|
return {
|
|
399
406
|
data,
|
|
400
|
-
itemSize
|
|
401
|
-
bitDepth: this.bitDepth
|
|
407
|
+
itemSize
|
|
402
408
|
};
|
|
403
409
|
};
|
|
@@ -48,7 +48,7 @@ function isEntityTransient(entity, dataset, smComponentIndex, componentInstance)
|
|
|
48
48
|
return isTransient;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
class
|
|
51
|
+
class BinaryBufferSerializer {
|
|
52
52
|
constructor() {
|
|
53
53
|
/**
|
|
54
54
|
*
|
|
@@ -171,4 +171,4 @@ class BinaryBufferSerialization {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
export default
|
|
174
|
+
export default BinaryBufferSerializer;
|
|
@@ -267,6 +267,15 @@ export class TerrainLayers {
|
|
|
267
267
|
return index;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
/**
|
|
271
|
+
*
|
|
272
|
+
* @param {TerrainLayer} layer
|
|
273
|
+
* @return {boolean}
|
|
274
|
+
*/
|
|
275
|
+
removeLayer(layer) {
|
|
276
|
+
return this.layers.removeOneOf(layer);
|
|
277
|
+
}
|
|
278
|
+
|
|
270
279
|
/**
|
|
271
280
|
*
|
|
272
281
|
* @param {TerrainLayer} layer
|
|
@@ -159,6 +159,39 @@ export class SplatMapping {
|
|
|
159
159
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
/**
|
|
163
|
+
*
|
|
164
|
+
* @param {Sampler2D} destination
|
|
165
|
+
* @param {number} index
|
|
166
|
+
* @param {number} channel
|
|
167
|
+
*/
|
|
168
|
+
readLayerToSampler(destination, index, channel = 0) {
|
|
169
|
+
const weightData = this.weightData;
|
|
170
|
+
|
|
171
|
+
const width = this.size.x;
|
|
172
|
+
const height = this.size.y;
|
|
173
|
+
|
|
174
|
+
assert.equal(destination.width, width, 'destination dimensions mismatch');
|
|
175
|
+
assert.equal(destination.height, height, 'destination dimensions mismatch');
|
|
176
|
+
|
|
177
|
+
const dataOffset = index * width * height;
|
|
178
|
+
|
|
179
|
+
for (let y = 0; y < height; y++) {
|
|
180
|
+
|
|
181
|
+
for (let x = 0; x < width; x++) {
|
|
182
|
+
|
|
183
|
+
const targetIndex = y * width + x;
|
|
184
|
+
const targetAddress = dataOffset + targetIndex;
|
|
185
|
+
|
|
186
|
+
const value = weightData[targetAddress];
|
|
187
|
+
|
|
188
|
+
destination.writeChannel(x, y, channel, value);
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
162
195
|
/**
|
|
163
196
|
*
|
|
164
197
|
* @param {Uint8Array} source
|
|
@@ -180,6 +180,29 @@ export class MicronGeometry {
|
|
|
180
180
|
return hits;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
+
/**
|
|
184
|
+
*
|
|
185
|
+
* @param {number} lod
|
|
186
|
+
* @returns {number}
|
|
187
|
+
*/
|
|
188
|
+
computeLodFaceCount(lod) {
|
|
189
|
+
let r = 0;
|
|
190
|
+
|
|
191
|
+
const patches = this.patches;
|
|
192
|
+
const patch_count = patches.length;
|
|
193
|
+
for (let i = 0; i < patch_count; i++) {
|
|
194
|
+
const patch = patches[i];
|
|
195
|
+
|
|
196
|
+
if (patch.lod !== lod) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
r += patch.polygon_count;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return r;
|
|
204
|
+
}
|
|
205
|
+
|
|
183
206
|
get patches() {
|
|
184
207
|
return this.__patches;
|
|
185
208
|
}
|
|
@@ -209,17 +232,21 @@ export class MicronGeometry {
|
|
|
209
232
|
|
|
210
233
|
/**
|
|
211
234
|
* Build geometry proxy from the patches
|
|
212
|
-
* @param {number}
|
|
235
|
+
* @param {number} fraction percentage of the original geometry to keep
|
|
236
|
+
* @param {number} min minimum number of triangles to keep, this will be respected first before percentage value
|
|
213
237
|
*/
|
|
214
|
-
buildProxy(
|
|
238
|
+
buildProxy(fraction, min) {
|
|
215
239
|
throw new Error('Not Implemented');
|
|
216
240
|
}
|
|
217
241
|
|
|
218
242
|
computeByteSize() {
|
|
219
243
|
let result = 0;
|
|
220
244
|
|
|
221
|
-
|
|
222
|
-
|
|
245
|
+
const patches = this.__patches;
|
|
246
|
+
const patch_count = patches.length;
|
|
247
|
+
|
|
248
|
+
for (let i = 0; i < patch_count; i++) {
|
|
249
|
+
result += patches[i].computeByteSize();
|
|
223
250
|
}
|
|
224
251
|
|
|
225
252
|
return result;
|
|
@@ -125,15 +125,15 @@ class GLTFAssetTransformer extends AssetTransformer {
|
|
|
125
125
|
/**
|
|
126
126
|
*
|
|
127
127
|
* @param {Asset} source
|
|
128
|
-
* @param asset_description
|
|
128
|
+
* @param {AssetDescription} asset_description
|
|
129
129
|
* @return {Promise<Asset>}
|
|
130
130
|
*/
|
|
131
131
|
async transform(source, asset_description) {
|
|
132
132
|
const animationClips = source.animations;
|
|
133
133
|
|
|
134
134
|
if (animationClips !== undefined && animationClips.length > 0) {
|
|
135
|
-
//
|
|
136
|
-
|
|
135
|
+
// animations might cause trouble
|
|
136
|
+
console.warn(`model '${asset_description.path}' contains animations, these animations might not works as intended with micron.`);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"productName": "Meep",
|
|
6
6
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.34.
|
|
8
|
+
"version": "2.34.6",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import { EngineHarness } from "../../engine/EngineHarness.js";
|
|
2
|
+
import EmptyView from "../../view/elements/EmptyView.js";
|
|
3
|
+
import { EngineConfiguration } from "../../engine/EngineConfiguration.js";
|
|
4
|
+
import { buildCubeURLs } from "../../engine/graphics/texture/cubemap/buildCubeURLs.js";
|
|
5
|
+
import { ArrayBufferLoader } from "../../engine/asset/loaders/ArrayBufferLoader.js";
|
|
6
|
+
import { TerrainFlags } from "../../engine/ecs/terrain/ecs/TerrainFlags.js";
|
|
7
|
+
import Signal from "../../core/events/signal/Signal.js";
|
|
8
|
+
import { NativeListController } from "../../view/controller/controls/NativeListController.js";
|
|
9
|
+
import { TerrainLayer } from "../../engine/ecs/terrain/ecs/layers/TerrainLayer.js";
|
|
10
|
+
import CheckersTextureURI from "../../engine/graphics/texture/CheckersTextureURI.js";
|
|
11
|
+
import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
|
|
12
|
+
import { Cache } from "../../core/cache/Cache.js";
|
|
13
|
+
import { computeStringHash } from "../../core/primitives/strings/computeStringHash.js";
|
|
14
|
+
import { noop, strictEquals } from "../../core/function/Functions.js";
|
|
15
|
+
import { scaleSampler2D } from "../../engine/graphics/texture/sampler/scaleSampler2D.js";
|
|
16
|
+
import { Sampler2D } from "../../engine/graphics/texture/sampler/Sampler2D.js";
|
|
17
|
+
import { DataType } from "../../core/collection/table/DataType.js";
|
|
18
|
+
import { compute_typed_array_constructor_from_data_type } from "../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
|
|
19
|
+
import { copy_Sampler2D_channel_data } from "../../engine/graphics/texture/sampler/copy_Sampler2D_channel_data.js";
|
|
20
|
+
import { TextureAssetLoader } from "../../engine/asset/loaders/texture/TextureAssetLoader.js";
|
|
21
|
+
import { CanvasView } from "../../view/elements/CanvasView.js";
|
|
22
|
+
import convertSampler2D2Canvas from "../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
|
|
23
|
+
import { drawSamplerHTML } from "../../engine/graphics/texture/sampler/util/drawSamplerHTML.js";
|
|
24
|
+
|
|
25
|
+
const engineHarness = new EngineHarness();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param {Engine} engine
|
|
30
|
+
*/
|
|
31
|
+
function makeConfig(engine) {
|
|
32
|
+
|
|
33
|
+
const config = new EngineConfiguration();
|
|
34
|
+
|
|
35
|
+
config.addLoader('arraybuffer', new ArrayBufferLoader());
|
|
36
|
+
config.addLoader('texture', new TextureAssetLoader());
|
|
37
|
+
|
|
38
|
+
return config;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
class EditorTextureSlot {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.onChanged = new Signal();
|
|
44
|
+
|
|
45
|
+
this.sampler = null;
|
|
46
|
+
|
|
47
|
+
this.__read = noop;
|
|
48
|
+
this.__write = noop;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @type {number}
|
|
53
|
+
*/
|
|
54
|
+
this.itemSize = 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
read() {
|
|
58
|
+
this.__read(this.sampler);
|
|
59
|
+
|
|
60
|
+
this.onChanged.send0();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
write() {
|
|
64
|
+
this.__write(this.sampler);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
*
|
|
69
|
+
* @param {(Sampler2D)=>any} read
|
|
70
|
+
* @param {(Sampler2D)=>any} write
|
|
71
|
+
* @param {number} [itemSize]
|
|
72
|
+
* @param {DataType} [dataType]
|
|
73
|
+
* @return {EditorTextureSlot}
|
|
74
|
+
*/
|
|
75
|
+
static from({ read, write, itemSize = 1, dataType = DataType.Uint8 }) {
|
|
76
|
+
const r = new EditorTextureSlot();
|
|
77
|
+
|
|
78
|
+
r.__read = read;
|
|
79
|
+
r.__write = write;
|
|
80
|
+
|
|
81
|
+
const TA = compute_typed_array_constructor_from_data_type(dataType);
|
|
82
|
+
|
|
83
|
+
r.sampler = new Sampler2D(new TA(itemSize), itemSize, 1, 1);
|
|
84
|
+
|
|
85
|
+
return r;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class TextureLayerEditor {
|
|
90
|
+
constructor() {
|
|
91
|
+
this.index = 0;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* @type {Terrain|null}
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
this.__terrain = null;
|
|
99
|
+
|
|
100
|
+
this.__splat = EditorTextureSlot.from({
|
|
101
|
+
read: (target) => {
|
|
102
|
+
const terrain = this.__terrain;
|
|
103
|
+
|
|
104
|
+
target.resize(terrain.splat.size.x, terrain.splat.size.y)
|
|
105
|
+
|
|
106
|
+
terrain.splat.readLayerToSampler(target, this.index, 0);
|
|
107
|
+
},
|
|
108
|
+
write: (source) => {
|
|
109
|
+
this.__terrain.splat.writeLayerFromSampler(source, this.index, 0);
|
|
110
|
+
},
|
|
111
|
+
itemSize: 1
|
|
112
|
+
});
|
|
113
|
+
this.__diffuse = EditorTextureSlot.from({
|
|
114
|
+
read: (target) => {
|
|
115
|
+
|
|
116
|
+
const layers = this.__terrain.layers;
|
|
117
|
+
|
|
118
|
+
const layer = layers.get(this.index);
|
|
119
|
+
|
|
120
|
+
target.resize(layer.diffuse.width, layer.diffuse.height);
|
|
121
|
+
copy_Sampler2D_channel_data(layer.diffuse, target);
|
|
122
|
+
},
|
|
123
|
+
write: (source) => {
|
|
124
|
+
const layer = this.__terrain.layers.get(this.index);
|
|
125
|
+
|
|
126
|
+
copy_Sampler2D_channel_data(source, layer.diffuse);
|
|
127
|
+
|
|
128
|
+
this.__terrain.layers.writeLayerDataIntoTexture(this.index);
|
|
129
|
+
},
|
|
130
|
+
itemSize: 3
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {Terrain} t
|
|
136
|
+
*/
|
|
137
|
+
set terrain(t) {
|
|
138
|
+
this.__terrain = t;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
init() {
|
|
142
|
+
this.__splat.read();
|
|
143
|
+
this.__diffuse.read();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
* @param {EditorTextureSlot} slot
|
|
150
|
+
*/
|
|
151
|
+
function makeTextureSlotView({ slot }) {
|
|
152
|
+
|
|
153
|
+
const preview = new CanvasView();
|
|
154
|
+
preview.size.set(64, 64);
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
function update() {
|
|
158
|
+
convertSampler2D2Canvas(slot.sampler, 1, 0, preview.el);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
preview.on.linked.add(update);
|
|
162
|
+
preview.bindSignal(slot.onChanged, update);
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
return preview;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
*
|
|
170
|
+
* @param {View} root
|
|
171
|
+
* @param {Terrain} terrain
|
|
172
|
+
* @param {Engine} engine
|
|
173
|
+
*/
|
|
174
|
+
function makeTerrainEditor(root, terrain, engine) {
|
|
175
|
+
/**
|
|
176
|
+
*
|
|
177
|
+
* @type {Cache<string, Sampler2D>}
|
|
178
|
+
*/
|
|
179
|
+
const PREVIEW_CACHE = new Cache({
|
|
180
|
+
keyHashFunction: computeStringHash,
|
|
181
|
+
keyEqualityFunction: strictEquals
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const PREVIEW_SIZE = 64;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @param {string} url
|
|
189
|
+
* @return {Promise<Sampler2D>}
|
|
190
|
+
*/
|
|
191
|
+
async function getPreviewFromURL(url) {
|
|
192
|
+
if (PREVIEW_CACHE.contains(url)) {
|
|
193
|
+
return PREVIEW_CACHE.get(url);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const asset = await engine.assetManager.promise(url, 'image');
|
|
197
|
+
|
|
198
|
+
// check cache again, might have been loaded in the meanwhile
|
|
199
|
+
if (PREVIEW_CACHE.contains(url)) {
|
|
200
|
+
return PREVIEW_CACHE.get(url);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const source = asset.create();
|
|
204
|
+
|
|
205
|
+
const preview = Sampler2D.uint8(4, PREVIEW_SIZE, PREVIEW_SIZE);
|
|
206
|
+
|
|
207
|
+
scaleSampler2D(source, preview);
|
|
208
|
+
|
|
209
|
+
PREVIEW_CACHE.put(url, preview);
|
|
210
|
+
|
|
211
|
+
return preview;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
*
|
|
216
|
+
* @type {EditorTextureSlot|null}
|
|
217
|
+
*/
|
|
218
|
+
let active_slot = null;
|
|
219
|
+
|
|
220
|
+
function rebuild() {
|
|
221
|
+
// rebuild terrain
|
|
222
|
+
terrain.clearFlag(TerrainFlags.Built);
|
|
223
|
+
terrain.build(engine.assetManager);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function build_splat_editor() {
|
|
227
|
+
/**
|
|
228
|
+
*
|
|
229
|
+
* @type {Map<TerrainLayer, TextureLayerEditor>}
|
|
230
|
+
*/
|
|
231
|
+
const editors = new Map();
|
|
232
|
+
|
|
233
|
+
return new NativeListController({
|
|
234
|
+
model: terrain.layers.layers,
|
|
235
|
+
elementFactory() {
|
|
236
|
+
return TerrainLayer.from(CheckersTextureURI, 1, 1);
|
|
237
|
+
},
|
|
238
|
+
/**
|
|
239
|
+
*
|
|
240
|
+
* @param {TerrainLayer} layer
|
|
241
|
+
*/
|
|
242
|
+
elementViewFactory(layer) {
|
|
243
|
+
const e = new TextureLayerEditor();
|
|
244
|
+
|
|
245
|
+
editors.set(layer, e);
|
|
246
|
+
|
|
247
|
+
const layer_index = terrain.layers.layers.indexOf(layer);
|
|
248
|
+
|
|
249
|
+
e.terrain = terrain;
|
|
250
|
+
e.index = layer_index;
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
e.init();
|
|
254
|
+
|
|
255
|
+
const view = new EmptyView();
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
view.addChild(makeTextureSlotView({
|
|
259
|
+
slot: e.__diffuse
|
|
260
|
+
}));
|
|
261
|
+
view.addChild(makeTextureSlotView({
|
|
262
|
+
slot: e.__splat
|
|
263
|
+
}));
|
|
264
|
+
|
|
265
|
+
view.bindSignal(layer.onChanged, e.__diffuse.read, e.__diffuse);
|
|
266
|
+
|
|
267
|
+
return view;
|
|
268
|
+
},
|
|
269
|
+
operationAdd(list, el) {
|
|
270
|
+
terrain.layers.addLayer(el);
|
|
271
|
+
terrain.splat.addWeightLayer();
|
|
272
|
+
},
|
|
273
|
+
operationRemove(list, el) {
|
|
274
|
+
const index = terrain.layers.layers.indexOf(el);
|
|
275
|
+
terrain.layers.removeLayer(el);
|
|
276
|
+
terrain.splat.removeWeightLayer(index);
|
|
277
|
+
|
|
278
|
+
editors.delete(el);
|
|
279
|
+
|
|
280
|
+
// re-shuffle remaining editors
|
|
281
|
+
|
|
282
|
+
for (const [layer, editor] of editors) {
|
|
283
|
+
if (editor.index > index) {
|
|
284
|
+
editor.index--;
|
|
285
|
+
editor.init();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
root.addChild(build_splat_editor());
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
*
|
|
297
|
+
* @param {Engine} engine
|
|
298
|
+
* @return {string}
|
|
299
|
+
*/
|
|
300
|
+
async function main(engine) {
|
|
301
|
+
|
|
302
|
+
//disable drag and drop on game canvas
|
|
303
|
+
engine.graphics.domElement.addEventListener('dragover', (e) => e.preventDefault());
|
|
304
|
+
engine.graphics.domElement.addEventListener('drop', (e) => e.preventDefault());
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
EngineHarness.buildLights({ engine });
|
|
308
|
+
const camera = EngineHarness.buildCamera({ engine });
|
|
309
|
+
EngineHarness.buildOrbitalCameraController({ engine, cameraEntity: camera.entity })
|
|
310
|
+
|
|
311
|
+
await EngineHarness.buildTerrain({ engine });
|
|
312
|
+
|
|
313
|
+
const vMain = new EmptyView({ classList: ['ui-texture-testing-tool-view'] });
|
|
314
|
+
|
|
315
|
+
vMain.css({
|
|
316
|
+
position: "absolute",
|
|
317
|
+
left: "0",
|
|
318
|
+
top: "0",
|
|
319
|
+
pointerEvents: "initial"
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
makeTerrainEditor(vMain, obtainTerrain(engine.entityManager.dataset), engine);
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
document.body.appendChild(vMain.el);
|
|
326
|
+
vMain.link();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
*
|
|
332
|
+
* @param {EngineHarness} harness
|
|
333
|
+
*/
|
|
334
|
+
async function init(harness) {
|
|
335
|
+
|
|
336
|
+
const engine = harness.engine;
|
|
337
|
+
|
|
338
|
+
await makeConfig(engine).apply(engine);
|
|
339
|
+
|
|
340
|
+
await engine.graphics.loadEnvironmentMap(buildCubeURLs('data/textures/cubemaps/hip_miramar/32/', '.png'));
|
|
341
|
+
|
|
342
|
+
await harness.initialize();
|
|
343
|
+
|
|
344
|
+
main(engine);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
init(engineHarness);
|
|
@@ -27,8 +27,8 @@ export class NativeListController extends View {
|
|
|
27
27
|
/**
|
|
28
28
|
* @template T
|
|
29
29
|
* @param {List<T>} model
|
|
30
|
-
* @param {
|
|
31
|
-
* @param {
|
|
30
|
+
* @param {(T)=>View} elementViewFactory
|
|
31
|
+
* @param {()=>T} elementFactory
|
|
32
32
|
* @param {string[]} [classList]
|
|
33
33
|
* @param {function(List<T>, T)} [operationAdd] Allows user to supply a special operation for adding an element to the list
|
|
34
34
|
* @param {function(List<T>, T)} [operationRemove] Allows user to supply a special operation for removing an element from the list
|
|
@@ -43,7 +43,7 @@ export class NativeListController extends View {
|
|
|
43
43
|
}) {
|
|
44
44
|
super();
|
|
45
45
|
|
|
46
|
-
assert.isFunction(elementViewFactory,'elementViewFactory');
|
|
46
|
+
assert.isFunction(elementViewFactory, 'elementViewFactory');
|
|
47
47
|
|
|
48
48
|
this.el = document.createElement('div');
|
|
49
49
|
|
|
@@ -55,6 +55,9 @@ export class NativeListController extends View {
|
|
|
55
55
|
elementFactory(el) {
|
|
56
56
|
const elementView = elementViewFactory(el);
|
|
57
57
|
|
|
58
|
+
assert.defined(elementView, 'elementView');
|
|
59
|
+
assert.equal(elementView.isView, true, 'elementView.isView !== true');
|
|
60
|
+
|
|
58
61
|
const vWrapper = new EmptyView({ classList: ['element-wrapper'] });
|
|
59
62
|
|
|
60
63
|
elementView.addClass('wrapped-element');
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Sampler2D } from "../Sampler2D.js";
|
|
2
|
-
import { scaleSampler2D } from "../scaleSampler2D.js";
|
|
3
|
-
import convertSampler2D2Canvas from "../Sampler2D2Canvas.js";
|
|
4
|
-
import { typedArrayConstructorByInstance } from "../typedArrayConstructorByInstance.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {Sampler2D} s
|
|
9
|
-
* @param {number} x
|
|
10
|
-
* @param {number} y
|
|
11
|
-
* @param scale
|
|
12
|
-
* @param offset
|
|
13
|
-
* @param {number} resolution
|
|
14
|
-
*/
|
|
15
|
-
export function paintSamplerOnHTML(s, x, y, scale, offset, resolution=256) {
|
|
16
|
-
|
|
17
|
-
const d = resolution;
|
|
18
|
-
|
|
19
|
-
const TA = typedArrayConstructorByInstance(s.data);
|
|
20
|
-
|
|
21
|
-
const target = new Sampler2D(new TA(d * d * s.itemSize), s.itemSize, d, d);
|
|
22
|
-
|
|
23
|
-
scaleSampler2D(s, target);
|
|
24
|
-
|
|
25
|
-
const c = convertSampler2D2Canvas(target, scale, offset);
|
|
26
|
-
c.style.zIndex = 1000;
|
|
27
|
-
c.style.position = "absolute";
|
|
28
|
-
c.style.left = `${x}px`;
|
|
29
|
-
c.style.top = `${y}px`;
|
|
30
|
-
|
|
31
|
-
document.body.appendChild(c);
|
|
32
|
-
}
|