@woosh/meep-engine 2.43.21 → 2.43.23
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/collection/HashMap.d.ts +2 -2
- package/core/collection/HashMap.js +22 -2
- package/core/geom/3d/morton/mortonEncode_magicbits.js +18 -0
- package/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js +2 -2
- package/core/geom/3d/topology/struct/TopoEdge.js +4 -0
- package/core/geom/3d/topology/struct/TopoMesh.js +25 -0
- package/core/geom/3d/topology/struct/TopoTriangle.js +4 -0
- package/core/geom/3d/topology/struct/TopoVertex.js +8 -0
- package/core/geom/3d/topology/struct/binary/BinaryElementPool.js +288 -0
- package/core/geom/3d/topology/struct/binary/BinaryElementPool.spec.js +36 -0
- package/core/geom/3d/topology/struct/binary/BinaryTopology.js +617 -0
- package/core/geom/3d/topology/struct/binary/BinaryTopology.spec.js +16 -0
- package/core/geom/3d/topology/struct/binary/io/OrderedEdge.js +66 -0
- package/core/geom/3d/topology/struct/binary/io/bt_index_geometry_to_topology.js +188 -0
- package/core/geom/3d/topology/struct/binary/io/bt_index_geometry_to_topology.spec.js +84 -0
- package/core/geom/3d/topology/struct/binary/io/bt_mesh_calc_edges.js +51 -0
- package/core/geom/3d/topology/struct/binary/io/create_edge.js +106 -0
- package/core/geom/3d/topology/struct/binary/io/get_or_create_edge_map.js +26 -0
- package/core/geom/3d/topology/struct/binary/query/bt_mesh_edge_has_vertex.js +16 -0
- package/core/geom/3d/topology/struct/binary/query/bt_mesh_edge_has_vertex.spec.js +15 -0
- package/core/geom/3d/topology/struct/binary/query/bt_mesh_edge_other_vertex.js +21 -0
- package/core/geom/3d/topology/struct/binary/query/bt_mesh_edge_other_vertex.spec.js +16 -0
- package/core/geom/3d/topology/struct/prototypeBinaryTopology.js +55 -0
- package/core/path/PATH_SEPARATOR.js +1 -0
- package/core/path/computeFileExtension.js +24 -0
- package/core/path/computeFileExtension.spec.js +13 -0
- package/core/path/computePathBase.js +21 -0
- package/core/path/computePathBase.spec.js +13 -0
- package/core/path/computePathDirectory.js +25 -0
- package/editor/view/library/MeshLibraryView.js +1 -1
- package/engine/asset/guessAssetType.js +1 -1
- package/engine/asset/loaders/image/ImageRGBADataLoader.js +1 -1
- package/engine/asset/loaders/texture/TextureAssetLoader.js +1 -1
- package/engine/ecs/storage/BinaryBufferSerializer.js +7 -0
- package/engine/graphics/material/composeCompile.js +3 -5
- package/engine/graphics/micron/plugin/GLTFAssetTransformer.js +90 -65
- package/engine/graphics/sh3/README.md +2 -0
- package/engine/graphics/sh3/path_tracer/PathTracer.js +2 -15
- package/engine/graphics/sh3/path_tracer/getBiasedNormalSample.js +1 -1
- package/engine/graphics/sh3/path_tracer/prototypePathTracer.js +14 -9
- package/engine/graphics/texture/cubemap/load_environment_map.js +1 -1
- package/engine/graphics/util/makeMeshPreviewScene.js +38 -26
- package/engine/network/RemoteController.js +98 -0
- package/engine/network/remoteEditor.js +33 -0
- package/engine/save/storage/IndexedDBStorage.js +1 -0
- package/package.json +1 -1
- package/view/elements/MeshPreview.js +5 -1
- package/core/FilePath.js +0 -73
- package/core/FilePath.spec.js +0 -25
- package/core/geom/3d/topology/struct/BinaryTopology.js +0 -112
|
@@ -2,13 +2,13 @@ import View from "../../../view/View.js";
|
|
|
2
2
|
import { makeModelView } from "../../../view/renderModel.js";
|
|
3
3
|
import Vector2 from "../../../core/geom/Vector2.js";
|
|
4
4
|
import domify from "../../../view/DOM.js";
|
|
5
|
-
import { computePathBase } from "../../../core/FilePath.js";
|
|
6
5
|
import LabelView from "../../../view/common/LabelView.js";
|
|
7
6
|
import List from "../../../core/collection/list/List.js";
|
|
8
7
|
import AABB2 from "../../../core/geom/AABB2.js";
|
|
9
8
|
import { DragEvents } from "../../../engine/input/devices/events/DragEvents.js";
|
|
10
9
|
import { MouseEvents } from "../../../engine/input/devices/events/MouseEvents.js";
|
|
11
10
|
import { TouchEvents } from "../../../engine/input/devices/events/TouchEvents.js";
|
|
11
|
+
import { computePathBase } from "../../../core/path/computePathBase.js";
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
const ICON_SIZE = 50;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AssetLoader } from "../AssetLoader.js";
|
|
2
|
-
import { computeFileExtension } from "../../../../core/FilePath.js";
|
|
3
2
|
import { GameAssetType } from "../../GameAssetType.js";
|
|
4
3
|
import { convertTexture2Sampler2D } from "../../../graphics/texture/sampler/convertTexture2Sampler2D.js";
|
|
5
4
|
import { ImageRGBADataAsset } from "./ImageRGBADataAsset.js";
|
|
@@ -7,6 +6,7 @@ import { ArrayBufferLoader } from "../ArrayBufferLoader.js";
|
|
|
7
6
|
import { CodecWithFallback } from "./codec/CodecWithFallback.js";
|
|
8
7
|
import { ThreadedImageDecoder } from "./codec/ThreadedImageDecoder.js";
|
|
9
8
|
import { NativeImageDecoder } from "./codec/NativeImageDecoder.js";
|
|
9
|
+
import { computeFileExtension } from "../../../../core/path/computeFileExtension.js";
|
|
10
10
|
|
|
11
11
|
const ASSET_TYPE_ARRAY_BUFFER = "arraybuffer";
|
|
12
12
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AssetLoader } from "../AssetLoader.js";
|
|
2
|
-
import { computeFileExtension } from "../../../../core/FilePath.js";
|
|
3
2
|
import { loadDDSTexture } from "./loadDDSTexture.js";
|
|
4
3
|
import { loadStandardImageTexture } from "./loadStandardImageTexture.js";
|
|
4
|
+
import { computeFileExtension } from "../../../../core/path/computeFileExtension.js";
|
|
5
5
|
|
|
6
6
|
export class TextureAssetLoader extends AssetLoader {
|
|
7
7
|
load(path, success, failure, progress) {
|
|
@@ -55,6 +55,11 @@ class BinaryBufferSerializer {
|
|
|
55
55
|
* @type {BinarySerializationRegistry}
|
|
56
56
|
*/
|
|
57
57
|
this.registry = null;
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @type {Engine|null}
|
|
61
|
+
*/
|
|
62
|
+
this.engine = null;
|
|
58
63
|
}
|
|
59
64
|
|
|
60
65
|
/**
|
|
@@ -92,6 +97,8 @@ class BinaryBufferSerializer {
|
|
|
92
97
|
|
|
93
98
|
let i;
|
|
94
99
|
|
|
100
|
+
const engine = this.engine;
|
|
101
|
+
|
|
95
102
|
for (i = 0; i < numSerializableTypes; i++) {
|
|
96
103
|
|
|
97
104
|
const componentType = serializableComponentTypes[i];
|
|
@@ -13,6 +13,7 @@ export function composeCompile(previous, next) {
|
|
|
13
13
|
let t1_cache = cache.get(previous);
|
|
14
14
|
|
|
15
15
|
if (t1_cache === undefined) {
|
|
16
|
+
// no caches starting from previous
|
|
16
17
|
t1_cache = new WeakMap();
|
|
17
18
|
|
|
18
19
|
cache.set(previous, t1_cache);
|
|
@@ -21,14 +22,11 @@ export function composeCompile(previous, next) {
|
|
|
21
22
|
let result_function = t1_cache.get(next);
|
|
22
23
|
|
|
23
24
|
if (result_function === undefined) {
|
|
25
|
+
// no matching function found for pair, let's create it
|
|
26
|
+
|
|
24
27
|
// we create a custom function just to be able to name our function, this is because of how three.js caches onBeforeCompile by just turning it into the string, so changing the function name will result in altered cache key
|
|
25
28
|
const f = new Function('previous, next', `return function f${id_counter++}(a,b,c,d){ previous(a,b,c,d); next(a,b,c,d); };`);
|
|
26
29
|
|
|
27
|
-
// result_function = function (a, b, c, d) {
|
|
28
|
-
// previous(a, b, c, d);
|
|
29
|
-
// next(a, b, c, d);
|
|
30
|
-
// };
|
|
31
|
-
//
|
|
32
30
|
|
|
33
31
|
result_function = f(previous, next);
|
|
34
32
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AssetTransformer } from "../../../asset/AssetTransformer.js";
|
|
2
|
-
import { computePathDirectory } from "../../../../core/FilePath.js";
|
|
3
2
|
import { BinaryBuffer } from "../../../../core/binary/BinaryBuffer.js";
|
|
4
3
|
import { MicronGeometry } from "../format/MicronGeometry.js";
|
|
5
4
|
import { MICRON_GEOMETRY_FIELD } from "../MICRON_GEOMETRY_FIELD.js";
|
|
@@ -12,6 +11,7 @@ import {
|
|
|
12
11
|
deserialize_geometry_collection
|
|
13
12
|
} from "../format/serialization/collection/geometry_collection_serialization.js";
|
|
14
13
|
import { GLTF_MICRON_ID_FIELD } from "./GLTF_MICRON_ID_FIELD.js";
|
|
14
|
+
import { computePathDirectory } from "../../../../core/path/computePathDirectory.js";
|
|
15
15
|
|
|
16
16
|
export const ASSET_TYPE_ARRAY_BUFFER = "arraybuffer";
|
|
17
17
|
|
|
@@ -56,14 +56,13 @@ function ensureProxy(object) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
class TransformContext {
|
|
60
60
|
/**
|
|
61
61
|
*
|
|
62
|
-
* @param {
|
|
62
|
+
* @param {AssetManager} assetManager
|
|
63
|
+
* @param {AbstractAsyncMap<THREE.BufferGeometry, MicronGeometry>} cache
|
|
63
64
|
*/
|
|
64
|
-
constructor(cache) {
|
|
65
|
-
super();
|
|
66
|
-
|
|
65
|
+
constructor(assetManager, cache) {
|
|
67
66
|
/**
|
|
68
67
|
*
|
|
69
68
|
* @type {AbstractAsyncMap<THREE.BufferGeometry, MicronGeometry>|undefined}
|
|
@@ -71,20 +70,6 @@ export class GLTFAssetTransformer extends AssetTransformer {
|
|
|
71
70
|
*/
|
|
72
71
|
this.__cache = cache;
|
|
73
72
|
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* @type {AssetManager|null}
|
|
77
|
-
* @private
|
|
78
|
-
*/
|
|
79
|
-
this.__am = null;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Minimum number of polygons required for micron to be used
|
|
83
|
-
* @type {number}
|
|
84
|
-
* @private
|
|
85
|
-
*/
|
|
86
|
-
this.__threshold_polycount = DEFAULT_THRESHOLD_POLYCOUNT;
|
|
87
|
-
|
|
88
73
|
/**
|
|
89
74
|
*
|
|
90
75
|
* @type {MicronGeometry[]}
|
|
@@ -92,31 +77,54 @@ export class GLTFAssetTransformer extends AssetTransformer {
|
|
|
92
77
|
*/
|
|
93
78
|
this.__active_mesh_micron_cache = [];
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
* @deprecated
|
|
97
|
-
* Whether override mesh will be created for the asset, this is generally outdated
|
|
98
|
-
* @type {boolean}
|
|
99
|
-
* @private
|
|
100
|
-
*/
|
|
101
|
-
this.__settings_build_override_mesh = false;
|
|
80
|
+
this.__am = assetManager;
|
|
102
81
|
}
|
|
103
82
|
|
|
104
83
|
/**
|
|
105
84
|
*
|
|
106
|
-
* @param {
|
|
85
|
+
* @param {{userData:{}}} gltf
|
|
86
|
+
* @param {AssetDescription} ad
|
|
107
87
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
88
|
+
async load_mesh_micron_data(gltf, ad) {
|
|
89
|
+
// clear active cache
|
|
90
|
+
this.__active_mesh_micron_cache = [];
|
|
111
91
|
|
|
92
|
+
const micron_metadata = gltf.userData.micron;
|
|
93
|
+
|
|
94
|
+
if (micron_metadata === undefined) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const uri = micron_metadata.geometry_data_uri;
|
|
99
|
+
if (uri === undefined) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const base = computePathDirectory(ad.path);
|
|
104
|
+
|
|
105
|
+
let micron_data;
|
|
106
|
+
|
|
107
|
+
const micron_path = `${base}/${uri}`;
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
micron_data = await this.__am.promise(micron_path, ASSET_TYPE_ARRAY_BUFFER, { skip_queue: true });
|
|
111
|
+
} catch (e) {
|
|
112
|
+
console.error(`Failed to load micron geometry '${micron_path}' referenced in GLTF (will skip): ${e}`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// deserialize micron data
|
|
117
|
+
const buffer = BinaryBuffer.fromArrayBuffer(micron_data.create());
|
|
118
|
+
|
|
119
|
+
deserialize_geometry_collection(this.__active_mesh_micron_cache, buffer);
|
|
120
|
+
}
|
|
112
121
|
|
|
113
122
|
/**
|
|
114
123
|
* @param {THREE.Object3D} object
|
|
115
124
|
* @param {{asset:AssetDescription}} ctx
|
|
116
125
|
* @return {Promise<void>}
|
|
117
|
-
* @private
|
|
118
126
|
*/
|
|
119
|
-
async
|
|
127
|
+
async visitObjectToLoadMicron(object, ctx) {
|
|
120
128
|
if (!object.isMesh) {
|
|
121
129
|
return;
|
|
122
130
|
}
|
|
@@ -150,46 +158,59 @@ export class GLTFAssetTransformer extends AssetTransformer {
|
|
|
150
158
|
}
|
|
151
159
|
}
|
|
152
160
|
|
|
161
|
+
}
|
|
153
162
|
|
|
163
|
+
export class GLTFAssetTransformer extends AssetTransformer {
|
|
154
164
|
/**
|
|
155
165
|
*
|
|
156
|
-
* @param {
|
|
157
|
-
* @param {AssetDescription} ad
|
|
158
|
-
* @private
|
|
166
|
+
* @param {AbstractAsyncMap<THREE.BufferGeometry, MicronGeometry>} [cache]
|
|
159
167
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
this.__active_mesh_micron_cache = [];
|
|
163
|
-
|
|
164
|
-
const micron_metadata = gltf.userData.micron;
|
|
165
|
-
|
|
166
|
-
if (micron_metadata === undefined) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const uri = micron_metadata.geometry_data_uri;
|
|
171
|
-
if (uri === undefined) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const base = computePathDirectory(ad.path);
|
|
168
|
+
constructor(cache) {
|
|
169
|
+
super();
|
|
176
170
|
|
|
177
|
-
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @type {AbstractAsyncMap<THREE.BufferGeometry, MicronGeometry>|undefined}
|
|
174
|
+
* @private
|
|
175
|
+
*/
|
|
176
|
+
this.__cache = cache;
|
|
178
177
|
|
|
179
|
-
|
|
178
|
+
/**
|
|
179
|
+
*
|
|
180
|
+
* @type {AssetManager|null}
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
this.__am = null;
|
|
180
184
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Minimum number of polygons required for micron to be used
|
|
187
|
+
* @type {number}
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
this.__threshold_polycount = DEFAULT_THRESHOLD_POLYCOUNT;
|
|
187
191
|
|
|
188
|
-
|
|
189
|
-
|
|
192
|
+
/**
|
|
193
|
+
*
|
|
194
|
+
* @type {MicronGeometry[]}
|
|
195
|
+
* @private
|
|
196
|
+
*/
|
|
197
|
+
this.__active_mesh_micron_cache = [];
|
|
190
198
|
|
|
191
|
-
|
|
199
|
+
/**
|
|
200
|
+
* @deprecated
|
|
201
|
+
* Whether override mesh will be created for the asset, this is generally outdated
|
|
202
|
+
* @type {boolean}
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
205
|
+
this.__settings_build_override_mesh = false;
|
|
206
|
+
}
|
|
192
207
|
|
|
208
|
+
/**
|
|
209
|
+
*
|
|
210
|
+
* @param {AssetManager|null} am
|
|
211
|
+
*/
|
|
212
|
+
set assetManager(am) {
|
|
213
|
+
this.__am = am;
|
|
193
214
|
}
|
|
194
215
|
|
|
195
216
|
|
|
@@ -212,10 +233,12 @@ export class GLTFAssetTransformer extends AssetTransformer {
|
|
|
212
233
|
*/
|
|
213
234
|
const root = source.create();
|
|
214
235
|
|
|
215
|
-
|
|
236
|
+
const context = new TransformContext(this.__am, this.__cache);
|
|
237
|
+
|
|
238
|
+
await context.load_mesh_micron_data(source.gltf, asset_description);
|
|
216
239
|
|
|
217
240
|
// attempt to load existing micron geometries
|
|
218
|
-
await async_traverse_three_object(root,
|
|
241
|
+
await async_traverse_three_object(root, context.visitObjectToLoadMicron, context, {
|
|
219
242
|
asset: asset_description
|
|
220
243
|
});
|
|
221
244
|
|
|
@@ -227,6 +250,8 @@ export class GLTFAssetTransformer extends AssetTransformer {
|
|
|
227
250
|
}
|
|
228
251
|
|
|
229
252
|
if (this.__settings_build_override_mesh) {
|
|
253
|
+
console.warn(`Deprecated OVERRIDE_MESH setting is ON, generating override mesh for asset: ${asset_description}`);
|
|
254
|
+
|
|
230
255
|
const micron_root = await convert_three_object_to_micron(root.clone(), this.__cache);
|
|
231
256
|
micron_root.boundingSphere = root.boundingSphere;
|
|
232
257
|
|
|
@@ -3,3 +3,5 @@ Path tracing ideas:
|
|
|
3
3
|
* [smallpt](https://www.kevinbeason.com/smallpt/) (100 line c implementation of path tracer)
|
|
4
4
|
* [three path tracer](https://github.com/gkjohnson/three-gpu-pathtracer)
|
|
5
5
|
* http://blog.hvidtfeldts.net/index.php/2015/01/path-tracing-3d-fractals/
|
|
6
|
+
* [Global Illumination and Path Tracing](https://www.scratchapixel.com/lessons/3d-basic-rendering/global-illumination-path-tracing/global-illumination-path-tracing-practical-implementation)
|
|
7
|
+
* [Path Tracing, by Steve Rotenberg](https://cseweb.ucsd.edu/classes/sp17/cse168-a/CSE168_08_PathTracing.pdf)
|
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
UnsignedByteType
|
|
21
21
|
} from "three";
|
|
22
22
|
import { linear_to_sRGB } from "../../../../core/color/linear_to_sRGB.js";
|
|
23
|
-
import { random_in_hemisphere } from "./random_in_hemisphere.js";
|
|
24
23
|
import { sample_triangle_attribute } from "./sample_triangle_attribute.js";
|
|
25
24
|
import { vec3_uint8_to_float } from "./vec3_uint8_to_float.js";
|
|
26
25
|
import { apply_texture_clamping_to_coordinate } from "./apply_texture_clamping_to_coordinate.js";
|
|
@@ -29,6 +28,7 @@ import { v3_dot } from "../../../../core/geom/v3_dot.js";
|
|
|
29
28
|
import { make_one_vector3 } from "./make_one_vector3.js";
|
|
30
29
|
import { transform_normal_m4 } from "./ray_hit_apply_transform.js";
|
|
31
30
|
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
31
|
+
import { getBiasedNormalSample } from "./getBiasedNormalSample.js";
|
|
32
32
|
|
|
33
33
|
/*
|
|
34
34
|
Ray hit data layout:
|
|
@@ -526,10 +526,6 @@ export class PathTracer {
|
|
|
526
526
|
break;
|
|
527
527
|
}
|
|
528
528
|
|
|
529
|
-
|
|
530
|
-
// irradiance[0] += m;
|
|
531
|
-
// irradiance[1] += m;
|
|
532
|
-
// irradiance[2] += m;
|
|
533
529
|
this.sample_material(tmp_0, trace_result);
|
|
534
530
|
|
|
535
531
|
// adjust normal on the hit
|
|
@@ -539,8 +535,7 @@ export class PathTracer {
|
|
|
539
535
|
// reflect ray
|
|
540
536
|
array_copy(trace_result, 0, _ray_0, 0, 3);
|
|
541
537
|
|
|
542
|
-
|
|
543
|
-
random_in_hemisphere(random, _ray_0, 3, tmp_0, 3);
|
|
538
|
+
getBiasedNormalSample(_ray_0, 3, tmp_0, 3, 1, random);
|
|
544
539
|
|
|
545
540
|
// accumulate
|
|
546
541
|
vec3.multiply(irradiance, irradiance, tmp_0);
|
|
@@ -555,14 +550,6 @@ export class PathTracer {
|
|
|
555
550
|
vec3.multiply(irradiance, irradiance, tmp_1);
|
|
556
551
|
}
|
|
557
552
|
|
|
558
|
-
//
|
|
559
|
-
// if (got_emission === false) {
|
|
560
|
-
// // no light source was hit, propagate shadow(darkness) along the ray
|
|
561
|
-
// irradiance[0] = 0;
|
|
562
|
-
// irradiance[1] = 0;
|
|
563
|
-
// irradiance[2] = 0;
|
|
564
|
-
// }
|
|
565
|
-
|
|
566
553
|
array_copy(irradiance, 0, out, 0, 3);
|
|
567
554
|
}
|
|
568
555
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @param {number} power
|
|
9
9
|
* @param {function():number} random
|
|
10
10
|
*/
|
|
11
|
-
function getBiasedNormalSample(out, out_offset, normal, normal_offset, power, random) {
|
|
11
|
+
export function getBiasedNormalSample(out, out_offset, normal, normal_offset, power, random) {
|
|
12
12
|
const dir_x = normal[normal_offset];
|
|
13
13
|
const dir_y = normal[normal_offset + 1];
|
|
14
14
|
const dir_z = normal[normal_offset + 2];
|
|
@@ -7,8 +7,7 @@ import {
|
|
|
7
7
|
OctahedronBufferGeometry,
|
|
8
8
|
PerspectiveCamera,
|
|
9
9
|
PlaneBufferGeometry,
|
|
10
|
-
Sphere
|
|
11
|
-
SphereBufferGeometry
|
|
10
|
+
Sphere
|
|
12
11
|
} from "three";
|
|
13
12
|
import { Sampler2D } from "../../texture/sampler/Sampler2D.js";
|
|
14
13
|
import sampler2D2Canvas from "../../texture/sampler/Sampler2D2Canvas.js";
|
|
@@ -134,8 +133,13 @@ function make_sun({
|
|
|
134
133
|
function prepare_scene_sphere_01(pt, camera) {
|
|
135
134
|
camera.position.set(0, 0, -2.1);
|
|
136
135
|
camera.lookAt(0, 0, 0);
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
const sphere_geo = new OctahedronBufferGeometry(1, 9);
|
|
139
|
+
makeGeometryIndexed(sphere_geo);
|
|
140
|
+
|
|
137
141
|
pt.addMesh(
|
|
138
|
-
|
|
142
|
+
sphere_geo,
|
|
139
143
|
// new MeshStandardMaterial({ color: '#FF0000' }),
|
|
140
144
|
new MeshStandardMaterial({ color: '#FFFFFF' }),
|
|
141
145
|
Transform.fromJSON({
|
|
@@ -185,9 +189,10 @@ function promise_gltf(url) {
|
|
|
185
189
|
* @param {PathTracer} pt
|
|
186
190
|
* @param {THREE.Camera} camera
|
|
187
191
|
* @param {string} url
|
|
192
|
+
* @param zoom
|
|
188
193
|
* @return {Promise<void>}
|
|
189
194
|
*/
|
|
190
|
-
async function prepare_scene_gltf(pt, camera, url) {
|
|
195
|
+
async function prepare_scene_gltf(pt, camera, url, zoom = 1) {
|
|
191
196
|
const gltf = await promise_gltf(url);
|
|
192
197
|
|
|
193
198
|
|
|
@@ -220,7 +225,7 @@ async function prepare_scene_gltf(pt, camera, url) {
|
|
|
220
225
|
|
|
221
226
|
camera.position.set(1, 1.3, 1)
|
|
222
227
|
.normalize()
|
|
223
|
-
.multiplyScalar(sphere.radius * 2.6);
|
|
228
|
+
.multiplyScalar(sphere.radius * 2.6 * (1 / zoom));
|
|
224
229
|
|
|
225
230
|
camera.lookAt(sphere.center);
|
|
226
231
|
}
|
|
@@ -459,7 +464,7 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
|
|
|
459
464
|
ray_direction.x, ray_direction.y, ray_direction.z
|
|
460
465
|
);
|
|
461
466
|
|
|
462
|
-
pt.path_trace(out, ray, Infinity,
|
|
467
|
+
pt.path_trace(out, ray, Infinity, 4, random);
|
|
463
468
|
|
|
464
469
|
out2[0] += out[0];
|
|
465
470
|
out2[1] += out[1];
|
|
@@ -509,12 +514,12 @@ const camera = new PerspectiveCamera();
|
|
|
509
514
|
async function start_renderer(camera) {
|
|
510
515
|
camera.aspect = vCanvas.size.x / vCanvas.size.y;
|
|
511
516
|
|
|
512
|
-
const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
|
|
517
|
+
// const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
|
|
513
518
|
// const path = 'data/models/road_bike/road_bike.gltf'; //large CAD-type model
|
|
514
519
|
|
|
515
520
|
// await prepare_scene_lucy(pt, camera);
|
|
516
|
-
await prepare_scene_rtiow(pt, camera);
|
|
517
|
-
|
|
521
|
+
// await prepare_scene_rtiow(pt, camera);
|
|
522
|
+
await prepare_scene_sphere_01(pt, camera);
|
|
518
523
|
// await prepare_scene_gltf(pt, camera, path);
|
|
519
524
|
|
|
520
525
|
pt.build();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader.js";
|
|
2
2
|
import { CubeTextureLoader, LinearFilter, PMREMGenerator, sRGBEncoding, TextureLoader, UnsignedByteType } from "three";
|
|
3
3
|
import { noop } from "../../../../core/function/Functions.js";
|
|
4
|
-
import { computeFileExtension } from "../../../../core/FilePath.js";
|
|
5
4
|
import { HDRCubeTextureLoader } from "three/examples/jsm/loaders/HDRCubeTextureLoader.js";
|
|
5
|
+
import { computeFileExtension } from "../../../../core/path/computeFileExtension.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
@@ -15,39 +15,51 @@ import AABB2 from "../../../core/geom/AABB2.js";
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
*
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {Vector2} size
|
|
20
|
-
* @param {AABB2} focus
|
|
21
|
-
* @returns {{scene: Scene, camera: PerspectiveCamera}}
|
|
18
|
+
* @param {THREE.OrthographicCamera} camera
|
|
22
19
|
*/
|
|
23
|
-
|
|
24
|
-
const
|
|
20
|
+
function setShadowCamera(camera) {
|
|
21
|
+
const sqrt2 = Math.sqrt(2);
|
|
22
|
+
let sqrt2_2 = sqrt2 / 2;
|
|
23
|
+
camera.left = -sqrt2_2;
|
|
24
|
+
camera.right = sqrt2_2;
|
|
25
|
+
|
|
26
|
+
camera.bottom = -sqrt2_2;
|
|
27
|
+
camera.top = sqrt2_2;
|
|
28
|
+
}
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {THREE.Scene} scene
|
|
33
|
+
*/
|
|
34
|
+
function setupLights(scene) {
|
|
35
|
+
const lightKey = new ThreeDirectionalLight(0xffffff, 1);
|
|
36
|
+
lightKey.position.set(-1, 1, 1);
|
|
37
|
+
lightKey.castShadow = true;
|
|
38
|
+
lightKey.shadow.mapSize.set(1024, 1024);
|
|
31
39
|
|
|
32
|
-
function setShadowCamera(camera) {
|
|
33
|
-
const sqrt2 = Math.sqrt(2);
|
|
34
|
-
let sqrt2_2 = sqrt2 / 2;
|
|
35
|
-
camera.left = -sqrt2_2;
|
|
36
|
-
camera.right = sqrt2_2;
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
+
setShadowCamera(lightKey.shadow.camera);
|
|
42
|
+
scene.add(lightKey);
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
const lightHighlight = new ThreeDirectionalLight(0xffffff, 0.50);
|
|
45
|
+
lightHighlight.position.set(0, 0, 1);
|
|
46
|
+
scene.add(lightHighlight);
|
|
44
47
|
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const lightFill = new ThreeAmbientLight(0xFFFFFF, 0.5);
|
|
49
|
+
scene.add(lightFill);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param {Mesh} mesh trhee.js mesh
|
|
55
|
+
* @param {Vector2} size
|
|
56
|
+
* @param {AABB2} focus
|
|
57
|
+
* @returns {{scene: Scene, camera: THREE.PerspectiveCamera}}
|
|
58
|
+
*/
|
|
59
|
+
export function makeMeshPreviewScene(mesh, size, focus = new AABB2(0, 0, size.x, size.y)) {
|
|
60
|
+
const scene = new ThreeScene();
|
|
48
61
|
|
|
49
|
-
|
|
50
|
-
scene.add(l2);
|
|
62
|
+
setupLights(scene);
|
|
51
63
|
|
|
52
64
|
scaleObject3ToBox(mesh, new Vector3(1, 1, 1), mesh.scale);
|
|
53
65
|
scene.add(mesh);
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { BinaryBuffer } from "../../core/binary/BinaryBuffer.js";
|
|
2
|
+
import BinaryBufferDeSerializer from "../ecs/storage/BinaryBufferDeSerializer.js";
|
|
3
|
+
|
|
4
|
+
const scratch_buffer = new BinaryBuffer();
|
|
5
|
+
|
|
6
|
+
class LocalAPI {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @type {Engine|null}
|
|
10
|
+
*/
|
|
11
|
+
engine = null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {BinaryBuffer} buffer
|
|
16
|
+
*/
|
|
17
|
+
async writeCurrentSceneDataset(buffer) {
|
|
18
|
+
const deSerializer = new BinaryBufferDeSerializer();
|
|
19
|
+
|
|
20
|
+
const engine = this.engine;
|
|
21
|
+
|
|
22
|
+
const ecd = engine.entityManager.dataset;
|
|
23
|
+
|
|
24
|
+
ecd.clear();
|
|
25
|
+
|
|
26
|
+
const task = deSerializer.process(buffer, engine, ecd);
|
|
27
|
+
|
|
28
|
+
const p = task.promise();
|
|
29
|
+
|
|
30
|
+
engine.executor.run(task);
|
|
31
|
+
|
|
32
|
+
await p;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class RemoteController {
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @type {WebSocket|null}
|
|
40
|
+
*/
|
|
41
|
+
socket = null;
|
|
42
|
+
|
|
43
|
+
localAPI = new LocalAPI();
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param {Engine} engine
|
|
48
|
+
*/
|
|
49
|
+
attach(engine) {
|
|
50
|
+
this.localAPI.engine = engine;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {ArrayBuffer} data
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
async __handle_message(data) {
|
|
60
|
+
// console.log(`received message `, data);
|
|
61
|
+
|
|
62
|
+
scratch_buffer.fromArrayBuffer(data);
|
|
63
|
+
|
|
64
|
+
// read packet ID
|
|
65
|
+
const packet_id = scratch_buffer.readUTF8String();
|
|
66
|
+
|
|
67
|
+
console.log(`packet ID: ${packet_id}`);
|
|
68
|
+
|
|
69
|
+
if (this.localAPI[packet_id] === undefined) {
|
|
70
|
+
console.error(`Local API does not have method '${packet_id}'`);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await this.localAPI[packet_id](scratch_buffer);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
//
|
|
78
|
+
console.error(`Failed to process remote call to '${packet_id}':`, e);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
startup() {
|
|
84
|
+
this.socket = new WebSocket('ws://localhost:9020');
|
|
85
|
+
|
|
86
|
+
this.socket.binaryType = "arraybuffer";
|
|
87
|
+
|
|
88
|
+
this.socket.addEventListener('open', () => {
|
|
89
|
+
console.log('socket connection open');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
this.socket.addEventListener('message', (event) => {
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
this.__handle_message(event.data);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|