@needle-tools/engine 2.55.1-pre → 2.55.2-pre
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/CHANGELOG.md +6 -0
- package/dist/needle-engine.d.ts +140 -132
- package/dist/needle-engine.js +355 -355
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +20 -20
- package/dist/needle-engine.min.js.map +4 -4
- package/dist/needle-engine.tsbuildinfo +1 -1
- package/lib/engine/engine_gizmos.d.ts +2 -0
- package/lib/engine/engine_gizmos.js +24 -1
- package/lib/engine/engine_gizmos.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +1 -0
- package/lib/engine/engine_physics.js +5 -2
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_setup.js +7 -1
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_time.js +3 -3
- package/lib/engine/engine_time.js.map +1 -1
- package/lib/engine/engine_types.d.ts +1 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine-components/Camera.js +2 -0
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CameraUtils.d.ts +2 -2
- package/lib/engine-components/CameraUtils.js +13 -4
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +4 -0
- package/lib/engine-components/RigidBody.js +16 -0
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/engine/codegen/register_types.js +2 -2
- package/src/engine/engine_gizmos.ts +27 -2
- package/src/engine/engine_physics.ts +5 -4
- package/src/engine/engine_setup.ts +9 -4
- package/src/engine/engine_time.ts +2 -2
- package/src/engine/engine_types.ts +1 -0
- package/src/engine-components/Camera.ts +2 -0
- package/src/engine-components/CameraUtils.ts +15 -5
- package/src/engine-components/RigidBody.ts +22 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/engine",
|
|
3
|
-
"version": "2.55.
|
|
3
|
+
"version": "2.55.2-pre",
|
|
4
4
|
"description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development, and can be deployed anywhere. It is flexible, extensible, and collaboration and XR come naturally.",
|
|
5
5
|
"main": "dist/needle-engine.js",
|
|
6
6
|
"module": "src/needle-engine.ts",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TypeStore } from "./../engine_typestore"
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
// Import types
|
|
4
4
|
import { __Ignore } from "../../engine-components/codegen/components.ts";
|
|
5
5
|
import { AlignmentConstraint } from "../../engine-components/AlignmentConstraint.ts";
|
|
@@ -172,7 +172,7 @@ import { XRGrabModel } from "../../engine-components/WebXRGrabRendering.ts";
|
|
|
172
172
|
import { XRGrabRendering } from "../../engine-components/WebXRGrabRendering.ts";
|
|
173
173
|
import { XRRig } from "../../engine-components/WebXRRig.ts";
|
|
174
174
|
import { XRState } from "../../engine-components/XRFlag.ts";
|
|
175
|
-
|
|
175
|
+
|
|
176
176
|
// Register types
|
|
177
177
|
TypeStore.add("__Ignore", __Ignore);
|
|
178
178
|
TypeStore.add("AlignmentConstraint", AlignmentConstraint);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import { BufferAttribute, Line, BoxGeometry, EdgesGeometry, Color, LineSegments, LineBasicMaterial, Object3D, Mesh, SphereGeometry, ColorRepresentation, Vector3, Box3, Quaternion } from 'three';
|
|
2
|
+
import { BufferAttribute, Line, BoxGeometry, EdgesGeometry, Color, LineSegments, LineBasicMaterial, Object3D, Mesh, SphereGeometry, ColorRepresentation, Vector3, Box3, Quaternion, CylinderGeometry } from 'three';
|
|
3
3
|
import { Context } from './engine_setup';
|
|
4
4
|
import { setWorldPosition, setWorldPositionXYZ } from './engine_three_utils';
|
|
5
5
|
import { Vec3, Vec4 } from './engine_types';
|
|
6
6
|
|
|
7
7
|
const _tmp = new Vector3();
|
|
8
|
+
const _tmp2 = new Vector3();
|
|
8
9
|
const _quat = new Quaternion();
|
|
9
10
|
|
|
10
11
|
const defaultColor: ColorRepresentation = 0x888888;
|
|
@@ -76,7 +77,7 @@ export class Gizmos {
|
|
|
76
77
|
obj.material["wireframe"] = true;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
static DrawBox3(box:Box3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
|
|
80
|
+
static DrawBox3(box: Box3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
|
|
80
81
|
const obj = Internal.getBox(duration);
|
|
81
82
|
obj.position.copy(box.getCenter(_tmp));
|
|
82
83
|
obj.scale.copy(box.getSize(_tmp));
|
|
@@ -84,6 +85,20 @@ export class Gizmos {
|
|
|
84
85
|
obj.material["depthTest"] = depthTest;
|
|
85
86
|
obj.material["wireframe"] = true;
|
|
86
87
|
}
|
|
88
|
+
|
|
89
|
+
private static _up = new Vector3(0, 1, 0);
|
|
90
|
+
static DrawArrow(pt0: Vec3, pt1: Vec3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true, wireframe: boolean = false) {
|
|
91
|
+
const obj = Internal.getArrowHead(duration);
|
|
92
|
+
obj.position.set(pt1.x, pt1.y, pt1.z);
|
|
93
|
+
obj.quaternion.setFromUnitVectors(this._up.set(0, 1, 0), _tmp.set(pt1.x, pt1.y, pt1.z).sub(_tmp2.set(pt0.x, pt0.y, pt0.z)).normalize());
|
|
94
|
+
const dist = _tmp.set(pt1.x, pt1.y, pt1.z).sub(_tmp2.set(pt0.x, pt0.y, pt0.z)).length();
|
|
95
|
+
const scale = dist * 0.1;
|
|
96
|
+
obj.scale.set(scale, scale, scale);
|
|
97
|
+
obj.material["color"].set(color);
|
|
98
|
+
obj.material["depthTest"] = depthTest;
|
|
99
|
+
obj.material["wireframe"] = wireframe;
|
|
100
|
+
this.DrawLine(pt0, pt1, color, duration, depthTest);
|
|
101
|
+
}
|
|
87
102
|
}
|
|
88
103
|
|
|
89
104
|
const box: BoxGeometry = new BoxGeometry(1, 1, 1);
|
|
@@ -141,9 +156,19 @@ class Internal {
|
|
|
141
156
|
return sphere;
|
|
142
157
|
}
|
|
143
158
|
|
|
159
|
+
static getArrowHead(duration: number): Mesh {
|
|
160
|
+
let arrowHead = this.arrowHeadsCache.pop();
|
|
161
|
+
if (!arrowHead) {
|
|
162
|
+
arrowHead = new Mesh(new CylinderGeometry(0, .5, 1, 8));
|
|
163
|
+
}
|
|
164
|
+
this.registerTimedObject(Context.Current, arrowHead, duration, this.arrowHeadsCache);
|
|
165
|
+
return arrowHead;
|
|
166
|
+
}
|
|
167
|
+
|
|
144
168
|
private static linesCache: Array<Line> = [];
|
|
145
169
|
private static spheresCache: Mesh[] = [];
|
|
146
170
|
private static boxesCache: Mesh[] = [];
|
|
171
|
+
private static arrowHeadsCache: Mesh[] = [];
|
|
147
172
|
|
|
148
173
|
private static registerTimedObject(context: Context, object: Object3D, duration: number, cache: Array<Object3D>) {
|
|
149
174
|
if (!this.contextPostRenderCallbacks.get(context)) {
|
|
@@ -386,10 +386,11 @@ export class Physics {
|
|
|
386
386
|
this._meshCache.set(key, scaledPositions);
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
|
-
|
|
390
389
|
const desc = convex ? ColliderDesc.convexMesh(positions) : ColliderDesc.trimesh(positions, indices);
|
|
391
390
|
if (desc) {
|
|
392
|
-
this.createCollider(collider, desc);
|
|
391
|
+
const col = this.createCollider(collider, desc);
|
|
392
|
+
col.setMassProperties(1, { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 0, w: 1 });
|
|
393
|
+
// rb?.setTranslation({ x: 0, y: 2, z: 0 });
|
|
393
394
|
// col.setTranslationWrtParent(new Vector3(0,2,0));
|
|
394
395
|
|
|
395
396
|
}
|
|
@@ -593,7 +594,7 @@ export class Physics {
|
|
|
593
594
|
rigidbody.enableCcd(rb.collisionDetectionMode !== CollisionDetectionMode.Discrete);
|
|
594
595
|
rigidbody.setLinearDamping(rb.drag);
|
|
595
596
|
rigidbody.setAngularDamping(rb.angularDrag);
|
|
596
|
-
rigidbody.setGravityScale(rb.useGravity ?
|
|
597
|
+
rigidbody.setGravityScale(rb.useGravity ? rb.gravityScale : 0, true);
|
|
597
598
|
|
|
598
599
|
// https://rapier.rs/docs/user_guides/javascript/rigid_bodies#mass-properties
|
|
599
600
|
// rigidbody.setAdditionalMass(rb.mass, true);
|
|
@@ -807,7 +808,7 @@ export class Physics {
|
|
|
807
808
|
}
|
|
808
809
|
|
|
809
810
|
|
|
810
|
-
|
|
811
|
+
/** The joint prevents any relative movement between two rigid-bodies, except for relative rotations along one axis. This is typically used to simulate wheels, fans, etc. They are characterized by one local anchor as well as one local axis on each rigid-body. */
|
|
811
812
|
addHingeJoint(body1: IRigidbody, body2: IRigidbody, anchor: { x: number, y: number, z: number }, axis: { x: number, y: number, z: number }) {
|
|
812
813
|
if (!this.world) {
|
|
813
814
|
console.error("Physics world not initialized");
|
|
@@ -26,6 +26,7 @@ import { PlayerViewManager } from './engine_playerview';
|
|
|
26
26
|
|
|
27
27
|
import { ICamera, IComponent, ILight } from "./engine_types"
|
|
28
28
|
import { destroy, foreachComponent } from './engine_gameobject';
|
|
29
|
+
import { createCameraWithOrbitControl } from '../engine-components/CameraUtils';
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
const debug = utils.getParam("debugSetup");
|
|
@@ -147,12 +148,12 @@ export class Context {
|
|
|
147
148
|
|
|
148
149
|
get domWidth(): number {
|
|
149
150
|
// for mozilla XR
|
|
150
|
-
if(this.isInAR) return window.innerWidth;
|
|
151
|
+
if (this.isInAR) return window.innerWidth;
|
|
151
152
|
return this.domElement.clientWidth;
|
|
152
153
|
}
|
|
153
154
|
get domHeight(): number {
|
|
154
155
|
// for mozilla XR
|
|
155
|
-
if(this.isInAR) return window.innerHeight;
|
|
156
|
+
if (this.isInAR) return window.innerHeight;
|
|
156
157
|
return this.domElement.clientHeight;
|
|
157
158
|
}
|
|
158
159
|
get domX(): number {
|
|
@@ -543,6 +544,8 @@ export class Context {
|
|
|
543
544
|
foreachComponent(this.scene, comp => {
|
|
544
545
|
const cam = comp as ICamera;
|
|
545
546
|
if (cam?.isCamera) {
|
|
547
|
+
looputils.updateActiveInHierarchyWithoutEventCall(cam.gameObject);
|
|
548
|
+
if (!cam.activeAndEnabled) return undefined;
|
|
546
549
|
if (cam.tag === "MainCamera") {
|
|
547
550
|
camera = cam;
|
|
548
551
|
return true;
|
|
@@ -554,8 +557,10 @@ export class Context {
|
|
|
554
557
|
if (camera) {
|
|
555
558
|
this.setCurrentCamera(camera);
|
|
556
559
|
}
|
|
557
|
-
else
|
|
560
|
+
else {
|
|
558
561
|
console.error("MISSING camera", this);
|
|
562
|
+
createCameraWithOrbitControl(this.scene, "unknown");
|
|
563
|
+
}
|
|
559
564
|
}
|
|
560
565
|
|
|
561
566
|
Context._current = this;
|
|
@@ -738,7 +743,7 @@ export class Context {
|
|
|
738
743
|
private onHandlePaused(): boolean {
|
|
739
744
|
const paused = this.evaluatePaused();
|
|
740
745
|
if (this._wasPaused !== paused) {
|
|
741
|
-
if(debugActive) console.log("Paused?", paused, "context:" + this.alias);
|
|
746
|
+
if (debugActive) console.log("Paused?", paused, "context:" + this.alias);
|
|
742
747
|
for (let i = 0; i < this.scripts_pausedChanged.length; i++) {
|
|
743
748
|
const script = this.scripts_pausedChanged[i];
|
|
744
749
|
if (!script.activeAndEnabled) continue;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Clock } from 'three'
|
|
2
2
|
import { getParam } from './engine_utils';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const timescaleUrl = getParam("timescale");
|
|
5
5
|
let timeScale = 1;
|
|
6
|
-
if(typeof
|
|
6
|
+
if(typeof timescaleUrl === "number") timeScale = timescaleUrl;
|
|
7
7
|
|
|
8
8
|
export class Time {
|
|
9
9
|
|
|
@@ -230,10 +230,12 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
230
230
|
else if (!this.orthographic) {
|
|
231
231
|
cam = new PerspectiveCamera(this.fieldOfView, window.innerWidth / window.innerHeight, this._nearClipPlane, this._farClipPlane);
|
|
232
232
|
cam.fov = this.fieldOfView;
|
|
233
|
+
this.gameObject.add(cam);
|
|
233
234
|
}
|
|
234
235
|
else {
|
|
235
236
|
const factor = this.orthographicSize * 100;
|
|
236
237
|
cam = new OrthographicCamera(window.innerWidth / -factor, window.innerWidth / factor, window.innerHeight / factor, window.innerHeight / -factor, this._nearClipPlane, this._farClipPlane);
|
|
238
|
+
this.gameObject.add(cam);
|
|
237
239
|
}
|
|
238
240
|
this._cam = cam;
|
|
239
241
|
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { OrbitControls } from "./OrbitControls";
|
|
2
2
|
import { Camera } from "./Camera";
|
|
3
3
|
import { addNewComponent } from "../engine/engine_components";
|
|
4
|
-
import { Object3D, Scene } from "three";
|
|
4
|
+
import { Color, Object3D, Scene, Vector3 } from "three";
|
|
5
|
+
import { ICamera, SourceIdentifier } from "../engine/engine_types";
|
|
6
|
+
import { lookAtInverse } from "../engine/engine_three_utils";
|
|
7
|
+
import { RGBAColor } from "./js-extensions/RGBAColor";
|
|
5
8
|
|
|
6
|
-
export function createCameraWithOrbitControl(scene: Scene):
|
|
7
|
-
const srcId =
|
|
9
|
+
export function createCameraWithOrbitControl(scene: Scene, source: SourceIdentifier): ICamera {
|
|
10
|
+
const srcId = source;
|
|
8
11
|
const go = new Object3D();
|
|
9
12
|
scene.add(go);
|
|
10
|
-
const
|
|
13
|
+
const camInstance = new Camera();
|
|
14
|
+
const cam = addNewComponent(go, camInstance, true) as ICamera
|
|
11
15
|
cam.sourceId = srcId;
|
|
12
|
-
|
|
16
|
+
cam.clearFlags = 2;
|
|
17
|
+
cam.backgroundColor = new RGBAColor(0.5, 0.5, 0.5, 1);
|
|
18
|
+
const orbit = addNewComponent(go, new OrbitControls(), false) as OrbitControls;
|
|
13
19
|
orbit.sourceId = srcId;
|
|
20
|
+
go.position.x = -2;
|
|
21
|
+
go.position.y = 2;
|
|
22
|
+
go.position.z = 2;
|
|
23
|
+
lookAtInverse(go, new Vector3(0, 0, 0));
|
|
14
24
|
return cam as Camera;
|
|
15
25
|
}
|
|
@@ -38,11 +38,11 @@ class TransformWatch {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
syncValues(){
|
|
42
|
-
for(const key of this._positionKeys){
|
|
41
|
+
syncValues() {
|
|
42
|
+
for (const key of this._positionKeys) {
|
|
43
43
|
this.position![key] = this.obj.position[key];
|
|
44
44
|
}
|
|
45
|
-
for(const key of this._quaternionKeys){
|
|
45
|
+
for (const key of this._quaternionKeys) {
|
|
46
46
|
this.quaternion![key] = this.obj.quaternion[key];
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -213,6 +213,14 @@ export class Rigidbody extends Behaviour implements IRigidbody {
|
|
|
213
213
|
else this.constraints &= ~RigidbodyConstraints.FreezeRotationZ;
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
set gravityScale(val: number) {
|
|
217
|
+
this._gravityScale = val;
|
|
218
|
+
}
|
|
219
|
+
get gravityScale() {
|
|
220
|
+
return this._gravityScale;
|
|
221
|
+
}
|
|
222
|
+
private _gravityScale: number = 1;
|
|
223
|
+
|
|
216
224
|
private static tempPosition: THREE.Vector3 = new THREE.Vector3();
|
|
217
225
|
private _propertiesChanged: boolean = false;
|
|
218
226
|
private _currentVelocity: THREE.Vector3 = new THREE.Vector3();
|
|
@@ -271,9 +279,9 @@ export class Rigidbody extends Behaviour implements IRigidbody {
|
|
|
271
279
|
return this.context.physics.internal_getRigidbody(this);
|
|
272
280
|
}
|
|
273
281
|
|
|
274
|
-
public teleport(pt: { x: number, y: number, z: number }, localspace:boolean = true) {
|
|
282
|
+
public teleport(pt: { x: number, y: number, z: number }, localspace: boolean = true) {
|
|
275
283
|
this._watch?.reset(true);
|
|
276
|
-
if(localspace) this.gameObject.position.set(pt.x, pt.y, pt.z);
|
|
284
|
+
if (localspace) this.gameObject.position.set(pt.x, pt.y, pt.z);
|
|
277
285
|
else this.setWorldPosition(pt.x, pt.y, pt.z);
|
|
278
286
|
this.resetForcesAndTorques();
|
|
279
287
|
this.resetVelocities();
|
|
@@ -343,6 +351,15 @@ export class Rigidbody extends Behaviour implements IRigidbody {
|
|
|
343
351
|
this.body?.setAngvel({ x: x, y: y, z: z }, true);
|
|
344
352
|
}
|
|
345
353
|
|
|
354
|
+
public getAngularVelocity(): Vector3 {
|
|
355
|
+
const vel = this.body?.angvel();
|
|
356
|
+
if (!vel) return this._currentVelocity.set(0, 0, 0);
|
|
357
|
+
this._currentVelocity.x = vel.x;
|
|
358
|
+
this._currentVelocity.y = vel.y;
|
|
359
|
+
this._currentVelocity.z = vel.z;
|
|
360
|
+
return this._currentVelocity;
|
|
361
|
+
}
|
|
362
|
+
|
|
346
363
|
public setTorque(x: number | Vector3, y: number, z: number) {
|
|
347
364
|
this.setAngularVelocity(x, y, z);
|
|
348
365
|
}
|