@woosh/meep-engine 2.47.3 → 2.47.10

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 (130) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -0
  2. package/build/bundle-worker-terrain.js +1 -0
  3. package/build/meep.cjs +1044 -933
  4. package/build/meep.min.js +1 -1
  5. package/build/meep.module.js +1044 -933
  6. package/package.json +2 -2
  7. package/src/core/binary/BitSet.spec.js +3 -3
  8. package/src/core/bvh2/BinaryNode.js +12 -10
  9. package/src/core/bvh2/aabb3/AABB3.js +30 -31
  10. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +1 -1
  11. package/src/core/bvh2/binary/BinaryBVH.js +1 -1
  12. package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +1 -1
  13. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -1
  14. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +2 -2
  15. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +1 -1
  16. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +1 -1
  17. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +10 -8
  18. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +14 -22
  19. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +13 -15
  20. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +14 -21
  21. package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +16 -24
  22. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +23 -26
  23. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +10 -11
  24. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +2 -2
  25. package/src/core/bvh2/transform/tryRotateSingleNode.js +2 -2
  26. package/src/core/bvh2/traversal/aabb3_detailed_volume_intersection_callback_based.js +1 -1
  27. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +1 -1
  28. package/src/core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js +13 -0
  29. package/src/core/color/Color.d.ts +2 -1
  30. package/src/core/color/Color.js +30 -5
  31. package/src/core/color/ColorUtils.js +7 -5
  32. package/src/core/color/parseHex.js +11 -3
  33. package/src/core/color/rgb2hex.js +1 -1
  34. package/src/core/geom/3d/SurfacePoint3.d.ts +7 -0
  35. package/src/core/geom/3d/SurfacePoint3.js +56 -1
  36. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_combine.js +2 -2
  37. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_contains_point.js +1 -1
  38. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_frustum_degree.js +2 -2
  39. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_combined_surface_area.js +2 -2
  40. package/src/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.js +1 -1
  41. package/src/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.spec.js +8 -0
  42. package/src/core/geom/3d/aabb/{computeAABB3PlaneSide.js → aabb3_compute_plane_side.js} +1 -1
  43. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_detailed_volume_intersection.js +7 -7
  44. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_from_v3_array.js +4 -4
  45. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_from_v3_array_transformed.js +2 -2
  46. package/src/core/{bvh2/aabb3/aabb3_intersect_aabb3.js → geom/3d/aabb/aabb3_intersects_aabb3.js} +2 -2
  47. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_frustum_array.js +2 -2
  48. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_frustum_degree.js +4 -4
  49. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_line_segment.js +1 -1
  50. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +87 -0
  51. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray.spec.js +1 -1
  52. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray_branchless.js +2 -2
  53. package/src/core/{bvh2/aabb3/aabb3_intersect_ray_slab.js → geom/3d/aabb/aabb3_intersects_ray_slab.js} +35 -17
  54. package/src/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +5 -1
  55. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_nearest_point_on_surface.js +2 -2
  56. package/src/core/geom/3d/aabb/aabb3_raycast.js +103 -0
  57. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_signed_distance_sqr_to_point.js +1 -1
  58. package/src/core/geom/3d/aabb/computeBoundingBoxFromVertexData.js +4 -12
  59. package/src/core/geom/3d/aabb/compute_aabb_from_points.js +8 -1
  60. package/src/core/geom/3d/shape/UnitCubeShape3D.js +1 -1
  61. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +4 -7
  62. package/src/core/model/node-graph/DataType.d.ts +4 -0
  63. package/src/core/model/node-graph/node/NodeDescription.d.ts +11 -1
  64. package/src/core/model/node-graph/node/NodeRegistry.spec.js +47 -1
  65. package/src/core/model/node-graph/node/Port.d.ts +3 -0
  66. package/src/core/model/node-graph/node/Port.js +7 -3
  67. package/src/core/model/node-graph/node/Port.spec.js +44 -0
  68. package/src/core/model/node-graph/node/PortDirection.d.ts +5 -0
  69. package/src/engine/asset/Asset.js +1 -1
  70. package/src/engine/asset/AssetLoadState.js +10 -0
  71. package/src/engine/asset/AssetManager.js +164 -228
  72. package/src/engine/asset/PendingAsset.js +61 -0
  73. package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
  74. package/src/engine/ecs/foliage/InstancedFoliage.js +1 -1
  75. package/src/engine/ecs/storage/BinaryBufferSerializer.js +13 -1
  76. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +11 -4
  77. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter2.js +54 -0
  78. package/src/engine/ecs/systems/RenderSystem.js +1 -33
  79. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +2 -4
  80. package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +6 -1
  81. package/src/engine/graphics/GraphicsEngine.js +5 -1
  82. package/src/engine/graphics/ecs/decal/v2/Decal.js +44 -2
  83. package/src/engine/graphics/ecs/decal/v2/DecalSerializationAdapter.js +31 -0
  84. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +16 -5
  85. package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +88 -56
  86. package/src/engine/graphics/geometry/buffered/compute_buffer_geometry_byte_size.js +5 -1
  87. package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +2 -2
  88. package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +1 -1
  89. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +3 -2
  90. package/src/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +3 -2
  91. package/src/engine/graphics/micron/format/MicronGeometry.js +1 -1
  92. package/src/engine/graphics/micron/format/validate_patch_bounds.js +1 -1
  93. package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +1 -1
  94. package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +16 -16
  95. package/src/engine/graphics/render/forward_plus/LightManager.js +3 -0
  96. package/src/engine/graphics/render/forward_plus/LightManager.spec.js +5 -5
  97. package/src/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_APPLY_DECALS.js +4 -0
  98. package/src/engine/graphics/render/forward_plus/model/Decal.js +10 -2
  99. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +2 -2
  100. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +18 -16
  101. package/src/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +2 -0
  102. package/src/engine/graphics/render/visibility/IncrementalDeltaSet.js +26 -13
  103. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +8 -2
  104. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +3 -3
  105. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +18 -15
  106. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_max.js +1 -1
  107. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min.js +1 -1
  108. package/src/engine/graphics/three/three_computeObjectBoundingBox.js +56 -0
  109. package/src/engine/input/devices/{InputDeviceButton.d.ts → InputDeviceSwitch.d.ts} +1 -1
  110. package/src/engine/input/devices/{InputDeviceButton.js → InputDeviceSwitch.js} +1 -1
  111. package/src/engine/input/devices/KeyboardDevice.d.ts +2 -2
  112. package/src/engine/input/devices/KeyboardDevice.js +58 -40
  113. package/src/engine/input/devices/PointerDevice.js +224 -179
  114. package/src/core/bvh2/aabb3/aabb3_intersects_ray.js +0 -97
  115. package/src/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane_max.spec.js +0 -8
  116. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_frustum_array.js +0 -0
  117. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_ray.js +0 -0
  118. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_ray_array.js +0 -0
  119. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_box_surface_area_2.js +0 -0
  120. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_compute_half_surface_area.js +0 -0
  121. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_compute_surface_area.js +0 -0
  122. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_corner_edge_mapping.js +0 -0
  123. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_corner_edge_mapping.spec.js +0 -0
  124. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_corner_mapping.js +0 -0
  125. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_corner_mapping.spec.js +0 -0
  126. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_plane_mapping.js +0 -0
  127. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_expand_array.js +0 -0
  128. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray_fast.js +0 -0
  129. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_score_boxes_SAH.js +0 -0
  130. /package/src/core/{bvh2/aabb3/aabb_score_boxes_SAH_delta.js → geom/3d/aabb/aabb3_score_boxes_SAH_delta.js} +0 -0
@@ -0,0 +1,61 @@
1
+ import BoundedValue from "../../core/model/BoundedValue.js";
2
+ import { AssetLoadState } from "./AssetLoadState.js";
3
+
4
+ export class PendingAsset {
5
+ /**
6
+ *
7
+ * @param {AssetDescription} description
8
+ * @constructor
9
+ */
10
+ constructor(description) {
11
+ /**
12
+ *
13
+ * @type {AssetDescription}
14
+ */
15
+ this.description = description;
16
+
17
+ /**
18
+ *
19
+ * @type {AssetRequest[]}
20
+ */
21
+ this.requests = [];
22
+
23
+ /**
24
+ *
25
+ * @type {BoundedValue}
26
+ */
27
+ this.progress = new BoundedValue(0, 0);
28
+
29
+ /**
30
+ *
31
+ * @type {AssetLoadState|number}
32
+ */
33
+ this.state = AssetLoadState.Initial;
34
+ }
35
+
36
+ /**
37
+ * Returns aggregated priority of the pending asset based on highest priority of associated requests
38
+ * @return {number}
39
+ */
40
+ get priority() {
41
+ let max_priority = 0;
42
+
43
+ const requests = this.requests;
44
+ const n = requests.length;
45
+
46
+ if (n > 0) {
47
+ max_priority = requests[0].priority;
48
+ }
49
+
50
+ for (let i = 1; i < n; i++) {
51
+ const request = requests[i];
52
+ const priority = request.priority;
53
+
54
+ if (priority > max_priority) {
55
+ max_priority = request;
56
+ }
57
+ }
58
+
59
+ return max_priority;
60
+ }
61
+ }
@@ -2,7 +2,6 @@ import { Transform } from "../../ecs/transform/Transform.js";
2
2
  import { Asset } from "../Asset.js";
3
3
  import { prepareMaterial, prepareObject } from "../../graphics/three/ThreeFactory.js";
4
4
  import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
5
- import { three_computeObjectBoundingBox } from "../../ecs/systems/RenderSystem.js";
6
5
  import { AABB3 } from "../../../core/bvh2/aabb3/AABB3.js";
7
6
  import { StaticMaterialCache } from "./material/StaticMaterialCache.js";
8
7
  import { DDSLoader } from "three/examples/jsm/loaders/DDSLoader.js";
@@ -28,6 +27,7 @@ import { traverseThreeObject } from "../../graphics/ecs/highlight/renderer/trave
28
27
  import { computeTextureHash } from "./material/computeTextureHash.js";
29
28
  import { computeTextureEquality } from "./material/computeTextureEquality.js";
30
29
  import { async_traverse_three_object } from "./async_traverse_three_object.js";
30
+ import { three_computeObjectBoundingBox } from "../../graphics/three/three_computeObjectBoundingBox.js";
31
31
 
32
32
  const animationOptimizer = new AnimationOptimizer();
33
33
  const materialCache = StaticMaterialCache.Global;
@@ -17,7 +17,7 @@ import {
17
17
  } from "../../graphics/geometry/buffered/computeGeometryBoundingSphereMiniball.js";
18
18
  import { serializeRowFirstTable } from "../../../core/collection/table/serializeRowFirstTable.js";
19
19
  import { deserializeRowFirstTable } from "../../../core/collection/table/deserializeRowFirstTable.js";
20
- import { aabb3_from_v3_array_transformed } from "../../../core/bvh2/aabb3/aabb3_from_v3_array_transformed.js";
20
+ import { aabb3_from_v3_array_transformed } from "../../../core/geom/3d/aabb/aabb3_from_v3_array_transformed.js";
21
21
  import { ViewState } from "./ViewState.js";
22
22
  import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
23
23
 
@@ -4,6 +4,7 @@ import { BinaryCollectionSerializer } from "./binary/collection/BinaryCollection
4
4
  import { COMPONENT_SERIALIZATION_TRANSIENT_FIELD } from "./COMPONENT_SERIALIZATION_TRANSIENT_FIELD.js";
5
5
  import { currentTimeInSeconds } from "../../Clock.js";
6
6
  import { BinaryObjectSerializationAdapter } from "./binary/object/BinaryObjectSerializationAdapter.js";
7
+ import { logger } from "../../logging/GlobalLogger.js";
7
8
 
8
9
  /**
9
10
  * @template T
@@ -112,7 +113,10 @@ class BinaryBufferSerializer {
112
113
  }
113
114
 
114
115
  collectionSerializer.setClass(className);
115
- collectionSerializer.initialize({
116
+
117
+ const problemLog = [];
118
+
119
+ const initialized = collectionSerializer.initialize({
116
120
  /**
117
121
  *
118
122
  * @param {string} className
@@ -121,9 +125,17 @@ class BinaryBufferSerializer {
121
125
  */
122
126
  adapterOptionsSupplier(className, klass, adapter) {
123
127
  return [engine, objectAdapter];
128
+ },
129
+ problemConsumer(message) {
130
+ problemLog.push(message);
124
131
  }
125
132
  });
126
133
 
134
+ if (!initialized) {
135
+ logger.error(`Failed to initialize serializer for class '${className}': ${problemLog.join('; ')}`)
136
+ continue;
137
+ }
138
+
127
139
  const __start_time = currentTimeInSeconds();
128
140
 
129
141
  let lastEntity = 0;
@@ -127,23 +127,28 @@ export class BinaryCollectionSerializer {
127
127
  /**
128
128
  *
129
129
  * @param {function(string,Class, BinaryClassSerializationAdapter):[]} [adapterOptionsSupplier]
130
+ * @param {function(string):*} [problemConsumer]
131
+ * @returns {boolean}
130
132
  */
131
133
  initialize({
132
- adapterOptionsSupplier = returnEmptyArray
134
+ adapterOptionsSupplier = returnEmptyArray,
135
+ problemConsumer = console.warn
133
136
  } = {}) {
134
137
 
135
- assert.typeOf(adapterOptionsSupplier, 'function', 'adapterOptionsSupplier');
138
+ assert.isFunction(adapterOptionsSupplier, 'adapterOptionsSupplier');
136
139
 
137
140
  const className = this.className;
138
141
 
139
- assert.typeOf(className, 'string', 'className');
142
+ assert.isString(className, 'className');
140
143
 
141
144
  const registry = this.registry;
142
145
 
143
146
  const adapter = registry.getAdapter(className);
144
147
 
145
148
  if (adapter === undefined) {
146
- throw new Error(`No adapter for class '${className}'`);
149
+ problemConsumer(`No adapter for class '${className}'`);
150
+
151
+ return false;
147
152
  }
148
153
 
149
154
  this.adapter = adapter;
@@ -181,6 +186,8 @@ export class BinaryCollectionSerializer {
181
186
 
182
187
  //clear dictionary
183
188
  this.dictionary.clear();
189
+
190
+ return true;
184
191
  }
185
192
 
186
193
  finalize() {
@@ -0,0 +1,54 @@
1
+ export class BinaryObjectSerializationAdapter2 {
2
+ /**
3
+ *
4
+ * @type {BinarySerializationRegistry|null}
5
+ */
6
+ #registry = null
7
+
8
+ /**
9
+ *
10
+ * @param {BinaryBuffer} buffer
11
+ * @param {Object} object
12
+ * @param {Object} schema
13
+ */
14
+ serialize(buffer, object, schema) {
15
+ const typeName = object.constructor.typeName;
16
+
17
+ const nativeAdapter = this.#registry.getAdapter(typeName);
18
+
19
+ // TODO write a header so we can reconstruct the serialization schema on the other side
20
+
21
+ if (nativeAdapter !== undefined) {
22
+ // serialize with native
23
+ nativeAdapter.serialize(buffer, object);
24
+ return;
25
+ }
26
+
27
+ for (const property in schema) {
28
+
29
+ const field_schema = schema[property];
30
+
31
+ const actual_value = object[field_schema];
32
+
33
+ this.serialize(buffer, actual_value, field_schema);
34
+ }
35
+
36
+ }
37
+
38
+ /**
39
+ *
40
+ * @param {BinaryBuffer} buffer
41
+ * @param {Object} object
42
+ */
43
+ deserialize(buffer, object) {
44
+
45
+ // read header
46
+
47
+ }
48
+ }
49
+
50
+ /**
51
+ * @readonly
52
+ * @type {number}
53
+ */
54
+ BinaryObjectSerializationAdapter2.prototype.version = 0;
@@ -5,44 +5,12 @@ import { System } from '../System.js';
5
5
  import Renderable from '../components/Renderable.js';
6
6
  import { Transform } from '../transform/Transform.js';
7
7
  import { SignalBinding } from "../../../core/events/signal/SignalBinding.js";
8
- import { Box3 } from "three";
9
8
  import { RenderableFlags } from "../components/RenderableFlags.js";
10
9
  import { rootObject3DFastMatrixUpdate } from "../../graphics/ecs/mesh/rootObject3DFastMatrixUpdate.js";
11
10
  import { updateNodeByTransformAndBBB } from "../../graphics/ecs/mesh/updateNodeByTransformAndBBB.js";
11
+ import { three_computeObjectBoundingBox } from "../../graphics/three/three_computeObjectBoundingBox.js";
12
12
 
13
13
 
14
- /**
15
- *
16
- * @param {Object3D} object
17
- * @param {AABB3} result
18
- */
19
- export function three_computeObjectBoundingBox(object, result) {
20
- const _sX = object.scale.x;
21
- const _sY = object.scale.y;
22
- const _sZ = object.scale.z;
23
-
24
- object.scale.set(1, 1, 1);
25
-
26
- const box3 = new Box3();
27
-
28
- box3.expandByObject(object);
29
-
30
- object.scale.set(_sX, _sY, _sZ);
31
-
32
- const min = box3.min;
33
- const max = box3.max;
34
-
35
- result.setBounds(
36
- min.x,
37
- min.y,
38
- min.z,
39
- max.x,
40
- max.y,
41
- max.z
42
- );
43
-
44
- }
45
-
46
14
  /**
47
15
  * @deprecated use {@link ShadedGeometry} instead
48
16
  */
@@ -1,6 +1,4 @@
1
1
  import WorkerBuilder from "../../../../core/process/worker/WorkerBuilder.js";
2
- import { sampler2d_channel_compute_max } from "../../../graphics/texture/sampler/sampler2d_channel_compute_max.js";
3
- import { sampler2d_channel_compute_min } from "../../../graphics/texture/sampler/sampler2d_channel_compute_min.js";
4
2
 
5
3
  /**
6
4
  *
@@ -29,8 +27,8 @@ export function makeTerrainWorkerProxy() {
29
27
 
30
28
  useSampler(function (sampler) {
31
29
 
32
- const min = sampler2d_channel_compute_min(sampler);
33
- const max = sampler2d_channel_compute_max(sampler);
30
+ const min = Lib.sampler2d_channel_compute_min(sampler);
31
+ const max = Lib.sampler2d_channel_compute_max(sampler);
34
32
 
35
33
  resolve({
36
34
  min: min.value,
@@ -6,12 +6,17 @@ import * as BinaryBVHFromBufferGeometry from '../../../graphics/geometry/bvh/buf
6
6
  import { Sampler2D } from '../../../graphics/texture/sampler/Sampler2D.js';
7
7
  import BufferedGeometryArraysBuilder from '../BufferedGeometryArraysBuilder.js';
8
8
  import { tensionOptimizeUV } from "../util/tensionOptimizeUV.js";
9
+ import { sampler2d_channel_compute_min } from "../../../graphics/texture/sampler/sampler2d_channel_compute_min.js";
10
+ import { sampler2d_channel_compute_max } from "../../../graphics/texture/sampler/sampler2d_channel_compute_max.js";
11
+
9
12
 
10
13
  self.Lib = {
11
14
  BinaryBVHFromBufferGeometry,
12
15
  Sampler2D,
13
16
  BufferedGeometryArraysBuilder,
14
- tensionOptimizeUV
17
+ tensionOptimizeUV,
18
+ sampler2d_channel_compute_min,
19
+ sampler2d_channel_compute_max
15
20
  };
16
21
 
17
22
 
@@ -355,7 +355,11 @@ GraphicsEngine.prototype.start = function () {
355
355
  antialias: true,
356
356
  logarithmicDepthBuffer: false,
357
357
  canvas,
358
- context
358
+ context,
359
+ /**
360
+ * @see https://registry.khronos.org/webgl/specs/latest/1.0/#5.2
361
+ */
362
+ powerPreference:"high-performance"
359
363
  };
360
364
 
361
365
  const webGLRenderer = this.renderer = new WebGLRenderer(rendererParameters);
@@ -1,3 +1,6 @@
1
+ import { Color } from "../../../../../core/color/Color.js";
2
+ import { computeStringHash } from "../../../../../core/primitives/strings/computeStringHash.js";
3
+
1
4
  export class Decal {
2
5
  constructor() {
3
6
  /**
@@ -12,6 +15,12 @@ export class Decal {
12
15
  */
13
16
  this.priority = 0;
14
17
 
18
+ /**
19
+ * Color of the decal will be pre-multiplied by this
20
+ * @type {Color}
21
+ */
22
+ this.color = new Color(1, 1, 1, 1);
23
+
15
24
  /**
16
25
  * Internal transient reference to loaded asset
17
26
  * @type {Sampler2D|null}
@@ -26,15 +35,26 @@ export class Decal {
26
35
  this.__cached_uri = null;
27
36
  }
28
37
 
38
+ static fromJSON(j) {
39
+ const r = new Decal();
40
+
41
+ r.fromJSON(j);
42
+
43
+ return r;
44
+ }
45
+
29
46
  toJSON() {
30
47
  return {
31
48
  uri: this.uri,
32
- priority: this.priority
49
+ priority: this.priority,
50
+ color: this.color.toCssRGBAString()
33
51
  };
34
52
  }
35
53
 
36
54
  fromJSON({
37
- uri, priority = 0
55
+ uri,
56
+ priority = 0,
57
+ color
38
58
  }) {
39
59
  this.uri = uri;
40
60
  this.priority = priority;
@@ -44,6 +64,28 @@ export class Decal {
44
64
  this.__cached_sampler = null;
45
65
  this.__cached_uri = null;
46
66
  }
67
+
68
+ if (color !== undefined) {
69
+ this.color.parse(color);
70
+ } else {
71
+ this.color.set(1, 1, 1, 1);
72
+ }
73
+ }
74
+
75
+ hash() {
76
+ return computeStringHash(this.uri) ^ this.color.hash()
77
+ }
78
+
79
+ /**
80
+ *
81
+ * @param {Decal} other
82
+ * @returns {boolean}
83
+ */
84
+ equals(other) {
85
+ return this.uri === other.uri
86
+ && this.color.equals(other.color)
87
+ && this.priority === other.priority
88
+ ;
47
89
  }
48
90
  }
49
91
 
@@ -0,0 +1,31 @@
1
+ import { BinaryClassSerializationAdapter } from "../../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
2
+ import { Decal } from "./Decal.js";
3
+
4
+ export class DecalSerializationAdapter extends BinaryClassSerializationAdapter {
5
+ constructor() {
6
+ super();
7
+
8
+ this.klass = Decal;
9
+ }
10
+
11
+ /**
12
+ *
13
+ * @param {BinaryBuffer} buffer
14
+ * @param {Decal} value
15
+ */
16
+ serialize(buffer, value) {
17
+
18
+ buffer.writeUTF8String(value.uri);
19
+ buffer.writeFloat32(value.priority);
20
+ buffer.writeFloat32Array(value.color, 0, 4);
21
+
22
+ }
23
+
24
+ deserialize(buffer, value) {
25
+
26
+ value.uri = buffer.readUTF8String();
27
+ value.priority = buffer.readFloat32();
28
+ buffer.readFloat32Array(value.color, 0, 4);
29
+
30
+ }
31
+ }
@@ -17,12 +17,12 @@ import {
17
17
  } from "../../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
18
18
  import { bvh_query_leaves_ray } from "../../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
19
19
  import { ray3_array_apply_matrix4 } from "../../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
20
- import { aabb3_intersects_ray } from "../../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
21
20
  import { ray3_array_compose } from "../../../../../core/geom/3d/ray/ray3_array_compose.js";
22
21
  import { mat4 } from "gl-matrix";
23
22
  import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
24
23
  import { EBBVHLeafProxy } from "../../../../../core/bvh2/bvh3/EBBVHLeafProxy.js";
25
24
  import { aabb3_matrix4_project } from "../../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
25
+ import { aabb3_raycast } from "../../../../../core/geom/3d/aabb/aabb3_raycast.js";
26
26
 
27
27
  const placeholder_texture = Sampler2D.uint8(4, 1, 1);
28
28
  placeholder_texture.data.fill(255);
@@ -146,9 +146,16 @@ class Context extends SystemEntityContext {
146
146
  const decal_spec = this.components[0];
147
147
 
148
148
  // propagate draw priority onto decal
149
- Object.defineProperty(fpDecal, 'draw_priority', {
150
- get() {
151
- return decal_spec.priority;
149
+ Object.defineProperties(fpDecal, {
150
+ 'draw_priority': {
151
+ get() {
152
+ return decal_spec.priority;
153
+ }
154
+ },
155
+ 'color':{
156
+ get(){
157
+ return decal_spec.color;
158
+ }
152
159
  }
153
160
  });
154
161
 
@@ -298,6 +305,7 @@ export class FPDecalSystem extends AbstractContextSystem {
298
305
  );
299
306
 
300
307
  const result = [];
308
+ const temp_hit = new Float32Array(6);
301
309
 
302
310
 
303
311
  for (let i = 0; i < hit_count; i++) {
@@ -338,7 +346,8 @@ export class FPDecalSystem extends AbstractContextSystem {
338
346
  // transform ray into decal's local space
339
347
  ray3_array_apply_matrix4(scratch_ray_0, 0, scratch_ray_0, 0, scratch_m4);
340
348
 
341
- if (aabb3_intersects_ray(
349
+ if (aabb3_raycast(
350
+ temp_hit, 0,
342
351
  -0.5, -0.5, -0.5,
343
352
  0.5, 0.5, 0.5,
344
353
 
@@ -347,6 +356,8 @@ export class FPDecalSystem extends AbstractContextSystem {
347
356
  )) {
348
357
  const contact = new SurfacePoint3();
349
358
 
359
+ contact.fromArray(temp_hit);
360
+
350
361
  // contact will be the center of decal, and normal will follow the decal normal
351
362
  contact.applyMatrix4(transform.matrix);
352
363