@woosh/meep-engine 2.33.61 → 2.33.65

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 (60) hide show
  1. package/core/FilePath.js +28 -2
  2. package/core/binary/BinaryBuffer.js +13 -0
  3. package/ecs/grid/pick.js +44 -0
  4. package/editor/actions/concrete/PaintTerrainOverlayAction.js +1 -1
  5. package/editor/process/ObstacleGridDisplayProcess.js +1 -1
  6. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
  7. package/editor/tools/FoliagePaintTool.js +1 -1
  8. package/editor/tools/GridPaintTool.js +2 -2
  9. package/editor/tools/paint/TerrainPaintTool.js +2 -2
  10. package/editor/tools/paint/TerrainTexturePaintTool.js +1 -1
  11. package/editor/view/EditorView.js +1 -1
  12. package/editor/view/GridPickCoordinateView.js +2 -2
  13. package/engine/asset/AssetManager.js +1 -1
  14. package/engine/asset/AssetTransformer.js +2 -1
  15. package/engine/asset/loaders/GLTFAssetLoader.js +5 -21
  16. package/engine/asset/loaders/async_traverse_three_object.js +24 -0
  17. package/engine/ecs/animation/InverseKinematicsSystem.js +1 -1
  18. package/engine/ecs/attachment/AttachmentSystem.js +3 -51
  19. package/engine/ecs/evaluation/world/ReadTerrainLayerWeightPointFitness.js +1 -1
  20. package/engine/ecs/fow/FogOfWarRevealerSystem.js +2 -2
  21. package/engine/ecs/team/Team.js +82 -0
  22. package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
  23. package/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +112 -0
  24. package/engine/ecs/terrain/util/obtainTerrain.js +23 -0
  25. package/engine/ecs/tooltip/TooltipComponentSystem.js +1 -1
  26. package/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +1 -1
  27. package/engine/graphics/ecs/water/WaterSystem.js +1 -1
  28. package/engine/graphics/ecs/water2/shader/testWaterShader.js +1 -1
  29. package/engine/graphics/geometry/AttributeSpec.d.ts +8 -0
  30. package/engine/graphics/geometry/VertexDataSpec.d.ts +15 -0
  31. package/engine/graphics/geometry/buffered/deinterleaveBufferAttribute.js +39 -0
  32. package/engine/graphics/geometry/buffered/deinterleaveBufferGeometry.js +50 -0
  33. package/engine/graphics/micron/MICRON_GEOMETRY_FIELD.js +1 -0
  34. package/engine/graphics/micron/MICRON_URI_FIELD.js +1 -0
  35. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +10 -7
  36. package/engine/graphics/micron/convert_three_object_to_micron.js +17 -2
  37. package/engine/graphics/micron/format/MicronGeometry.d.ts +4 -0
  38. package/engine/graphics/micron/format/MicronGeometry.js +6 -0
  39. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +107 -6
  40. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +5 -3
  41. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -2
  42. package/engine/graphics/render/webgpu/sample/MeshInstance.js +108 -0
  43. package/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +7 -3
  44. package/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +4 -3
  45. package/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +13 -6
  46. package/engine/graphics/render/webgpu/sample/main.js +83 -45
  47. package/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +5 -3
  48. package/engine/graphics/util/modelHitTest.js +63 -0
  49. package/engine/grid/systems/GridPosition2TransformSystem.js +1 -1
  50. package/engine/grid/systems/ViewportGridProjectionSystem.js +1 -1
  51. package/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
  52. package/engine/scene/transitionToScene.js +1 -1
  53. package/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.js +1 -1
  54. package/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
  55. package/generation/markers/debug/visualizeMarkers.js +1 -1
  56. package/generation/theme/ThemeEngine.js +1 -1
  57. package/package.json +1 -1
  58. package/samples/terrain/main.js +1 -1
  59. package/view/minimap/Minimap.js +1 -1
  60. package/engine/graphics/render/webgpu/sample/_main.ts +0 -650
@@ -0,0 +1,112 @@
1
+ import TopDownCameraControllerSystem from "../../../graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
2
+ import { Camera } from "../../../graphics/ecs/camera/Camera.js";
3
+ import { obtainTerrain } from "./obtainTerrain.js";
4
+ import { assert } from "../../../../core/assert.js";
5
+ import TerrainSystem from "../ecs/TerrainSystem.js";
6
+ import Task from "../../../../core/process/task/Task.js";
7
+ import TaskSignal from "../../../../core/process/task/TaskSignal.js";
8
+
9
+ /**
10
+ *
11
+ * @param {EntityManager} em
12
+ * @param {EntityComponentDataset} ecd
13
+ * @returns {Task}
14
+ */
15
+ export function loadVisibleTerrainTiles(em, ecd) {
16
+
17
+ let totalTiles = 0;
18
+ let loadedTiles = 0;
19
+ let failedTiles = 0;
20
+
21
+ let attempt = 0;
22
+
23
+ let failureFlag = false;
24
+
25
+ function init() {
26
+ const attemptId = attempt;
27
+
28
+ //force update by camera controller, to ensure correct focus is set
29
+ em.getSystem(TopDownCameraControllerSystem).update(0);
30
+
31
+ ecd.traverseComponents(Camera, function (c) {
32
+ c.updateMatrices();
33
+ });
34
+
35
+ const tiles = [];
36
+
37
+ const terrain = obtainTerrain(ecd);
38
+
39
+ assert.notEqual(terrain, null, 'terrain not found');
40
+
41
+ TerrainSystem.traverseVisibleTiles(ecd, terrain, function (tile) {
42
+ tiles.push(tile);
43
+ });
44
+
45
+ totalTiles = tiles.length;
46
+ const tileManager = terrain.tiles;
47
+
48
+ function handleObtainedTile(t) {
49
+ if (attemptId !== attempt) {
50
+ return;
51
+ }
52
+
53
+ loadedTiles++;
54
+ }
55
+
56
+ function handleFailedTile(t) {
57
+ if (attemptId !== attempt) {
58
+ return;
59
+ }
60
+
61
+ attempt++;
62
+
63
+ failedTiles++;
64
+
65
+ if (attempt < 10) {
66
+ init();
67
+ } else {
68
+ failureFlag = true;
69
+ }
70
+ }
71
+
72
+ if (totalTiles !== 0) {
73
+ tiles.forEach(function (tile) {
74
+ tileManager.obtain(tile.gridPosition.x, tile.gridPosition.y).then(handleObtainedTile, handleFailedTile);
75
+ });
76
+ }
77
+ }
78
+
79
+ const task = new Task({
80
+ name: "Building visible terrain tiles",
81
+
82
+ initializer: init,
83
+
84
+ cycleFunction() {
85
+ if (failureFlag) {
86
+ return TaskSignal.EndFailure;
87
+ }
88
+
89
+ if (loadedTiles >= totalTiles) {
90
+ return TaskSignal.EndSuccess;
91
+ } else {
92
+ return TaskSignal.Yield;
93
+ }
94
+ },
95
+
96
+ computeProgress() {
97
+ if (totalTiles === 0) {
98
+ return 0;
99
+ }
100
+
101
+ const f = loadedTiles / totalTiles;
102
+
103
+ if (f >= 1) {
104
+ return 1;
105
+ }
106
+
107
+ return f;
108
+ }
109
+ });
110
+
111
+ return task;
112
+ }
@@ -0,0 +1,23 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+ import Terrain from "../ecs/Terrain.js";
3
+
4
+ /**
5
+ *
6
+ * @param {EntityComponentDataset} ecd
7
+ * @param {function(terrain:Terrain,entity:number)} [callback]
8
+ * @returns {Terrain|null}
9
+ */
10
+ export function obtainTerrain(ecd, callback) {
11
+ assert.notEqual(ecd, null, 'ecd is null');
12
+ assert.notEqual(ecd, undefined, 'ecd is undefined');
13
+
14
+ const object = ecd.getAnyComponent(Terrain);
15
+
16
+ const terrain = object.component;
17
+
18
+ if (terrain !== null && typeof callback === "function") {
19
+ callback(terrain, object.entity);
20
+ }
21
+
22
+ return terrain;
23
+ }
@@ -2,10 +2,10 @@ import { System } from "../System.js";
2
2
  import { TooltipComponent } from "./TooltipComponent.js";
3
3
  import Vector3 from "../../../core/geom/Vector3.js";
4
4
  import { MeshSystem } from "../../graphics/ecs/mesh/MeshSystem.js";
5
- import { modelHitTest } from "../../../../model/game/util/ScreenGridPicker.js";
6
5
  import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
7
6
  import { VisualTip } from "../../../view/tooltip/VisualTip.js";
8
7
  import Rectangle from "../../../core/geom/Rectangle.js";
8
+ import { modelHitTest } from "../../graphics/util/modelHitTest.js";
9
9
 
10
10
  const ray_source = new Vector3();
11
11
  const ray_direction = new Vector3();
@@ -2,11 +2,11 @@ import { clamp } from "../../../../../core/math/clamp.js";
2
2
  import { System } from "../../../../ecs/System.js";
3
3
  import { TopDownCameraLander } from "./TopDownCameraLander.js";
4
4
  import { Cache } from "../../../../../core/cache/Cache.js";
5
- import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
6
5
  import { buildCameraTargetSampler } from "../../../../input/ecs/util/TerrainCameraTargetSampler.js";
7
6
  import TopDownCameraController from "./TopDownCameraController.js";
8
7
  import Vector2 from "../../../../../core/geom/Vector2.js";
9
8
  import { SignalBinding } from "../../../../../core/events/signal/SignalBinding.js";
9
+ import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
10
10
 
11
11
 
12
12
  /**
@@ -8,10 +8,10 @@ import { LeafNode } from '../../../../core/bvh2/LeafNode.js';
8
8
  import { buildPlanarRenderLayerClipPlaneComputationMethod } from "../../render/layers/RenderLayerUtils.js";
9
9
  import ThreeFactory from "../../three/ThreeFactory.js";
10
10
  import { RenderPassType } from "../../render/RenderPassType.js";
11
- import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
12
11
  import { makeAlexWaterMaterial } from "../water2/shader/AlexWaterShader.js";
13
12
  import { threeUpdateTransform } from "../../util/threeUpdateTransform.js";
14
13
  import { StandardFrameBuffers } from "../../StandardFrameBuffers.js";
14
+ import { obtainTerrain } from "../../../ecs/terrain/util/obtainTerrain.js";
15
15
 
16
16
  const WATER_SIZE = 800;
17
17
 
@@ -1,4 +1,3 @@
1
- import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
2
1
  import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
3
2
  import { EngineConfiguration } from "../../../../EngineConfiguration.js";
4
3
  import ScriptSystem from "../../../../ecs/systems/ScriptSystem.js";
@@ -28,6 +27,7 @@ import { EngineHarness } from "../../../../EngineHarness.js";
28
27
  import Vector2 from "../../../../../core/geom/Vector2.js";
29
28
  import Vector3 from "../../../../../core/geom/Vector3.js";
30
29
  import SimplexNoise from 'simplex-noise';
30
+ import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
31
31
 
32
32
  const engineHarness = new EngineHarness();
33
33
 
@@ -0,0 +1,8 @@
1
+ import {DataType} from "../../../core/parser/simple/DataType";
2
+
3
+ export class AttributeSpec {
4
+ readonly name: string
5
+ readonly type: DataType
6
+ readonly itemSize: number
7
+ readonly normalized: boolean
8
+ }
@@ -0,0 +1,15 @@
1
+ import {AttributeSpec} from "./AttributeSpec";
2
+
3
+ export class VertexDataSpec {
4
+ readonly attributes: AttributeSpec[]
5
+
6
+ getAttributeByName(name: string): AttributeSpec | undefined
7
+
8
+ add(attribute: AttributeSpec): this
9
+
10
+ setAttributes(attributes: AttributeSpec[]): void
11
+
12
+ equals(other: VertexDataSpec): boolean
13
+
14
+ hash(): number
15
+ }
@@ -0,0 +1,39 @@
1
+ import { BufferAttribute } from "three";
2
+
3
+
4
+ /**
5
+ *
6
+ * @param {THREE.InterleavedBufferAttribute|THREE.BufferAttribute} source_attribute
7
+ * @returns {THREE.BufferAttribute}
8
+ */
9
+ export function deinterleaveBufferAttribute(source_attribute) {
10
+ if (source_attribute.isInterleavedBufferAttribute !== true && source_attribute.isBufferAttribute) {
11
+ return source_attribute;
12
+ }
13
+
14
+ const source_data = source_attribute.data;
15
+ const source_data_array = source_data.array;
16
+ const stride = source_data.stride;
17
+
18
+ const item_count = source_attribute.count;
19
+ const itemSize = source_attribute.itemSize;
20
+ const array_size = item_count * itemSize;
21
+
22
+ const offset = source_attribute.offset;
23
+
24
+ const destination_array = new source_data_array.constructor(array_size);
25
+
26
+ const attribute = new BufferAttribute(destination_array, itemSize);
27
+
28
+ attribute.normalized = source_attribute.normalized;
29
+ attribute.name = source_attribute.name;
30
+
31
+ // copy data
32
+ for (let i = 0; i < item_count; i++) {
33
+ for (let j = 0; j < itemSize; j++) {
34
+ destination_array[i * itemSize + j] = source_data_array[i * stride + offset + j];
35
+ }
36
+ }
37
+
38
+ return attribute;
39
+ }
@@ -0,0 +1,50 @@
1
+ import { BufferGeometry } from "three";
2
+ import { deinterleaveBufferAttribute } from "./deinterleaveBufferAttribute.js";
3
+
4
+ /**
5
+ *
6
+ * @param {THREE.BufferGeometry} geometry
7
+ * @returns {THREE.BufferGeometry}
8
+ */
9
+ export function deinterleaveBufferGeometry(geometry) {
10
+ const result = new BufferGeometry();
11
+
12
+ if (geometry.getIndex() !== null) {
13
+ result.setIndex(deinterleaveBufferAttribute(geometry.getIndex()));
14
+ }
15
+
16
+ for (const attribute_key in geometry.attributes) {
17
+ const source_attribute = geometry.attributes[attribute_key];
18
+
19
+ result.setAttribute(attribute_key, deinterleaveBufferAttribute(source_attribute));
20
+ }
21
+
22
+ // copy other bits
23
+ result.name = geometry.name;
24
+
25
+ result.morphTargetsRelative = geometry.morphTargetsRelative;
26
+
27
+ for (const attribute_key in geometry.morphAttributes) {
28
+ const source_attributes = geometry.morphAttributes[attribute_key];
29
+
30
+ const result_attributes = [];
31
+
32
+ result.morphAttributes[attribute_key] = result_attributes;
33
+
34
+ for (let i = 0; i < source_attributes.length; i++) {
35
+ const source_attribute = source_attributes[i];
36
+ result_attributes[i] = deinterleaveBufferAttribute(source_attribute);
37
+ }
38
+ }
39
+
40
+ result.groups = geometry.groups.slice();
41
+
42
+
43
+ result.boundingBox = geometry.boundingBox !== null ? geometry.boundingBox.clone() : null;
44
+ result.boundingSphere = geometry.boundingSphere !== null ? geometry.boundingSphere.clone() : null;
45
+ result.drawRange.start = geometry.drawRange.start;
46
+ result.drawRange.count = geometry.drawRange.count;
47
+ result.userData = JSON.parse(JSON.stringify(geometry.userData));
48
+
49
+ return result;
50
+ }
@@ -0,0 +1 @@
1
+ export const MICRON_GEOMETRY_FIELD = '@micron_geometry';
@@ -0,0 +1 @@
1
+ export const MICRON_URI_FIELD = '@micron_path';
@@ -12,6 +12,7 @@ import { expandConnectivityByLocality } from "../../../../core/geom/3d/topology/
12
12
  import { build_geometry_info } from "./build_geometry_info.js";
13
13
  import { build_leaf_patches_metis } from "./clustering/build_leaf_patches_metis.js";
14
14
  import { compute_buffer_geometry_byte_size } from "../../geometry/buffered/compute_buffer_geometry_byte_size.js";
15
+ import { deinterleaveBufferGeometry } from "../../geometry/buffered/deinterleaveBufferGeometry.js";
15
16
 
16
17
  /**
17
18
  * Returns current time in milliseconds
@@ -105,11 +106,13 @@ const PRINT_VERBOSE_STATS = false;
105
106
  * @returns {MicronGeometry}
106
107
  */
107
108
  export async function buildMicronGeometryFromBufferGeometry(input) {
109
+ const source_geometry = deinterleaveBufferGeometry(input);
110
+
108
111
  // build topology representation
109
112
  const topoMesh = new TopoMesh();
110
113
 
111
- const position_attribute = input.getAttribute("position");
112
- const index_attribute = input.index;
114
+ const position_attribute = source_geometry.getAttribute("position");
115
+ const index_attribute = source_geometry.index;
113
116
 
114
117
  const face_index_array = index_attribute.array;
115
118
  const vertex_position_array = position_attribute.array;
@@ -183,18 +186,18 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
183
186
 
184
187
  const r = new MicronGeometry();
185
188
 
186
- r.proxy = input; // TODO use r.buildProxy(1) instead
189
+ r.proxy = source_geometry; // TODO use r.buildProxy(1) instead
187
190
 
188
191
  r.source_triangle_count = index_attribute.count / 3;
189
- r.source_vertex_count = input.getAttribute('position').count;
190
- r.source_byte_size = compute_buffer_geometry_byte_size(input);
192
+ r.source_vertex_count = source_geometry.getAttribute('position').count;
193
+ r.source_byte_size = compute_buffer_geometry_byte_size(source_geometry);
191
194
 
192
195
  // console.time('build geometry');
193
196
 
194
- const vertex_attributes = attributes_from_buffer_geometry(input);
197
+ const vertex_attributes = attributes_from_buffer_geometry(source_geometry);
195
198
 
196
199
  r.vertex_spec.setAttributes(vertex_attributes);
197
- r.root = compilePatchGraph(root, input, r.vertex_spec);
200
+ r.root = compilePatchGraph(root, source_geometry, r.vertex_spec);
198
201
 
199
202
  r.initialize();
200
203
 
@@ -4,6 +4,7 @@ import { computeGeometryEquality } from "../../asset/loaders/geometry/geometry/c
4
4
  import { buildMicronGeometryFromBufferGeometry } from "./build/buildMicronGeometryFromBufferGeometry.js";
5
5
  import { ThreeMicronMesh } from "./format/ThreeMicronMesh.js";
6
6
  import { AsyncMapWrapper } from "../../../core/collection/map/AsyncMapWrapper.js";
7
+ import { MICRON_GEOMETRY_FIELD } from "./MICRON_GEOMETRY_FIELD.js";
7
8
 
8
9
  /**
9
10
  *
@@ -19,7 +20,6 @@ const pending_cache = new HashMap({
19
20
  keyEqualityFunction: computeGeometryEquality
20
21
  });
21
22
 
22
-
23
23
  /**
24
24
  *
25
25
  * @param {THREE.Object3D} object
@@ -36,6 +36,13 @@ export async function convert_three_object_to_micron(object, micron_cache = defa
36
36
  * @returns {MicronGeometry}
37
37
  */
38
38
  async function obtain_geometry(g) {
39
+ const attached_micron = g[MICRON_GEOMETRY_FIELD];
40
+
41
+ if (attached_micron !== undefined && attached_micron.isMicronGeometry) {
42
+ // micron geometry is already attached, use it
43
+ return attached_micron;
44
+ }
45
+
39
46
  const existing = await micron_cache.get(g);
40
47
 
41
48
  if (existing !== undefined && existing !== null) {
@@ -90,7 +97,15 @@ export async function convert_three_object_to_micron(object, micron_cache = defa
90
97
  && !mesh.isSkinnedMesh // skinned meshes not supported
91
98
  ) {
92
99
 
93
- const micronGeometry = await obtain_geometry(mesh.geometry);
100
+ let micronGeometry;
101
+ try {
102
+ micronGeometry = await obtain_geometry(mesh.geometry);
103
+ } catch (e) {
104
+ console.error(`Failed to convert geometry to micron, skipping : ${e}`);
105
+
106
+ // return original
107
+ return mesh;
108
+ }
94
109
 
95
110
  const micron_mesh = new ThreeMicronMesh(micronGeometry, mesh.material);
96
111
 
@@ -1,5 +1,9 @@
1
1
  import {BufferGeometry} from "three";
2
+ import {VertexDataSpec} from "../../geometry/VertexDataSpec";
2
3
 
3
4
  export class MicronGeometry {
5
+ vertex_spec: VertexDataSpec
4
6
  public proxy: BufferGeometry
7
+
8
+ initialize(): void
5
9
  }
@@ -117,3 +117,9 @@ export class MicronGeometry {
117
117
  return this.__patches[id];
118
118
  }
119
119
  }
120
+
121
+ /**
122
+ * @readonly
123
+ * @type {boolean}
124
+ */
125
+ MicronGeometry.prototype.isMicronGeometry = true;
@@ -13,6 +13,13 @@ import { AsyncRemoteHashMap } from "../../../../core/collection/map/AsyncRemoteH
13
13
  import { BufferGeometrySerializationAdapter } from "./serialization/BufferGeometrySerializationAdapter.js";
14
14
  import { MicronGeometryBinarySerializationAdapter } from "../format/serialization/MicronGeometryBinarySerializationAdapter.js";
15
15
  import { AsyncMapWrapper } from "../../../../core/collection/map/AsyncMapWrapper.js";
16
+ import { async_traverse_three_object } from "../../../asset/loaders/async_traverse_three_object.js";
17
+ import { computePathDirectory } from "../../../../core/FilePath.js";
18
+ import { BinaryBuffer } from "../../../../core/binary/BinaryBuffer.js";
19
+ import { MicronGeometry } from "../format/MicronGeometry.js";
20
+ import { ArrayBufferLoader } from "../../../asset/loaders/ArrayBufferLoader.js";
21
+ import { MICRON_URI_FIELD } from "../MICRON_URI_FIELD.js";
22
+ import { MICRON_GEOMETRY_FIELD } from "../MICRON_GEOMETRY_FIELD.js";
16
23
 
17
24
  /**
18
25
  *
@@ -20,6 +27,7 @@ import { AsyncMapWrapper } from "../../../../core/collection/map/AsyncMapWrapper
20
27
  */
21
28
  const STORAGE_KEY = '@plugin/virtual-geometry-micron/geometry-cache';
22
29
 
30
+ const ASSET_TYPE_ARRAY_BUFFER = "arraybuffer";
23
31
 
24
32
  class GLTFAssetTransformer extends AssetTransformer {
25
33
  /**
@@ -35,17 +43,97 @@ class GLTFAssetTransformer extends AssetTransformer {
35
43
  * @private
36
44
  */
37
45
  this.__cache = cache;
46
+
47
+ /**
48
+ *
49
+ * @type {AssetManager|null}
50
+ * @private
51
+ */
52
+ this.__am = null;
53
+
54
+ /**
55
+ *
56
+ * @type {MicronGeometryBinarySerializationAdapter}
57
+ * @private
58
+ */
59
+ this.__serde = new MicronGeometryBinarySerializationAdapter();
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @param {AssetManager|null} am
65
+ */
66
+ set assetManager(am) {
67
+ this.__am = am;
68
+ }
69
+
70
+
71
+ /**
72
+ * @param {THREE.Object3D} object
73
+ * @param {{asset:AssetDescription}} ctx
74
+ * @return {Promise<void>}
75
+ * @private
76
+ */
77
+ async __visitObjectToLoadMicron(object, ctx) {
78
+ if (!object.isMesh) {
79
+ return;
80
+ }
81
+
82
+ /**
83
+ * @type {THREE.BufferGeometry}
84
+ */
85
+ const geometry = object.geometry;
86
+
87
+ const micron_uri = geometry.userData[MICRON_URI_FIELD];
88
+
89
+ if (typeof micron_uri !== "string") {
90
+ return;
91
+ }
92
+
93
+
94
+ /**
95
+ * @type {AssetDescription}
96
+ */
97
+ const ad = ctx.asset;
98
+
99
+ const base = computePathDirectory(ad.path);
100
+
101
+ const micron_data = await this.__am.promise(`${base}/${micron_uri}`, ASSET_TYPE_ARRAY_BUFFER);
102
+
103
+ // deserialize micron data
104
+ const buffer = BinaryBuffer.fromArrayBuffer(micron_data.create());
105
+ const micron_geometry = new MicronGeometry();
106
+
107
+ this.__serde.deserialize(buffer, micron_geometry);
108
+
109
+ geometry[MICRON_GEOMETRY_FIELD] = micron_geometry;
38
110
  }
39
111
 
40
- async transform(source) {
112
+
113
+ /**
114
+ *
115
+ * @param {Asset} source
116
+ * @param asset_description
117
+ * @return {Promise<Asset>}
118
+ */
119
+ async transform(source, asset_description) {
41
120
  const animationClips = source.animations;
121
+
42
122
  if (animationClips !== undefined && animationClips.length > 0) {
43
123
  // not suitable
44
124
  return source;
45
125
  }
46
126
 
127
+ /**
128
+ * @type {THREE.Object3D}
129
+ */
47
130
  const root = source.create();
48
131
 
132
+ // attempt to load existing micron geometries
133
+ await async_traverse_three_object(root, this.__visitObjectToLoadMicron, this, {
134
+ asset: asset_description
135
+ });
136
+
49
137
  const micron_root = await convert_three_object_to_micron(root.clone(), this.__cache);
50
138
  micron_root.boundingSphere = root.boundingSphere;
51
139
 
@@ -117,7 +205,7 @@ export class MicronRenderPlugin extends EnginePlugin {
117
205
 
118
206
  /**
119
207
  *
120
- * @type {AssetTransformer}
208
+ * @type {GLTFAssetTransformer}
121
209
  * @private
122
210
  */
123
211
  this.__asset_transformer = new GLTFAssetTransformer(this.__cache);
@@ -180,8 +268,17 @@ export class MicronRenderPlugin extends EnginePlugin {
180
268
 
181
269
  const engine = this.engine;
182
270
 
183
- engine.assetManager.registerTransformer("model/gltf", this.__asset_transformer);
184
- engine.assetManager.registerTransformer("model/gltf+json", this.__asset_transformer);
271
+ const am = engine.assetManager;
272
+
273
+ // ensure that "arraybuffer" asset loader is present
274
+ if (am.getLoaderByType(ASSET_TYPE_ARRAY_BUFFER) === undefined) {
275
+ am.registerLoader(ASSET_TYPE_ARRAY_BUFFER, new ArrayBufferLoader());
276
+ }
277
+
278
+ this.__asset_transformer.assetManager = am;
279
+
280
+ am.registerTransformer("model/gltf", this.__asset_transformer);
281
+ am.registerTransformer("model/gltf+json", this.__asset_transformer);
185
282
 
186
283
  /**
187
284
  *
@@ -207,8 +304,12 @@ export class MicronRenderPlugin extends EnginePlugin {
207
304
 
208
305
  this.__persisted_geometry.detach_storage();
209
306
 
210
- engine.assetManager.unregisterTransformer("model/gltf", this.__asset_transformer);
211
- engine.assetManager.unregisterTransformer("model/gltf+json", this.__asset_transformer);
307
+ const am = engine.assetManager;
308
+
309
+ am.unregisterTransformer("model/gltf", this.__asset_transformer);
310
+ am.unregisterTransformer("model/gltf+json", this.__asset_transformer);
311
+
312
+ this.__asset_transformer.assetManager = null;
212
313
 
213
314
  const ge = engine.graphics;
214
315
 
@@ -42,8 +42,6 @@ import { RepeatBehavior } from "../../../../../../intelligence/behavior/decorato
42
42
  import { ActionBehavior } from "../../../../../../intelligence/behavior/primitive/ActionBehavior.js";
43
43
  import { pingpong } from "../../../../../../../core/math/pingpong.js";
44
44
  import { ParameterLookupTable } from "../../parameter/ParameterLookupTable.js";
45
- import { pick } from "../../../../../../../../model/game/util/ScreenGridPicker.js";
46
- import { obtainTerrain } from "../../../../../../../../model/game/scenes/SceneUtils.js";
47
45
  import GUIElement from "../../../../../../ecs/gui/GUIElement.js";
48
46
  import EmptyView from "../../../../../../../view/elements/EmptyView.js";
49
47
  import HeadsUpDisplay from "../../../../../../ecs/gui/hud/HeadsUpDisplay.js";
@@ -77,6 +75,8 @@ import { UnitSphereShape3D } from "../../../../../../../core/geom/3d/shape/UnitS
77
75
  import TopDownCameraController from "../../../../../ecs/camera/topdown/TopDownCameraController.js";
78
76
  import { randomFloatBetween } from "../../../../../../../core/math/random/randomFloatBetween.js";
79
77
  import { MicronRenderPlugin } from "../../../../../micron/plugin/MicronRenderPlugin.js";
78
+ import { obtainTerrain } from "../../../../../../ecs/terrain/util/obtainTerrain.js";
79
+ import { pick } from "../../../../../../../ecs/grid/pick.js";
80
80
 
81
81
  const engineHarness = new EngineHarness();
82
82
 
@@ -433,7 +433,9 @@ async function sample_scene_nam(engine) {
433
433
  "distanceMax": 1000
434
434
  });
435
435
 
436
- load_model('moicon/20_Dec_2021_Nammo/with_assets(for_alex)/model.gltf', ecd)
436
+ // load_model('moicon/20_Dec_2021_Nammo/with_assets(for_alex)/model.gltf', ecd)
437
+ load_model('moicon/20_Dec_2021_Nammo/with_assets_micron_conveted/model.gltf', ecd)
438
+ // load_model('moicon/micron_container/model.gltf', ecd)
437
439
 
438
440
  const P_SIZE_SMALL = 0.15;
439
441
  const P_SIZE_MEDIUM = 0.6;
@@ -69,7 +69,6 @@ import Renderable from "../../../../ecs/components/Renderable.js";
69
69
  import { makeHelperSphereGeometry } from "../../../../../editor/process/symbolic/makeHelperSphereGeometry.js";
70
70
  import TopDownCameraController from "../../../ecs/camera/topdown/TopDownCameraController.js";
71
71
  import ThreeFactory from "../../../three/ThreeFactory.js";
72
- import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
73
72
  import { JsonAssetLoader } from "../../../../asset/loaders/JsonAssetLoader.js";
74
73
  import { TextureAssetLoader } from "../../../../asset/loaders/texture/TextureAssetLoader.js";
75
74
  import { GameAssetType } from "../../../../asset/GameAssetType.js";
@@ -81,8 +80,9 @@ import { ParticleEmitterSystem } from "../../../particles/ecs/ParticleEmitterSys
81
80
  import { ShadedGeometrySystem } from "../../../ecs/mesh-v2/ShadedGeometrySystem.js";
82
81
  import { FogOfWar } from "../../../../ecs/fow/FogOfWar.js";
83
82
  import { FogOfWarRevealer } from "../../../../ecs/fow/FogOfWarRevealer.js";
84
- import Team from "../../../../../../model/game/ecs/component/Team.js";
83
+ import Team from "../../../../ecs/team/Team.js";
85
84
  import { AmbientOcclusionPostProcessEffect } from "../../buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js";
85
+ import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
86
86
 
87
87
  const geo_light_center_octahedron = new BoxBufferGeometry(0.1, 0.1, 0.1);
88
88
  const engineHarness = new EngineHarness();