@woosh/meep-engine 2.43.22 → 2.43.24

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.
Files changed (47) hide show
  1. package/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js +2 -2
  2. package/core/geom/3d/topology/struct/{BinaryElementPool.js → binary/BinaryElementPool.js} +7 -11
  3. package/core/geom/3d/topology/struct/{BinaryElementPool.spec.js → binary/BinaryElementPool.spec.js} +0 -0
  4. package/core/geom/3d/topology/struct/{BinaryTopology.js → binary/BinaryTopology.js} +123 -6
  5. package/core/geom/3d/topology/struct/{BinaryTopology.spec.js → binary/BinaryTopology.spec.js} +0 -0
  6. package/core/geom/3d/topology/struct/binary/io/OrderedEdge.js +66 -0
  7. package/core/geom/3d/topology/struct/binary/io/bt_index_geometry_to_topology.js +188 -0
  8. package/core/geom/3d/topology/struct/binary/io/bt_index_geometry_to_topology.spec.js +84 -0
  9. package/core/geom/3d/topology/struct/binary/io/bt_mesh_calc_edges.js +51 -0
  10. package/core/geom/3d/topology/struct/binary/io/create_edge.js +106 -0
  11. package/core/geom/3d/topology/struct/binary/io/get_or_create_edge_map.js +26 -0
  12. package/core/geom/3d/topology/struct/binary/query/bt_mesh_edge_has_vertex.js +16 -0
  13. package/core/geom/3d/topology/struct/binary/query/bt_mesh_edge_has_vertex.spec.js +15 -0
  14. package/core/geom/3d/topology/struct/binary/query/bt_mesh_edge_other_vertex.js +21 -0
  15. package/core/geom/3d/topology/struct/binary/query/bt_mesh_edge_other_vertex.spec.js +16 -0
  16. package/core/geom/3d/topology/struct/prototypeBinaryTopology.js +14 -14
  17. package/core/path/PATH_SEPARATOR.js +1 -0
  18. package/core/path/computeFileExtension.js +24 -0
  19. package/core/path/computeFileExtension.spec.js +13 -0
  20. package/core/path/computePathBase.js +21 -0
  21. package/core/path/computePathBase.spec.js +13 -0
  22. package/core/path/computePathDirectory.js +25 -0
  23. package/editor/Editor.js +3 -2
  24. package/editor/view/library/MeshLibraryView.js +1 -1
  25. package/engine/EngineHarness.js +25 -1
  26. package/engine/asset/guessAssetType.js +1 -1
  27. package/engine/asset/loaders/image/ImageRGBADataLoader.js +1 -1
  28. package/engine/asset/loaders/texture/TextureAssetLoader.js +1 -1
  29. package/engine/ecs/storage/BinaryBufferSerializer.js +7 -0
  30. package/engine/graphics/camera/camera_compute_distance_to_fit_length.js +5 -1
  31. package/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +33 -0
  32. package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +1 -0
  33. package/engine/graphics/material/composeCompile.js +3 -5
  34. package/engine/graphics/micron/plugin/GLTFAssetTransformer.js +1 -1
  35. package/engine/graphics/sh3/README.md +2 -0
  36. package/engine/graphics/sh3/path_tracer/PathTracer.js +0 -14
  37. package/engine/graphics/sh3/path_tracer/prototypePathTracer.js +11 -7
  38. package/engine/graphics/texture/cubemap/load_environment_map.js +1 -1
  39. package/engine/graphics/util/makeMeshPreviewScene.js +38 -26
  40. package/engine/network/RemoteController.js +138 -0
  41. package/engine/network/remoteEditor.js +36 -0
  42. package/package.json +1 -1
  43. package/view/elements/MeshPreview.js +5 -1
  44. package/core/FilePath.js +0 -73
  45. package/core/FilePath.spec.js +0 -25
  46. package/core/geom/3d/topology/struct/bt_index_geometry_to_topology.js +0 -329
  47. package/core/geom/3d/topology/struct/bt_index_geometry_to_topology.spec.js +0 -26
@@ -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
- new SphereBufferGeometry(1, 16, 16),
142
+ sphere_geo,
139
143
  // new MeshStandardMaterial({ color: '#FF0000' }),
140
144
  new MeshStandardMaterial({ color: '#FFFFFF' }),
141
145
  Transform.fromJSON({
@@ -460,7 +464,7 @@ function* render(target, pt, camera, progress = { current: 0, total: 0 }) {
460
464
  ray_direction.x, ray_direction.y, ray_direction.z
461
465
  );
462
466
 
463
- pt.path_trace(out, ray, Infinity, 16, random);
467
+ pt.path_trace(out, ray, Infinity, 4, random);
464
468
 
465
469
  out2[0] += out[0];
466
470
  out2[1] += out[1];
@@ -510,13 +514,13 @@ const camera = new PerspectiveCamera();
510
514
  async function start_renderer(camera) {
511
515
  camera.aspect = vCanvas.size.x / vCanvas.size.y;
512
516
 
513
- const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
517
+ // const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
514
518
  // const path = 'data/models/road_bike/road_bike.gltf'; //large CAD-type model
515
519
 
516
520
  // await prepare_scene_lucy(pt, camera);
517
521
  // await prepare_scene_rtiow(pt, camera);
518
- // await prepare_scene_sphere_01(pt, camera);
519
- await prepare_scene_gltf(pt, camera, path);
522
+ await prepare_scene_sphere_01(pt, camera);
523
+ // await prepare_scene_gltf(pt, camera, path);
520
524
 
521
525
  pt.build();
522
526
  pt.optimize();
@@ -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 {Mesh} mesh trhee.js mesh
19
- * @param {Vector2} size
20
- * @param {AABB2} focus
21
- * @returns {{scene: Scene, camera: PerspectiveCamera}}
18
+ * @param {THREE.OrthographicCamera} camera
22
19
  */
23
- export function makeMeshPreviewScene(mesh, size, focus = new AABB2(0, 0, size.x, size.y)) {
24
- const scene = new ThreeScene();
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
- //lights
27
- const l0 = new ThreeDirectionalLight(0xffffff, 1);
28
- l0.position.set(-1, 1, 1);
29
- l0.castShadow = true;
30
- l0.shadow.mapSize.set(1024, 1024);
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
- camera.bottom = -sqrt2_2;
39
- camera.top = sqrt2_2;
40
- }
41
+ setShadowCamera(lightKey.shadow.camera);
42
+ scene.add(lightKey);
41
43
 
42
- setShadowCamera(l0.shadow.camera);
43
- scene.add(l0);
44
+ const lightHighlight = new ThreeDirectionalLight(0xffffff, 0.50);
45
+ lightHighlight.position.set(0, 0, 1);
46
+ scene.add(lightHighlight);
44
47
 
45
- const l1 = new ThreeDirectionalLight(0xffffff, 0.50);
46
- l1.position.set(0, 0, 1);
47
- scene.add(l1);
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
- const l2 = new ThreeAmbientLight(0xFFFFFF, 0.5);
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,138 @@
1
+ import { BinaryBuffer } from "../../core/binary/BinaryBuffer.js";
2
+ import BinaryBufferDeSerializer from "../ecs/storage/BinaryBufferDeSerializer.js";
3
+ import { BinaryObjectSerializationAdapter } from "../ecs/storage/binary/object/BinaryObjectSerializationAdapter.js";
4
+
5
+ class LocalAPI {
6
+ /**
7
+ *
8
+ * @type {Engine|null}
9
+ */
10
+ engine = null;
11
+
12
+ _object_serde = new BinaryObjectSerializationAdapter();
13
+
14
+ get _registry() {
15
+ return this.engine.binarySerializationRegistry;
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @return {EntityComponentDataset}
21
+ * @private
22
+ */
23
+ get _current_dataset() {
24
+ return this.engine.entityManager.dataset;
25
+ }
26
+
27
+ /**
28
+ * Server sent us a new world state
29
+ * @param {BinaryBuffer} buffer
30
+ */
31
+ async writeCurrentSceneDataset(buffer) {
32
+ const deSerializer = new BinaryBufferDeSerializer();
33
+
34
+ const engine = this.engine;
35
+
36
+ deSerializer.registry = this._registry;
37
+
38
+ const ecd = this._current_dataset;
39
+
40
+ ecd.clear();
41
+
42
+ const task = deSerializer.process(buffer, engine, ecd);
43
+
44
+ const p = task.promise();
45
+
46
+ engine.executor.run(task);
47
+
48
+ await p;
49
+ }
50
+
51
+ /**
52
+ *
53
+ * @param {BinaryBuffer} buffer
54
+ * @return {Promise<void>}
55
+ */
56
+ async createEntity(buffer) {
57
+ // create entity on the current scene with a given ID
58
+
59
+ const entity_id = buffer.readUintVar();
60
+
61
+ this._current_dataset.createEntitySpecific(entity_id);
62
+ }
63
+
64
+ async addComponentToEntity(buffer) {
65
+ const entity_id = buffer.readUintVar();
66
+
67
+ this._object_serde.registry = this._registry;
68
+ const component_instance = this._object_serde.deserialize(buffer);
69
+
70
+ this._current_dataset.addComponentToEntity(entity_id, component_instance);
71
+
72
+ }
73
+
74
+ }
75
+
76
+ export class RemoteController {
77
+ /**
78
+ *
79
+ * @type {WebSocket|null}
80
+ */
81
+ socket = null;
82
+
83
+ localAPI = new LocalAPI();
84
+
85
+ /**
86
+ *
87
+ * @param {Engine} engine
88
+ */
89
+ attach(engine) {
90
+ this.localAPI.engine = engine;
91
+
92
+ }
93
+
94
+ /**
95
+ *
96
+ * @param {ArrayBuffer} data
97
+ * @private
98
+ */
99
+ async __handle_message(data) {
100
+ // console.log(`received message `, data);
101
+
102
+ const buffer = BinaryBuffer.fromArrayBuffer(data);
103
+
104
+ // read packet ID
105
+ const packet_id = buffer.readUTF8String();
106
+
107
+ console.log(`packet ID: ${packet_id}`);
108
+
109
+ if (this.localAPI[packet_id] === undefined) {
110
+ console.error(`Local API does not have method '${packet_id}'`);
111
+ return;
112
+ }
113
+
114
+ try {
115
+ await this.localAPI[packet_id](buffer);
116
+ } catch (e) {
117
+ //
118
+ console.error(`Failed to process remote call to '${packet_id}':`, e);
119
+ }
120
+ }
121
+
122
+
123
+ startup() {
124
+ this.socket = new WebSocket('ws://localhost:9020');
125
+
126
+ this.socket.binaryType = "arraybuffer";
127
+
128
+ this.socket.addEventListener('open', () => {
129
+ console.log('socket connection open');
130
+ });
131
+
132
+ this.socket.addEventListener('message', (event) => {
133
+
134
+
135
+ this.__handle_message(event.data);
136
+ });
137
+ }
138
+ }
@@ -0,0 +1,36 @@
1
+ import { EngineHarness } from "../EngineHarness.js";
2
+ import { RemoteController } from "./RemoteController.js";
3
+ import { ShadedGeometrySystem } from "../graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
4
+ import { initializeGameBinarySerializationRegistry } from "../../../model/game/GameBinarySerializationRegistry.js";
5
+
6
+ const harness = new EngineHarness();
7
+
8
+ /**
9
+ *
10
+ * @param {Engine} engine
11
+ * @return {Promise<void>}
12
+ */
13
+ async function main(engine) {
14
+
15
+ await EngineHarness.buildBasics({
16
+ engine
17
+ });
18
+
19
+ initializeGameBinarySerializationRegistry(engine.binarySerializationRegistry);
20
+
21
+ const remote = new RemoteController();
22
+
23
+ remote.attach(engine);
24
+ remote.startup();
25
+
26
+ }
27
+
28
+ harness.initialize({
29
+ configuration(config, engine) {
30
+
31
+ config.addSystem(new ShadedGeometrySystem(engine));
32
+
33
+ }
34
+ }).then(main);
35
+
36
+
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.43.22",
8
+ "version": "2.43.24",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",
@@ -11,10 +11,14 @@ import { PointerDevice } from '../../engine/input/devices/PointerDevice.js';
11
11
  import dom from "../DOM.js";
12
12
  import { WebGLRendererPool } from "../../engine/graphics/render/RendererPool.js";
13
13
  import { advanceAnimation } from "../../engine/ecs/systems/AnimationSystem.js";
14
+ import { computeFileExtension } from "../../core/path/computeFileExtension.js";
14
15
 
15
16
  const mapExtension2Mime = {
16
17
  gltf: "model/gltf+json",
17
18
  glb: "model/gltf",
19
+ /**
20
+ * @deprecated no longer supported, please don't use
21
+ */
18
22
  json: "three.js"
19
23
  };
20
24
 
@@ -56,7 +60,7 @@ class MeshPreview extends View {
56
60
  throw new Error(`Mesh URL was expected to be a string, instead was ${typeof url}: ${s}`);
57
61
  }
58
62
 
59
- const extension = url.substring(url.lastIndexOf(".") + 1);
63
+ const extension = computeFileExtension(url);
60
64
 
61
65
  if (extension.length === 0) {
62
66
  throw new Error(`No file extension on url '${url}'`);
package/core/FilePath.js DELETED
@@ -1,73 +0,0 @@
1
- const PATH_SEPARATOR = '/';
2
-
3
- /**
4
- * Strips all directories from the path.
5
- * @example 'a/b/c' -> 'c'
6
- * @param {string} path
7
- * @returns {string}
8
- */
9
- function computePathBase(path) {
10
- if (typeof path !== "string") {
11
- throw new Error('path is not a string');
12
- }
13
-
14
- const lastSlashIndex = path.lastIndexOf(PATH_SEPARATOR);
15
-
16
- if (lastSlashIndex !== -1) {
17
- return path.substring(lastSlashIndex + 1);
18
- } else {
19
- return path;
20
- }
21
- }
22
-
23
- /**
24
- * Returns the directory name of a path, similar to the Unix dirname command.
25
- * @param {string} path
26
- * @return {string}
27
- */
28
- export function computePathDirectory(path) {
29
- if (typeof path !== "string") {
30
- throw new Error('path is not a string');
31
- }
32
-
33
- let lastSlashIndex = path.lastIndexOf(PATH_SEPARATOR);
34
-
35
- //rewind in case of trailing slashes
36
- while (lastSlashIndex > 0 && path.charAt(lastSlashIndex - 1) === PATH_SEPARATOR) {
37
- lastSlashIndex--;
38
- }
39
-
40
- if (lastSlashIndex !== -1) {
41
- return path.substring(0, lastSlashIndex);
42
- } else {
43
- return path;
44
- }
45
- }
46
-
47
- /**
48
- *
49
- * @param {string} path
50
- * @returns {String|null}
51
- */
52
- function computeFileExtension(path) {
53
- if (typeof path !== "string") {
54
- throw new Error('path is not a string');
55
- }
56
-
57
- //get base
58
- const pathBase = computePathBase(path);
59
-
60
- const lastDotIndex = pathBase.lastIndexOf('.');
61
-
62
- if (lastDotIndex !== -1) {
63
- return pathBase.substring(lastDotIndex + 1);
64
- } else {
65
- //no extension
66
- return null;
67
- }
68
- }
69
-
70
- export {
71
- computePathBase,
72
- computeFileExtension
73
- };
@@ -1,25 +0,0 @@
1
- import { computeFileExtension, computePathBase } from "./FilePath.js";
2
-
3
- test('extract extension of cat.txt', () => {
4
- expect(computeFileExtension('cat.txt')).toEqual('txt');
5
- });
6
-
7
- test('extract extension of ../hmm/cat.txt', () => {
8
- expect(computeFileExtension('../hmm/cat.txt')).toEqual('txt');
9
- });
10
-
11
- test('extract extension of empty string', () => {
12
- expect(computeFileExtension('')).toBeNull();
13
- });
14
-
15
- test('extract base path of empty string', () => {
16
- expect(computePathBase('')).toBe('');
17
- });
18
-
19
- test('extract base path of hello', () => {
20
- expect(computePathBase('hello')).toBe('hello');
21
- });
22
-
23
- test('extract base path of hello/there/world', () => {
24
- expect(computePathBase('hello/there/world')).toBe('world');
25
- });