@woosh/meep-engine 2.43.32 → 2.43.34
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.
- package/core/geom/3d/line/line3_compute_nearest_point_to_point.js +36 -0
- package/core/geom/Quaternion.d.ts +2 -0
- package/engine/graphics/render/Lines.js +122 -0
- package/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +7 -2
- package/engine/graphics/render/gizmo/prototypeGizmo.js +29 -0
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { v3_dot } from "../../v3_dot.js";
|
|
2
|
+
import { clamp01 } from "../../../math/clamp01.js";
|
|
3
|
+
|
|
4
|
+
export function line3_compute_nearest_point_to_point(
|
|
5
|
+
result, result_offset,
|
|
6
|
+
ax, ay, az,
|
|
7
|
+
bx, by, bz,
|
|
8
|
+
ref_x, ref_y, ref_z
|
|
9
|
+
) {
|
|
10
|
+
|
|
11
|
+
const direction_x = bx - ax;
|
|
12
|
+
const direction_y = by - ay;
|
|
13
|
+
const direction_z = bz - az;
|
|
14
|
+
|
|
15
|
+
// find closest point
|
|
16
|
+
const sp0_x = ref_x - ax;
|
|
17
|
+
const sp0_y = ref_y - ay;
|
|
18
|
+
const sp0_z = ref_z - az;
|
|
19
|
+
|
|
20
|
+
//
|
|
21
|
+
const d2 = v3_dot(direction_x, direction_y, direction_z, direction_x, direction_y, direction_z);
|
|
22
|
+
const d3 = v3_dot(direction_x, direction_y, direction_z, sp0_x, sp0_y, sp0_z);
|
|
23
|
+
|
|
24
|
+
const t = d3 / d2;
|
|
25
|
+
|
|
26
|
+
const t_clamped = clamp01(t);
|
|
27
|
+
|
|
28
|
+
// compute point on the line
|
|
29
|
+
const lp_x = direction_x * t_clamped + ax;
|
|
30
|
+
const lp_y = direction_y * t_clamped + ay;
|
|
31
|
+
const lp_z = direction_z * t_clamped + az;
|
|
32
|
+
|
|
33
|
+
result[result_offset + 0] = lp_x;
|
|
34
|
+
result[result_offset + 1] = lp_y;
|
|
35
|
+
result[result_offset + 2] = lp_z;
|
|
36
|
+
}
|
|
@@ -21,6 +21,8 @@ export default class Quaternion {
|
|
|
21
21
|
copy(other: ThreeQuaternion): void
|
|
22
22
|
copy(other: { x: number, y: number, z: number, w: number }): void
|
|
23
23
|
|
|
24
|
+
clone():Quaternion
|
|
25
|
+
|
|
24
26
|
equals(other: { x: number, y: number, z: number, w: number }): boolean
|
|
25
27
|
|
|
26
28
|
slerp(other: Quaternion, t: number): void
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { DynamicDrawUsage, LineBasicMaterial, LineSegments } from "three";
|
|
2
|
+
import { array_copy } from "../../../core/collection/array/copyArray.js";
|
|
3
|
+
import { BufferGeometry } from "three/src/core/BufferGeometry.js";
|
|
4
|
+
import { Float32BufferAttribute } from "three/src/core/BufferAttribute.js";
|
|
5
|
+
|
|
6
|
+
function buildGeometry(capacity) {
|
|
7
|
+
const geometry = new BufferGeometry();
|
|
8
|
+
|
|
9
|
+
geometry.dynamic = true;
|
|
10
|
+
// no index
|
|
11
|
+
|
|
12
|
+
const attribute_position = new Float32BufferAttribute(capacity * 3 * 2, 3, false);
|
|
13
|
+
const attribute_color = new Float32BufferAttribute(capacity * 4 * 2, 4, false);
|
|
14
|
+
|
|
15
|
+
attribute_position.setUsage(DynamicDrawUsage);
|
|
16
|
+
attribute_color.setUsage(DynamicDrawUsage);
|
|
17
|
+
|
|
18
|
+
geometry.setAttribute('position', attribute_position);
|
|
19
|
+
geometry.setAttribute('color', attribute_color);
|
|
20
|
+
|
|
21
|
+
return geometry;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class Lines {
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
this.count = 0;
|
|
28
|
+
this.capacity = 64;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @type {BufferGeometry|null}
|
|
33
|
+
*/
|
|
34
|
+
this.geometry = buildGeometry(this.capacity);
|
|
35
|
+
|
|
36
|
+
this.mesh = new LineSegments(this.geometry, new LineBasicMaterial());
|
|
37
|
+
|
|
38
|
+
// disable automatic culling/updates
|
|
39
|
+
this.mesh.matrixAutoUpdate = false;
|
|
40
|
+
this.mesh.frustumCulled = false;
|
|
41
|
+
this.mesh.matrixWorldNeedsUpdate = false;
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param {number} x
|
|
48
|
+
*/
|
|
49
|
+
setCount(x) {
|
|
50
|
+
this.ensure_capacity(x);
|
|
51
|
+
|
|
52
|
+
this.count = x;
|
|
53
|
+
this.geometry.drawRange.count = x * 6;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param {number} x
|
|
59
|
+
*/
|
|
60
|
+
ensure_capacity(x) {
|
|
61
|
+
if (this.capacity >= x) {
|
|
62
|
+
// enough capacity
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.capacity = x;
|
|
67
|
+
|
|
68
|
+
this.build();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @param {vec3} from
|
|
74
|
+
* @param {vec3} to
|
|
75
|
+
* @param {vec4} color
|
|
76
|
+
*/
|
|
77
|
+
add_line(from, to, color) {
|
|
78
|
+
const index = this.count;
|
|
79
|
+
|
|
80
|
+
this.setCount(index + 1);
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
const position_attribute = this.geometry.getAttribute('position');
|
|
84
|
+
const color_attribute = this.geometry.getAttribute('color');
|
|
85
|
+
|
|
86
|
+
const position_array = position_attribute.array;
|
|
87
|
+
|
|
88
|
+
array_copy(from, 0, position_array, index * 6, 3);
|
|
89
|
+
array_copy(to, 0, position_array, index * 6 + 3, 3);
|
|
90
|
+
|
|
91
|
+
const color_array = color_attribute.array;
|
|
92
|
+
|
|
93
|
+
array_copy(color, 0, color_array, index * 8, 4);
|
|
94
|
+
array_copy(color, 0, color_array, index * 8 + 4, 4);
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
this.geometry.drawRange.count = this.count;
|
|
98
|
+
|
|
99
|
+
//
|
|
100
|
+
position_attribute.needsUpdate = true;
|
|
101
|
+
color_attribute.needsUpdate = true;
|
|
102
|
+
|
|
103
|
+
console.warn('feature not fully implemented');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
build() {
|
|
107
|
+
|
|
108
|
+
const geometry = buildGeometry(this.capacity);
|
|
109
|
+
|
|
110
|
+
// TODO copy existing attribute values
|
|
111
|
+
|
|
112
|
+
this.geometry = geometry;
|
|
113
|
+
|
|
114
|
+
this.mesh.geometry = geometry;
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
dispose() {
|
|
119
|
+
this.geometry.dispose();
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -8,6 +8,7 @@ import Quaternion from "../../../../core/geom/Quaternion.js";
|
|
|
8
8
|
import { makeHelperBoxGeometry } from "../../../../editor/process/symbolic/makeHelperBoxGeometry.js";
|
|
9
9
|
import { DrawMode } from "../../ecs/mesh-v2/DrawMode.js";
|
|
10
10
|
import { makeHelperSphereGeometry } from "../../../../editor/process/symbolic/makeHelperSphereGeometry.js";
|
|
11
|
+
import { Lines } from "../Lines.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
@@ -55,6 +56,9 @@ export class GizmoShapeRenderingInterface {
|
|
|
55
56
|
this.__sphere_wire = InstancedMeshGroup.from(makeHelperSphereGeometry(), new LineBasicMaterial());
|
|
56
57
|
|
|
57
58
|
this.__sphere_wire.draw_mode = DrawMode.Lines;
|
|
59
|
+
|
|
60
|
+
// lines are handles different because they are relatively simple and require 2 archor points
|
|
61
|
+
this.__lines = new Lines();
|
|
58
62
|
}
|
|
59
63
|
|
|
60
64
|
__get_groups() {
|
|
@@ -62,7 +66,8 @@ export class GizmoShapeRenderingInterface {
|
|
|
62
66
|
this.__boxes_wire,
|
|
63
67
|
this.__boxes_solid,
|
|
64
68
|
this.__sphere_wire,
|
|
65
|
-
this.__sphere_solid
|
|
69
|
+
this.__sphere_solid,
|
|
70
|
+
this.__lines
|
|
66
71
|
];
|
|
67
72
|
}
|
|
68
73
|
|
|
@@ -131,7 +136,7 @@ export class GizmoShapeRenderingInterface {
|
|
|
131
136
|
* @param {number[]} to
|
|
132
137
|
*/
|
|
133
138
|
draw_line(from, to) {
|
|
134
|
-
|
|
139
|
+
this.__lines.add_line(from, to, this.__color);
|
|
135
140
|
}
|
|
136
141
|
|
|
137
142
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../EngineHarness.js";
|
|
2
|
+
import { GizmoRenderingPlugin } from "./GizmoRenderingPlugin.js";
|
|
3
|
+
import { Gizmo } from "./Gizmo.js";
|
|
4
|
+
|
|
5
|
+
const harness = new EngineHarness();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {Engine} engine
|
|
10
|
+
* @return {Promise<void>}
|
|
11
|
+
*/
|
|
12
|
+
async function main(engine) {
|
|
13
|
+
await EngineHarness.buildBasics({
|
|
14
|
+
engine
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
engine.graphics.on.preRender.add(()=>{
|
|
19
|
+
Gizmo.draw_line([0,0,0],[10,10,10]);
|
|
20
|
+
|
|
21
|
+
Gizmo.draw_wire_sphere([1,1,1],2);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
harness.initialize({
|
|
26
|
+
configuration(config, engine) {
|
|
27
|
+
config.addPlugin(GizmoRenderingPlugin);
|
|
28
|
+
}
|
|
29
|
+
}).then(main);
|
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.
|
|
8
|
+
"version": "2.43.34",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|