@woosh/meep-engine 2.39.7 → 2.39.11

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.
@@ -1,4 +1,5 @@
1
1
  import { v3_dot } from "../../v3_dot.js";
2
+ import { assert } from "../../../assert.js";
2
3
 
3
4
  /**
4
5
  * NOTE: adapted from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
@@ -29,6 +30,44 @@ export function computeTriangleRayIntersection(
29
30
  bx, by, bz,
30
31
  cx, cy, cz
31
32
  ) {
33
+ assert.isNumber(ax,'ax');
34
+ assert.isNumber(ay,'ay');
35
+ assert.isNumber(az,'az');
36
+
37
+ assert.isNumber(bx,'bx');
38
+ assert.isNumber(by,'by');
39
+ assert.isNumber(bz,'bz');
40
+
41
+ assert.isNumber(cx,'cx');
42
+ assert.isNumber(cy,'cy');
43
+ assert.isNumber(cz,'cz');
44
+
45
+ // nan checks
46
+ assert.notNaN(ax,'ax');
47
+ assert.notNaN(ay,'ay');
48
+ assert.notNaN(az,'az');
49
+
50
+ assert.notNaN(bx,'bx');
51
+ assert.notNaN(by,'by');
52
+ assert.notNaN(bz,'bz');
53
+
54
+ assert.notNaN(cx,'cx');
55
+ assert.notNaN(cy,'cy');
56
+ assert.notNaN(cz,'cz');
57
+
58
+ // finate number check
59
+ assert.isFiniteNumber(ax,'ax');
60
+ assert.isFiniteNumber(ay,'ay');
61
+ assert.isFiniteNumber(az,'az');
62
+
63
+ assert.isFiniteNumber(bx,'bx');
64
+ assert.isFiniteNumber(by,'by');
65
+ assert.isFiniteNumber(bz,'bz');
66
+
67
+ assert.isFiniteNumber(cx,'cx');
68
+ assert.isFiniteNumber(cy,'cy');
69
+ assert.isFiniteNumber(cz,'cz');
70
+
32
71
 
33
72
  // edge1 = a - b
34
73
  const edge1_x = bx - ax;
package/engine/Engine.js CHANGED
@@ -514,8 +514,4 @@ class Engine {
514
514
  */
515
515
  Engine.prototype.isEngine = true;
516
516
 
517
- function printError(reason) {
518
- logger.error(reason);
519
- }
520
-
521
517
  export default Engine;
@@ -0,0 +1,10 @@
1
+ import Engine from "../../../Engine";
2
+ import {Texture} from "three";
3
+
4
+ export default class Terrain {
5
+ fromJSON(json: any, engine: Engine): void;
6
+
7
+ toJSON(): any
8
+
9
+ buildLightMap(quality: number): Promise<Texture>
10
+ }
@@ -1,7 +1,8 @@
1
1
  import {System} from "../../System";
2
2
  import {GraphicsEngine} from "../../../graphics/GraphicsEngine";
3
3
  import {AssetManager} from "../../../asset/AssetManager";
4
+ import Terrain from "./Terrain";
4
5
 
5
- export default class TerrainSystem extends System {
6
+ export default class TerrainSystem extends System<Terrain> {
6
7
  constructor(graphics: GraphicsEngine, assetManager: AssetManager)
7
8
  }
@@ -23,6 +23,9 @@ export const ProjectionType = {
23
23
  Orthographic: "orthographic"
24
24
  };
25
25
 
26
+ /**
27
+ * @class
28
+ */
26
29
  export class Camera {
27
30
  constructor() {
28
31
  /**
@@ -176,7 +179,7 @@ export class Camera {
176
179
  // assert.ok(y >= -1, `Y(=${y}) must be greater than or equal to -1.0, not a clip-space coordinate`);
177
180
  // assert.ok(y <= 1, `Y(=${y}) must be less than or equal to 1.0, not a clip-space coordinate`);
178
181
 
179
- if (camera.isPerspectiveCamera) {
182
+ if (camera.isPerspectiveCamera || camera.isOrthographicCamera) {
180
183
  scratch_v3_1.setFromMatrixPosition(camera.matrixWorld.elements);
181
184
 
182
185
  scratch_v3_0.set(x, y, 0.5);
@@ -197,9 +200,7 @@ export class Camera {
197
200
  source.copy(scratch_v3_1);
198
201
  direction.copy(scratch_v3_0);
199
202
 
200
- } else if (camera.isOrthographicCamera) {
201
- throw new Error('Unsupported camera type: "Orthographic" ');
202
- } else {
203
+ } else {
203
204
  throw new Error('Unsupported camera type');
204
205
  }
205
206
  }
@@ -70,6 +70,7 @@ import { BasicMaterialDefinition } from "./tube/BasicMaterialDefinition.js";
70
70
  import '../../../../../../../css/game.scss';
71
71
  import { GizmoRenderingPlugin } from "../../render/gizmo/GizmoRenderingPlugin.js";
72
72
  import { PathNormalType } from "./tube/PathNormalType.js";
73
+ import { Camera, ProjectionType } from "../camera/Camera.js";
73
74
 
74
75
  const engineHarness = new EngineHarness();
75
76
 
@@ -427,6 +428,11 @@ function makePath({
427
428
  function main(engine) {
428
429
  EngineHarness.buildBasics({ engine });
429
430
 
431
+ const ecd = engine.entityManager.dataset;
432
+
433
+ const cam = ecd.getAnyComponent(Camera);
434
+ // cam.component.projectionType.set(ProjectionType.Orthographic);
435
+
430
436
  makePath({
431
437
  points: [
432
438
  3, 1, 1,
@@ -437,7 +443,7 @@ function main(engine) {
437
443
  3, 1, 8
438
444
  ],
439
445
  interp: InterpolationType.Linear
440
- }).build(engine.entityManager.dataset);
446
+ }).build(ecd);
441
447
 
442
448
  makePath({
443
449
  points: [
@@ -447,7 +453,7 @@ function main(engine) {
447
453
  16.719999313354492, 3.130000114440918, -6.889999866485596
448
454
  ],
449
455
  interp: InterpolationType.Linear
450
- }).build(engine.entityManager.dataset);
456
+ }).build(ecd);
451
457
  }
452
458
 
453
459
  init(engineHarness);
@@ -116,6 +116,23 @@ export class TubePathStyle {
116
116
  return r;
117
117
  }
118
118
 
119
+ /**
120
+ *
121
+ * @param {string|{r:number,g:number,b:number}} color
122
+ * @param material_type
123
+ * @param material
124
+ * @param opacity
125
+ * @param width
126
+ * @param radial_resolution
127
+ * @param resolution
128
+ * @param cast_shadow
129
+ * @param receive_shadow
130
+ * @param path_mask
131
+ * @param cap_type
132
+ * @param shape
133
+ * @param path_normal
134
+ * @param path_normal_type
135
+ */
119
136
  fromJSON({
120
137
  color = DEFAULT_COLOR,
121
138
  material_type,
@@ -148,7 +165,7 @@ export class TubePathStyle {
148
165
  assert.greaterThanOrEqual(path_mask.length, 2, 'path_mask length bust be at least 2');
149
166
  assert.ok(path_mask.length % 2 === 0, 'path_mask length bust be multiple of 2');
150
167
  assert.enum(cap_type, CapType, 'cap_type');
151
- assert.enum(path_normal_type, 'path_normal_type');
168
+ assert.enum(path_normal_type, PathNormalType, 'path_normal_type');
152
169
 
153
170
  if (shape === undefined) {
154
171
  // legacy API, using circle
@@ -4,6 +4,7 @@ import Vector3 from "../../../../../core/geom/Vector3.js";
4
4
  import { computeTriangleRayIntersection } from "../../../../../core/geom/3d/triangle/computeTriangleRayIntersection.js";
5
5
  import { GeometrySpatialAcceleratorVisitor } from "./GeometryVisitor.js";
6
6
  import { aabb3_intersects_ray } from "../../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
7
+ import { assert } from "../../../../../core/assert.js";
7
8
 
8
9
  export class RaycastNearestHitComputingVisitor extends GeometrySpatialAcceleratorVisitor {
9
10
  constructor() {
@@ -18,14 +19,14 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
18
19
  this.__nearest_distance = Number.POSITIVE_INFINITY;
19
20
 
20
21
  /**
21
- *
22
+ * @readonly
22
23
  * @type {SurfacePoint3}
23
24
  * @private
24
25
  */
25
26
  this.__nearest_hit = new SurfacePoint3();
26
27
 
27
28
  /**
28
- *
29
+ * @readonly
29
30
  * @type {SurfacePoint3}
30
31
  * @private
31
32
  */
@@ -39,7 +40,18 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
39
40
  */
40
41
  this.__hit_found = false;
41
42
 
43
+ /**
44
+ * @readonly
45
+ * @type {Vector3}
46
+ * @private
47
+ */
42
48
  this.__ray_origin = new Vector3();
49
+
50
+ /**
51
+ * @readonly
52
+ * @type {Vector3}
53
+ * @private
54
+ */
43
55
  this.__ray_direction = new Vector3();
44
56
  }
45
57
 
@@ -98,6 +110,8 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
98
110
 
99
111
  const indices = this.__buffer_indices;
100
112
 
113
+ assert.lessThan(index3 + 2, indices.length, 'triangle index overflow, possibly geometry changed but tree was not rebuilt?');
114
+
101
115
  const a = indices[index3];
102
116
  const b = indices[index3 + 1];
103
117
  const c = indices[index3 + 2];
@@ -111,6 +125,10 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
111
125
  const b_address = b * stride + offset;
112
126
  const c_address = c * stride + offset;
113
127
 
128
+ assert.lessThan(a_address + 2, vertices.length, 'a-vertex overflow');
129
+ assert.lessThan(b_address + 2, vertices.length, 'b-vertex overflow');
130
+ assert.lessThan(c_address + 2, vertices.length, 'c-vertex overflow');
131
+
114
132
  const ax = vertices[a_address];
115
133
  const ay = vertices[a_address + 1];
116
134
  const az = vertices[a_address + 2];
@@ -123,8 +141,10 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
123
141
  const cy = vertices[c_address + 1];
124
142
  const cz = vertices[c_address + 2];
125
143
 
144
+ const temp_hit = this.__temp_hit;
145
+
126
146
  if (computeTriangleRayIntersection(
127
- this.__temp_hit,
147
+ temp_hit,
128
148
  rayOrigin.x,
129
149
  rayOrigin.y,
130
150
  rayOrigin.z,
@@ -135,10 +155,10 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
135
155
  bx, by, bz,
136
156
  cx, cy, cz
137
157
  )) {
138
- const d = this.__temp_hit.position.distanceSqrTo(rayOrigin);
158
+ const d = temp_hit.position.distanceSqrTo(rayOrigin);
139
159
 
140
160
  if (d < this.__nearest_distance) {
141
- this.__nearest_hit.copy(this.__temp_hit);
161
+ this.__nearest_hit.copy(temp_hit);
142
162
  this.__nearest_distance = d;
143
163
 
144
164
  this.__hit_found = true;
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.39.7",
8
+ "version": "2.39.11",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",