@needle-tools/engine 3.5.9-beta.2 → 3.5.10-beta
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 +11 -0
- package/dist/needle-engine.js +3865 -3825
- package/dist/needle-engine.light.js +5487 -5270
- package/dist/needle-engine.light.min.js +94 -94
- package/dist/needle-engine.light.umd.cjs +88 -88
- package/dist/needle-engine.min.js +89 -89
- package/dist/needle-engine.umd.cjs +90 -90
- package/lib/engine/debug/debug_overlay.js +4 -1
- package/lib/engine/debug/debug_overlay.js.map +1 -1
- package/lib/engine/engine_context.js +9 -4
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_element.d.ts +1 -0
- package/lib/engine/engine_element.js +9 -2
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.js +9 -10
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_license.js +5 -4
- package/lib/engine/engine_license.js.map +1 -1
- package/lib/engine/engine_physics_rapier.js +33 -30
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine-components/CameraUtils.js +5 -2
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/Component.d.ts +2 -2
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +1 -1
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/SpriteRenderer.d.ts +3 -0
- package/lib/engine-components/SpriteRenderer.js +18 -0
- package/lib/engine-components/SpriteRenderer.js.map +1 -1
- package/package.json +1 -1
- package/plugins/vite/config.js +8 -1
- package/plugins/vite/defines.js +1 -1
- package/plugins/vite/license.js +4 -1
- package/src/engine/debug/debug_overlay.ts +5 -2
- package/src/engine/engine_context.ts +11 -5
- package/src/engine/engine_element.ts +8 -3
- package/src/engine/engine_element_loading.ts +9 -10
- package/src/engine/engine_license.ts +5 -4
- package/src/engine/engine_physics_rapier.ts +33 -31
- package/src/engine-components/CameraUtils.ts +7 -3
- package/src/engine-components/Component.ts +2 -2
- package/src/engine-components/OrbitControls.ts +1 -1
- package/src/engine-components/SpriteRenderer.ts +13 -0
|
@@ -73,14 +73,15 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
onLoadingBegin(message?: string) {
|
|
76
|
+
const _element = this._element.shadowRoot || this._element;
|
|
76
77
|
if (debug) console.warn("Begin Loading")
|
|
77
78
|
if (!this._loadingElement) {
|
|
78
|
-
for (let i = 0; i <
|
|
79
|
-
const el =
|
|
79
|
+
for (let i = 0; i < _element.children.length; i++) {
|
|
80
|
+
const el = _element.children[i] as HTMLElement;
|
|
80
81
|
if (el.classList.contains(EngineLoadingView.LoadingContainerClassName)) {
|
|
81
82
|
if (!this._allowCustomLoadingElement) {
|
|
82
83
|
if (debug) console.warn("Remove custom loading container")
|
|
83
|
-
|
|
84
|
+
_element.removeChild(el);
|
|
84
85
|
continue;
|
|
85
86
|
}
|
|
86
87
|
this._loadingElement = this.createLoadingElement(el);
|
|
@@ -92,7 +93,7 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
92
93
|
this._progress = 0;
|
|
93
94
|
this.loadingProgress = 0;
|
|
94
95
|
this._loadingElement.style.display = "flex";
|
|
95
|
-
|
|
96
|
+
_element.appendChild(this._loadingElement);
|
|
96
97
|
this.smoothProgressLoop();
|
|
97
98
|
this.setMessage(message ?? "");
|
|
98
99
|
}
|
|
@@ -141,7 +142,7 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
141
142
|
if (typeof debugRendering === "number") dt *= debugRendering;
|
|
142
143
|
}
|
|
143
144
|
this._progressLoop = setInterval(() => {
|
|
144
|
-
//
|
|
145
|
+
// increase loading speed when almost done
|
|
145
146
|
if (this.loadingProgress >= .95 && !debugRendering) dt = .9;
|
|
146
147
|
this._progress = Mathf.lerp(this._progress, this.loadingProgress, dt * this.loadingProgress);
|
|
147
148
|
this.updateDisplay();
|
|
@@ -229,15 +230,12 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
229
230
|
else
|
|
230
231
|
loadingBarContainer.style.backgroundColor = "rgba(255,255,255,.2)"
|
|
231
232
|
// loadingBarContainer.style.alignItems = "center";
|
|
232
|
-
this._loadingElement.appendChild(loadingBarContainer);
|
|
233
233
|
|
|
234
234
|
const logo = document.createElement("img");
|
|
235
235
|
const logoSize = 64;
|
|
236
236
|
logo.style.width = `${logoSize}px`;
|
|
237
237
|
logo.style.height = `${logoSize}px`;
|
|
238
|
-
logo.style.
|
|
239
|
-
logo.style.left = "50%";
|
|
240
|
-
logo.style.transform = `translate(-${logoSize * .5}px, -${logoSize + 32}px)`;
|
|
238
|
+
logo.style.marginBottom = "20px";
|
|
241
239
|
logo.addEventListener("click", () => window.open("https://needle.tools", "_blank"));
|
|
242
240
|
logo.style.cursor = "pointer";
|
|
243
241
|
logo.style.userSelect = "none";
|
|
@@ -250,7 +248,8 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
250
248
|
logo.src = customLogo;
|
|
251
249
|
}
|
|
252
250
|
}
|
|
253
|
-
|
|
251
|
+
this._loadingElement.appendChild(logo);
|
|
252
|
+
this._loadingElement.appendChild(loadingBarContainer);
|
|
254
253
|
|
|
255
254
|
|
|
256
255
|
this._loadingBar = document.createElement("div");
|
|
@@ -64,9 +64,10 @@ function insertNonCommercialUseHint(ctx: IContext) {
|
|
|
64
64
|
|
|
65
65
|
const interval = setInterval(() => {
|
|
66
66
|
if (!licenseElement) return;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const parent = ctx.domElement.shadowRoot || ctx.domElement;
|
|
68
|
+
if (licenseElement.parentNode !== parent) {
|
|
69
|
+
parent.appendChild(licenseElement);
|
|
70
|
+
if (style) parent.appendChild(style);
|
|
70
71
|
}
|
|
71
72
|
}, 100);
|
|
72
73
|
|
|
@@ -121,7 +122,7 @@ async function logNonCommercialUse(_logo?: string) {
|
|
|
121
122
|
function createLicenseElement() {
|
|
122
123
|
const licenseElement = document.createElement("div");
|
|
123
124
|
licenseElement.setAttribute(licenseElementIdentifier, "");
|
|
124
|
-
licenseElement.style.position = "
|
|
125
|
+
licenseElement.style.position = "absolute";
|
|
125
126
|
licenseElement.style.bottom = "12px";
|
|
126
127
|
licenseElement.style.right = "15px";
|
|
127
128
|
|
|
@@ -21,6 +21,7 @@ import { Gizmos } from './engine_gizmos';
|
|
|
21
21
|
import { Mathf } from './engine_math';
|
|
22
22
|
import { SphereOverlapResult } from './engine_types';
|
|
23
23
|
import { ContextEvent, ContextRegistry } from './engine_context_registry';
|
|
24
|
+
import { isDevEnvironment } from './debug/debug';
|
|
24
25
|
|
|
25
26
|
const debugPhysics = getParam("debugphysics");
|
|
26
27
|
const debugColliderPlacement = getParam("debugphysicscolliders");
|
|
@@ -61,48 +62,49 @@ declare type PhysicsBody = {
|
|
|
61
62
|
export class RapierPhysics implements IPhysicsEngine {
|
|
62
63
|
|
|
63
64
|
removeBody(obj: IComponent) {
|
|
65
|
+
if (!obj) return;
|
|
64
66
|
this.validate();
|
|
65
67
|
const body = obj[$bodyKey];
|
|
66
68
|
obj[$bodyKey] = null;
|
|
67
69
|
if (body && this.world) {
|
|
68
70
|
const index = this.objects.findIndex(o => o === obj);
|
|
69
71
|
if (index >= 0) {
|
|
70
|
-
const
|
|
72
|
+
const rapierBody = this.bodies[index];
|
|
73
|
+
// Remove references
|
|
71
74
|
this.bodies.splice(index, 1);
|
|
72
75
|
this.objects.splice(index, 1);
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
// Remove the collider from the physics world
|
|
78
|
+
if (rapierBody instanceof Collider) {
|
|
79
|
+
const rapierCollider = rapierBody as Collider;
|
|
80
|
+
this.world?.removeCollider(rapierCollider, true);
|
|
77
81
|
|
|
78
|
-
// remove the rigidbody if it doesnt have colliders anymore
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
+
// also remove the rigidbody if it doesnt have colliders anymore
|
|
83
|
+
const rapierRigidbody: RigidBody | null = rapierCollider.parent();
|
|
84
|
+
if (rapierRigidbody && rapierRigidbody.numColliders() <= 0) {
|
|
85
|
+
const rigidbody = rapierRigidbody[$componentKey] as IRigidbody;
|
|
86
|
+
this.removeBody(rigidbody);
|
|
82
87
|
}
|
|
83
88
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
// Remove the rigidbody from the physics world
|
|
90
|
+
else if (rapierBody instanceof RigidBody) {
|
|
91
|
+
if (rapierBody.numColliders() <= 0) {
|
|
92
|
+
this.world?.removeRigidBody(rapierBody);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
if (isDevEnvironment()) {
|
|
96
|
+
if (!rapierBody["did_log_removing"]) {
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
if (rapierBody.numColliders() > 0) {
|
|
99
|
+
rapierBody["did_log_removing"] = true;
|
|
100
|
+
console.warn("RapierPhysics: removing rigidbody with colliders from the physics world is not possible right now, please remove the colliders first");
|
|
101
|
+
}
|
|
102
|
+
}, 1);
|
|
97
103
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// if (rb && rb.numColliders() <= 0) {
|
|
103
|
-
// // this.world?.removeRigidBody(rb);
|
|
104
|
-
// }
|
|
105
|
-
// }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
}
|
|
@@ -128,7 +130,7 @@ export class RapierPhysics implements IPhysicsEngine {
|
|
|
128
130
|
|
|
129
131
|
updateProperties(rigidbody: IRigidbody) {
|
|
130
132
|
this.validate();
|
|
131
|
-
const physicsBody = rigidbody
|
|
133
|
+
const physicsBody = this.internal_getRigidbody(rigidbody);
|
|
132
134
|
if (physicsBody) {
|
|
133
135
|
this.internalUpdateProperties(rigidbody, physicsBody);
|
|
134
136
|
}
|
|
@@ -206,7 +208,7 @@ export class RapierPhysics implements IPhysicsEngine {
|
|
|
206
208
|
|
|
207
209
|
private async internalInitialization() {
|
|
208
210
|
// NEEDLE_PHYSICS_INIT_START
|
|
209
|
-
// use .env file with VITE_NEEDLE_USE_RAPIER=false to
|
|
211
|
+
// use .env file with VITE_NEEDLE_USE_RAPIER=false to treeshake rapier
|
|
210
212
|
// @ts-ignore
|
|
211
213
|
if ("env" in import.meta && import.meta.env.VITE_NEEDLE_USE_RAPIER === "false") {
|
|
212
214
|
return false;
|
|
@@ -16,14 +16,15 @@ ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
|
|
|
16
16
|
scene.add(cameraObject);
|
|
17
17
|
|
|
18
18
|
const camInstance = new Camera();
|
|
19
|
-
const cam = addNewComponent(cameraObject, camInstance, true) as ICamera
|
|
19
|
+
const cam = addNewComponent(cameraObject, camInstance, true) as ICamera;
|
|
20
20
|
cam.sourceId = srcId;
|
|
21
21
|
cam.clearFlags = 2;
|
|
22
22
|
cam.backgroundColor = new RGBAColor(0.5, 0.5, 0.5, 1);
|
|
23
23
|
|
|
24
|
-
cameraObject.position.x =
|
|
25
|
-
cameraObject.position.y =
|
|
24
|
+
cameraObject.position.x = 0;
|
|
25
|
+
cameraObject.position.y = 1;
|
|
26
26
|
cameraObject.position.z = 2;
|
|
27
|
+
|
|
27
28
|
return cam;
|
|
28
29
|
});
|
|
29
30
|
|
|
@@ -46,6 +47,9 @@ ContextRegistry.registerCallback(ContextEvent.ContextCreated, (evt) => {
|
|
|
46
47
|
if (cameraObject) {
|
|
47
48
|
const orbit = addNewComponent(cameraObject, new OrbitControls(), false) as OrbitControls;
|
|
48
49
|
orbit.sourceId = "unknown";
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
orbit.fitCameraToObjects(evt.context.scene.children, 1);
|
|
52
|
+
}, 100);
|
|
49
53
|
}
|
|
50
54
|
else {
|
|
51
55
|
console.warn("Missing camera object, can not add orbit controls")
|
|
@@ -185,7 +185,7 @@ export abstract class GameObject extends Object3D implements Object3D, IGameObje
|
|
|
185
185
|
* @param go component to move the component to
|
|
186
186
|
* @param instance component to move to the GO
|
|
187
187
|
*/
|
|
188
|
-
public static addComponent(go: IGameObject, instance: Component): void {
|
|
188
|
+
public static addComponent(go: IGameObject | Object3D, instance: Component): void {
|
|
189
189
|
return this.moveComponent(go, instance);
|
|
190
190
|
}
|
|
191
191
|
|
|
@@ -194,7 +194,7 @@ export abstract class GameObject extends Object3D implements Object3D, IGameObje
|
|
|
194
194
|
* @param go component to move the component to
|
|
195
195
|
* @param instance component to move to the GO
|
|
196
196
|
*/
|
|
197
|
-
public static moveComponent(go: IGameObject, instance: Component): void {
|
|
197
|
+
public static moveComponent(go: IGameObject | Object3D, instance: Component): void {
|
|
198
198
|
moveComponentInstance(go, instance as any);
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -87,7 +87,7 @@ export class OrbitControls extends Behaviour implements ICameraController {
|
|
|
87
87
|
if (camGo && !this.setFromTargetPosition()) {
|
|
88
88
|
if (this.debugLog)
|
|
89
89
|
console.log("NO TARGET");
|
|
90
|
-
const forward = new Vector3(0, 0, -
|
|
90
|
+
const forward = new Vector3(0, 0, -10).applyMatrix4(camGo.cam.matrixWorld);
|
|
91
91
|
this.setTarget(forward, true);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -161,6 +161,14 @@ export class SpriteRenderer extends Behaviour {
|
|
|
161
161
|
private _spriteSheet?: SpriteData;
|
|
162
162
|
private _currentSprite?: THREE.Mesh;
|
|
163
163
|
|
|
164
|
+
// additional data
|
|
165
|
+
@serializable()
|
|
166
|
+
transparent: boolean = true;
|
|
167
|
+
@serializable()
|
|
168
|
+
cutoutThreshold: number = 0;
|
|
169
|
+
@serializable()
|
|
170
|
+
castShadows: boolean = false;
|
|
171
|
+
|
|
164
172
|
awake(): void {
|
|
165
173
|
this._currentSprite = undefined;
|
|
166
174
|
if(debug) {
|
|
@@ -221,6 +229,11 @@ export class SpriteRenderer extends Behaviour {
|
|
|
221
229
|
this._currentSprite.layers.set(this.layer)
|
|
222
230
|
}
|
|
223
231
|
|
|
232
|
+
if (this.sharedMaterial) {
|
|
233
|
+
this.sharedMaterial.alphaTest = this.cutoutThreshold;
|
|
234
|
+
this.sharedMaterial.transparent = this.transparent;
|
|
235
|
+
}
|
|
236
|
+
this._currentSprite.castShadow = this.castShadows;
|
|
224
237
|
this._spriteSheet?.update();
|
|
225
238
|
}
|
|
226
239
|
}
|