@woosh/meep-engine 2.75.3 → 2.75.5

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 (48) hide show
  1. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +35 -21
  2. package/package.json +2 -2
  3. package/src/core/collection/array/array_compute_min_max.js +20 -0
  4. package/src/core/collection/map/HashMap.js +16 -14
  5. package/src/core/geom/2d/convex-hull/fixed_convex_hull_humus.js +23 -13
  6. package/src/core/geom/2d/intersect_ray_2d.js +7 -14
  7. package/src/core/geom/3d/aabb/AABB3.js +13 -0
  8. package/src/core/geom/3d/topology/samples/sampleFloodFill.js +21 -21
  9. package/src/core/geom/3d/topology/tm_face_area.js +1 -1
  10. package/src/core/geom/3d/triangle/computeTriangleSurfaceArea.js +39 -0
  11. package/src/core/process/task/util/countTask.js +1 -2
  12. package/src/engine/EngineBootstrapper.js +15 -7
  13. package/src/engine/animation/curve/AnimationCurve.js +50 -31
  14. package/src/engine/animation/curve/AnimationCurve.spec.js +9 -1
  15. package/src/engine/animation/curve/compression/prototypeCurveCompression.js +20 -11
  16. package/src/engine/animation/curve/compute_curve_aabb.js +26 -0
  17. package/src/engine/animation/curve/draw/build_curve_editor.js +82 -42
  18. package/src/engine/animation/curve/draw/build_plot_entity_from_array.js +5 -5
  19. package/src/engine/animation/curve/preset/CURVE_EASE_IN.js +8 -0
  20. package/src/engine/animation/curve/preset/CURVE_EASE_IN_OUT.js +7 -0
  21. package/src/engine/animation/curve/preset/CURVE_EASE_OUT.js +7 -0
  22. package/src/engine/asset/loaders/image/png/PNGReader.js +119 -1
  23. package/src/engine/graphics/GraphicsEngine.d.ts +6 -3
  24. package/src/engine/graphics/canvas/canvas2d_draw_grid.js +42 -0
  25. package/src/engine/{animation/curve/draw/draw_label.js → graphics/canvas/canvas2d_draw_label.js} +6 -1
  26. package/src/engine/graphics/canvas/canvas2d_draw_linear_scale.js +64 -0
  27. package/src/engine/graphics/canvas/canvas2d_draw_path.js +60 -0
  28. package/src/engine/graphics/canvas/canvas2d_plot_data_line.js +84 -0
  29. package/src/engine/{animation/curve/draw/plot_array.js → graphics/canvas/canvas2d_plot_line_array.js} +8 -25
  30. package/src/engine/graphics/geometry/VertexDataSpec.d.ts +10 -0
  31. package/src/engine/graphics/geometry/VertexDataSpec.js +20 -21
  32. package/src/engine/graphics/geometry/computeMeshSurfaceArea.js +2 -37
  33. package/src/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +8 -26
  34. package/src/engine/graphics/material/manager/MaterialManager.d.ts +6 -0
  35. package/src/engine/graphics/sh3/LightProbeVolume.js +38 -17
  36. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +26 -35
  37. package/src/engine/graphics/sh3/prototypeSH3Probe.js +166 -100
  38. package/src/engine/graphics/texture/makeOnePixelTexture.js +19 -0
  39. package/src/engine/graphics/texture/sprite/prototypeSpriteCutoutGeometry.js +5 -68
  40. package/src/engine/graphics/texture/virtual/v2/VirtualTexturePage.js +1 -1
  41. package/src/engine/input/devices/PointerDevice.js +6 -3
  42. package/src/engine/makeSimpleTaskProgressView.js +33 -0
  43. package/src/engine/scene/transitionToScene.js +9 -10
  44. package/src/view/task/TaskLoadingScreen.js +5 -12
  45. package/src/view/task/TaskProgressView.js +9 -9
  46. package/src/engine/animation/curve/draw/draw_grid.js +0 -27
  47. package/src/engine/animation/curve/draw/plot_data.js +0 -49
  48. package/src/engine/graphics/geometry/QuadGeometry.js +0 -13
@@ -1,9 +1,10 @@
1
1
  import {PerspectiveCamera, Scene, WebGLRenderer} from "three";
2
- import {RenderLayerManager} from "./render/layers/RenderLayerManager";
3
- import Vector3 from "../../core/geom/Vector3";
2
+ import Signal from "../../core/events/signal/Signal";
4
3
  import Vector2 from "../../core/geom/Vector2";
4
+ import Vector3 from "../../core/geom/Vector3";
5
5
  import View from "../../view/View";
6
- import Signal from "../../core/events/signal/Signal";
6
+ import {MaterialManager} from "./material/manager/MaterialManager";
7
+ import {RenderLayerManager} from "./render/layers/RenderLayerManager";
7
8
 
8
9
  interface IGraphicsEngineSignals {
9
10
  readonly preRender: Signal
@@ -35,4 +36,6 @@ export class GraphicsEngine {
35
36
  viewportProjectionRay(x: number, y: number, source: Vector3, direction: Vector3): void
36
37
 
37
38
  getRenderer(): WebGLRenderer
39
+
40
+ getMaterialManager():MaterialManager
38
41
  }
@@ -0,0 +1,42 @@
1
+ /**
2
+ *
3
+ * @param {CanvasRenderingContext2D} ctx
4
+ * @param {number} width
5
+ * @param {number} height
6
+ * @param {string} [color] CSS color specification
7
+ * @param {number} [spacing] distance between grid lines
8
+ * @param {number} [offset_x]
9
+ * @param {number} [offset_y]
10
+ * @param {number} [thickness] Like thickness
11
+ */
12
+ export function canvas2d_draw_grid({
13
+ ctx,
14
+ width,
15
+ height,
16
+ color = 'red',
17
+ spacing = 10,
18
+ offset_x = 0,
19
+ offset_y = 0,
20
+ thickness = 1
21
+ }) {
22
+ ctx.fillStyle = 'none';
23
+ ctx.lineWidth = thickness;
24
+ ctx.strokeStyle = color;
25
+
26
+
27
+ ctx.beginPath();
28
+
29
+ for (let x = offset_x; x < width; x += spacing) {
30
+ // horizontal
31
+ ctx.moveTo(x, 0);
32
+ ctx.lineTo(x, height);
33
+ }
34
+
35
+ for (let y = offset_y; y < width; y += spacing) {
36
+ // vertical
37
+ ctx.moveTo(0, y);
38
+ ctx.lineTo(width, y);
39
+ }
40
+
41
+ ctx.stroke();
42
+ }
@@ -5,7 +5,12 @@
5
5
  * @param {number} x
6
6
  * @param {number} y
7
7
  */
8
- export function draw_label(ctx, text, x, y) {
8
+ export function canvas2d_draw_label({
9
+ ctx,
10
+ text,
11
+ x,
12
+ y
13
+ }) {
9
14
 
10
15
  ctx.fillStyle = 'white';
11
16
  ctx.font = '10px Tahoma';
@@ -0,0 +1,64 @@
1
+ import { lerp } from "../../../core/math/lerp.js";
2
+ import { number_pretty_print } from "../../../core/primitives/numbers/number_pretty_print.js";
3
+ import { canvas2d_draw_label } from "./canvas2d_draw_label.js";
4
+
5
+ /**
6
+ *
7
+ * @param {CanvasRenderingContext2D} ctx
8
+ * @param {number} position_x0
9
+ * @param {number} position_y0
10
+ * @param {number} position_x1
11
+ * @param {number} position_y1
12
+ * @param {number} spacing
13
+ * @param {number} value_0
14
+ * @param {number} value_1
15
+ * @param {string} [align] which side of the point should the text appear on
16
+ */
17
+ export function canvas2d_draw_linear_scale({
18
+ ctx,
19
+ position_x0, position_y0,
20
+ position_x1, position_y1,
21
+ spacing = 10,
22
+ value_0, value_1,
23
+ align
24
+ }) {
25
+
26
+ if (spacing <= 0) {
27
+ throw new Error(`Spacing must be greater than 0`);
28
+ }
29
+
30
+ // figure out direction vector
31
+ const delta_x = position_x1 - position_x0;
32
+ const delta_y = position_y1 - position_y0;
33
+
34
+ const distance = Math.hypot(delta_x, delta_y);
35
+
36
+ if (distance === 0) {
37
+ throw new Error(`Distance must be greater than 0`);
38
+ }
39
+
40
+ const direction_x = delta_x / distance;
41
+ const direction_y = delta_y / distance;
42
+
43
+ const mark_count = Math.ceil(distance / spacing);
44
+
45
+ for (let i = 0; i <= mark_count; i++) {
46
+
47
+ const offset = spacing * i;
48
+
49
+ const f = offset / distance;
50
+
51
+ const point_x = position_x0 + direction_x * offset;
52
+ const point_y = position_y0 + direction_y * spacing * i;
53
+
54
+ const value = lerp(value_0, value_1, f);
55
+
56
+ canvas2d_draw_label({
57
+ ctx,
58
+ text: number_pretty_print(value),
59
+ x: point_x,
60
+ y: point_y
61
+ });
62
+ }
63
+
64
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ *
3
+ * @param {number[]} vertices
4
+ * @param {CanvasRenderingContext2D} ctx
5
+ * @param [fillColor]
6
+ * @param [strokeColor]
7
+ * @param [highlight_vertices]
8
+ * @param [vertex_draw_size]
9
+ * @param {number} [offset] in pixels
10
+ */
11
+ export function canvas2d_draw_path({
12
+ vertices,
13
+ ctx,
14
+ fillColor = 'transparent',
15
+ strokeColor = 'red',
16
+ highlight_vertices = true,
17
+ vertex_draw_size = 8,
18
+ offset = [0, 0]
19
+ }) {
20
+
21
+ function draw_point(x, y) {
22
+ ctx.fillStyle = 'rgba(255,255,255,0.8)';
23
+ ctx.strokeStyle = 'black';
24
+ ctx.lineWidth = "1px";
25
+
26
+ const x1 = x - vertex_draw_size / 2 + offset[0];
27
+ const y1 = y - vertex_draw_size / 2 + offset[1];
28
+
29
+ ctx.fillRect(x1, y1, vertex_draw_size, vertex_draw_size);
30
+
31
+ ctx.strokeRect(x1, y1, vertex_draw_size, vertex_draw_size);
32
+ }
33
+
34
+ if (highlight_vertices) {
35
+ for (let i = 0; i < vertices.length / 2; i++) {
36
+ draw_point(vertices[i * 2], vertices[i * 2 + 1]);
37
+ }
38
+ }
39
+
40
+ ctx.fillStyle = fillColor;
41
+ ctx.strokeStyle = strokeColor;
42
+ ctx.lineWidth = "1px";
43
+
44
+ ctx.beginPath();
45
+
46
+ ctx.moveTo(vertices[0] + offset[0], vertices[1] + offset[1]);
47
+ // drawPoint(jarvis_vertices[0].x, jarvis_vertices[0].y, jarvis_vertices[0].z, 'red');
48
+
49
+ for (let i = 1; i < vertices.length / 2; i++) {
50
+
51
+ ctx.lineTo(vertices[i * 2] + offset[0], vertices[i * 2 + 1] + offset[1]);
52
+
53
+ // drawPoint(last.x, last.y, last.z, 'red');
54
+ }
55
+
56
+ ctx.closePath();
57
+ ctx.stroke();
58
+ ctx.fill();
59
+
60
+ }
@@ -0,0 +1,84 @@
1
+ import Vector2 from "../../../core/geom/Vector2.js";
2
+ import { canvas2d_draw_grid } from "./canvas2d_draw_grid.js";
3
+ import { canvas2d_draw_linear_scale } from "./canvas2d_draw_linear_scale.js";
4
+ import { canvas2d_plot_line_array } from "./canvas2d_plot_line_array.js";
5
+
6
+ /**
7
+ *
8
+ * @param {CanvasRenderingContext2D} ctx
9
+ * @param {number[]|Float32Array} data
10
+ * @param {Vector2} [margin]
11
+ * @param {number} width
12
+ * @param {number} height
13
+ * @param {number[]} [range_y]
14
+ * @param {number[]} range_x
15
+ */
16
+ export function canvas2d_plot_data_line({
17
+ ctx,
18
+ data,
19
+ margin = Vector2.zero,
20
+ width,
21
+ height,
22
+ range_y,
23
+ range_x
24
+ }) {
25
+
26
+ ctx.fillStyle = '#222222';
27
+ ctx.fillRect(0, 0, width, height);
28
+
29
+ const data_x0 = range_x[0];
30
+ const data_x1 = range_x[1];
31
+ const data_y0 = range_y[0];
32
+ const data_y1 = range_y[1];
33
+
34
+ const plot_area_width = width - margin.x * 2;
35
+ const plot_area_height = height - margin.y * 2;
36
+
37
+ canvas2d_draw_grid({
38
+ ctx,
39
+ width,
40
+ height,
41
+ color: '#262626',
42
+ spacing: 32,
43
+ offset_x: 0
44
+ });
45
+
46
+ canvas2d_draw_grid({
47
+ ctx,
48
+ width,
49
+ height,
50
+ color: '#303030',
51
+ spacing: 32,
52
+ offset_x: 16,
53
+ offset_y: 16
54
+ });
55
+
56
+ canvas2d_draw_linear_scale({
57
+ ctx,
58
+ position_x0: margin.x,
59
+ position_x1: width - margin.x,
60
+ position_y0: height - 4,
61
+ position_y1: height - 4,
62
+ value_0: data_x0,
63
+ value_1: data_x1,
64
+ spacing: 64
65
+ });
66
+ canvas2d_draw_linear_scale({
67
+ ctx,
68
+ position_x0: 4,
69
+ position_x1: 4,
70
+ position_y0: height - margin.y,
71
+ position_y1: margin.y,
72
+ value_0: data_y0,
73
+ value_1: data_y1,
74
+ spacing: 64
75
+ });
76
+
77
+ ctx.fillStyle = 'none';
78
+ ctx.strokeStyle = '#00ff00';
79
+ ctx.lineWidth = 1;
80
+ canvas2d_plot_line_array(
81
+ ctx, plot_area_width, plot_area_height, margin.x, margin.y, data, range_y
82
+ );
83
+
84
+ }
@@ -1,23 +1,4 @@
1
- import { min2 } from "../../../../core/math/min2.js";
2
- import { max2 } from "../../../../core/math/max2.js";
3
-
4
- /**
5
- *
6
- * @param {number[]} data
7
- * @return {number[]}
8
- */
9
- export function array_compute_min_max(data) {
10
- const point_count = data.length;
11
-
12
- let min = Number.POSITIVE_INFINITY;
13
- let max = Number.NEGATIVE_INFINITY;
14
- for (let i = 0; i < point_count; i++) {
15
- min = min2(data[i], min);
16
- max = max2(data[i], max);
17
- }
18
-
19
- return [min, max];
20
- }
1
+ import { array_compute_min_max } from "../../../core/collection/array/array_compute_min_max.js";
21
2
 
22
3
  /**
23
4
  *
@@ -27,9 +8,9 @@ export function array_compute_min_max(data) {
27
8
  * @param {number} x_offset
28
9
  * @param {number} y_offset
29
10
  * @param {number[]} data
30
- * @param {number[]} data_range_y
11
+ * @param {number[]} [data_range_y]
31
12
  */
32
- export function plot_array(
13
+ export function canvas2d_plot_line_array(
33
14
  ctx,
34
15
  width,
35
16
  height,
@@ -40,11 +21,13 @@ export function plot_array(
40
21
  ) {
41
22
  const point_count = data.length;
42
23
 
43
- if (data_range_y === undefined) {
44
- data_range_y = array_compute_min_max(data)
24
+ let _data_range_y = data_range_y;
25
+
26
+ if (_data_range_y === undefined) {
27
+ _data_range_y = array_compute_min_max(data)
45
28
  }
46
29
 
47
- const [min, max] = data_range_y;
30
+ const [min, max] = _data_range_y;
48
31
 
49
32
  const value_span = max - min;
50
33
  const normalization_multiplier = value_span !== 0 ? 1 / value_span : 0;
@@ -3,6 +3,8 @@ import {AttributeSpec} from "./AttributeSpec";
3
3
  export class VertexDataSpec {
4
4
  readonly attributes: AttributeSpec[]
5
5
 
6
+ static from(...attributes: AttributeSpec[]): VertexDataSpec
7
+
6
8
  getAttributeByName(name: string): AttributeSpec | undefined
7
9
 
8
10
  add(attribute: AttributeSpec): this
@@ -12,4 +14,12 @@ export class VertexDataSpec {
12
14
  equals(other: VertexDataSpec): boolean
13
15
 
14
16
  hash(): number
17
+
18
+ toJSON(): any
19
+
20
+ fromJSON(json: any): void
21
+
22
+ getByteSize(): number
23
+
24
+ readonly isVertexDataSpec: true
15
25
  }
@@ -1,8 +1,8 @@
1
- import { invokeObjectHash } from "../../../core/model/object/invokeObjectHash.js";
1
+ import { assert } from "../../../core/assert.js";
2
2
  import { computeHashArray } from "../../../core/collection/array/computeHashArray.js";
3
3
  import { isArrayEqual } from "../../../core/collection/array/isArrayEqual.js";
4
+ import { invokeObjectHash } from "../../../core/model/object/invokeObjectHash.js";
4
5
  import { AttributeSpec } from "./AttributeSpec.js";
5
- import { assert } from "../../../core/assert.js";
6
6
 
7
7
  /**
8
8
  * @readonly
@@ -15,20 +15,19 @@ const DEFAULT_HASH = 1234567;
15
15
  * @example "uv","position" and "normal" attributes of geometry vertices
16
16
  */
17
17
  export class VertexDataSpec {
18
- constructor() {
19
- /**
20
- *
21
- * @type {AttributeSpec[]}
22
- */
23
- this.attributes = [];
24
-
25
- /**
26
- * Cached hash for speed
27
- * @type {number}
28
- * @private
29
- */
30
- this.__hash = DEFAULT_HASH;
31
- }
18
+
19
+ /**
20
+ *
21
+ * @type {AttributeSpec[]}
22
+ */
23
+ attributes = [];
24
+
25
+ /**
26
+ * Cached hash for speed
27
+ * @type {number}
28
+ * @private
29
+ */
30
+ #hash = DEFAULT_HASH;
32
31
 
33
32
  /**
34
33
  *
@@ -112,7 +111,7 @@ export class VertexDataSpec {
112
111
  this.attributes.push(attribute);
113
112
 
114
113
  // reset hash
115
- this.__hash = DEFAULT_HASH;
114
+ this.#hash = DEFAULT_HASH;
116
115
 
117
116
  //for chaining, return self
118
117
  return this;
@@ -138,7 +137,7 @@ export class VertexDataSpec {
138
137
  this.attributes.splice(0, this.attributes.length);
139
138
 
140
139
  // reset hash to trigger hash update
141
- this.__hash = DEFAULT_HASH;
140
+ this.#hash = DEFAULT_HASH;
142
141
  }
143
142
 
144
143
  /**
@@ -159,11 +158,11 @@ export class VertexDataSpec {
159
158
  }
160
159
 
161
160
  hash() {
162
- if (this.__hash === DEFAULT_HASH) {
163
- this.__hash = this.computeHash();
161
+ if (this.#hash === DEFAULT_HASH) {
162
+ this.#hash = this.computeHash();
164
163
  }
165
164
 
166
- return this.__hash;
165
+ return this.#hash;
167
166
  }
168
167
 
169
168
  toJSON() {
@@ -1,4 +1,5 @@
1
1
  import { assert } from "../../../core/assert.js";
2
+ import { computeTriangleSurfaceArea } from "../../../core/geom/3d/triangle/computeTriangleSurfaceArea.js";
2
3
 
3
4
  /**
4
5
  *
@@ -49,40 +50,4 @@ export function computeMeshSurfaceArea(result, points, indices, polygon_count =
49
50
  }
50
51
 
51
52
  return total;
52
- }
53
-
54
-
55
- /**
56
- * Based on: https://gamedev.stackexchange.com/questions/165643/how-to-calculate-the-surface-area-of-a-mesh
57
- * @param {number} x0
58
- * @param {number} y0
59
- * @param {number} z0
60
- * @param {number} x1
61
- * @param {number} y1
62
- * @param {number} z1
63
- * @param {number} x2
64
- * @param {number} y2
65
- * @param {number} z2
66
- * @returns {number}
67
- */
68
- export function computeTriangleSurfaceArea(x0, y0, z0, x1, y1, z1, x2, y2, z2) {
69
- const ax = x1 - x0;
70
- const ay = y1 - y0;
71
- const az = z1 - z0;
72
-
73
- const bx = x2 - x0;
74
- const by = y2 - y0;
75
- const bz = z2 - z0;
76
-
77
- //compute cross product
78
- const x = ay * bz - az * by;
79
- const y = az * bx - ax * bz;
80
- const z = ax * by - ay * bx;
81
-
82
- //area is equal to half-magnitude of the cross-product
83
- const magnitude = Math.sqrt(x * x + y * y + z * z);
84
-
85
- const area = magnitude / 2;
86
-
87
- return area;
88
- }
53
+ }
@@ -1,24 +1,6 @@
1
- import { DataTexture, UnsignedByteType } from "three";
2
1
  import { float2uint8 } from "../../../../../core/binary/float2uint8.js";
3
2
  import { clamp01 } from "../../../../../core/math/clamp01.js";
4
-
5
- /**
6
- *
7
- * @param contents
8
- * @param {Signal} cleanup_signal
9
- * @returns {DataTexture}
10
- */
11
- function onePixelTexture(contents, cleanup_signal) {
12
- const t = new DataTexture(new Uint8Array(contents), 1, 1);
13
-
14
- t.generateMipmaps = false;
15
- t.needsUpdate = true;
16
- t.type = UnsignedByteType;
17
-
18
- cleanup_signal.addOne(t.dispose, t);
19
-
20
- return t;
21
- }
3
+ import { makeOnePixelTexture } from "../../../texture/makeOnePixelTexture.js";
22
4
 
23
5
 
24
6
  /**
@@ -57,13 +39,13 @@ export function prepare_bake_material({
57
39
 
58
40
  if (texture_metalness === null) {
59
41
  const m = float2uint8(clamp01(source_material.metalness));
60
- texture_metalness = onePixelTexture([m, m, m, 255], cleanup_signal);
42
+ texture_metalness = makeOnePixelTexture([m, m, m, 255], cleanup_signal);
61
43
  }
62
44
 
63
45
  if (texture_roughness === null) {
64
46
  const r = float2uint8(clamp01(source_material.roughness));
65
47
 
66
- texture_roughness = onePixelTexture([r, r, r, 255], cleanup_signal);
48
+ texture_roughness = makeOnePixelTexture([r, r, r, 255], cleanup_signal);
67
49
  }
68
50
 
69
51
  } else {
@@ -74,22 +56,22 @@ export function prepare_bake_material({
74
56
 
75
57
  if (texture_diffuse === null) {
76
58
  // plug white texture
77
- texture_diffuse = onePixelTexture([255, 255, 255, 255], cleanup_signal);
59
+ texture_diffuse = makeOnePixelTexture([255, 255, 255, 255], cleanup_signal);
78
60
  }
79
61
  if (texture_roughness === null) {
80
- texture_roughness = onePixelTexture([255, 255, 255, 255], cleanup_signal);
62
+ texture_roughness = makeOnePixelTexture([255, 255, 255, 255], cleanup_signal);
81
63
  }
82
64
 
83
65
  if (texture_metalness === null) {
84
- texture_metalness = onePixelTexture([0, 0, 0, 0], cleanup_signal);
66
+ texture_metalness = makeOnePixelTexture([0, 0, 0, 0], cleanup_signal);
85
67
  }
86
68
 
87
69
  if (texture_occlusion === null) {
88
- texture_occlusion = onePixelTexture([255, 255, 255, 255], cleanup_signal);
70
+ texture_occlusion = makeOnePixelTexture([255, 255, 255, 255], cleanup_signal);
89
71
  }
90
72
 
91
73
  if (texture_emissive === null) {
92
- texture_emissive = onePixelTexture([0, 0, 0, 0], cleanup_signal);
74
+ texture_emissive = makeOnePixelTexture([0, 0, 0, 0], cleanup_signal);
93
75
  }
94
76
 
95
77
  // set rendering parameters on textures
@@ -0,0 +1,6 @@
1
+ import {Material} from "three";
2
+ import {Reference} from "../../../reference/v2/Reference";
3
+
4
+ export class MaterialManager{
5
+ obtain(source:Material):Reference<Material>
6
+ }
@@ -3,6 +3,7 @@ import {
3
3
  LinearEncoding,
4
4
  LinearFilter,
5
5
  LineBasicMaterial,
6
+ MeshStandardMaterial,
6
7
  RGBAFormat,
7
8
  Scene,
8
9
  WebGLCubeRenderTarget
@@ -19,6 +20,9 @@ import {
19
20
  } from "../../../core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js";
20
21
  import { TetrahedralMesh } from "../../../core/geom/3d/tetrahedra/TetrahedralMesh.js";
21
22
  import { v3_length_sqr } from "../../../core/geom/vec3/v3_length_sqr.js";
23
+ import TaskGroup from "../../../core/process/task/TaskGroup.js";
24
+ import { actionTask } from "../../../core/process/task/util/actionTask.js";
25
+ import { countTask } from "../../../core/process/task/util/countTask.js";
22
26
  import Entity from "../../ecs/Entity.js";
23
27
  import { Transform } from "../../ecs/transform/Transform.js";
24
28
  import { threeMakeLight } from "../ecs/light/binding/three/threeMakeLight.js";
@@ -229,15 +233,15 @@ class CubeRenderer {
229
233
  const source_material = sg.material;
230
234
 
231
235
  //
232
- // if (source_material.isMeshStandardMaterial === true) {
233
- // object3D.material = new MeshStandardMaterial({
234
- // map: source_material.map,
235
- // });
236
- //
237
- // object3D.material.color.copy(source_material.color);
238
- // } else {
239
- object3D.material = source_material.clone();
240
- // }
236
+ if (source_material.isMeshStandardMaterial === true) {
237
+ object3D.material = new MeshStandardMaterial({
238
+ map: source_material.map,
239
+ });
240
+
241
+ object3D.material.color.copy(source_material.color);
242
+ } else {
243
+ object3D.material = source_material.clone();
244
+ }
241
245
 
242
246
  applyTransformToThreeObject(object3D, t);
243
247
 
@@ -507,30 +511,46 @@ export class LightProbeVolume {
507
511
  /**
508
512
  * Bake light probes
509
513
  * @param {Engine} engine
514
+ * @returns {TaskGroup}
510
515
  */
511
516
  bake(engine) {
512
517
  const baker = new Baker();
513
518
  // baker.set_bvh(entityManager.getSystem(ShadedGeometrySystem).__bvh_binary);
514
519
 
515
- baker.prepare(engine);
516
520
 
517
- const t0 = performance.now();
521
+ const tPrepare = actionTask(() => {
522
+ baker.prepare(engine);
523
+ });
518
524
 
519
525
 
520
- for (let i = 0; i < this.__length; i++) {
526
+ const probe_count = this.__length;
527
+ const tBake = countTask(0, probe_count, (i) => {
521
528
 
522
529
  baker.bake_sh3_cube(
523
530
  this.__positions, i * 3,
524
531
  this.__probe_data, i * 9 * 3
525
532
  );
526
533
 
527
- }
534
+ });
528
535
 
529
- const t1 = performance.now();
536
+ tBake.promise().then(()=>{
537
+
538
+ const duration =tBake.__executedCpuTime;
539
+
540
+ console.log(`Baked ${probe_count} probes in ${duration}ms, ~${(duration / probe_count).toFixed(2)}ms per probe`);
541
+
542
+ })
543
+
544
+ const tFinish = actionTask(() => {
545
+ baker.finish();
546
+ });
530
547
 
531
- console.log(`Baked ${this.__length} probes in ${(t1 - t0)}ms, ~${((t1 - t0) / this.__length).toFixed(2)}ms per probe`);
548
+ tFinish.addDependency(tBake);
549
+ tBake.addDependency(tPrepare);
532
550
 
533
- baker.finish();
551
+ return new TaskGroup([
552
+ tPrepare, tBake, tFinish
553
+ ]);
534
554
  }
535
555
 
536
556
  /**
@@ -580,9 +600,10 @@ export class LightProbeVolume {
580
600
  /**
581
601
  *
582
602
  * @param {Engine} engine
603
+ * @returns {TaskGroup}
583
604
  */
584
605
  build(engine) {
585
606
  this.build_mesh();
586
- this.bake(engine);
607
+ return this.bake(engine);
587
608
  }
588
609
  }