@needle-tools/engine 2.41.0-pre → 2.42.0-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 +11 -0
- package/dist/needle-engine.d.ts +100 -40
- package/dist/needle-engine.js +367 -367
- package/dist/needle-engine.js.map +3 -3
- package/dist/needle-engine.min.js +37 -37
- package/dist/needle-engine.min.js.map +3 -3
- package/lib/engine/engine_element.js +1 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.js +6 -1
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gizmos.d.ts +8 -22
- package/lib/engine/engine_gizmos.js +37 -3
- package/lib/engine/engine_gizmos.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +3 -0
- package/lib/engine/engine_setup.js +15 -0
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_three_utils.d.ts +16 -1
- package/lib/engine/engine_three_utils.js +94 -54
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_types.d.ts +6 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine-components/AnimationCurve.js +2 -2
- package/lib/engine-components/AnimationCurve.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.js +9 -10
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/ParticleSystem.d.ts +24 -10
- package/lib/engine-components/ParticleSystem.js +136 -41
- package/lib/engine-components/ParticleSystem.js.map +1 -1
- package/lib/engine-components/ParticleSystemModules.d.ts +40 -6
- package/lib/engine-components/ParticleSystemModules.js +103 -21
- package/lib/engine-components/ParticleSystemModules.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.js +29 -11
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +1 -0
- package/lib/engine-components/Renderer.js +4 -2
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +1 -0
- package/lib/engine-components/codegen/components.js +1 -0
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/codegen/register_types.js +4 -0
- package/src/engine/dist/engine_three_utils.js +279 -0
- package/src/engine/engine_element.ts +1 -1
- package/src/engine/engine_element_loading.ts +5 -1
- package/src/engine/engine_gizmos.ts +45 -8
- package/src/engine/engine_setup.ts +25 -2
- package/src/engine/engine_three_utils.ts +103 -62
- package/src/engine/engine_types.ts +8 -1
- package/src/engine-components/AnimationCurve.ts +2 -2
- package/src/engine-components/BoxHelperComponent.ts +12 -15
- package/src/engine-components/ParticleSystem.ts +151 -75
- package/src/engine-components/ParticleSystemModules.ts +127 -24
- package/src/engine-components/ReflectionProbe.ts +37 -13
- package/src/engine-components/Renderer.ts +4 -2
- package/src/engine-components/codegen/components.ts +1 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.textureToCanvas = exports.copyTexture = exports.Graphics = exports.logHierarchy = exports.setWorldRotationXYZ = exports.setWorldRotation = exports.getWorldRotation = exports.setWorldEuler = exports.getWorldEuler = exports.forward = exports.setWorldScale = exports.getWorldScale = exports.setWorldQuaternionXYZW = exports.setWorldQuaternion = exports.getWorldQuaternion = exports.setWorldPositionXYZ = exports.setWorldPosition = exports.getWorldPosition = exports.lookAtInverse = void 0;
|
|
4
|
+
var THREE = require("three");
|
|
5
|
+
var engine_math_1 = require("./engine_math");
|
|
6
|
+
var three_1 = require("three");
|
|
7
|
+
var engine_utils_1 = require("./engine_utils");
|
|
8
|
+
var flipYQuat = new three_1.Quaternion().setFromAxisAngle(new three_1.Vector3(0, 1, 0), Math.PI);
|
|
9
|
+
function lookAtInverse(obj, target) {
|
|
10
|
+
obj.lookAt(target);
|
|
11
|
+
obj.quaternion.multiply(flipYQuat);
|
|
12
|
+
}
|
|
13
|
+
exports.lookAtInverse = lookAtInverse;
|
|
14
|
+
var _worldPositions = new engine_utils_1.CircularBuffer(function () { return new THREE.Vector3(); }, 100);
|
|
15
|
+
function getWorldPosition(obj, vec, updateParents) {
|
|
16
|
+
if (vec === void 0) { vec = null; }
|
|
17
|
+
if (updateParents === void 0) { updateParents = true; }
|
|
18
|
+
var wp = vec !== null && vec !== void 0 ? vec : _worldPositions.get();
|
|
19
|
+
if (!obj)
|
|
20
|
+
return wp.set(0, 0, 0);
|
|
21
|
+
if (!obj.parent)
|
|
22
|
+
return wp.copy(obj.position);
|
|
23
|
+
if (updateParents)
|
|
24
|
+
obj.updateWorldMatrix(true, false);
|
|
25
|
+
if (obj.matrixWorldNeedsUpdate)
|
|
26
|
+
obj.updateMatrixWorld();
|
|
27
|
+
wp.setFromMatrixPosition(obj.matrixWorld);
|
|
28
|
+
return wp;
|
|
29
|
+
}
|
|
30
|
+
exports.getWorldPosition = getWorldPosition;
|
|
31
|
+
function setWorldPosition(obj, val) {
|
|
32
|
+
var _a;
|
|
33
|
+
if (!obj)
|
|
34
|
+
return;
|
|
35
|
+
var wp = _worldPositions.get();
|
|
36
|
+
if (val !== wp)
|
|
37
|
+
wp.copy(val);
|
|
38
|
+
var obj2 = (_a = obj === null || obj === void 0 ? void 0 : obj.parent) !== null && _a !== void 0 ? _a : obj;
|
|
39
|
+
obj2.worldToLocal(wp);
|
|
40
|
+
obj.position.set(wp.x, wp.y, wp.z);
|
|
41
|
+
}
|
|
42
|
+
exports.setWorldPosition = setWorldPosition;
|
|
43
|
+
function setWorldPositionXYZ(obj, x, y, z) {
|
|
44
|
+
var wp = _worldPositions.get();
|
|
45
|
+
wp.set(x, y, z);
|
|
46
|
+
setWorldPosition(obj, wp);
|
|
47
|
+
}
|
|
48
|
+
exports.setWorldPositionXYZ = setWorldPositionXYZ;
|
|
49
|
+
var _worldQuaternionBuffer = new THREE.Quaternion();
|
|
50
|
+
var _worldQuaternion = new THREE.Quaternion();
|
|
51
|
+
var _tempQuaternionBuffer2 = new THREE.Quaternion();
|
|
52
|
+
function getWorldQuaternion(obj, target) {
|
|
53
|
+
if (target === void 0) { target = null; }
|
|
54
|
+
if (!obj)
|
|
55
|
+
return _worldQuaternion.set(0, 0, 0, 1);
|
|
56
|
+
var quat = target !== null && target !== void 0 ? target : _worldQuaternion;
|
|
57
|
+
if (!obj.parent)
|
|
58
|
+
return quat.copy(obj.quaternion);
|
|
59
|
+
obj.getWorldQuaternion(quat);
|
|
60
|
+
return quat;
|
|
61
|
+
}
|
|
62
|
+
exports.getWorldQuaternion = getWorldQuaternion;
|
|
63
|
+
function setWorldQuaternion(obj, val) {
|
|
64
|
+
if (!obj)
|
|
65
|
+
return;
|
|
66
|
+
if (val !== _worldQuaternionBuffer)
|
|
67
|
+
_worldQuaternionBuffer.copy(val);
|
|
68
|
+
var tempVec = _worldQuaternionBuffer;
|
|
69
|
+
var parent = obj === null || obj === void 0 ? void 0 : obj.parent;
|
|
70
|
+
parent === null || parent === void 0 ? void 0 : parent.getWorldQuaternion(_tempQuaternionBuffer2);
|
|
71
|
+
_tempQuaternionBuffer2.invert();
|
|
72
|
+
var q = _tempQuaternionBuffer2.multiply(tempVec);
|
|
73
|
+
// console.log(tempVec);
|
|
74
|
+
obj.quaternion.set(q.x, q.y, q.z, q.w);
|
|
75
|
+
// console.error("quaternion world to local is not yet implemented");
|
|
76
|
+
}
|
|
77
|
+
exports.setWorldQuaternion = setWorldQuaternion;
|
|
78
|
+
function setWorldQuaternionXYZW(obj, x, y, z, w) {
|
|
79
|
+
_worldQuaternionBuffer.set(x, y, z, w);
|
|
80
|
+
setWorldQuaternion(obj, _worldQuaternionBuffer);
|
|
81
|
+
}
|
|
82
|
+
exports.setWorldQuaternionXYZW = setWorldQuaternionXYZW;
|
|
83
|
+
var _worldScale = new THREE.Vector3();
|
|
84
|
+
var _worldScale2 = new THREE.Vector3();
|
|
85
|
+
function getWorldScale(obj, vec) {
|
|
86
|
+
if (vec === void 0) { vec = null; }
|
|
87
|
+
if (!obj)
|
|
88
|
+
return _worldScale.set(0, 0, 0);
|
|
89
|
+
if (!obj.parent)
|
|
90
|
+
return _worldScale.copy(obj.position);
|
|
91
|
+
obj.getWorldScale(vec !== null && vec !== void 0 ? vec : _worldScale);
|
|
92
|
+
return vec !== null && vec !== void 0 ? vec : _worldScale;
|
|
93
|
+
}
|
|
94
|
+
exports.getWorldScale = getWorldScale;
|
|
95
|
+
function setWorldScale(obj, vec) {
|
|
96
|
+
if (!obj)
|
|
97
|
+
return;
|
|
98
|
+
if (!obj.parent) {
|
|
99
|
+
obj.scale.copy(vec);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
var tempVec = _worldScale2;
|
|
103
|
+
var obj2 = obj.parent;
|
|
104
|
+
obj2.getWorldScale(tempVec);
|
|
105
|
+
tempVec.divide(vec);
|
|
106
|
+
obj.scale.copy(tempVec);
|
|
107
|
+
}
|
|
108
|
+
exports.setWorldScale = setWorldScale;
|
|
109
|
+
var _forward = new THREE.Vector3();
|
|
110
|
+
var _forwardQuat = new THREE.Quaternion();
|
|
111
|
+
function forward(obj) {
|
|
112
|
+
getWorldQuaternion(obj, _forwardQuat);
|
|
113
|
+
return _forward.set(0, 0, 1).applyQuaternion(_forwardQuat);
|
|
114
|
+
}
|
|
115
|
+
exports.forward = forward;
|
|
116
|
+
var _worldEulerBuffer = new THREE.Euler();
|
|
117
|
+
var _worldEuler = new THREE.Euler();
|
|
118
|
+
var _worldRotation = new THREE.Vector3();
|
|
119
|
+
// world euler (in radians)
|
|
120
|
+
function getWorldEuler(obj) {
|
|
121
|
+
obj.getWorldQuaternion(_worldQuaternion);
|
|
122
|
+
_worldEuler.setFromQuaternion(_worldQuaternion);
|
|
123
|
+
return _worldEuler;
|
|
124
|
+
}
|
|
125
|
+
exports.getWorldEuler = getWorldEuler;
|
|
126
|
+
// world euler (in radians)
|
|
127
|
+
function setWorldEuler(obj, val) {
|
|
128
|
+
setWorldQuaternion(obj, _worldQuaternion.setFromEuler(val));
|
|
129
|
+
;
|
|
130
|
+
}
|
|
131
|
+
exports.setWorldEuler = setWorldEuler;
|
|
132
|
+
// returns rotation in degrees
|
|
133
|
+
function getWorldRotation(obj) {
|
|
134
|
+
var rot = getWorldEuler(obj);
|
|
135
|
+
var wr = _worldRotation;
|
|
136
|
+
wr.set(rot.x, rot.y, rot.z);
|
|
137
|
+
wr.x = engine_math_1.Mathf.toDegrees(wr.x);
|
|
138
|
+
wr.y = engine_math_1.Mathf.toDegrees(wr.y);
|
|
139
|
+
wr.z = engine_math_1.Mathf.toDegrees(wr.z);
|
|
140
|
+
return wr;
|
|
141
|
+
}
|
|
142
|
+
exports.getWorldRotation = getWorldRotation;
|
|
143
|
+
function setWorldRotation(obj, val) {
|
|
144
|
+
setWorldRotationXYZ(obj, val.x, val.y, val.z, true);
|
|
145
|
+
}
|
|
146
|
+
exports.setWorldRotation = setWorldRotation;
|
|
147
|
+
function setWorldRotationXYZ(obj, x, y, z, degrees) {
|
|
148
|
+
if (degrees === void 0) { degrees = true; }
|
|
149
|
+
if (degrees) {
|
|
150
|
+
x = engine_math_1.Mathf.toRadians(x);
|
|
151
|
+
y = engine_math_1.Mathf.toRadians(y);
|
|
152
|
+
z = engine_math_1.Mathf.toRadians(z);
|
|
153
|
+
}
|
|
154
|
+
_worldEulerBuffer.set(x, y, z);
|
|
155
|
+
_worldQuaternionBuffer.setFromEuler(_worldEulerBuffer);
|
|
156
|
+
setWorldQuaternion(obj, _worldQuaternionBuffer);
|
|
157
|
+
}
|
|
158
|
+
exports.setWorldRotationXYZ = setWorldRotationXYZ;
|
|
159
|
+
// from https://github.com/mrdoob/three.js/pull/10995#issuecomment-287614722
|
|
160
|
+
function logHierarchy(root, collapsible) {
|
|
161
|
+
if (collapsible === void 0) { collapsible = true; }
|
|
162
|
+
if (!root)
|
|
163
|
+
return;
|
|
164
|
+
if (collapsible) {
|
|
165
|
+
(function printGraph(obj) {
|
|
166
|
+
console.groupCollapsed((obj.name ? obj.name : '(no name : ' + obj.type + ')') + ' %o', obj);
|
|
167
|
+
obj.children.forEach(printGraph);
|
|
168
|
+
console.groupEnd();
|
|
169
|
+
}(root));
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
root.traverse(function (obj) {
|
|
173
|
+
var s = '|___';
|
|
174
|
+
var obj2 = obj;
|
|
175
|
+
while (obj2.parent !== null) {
|
|
176
|
+
s = '\t' + s;
|
|
177
|
+
obj2 = obj2.parent;
|
|
178
|
+
}
|
|
179
|
+
console.log(s + obj.name + ' <' + obj.type + '>');
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
;
|
|
183
|
+
}
|
|
184
|
+
exports.logHierarchy = logHierarchy;
|
|
185
|
+
var Graphics = /** @class */ (function () {
|
|
186
|
+
function Graphics() {
|
|
187
|
+
}
|
|
188
|
+
Graphics.createBlitMaterial = function (fragment) {
|
|
189
|
+
return new three_1.ShaderMaterial({
|
|
190
|
+
uniforms: { map: new three_1.Uniform(null) },
|
|
191
|
+
vertexShader: this.vertex,
|
|
192
|
+
fragmentShader: fragment
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
Graphics.copyTexture = function (texture, blitMaterial) {
|
|
196
|
+
var material = blitMaterial !== null && blitMaterial !== void 0 ? blitMaterial : this.blipMaterial;
|
|
197
|
+
material.uniforms.map.value = texture;
|
|
198
|
+
material.needsUpdate = true;
|
|
199
|
+
material.uniformsNeedUpdate = true;
|
|
200
|
+
var mesh = this.mesh;
|
|
201
|
+
mesh.material = material;
|
|
202
|
+
mesh.frustumCulled = false;
|
|
203
|
+
this.scene.children.length = 0;
|
|
204
|
+
this.scene.add(mesh);
|
|
205
|
+
this.renderer.setSize(texture.image.width, texture.image.height);
|
|
206
|
+
this.renderer.clear();
|
|
207
|
+
this.renderer.render(this.scene, this.perspectiveCam);
|
|
208
|
+
var tex = new three_1.Texture(this.renderer.domElement);
|
|
209
|
+
tex.name = "Copy";
|
|
210
|
+
tex.needsUpdate = true; // < important!
|
|
211
|
+
return tex;
|
|
212
|
+
};
|
|
213
|
+
// static blit(src: Texture, target: Texture, blitMaterial?: ShaderMaterial) {
|
|
214
|
+
// let material = blitMaterial ?? this.blipMaterial;
|
|
215
|
+
// material.uniforms.map.value = src;
|
|
216
|
+
// this.mesh.material = material;
|
|
217
|
+
// this.mesh.frustumCulled = false;
|
|
218
|
+
// this.mesh.matrix.identity();
|
|
219
|
+
// this.scene.children.length = 0;
|
|
220
|
+
// this.scene.add(this.mesh);
|
|
221
|
+
// this.renderer.setSize(src.image.width, src.image.height);
|
|
222
|
+
// this.renderer.clear();
|
|
223
|
+
// this.renderer.render(this.scene, this.perspectiveCam);
|
|
224
|
+
// return new Texture(this.renderer.domElement);
|
|
225
|
+
// }
|
|
226
|
+
Graphics.textureToCanvas = function (texture, force) {
|
|
227
|
+
if (!texture)
|
|
228
|
+
return null;
|
|
229
|
+
if (force === true || texture["isCompressedTexture"] === true) {
|
|
230
|
+
texture = copyTexture(texture);
|
|
231
|
+
}
|
|
232
|
+
var image = texture.image;
|
|
233
|
+
if (isImageBitmap(image)) {
|
|
234
|
+
var canvas = document.createElement('canvas');
|
|
235
|
+
canvas.width = image.width;
|
|
236
|
+
canvas.height = image.height;
|
|
237
|
+
var context = canvas.getContext('2d');
|
|
238
|
+
if (!context) {
|
|
239
|
+
console.error("Failed getting canvas 2d context");
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
243
|
+
return canvas;
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
};
|
|
247
|
+
Graphics.planeGeometry = new THREE.PlaneGeometry(2, 2, 1, 1);
|
|
248
|
+
Graphics.renderer = new three_1.WebGLRenderer({ antialias: false });
|
|
249
|
+
Graphics.perspectiveCam = new THREE.PerspectiveCamera();
|
|
250
|
+
Graphics.scene = new THREE.Scene();
|
|
251
|
+
Graphics.vertex = "\n varying vec2 vUv;\n void main(){\n vUv = uv;\n gl_Position = vec4(position.xy * 1.0,0.,.999999);\n }";
|
|
252
|
+
Graphics.fragment = "\n uniform sampler2D map; \n varying vec2 vUv;\n void main(){ \n vec2 uv = vUv;\n uv.y = 1.0 - uv.y;\n gl_FragColor = texture2D( map, uv);\n gl_FragColor = vec4(uv.xy, 0, 1);\n }";
|
|
253
|
+
Graphics.blipMaterial = new three_1.ShaderMaterial({
|
|
254
|
+
uniforms: { map: new three_1.Uniform(null) },
|
|
255
|
+
vertexShader: this.vertex,
|
|
256
|
+
fragmentShader: this.fragment
|
|
257
|
+
});
|
|
258
|
+
Graphics.mesh = new THREE.Mesh(this.planeGeometry, this.blipMaterial);
|
|
259
|
+
return Graphics;
|
|
260
|
+
}());
|
|
261
|
+
exports.Graphics = Graphics;
|
|
262
|
+
/**@obsolete use Graphics.copyTexture */
|
|
263
|
+
function copyTexture(texture) {
|
|
264
|
+
return Graphics.copyTexture(texture);
|
|
265
|
+
}
|
|
266
|
+
exports.copyTexture = copyTexture;
|
|
267
|
+
/**@obsolete use Graphics.textureToCanvas */
|
|
268
|
+
function textureToCanvas(texture, force) {
|
|
269
|
+
if (force === void 0) { force = false; }
|
|
270
|
+
return Graphics.textureToCanvas(texture, force);
|
|
271
|
+
}
|
|
272
|
+
exports.textureToCanvas = textureToCanvas;
|
|
273
|
+
;
|
|
274
|
+
function isImageBitmap(image) {
|
|
275
|
+
return (typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement) ||
|
|
276
|
+
(typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement) ||
|
|
277
|
+
(typeof OffscreenCanvas !== 'undefined' && image instanceof OffscreenCanvas) ||
|
|
278
|
+
(typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap);
|
|
279
|
+
}
|
|
@@ -168,7 +168,7 @@ export class EngineElement extends HTMLElement implements INeedleEngineComponent
|
|
|
168
168
|
if (fn) {
|
|
169
169
|
this.classList.add("loading");
|
|
170
170
|
console.log("Needle Engine: Begin loading", alias ?? "");
|
|
171
|
-
const allowOverridingDefaultLoading =
|
|
171
|
+
const allowOverridingDefaultLoading = true;
|
|
172
172
|
// default loading can be overriden by calling preventDefault in the onload start event
|
|
173
173
|
const useDefaultLoading = this.dispatchEvent(new CustomEvent("loadstart", {
|
|
174
174
|
detail: {
|
|
@@ -16,7 +16,11 @@ export interface ILoadingViewHandler {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function calculateProgress01(progress: LoadingProgressArgs) {
|
|
19
|
-
|
|
19
|
+
if(debug) console.log(progress);
|
|
20
|
+
const count = Math.max(1, progress.count);
|
|
21
|
+
const total = Math.max(1, progress.progress.total);
|
|
22
|
+
const prog = progress.index / count + (progress.progress.loaded / total) / count;
|
|
23
|
+
return Mathf.clamp01(prog);
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
export class EngineLoadingView implements ILoadingViewHandler {
|
|
@@ -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 } from 'three';
|
|
2
|
+
import { BufferAttribute, Line, BoxGeometry, EdgesGeometry, Color, LineSegments, LineBasicMaterial, Object3D, Mesh, SphereGeometry, ColorRepresentation, Vector3, Box3, Quaternion } from 'three';
|
|
3
3
|
import { Context } from './engine_setup';
|
|
4
4
|
import { setWorldPosition, setWorldPositionXYZ } from './engine_three_utils';
|
|
5
|
-
import { Vec3 } from './engine_types';
|
|
5
|
+
import { Vec3, Vec4 } from './engine_types';
|
|
6
6
|
|
|
7
7
|
const _tmp = new Vector3();
|
|
8
|
+
const _quat = new Quaternion();
|
|
8
9
|
|
|
9
10
|
const defaultColor: ColorRepresentation = 0x888888;
|
|
10
11
|
|
|
@@ -21,12 +22,19 @@ export class Gizmos {
|
|
|
21
22
|
obj.material["depthTest"] = depthTest;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
static DrawDirection(pt: Vec3, direction: Vec3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true, lengthFactor: number = 1) {
|
|
25
|
+
static DrawDirection(pt: Vec3, direction: Vec3 | Vec4, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true, lengthFactor: number = 1) {
|
|
25
26
|
const obj = Internal.getLine(duration);
|
|
26
27
|
const positions = obj.geometry.getAttribute("position");
|
|
27
28
|
positions.setXYZ(0, pt.x, pt.y, pt.z);
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
if (direction["w"] !== undefined) {
|
|
30
|
+
_tmp.set(0, 0, -lengthFactor);
|
|
31
|
+
_quat.set(direction["x"], direction["y"], direction["z"], direction["w"]);
|
|
32
|
+
_tmp.applyQuaternion(_quat);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
_tmp.set(direction.x, direction.y, direction.z);
|
|
36
|
+
_tmp.multiplyScalar(lengthFactor);
|
|
37
|
+
}
|
|
30
38
|
positions.setXYZ(1, pt.x + _tmp.x, pt.y + _tmp.y, pt.z + _tmp.z);
|
|
31
39
|
positions.needsUpdate = true;
|
|
32
40
|
obj.material["color"].set(color);
|
|
@@ -34,7 +42,7 @@ export class Gizmos {
|
|
|
34
42
|
|
|
35
43
|
}
|
|
36
44
|
|
|
37
|
-
static DrawLine(pt0:
|
|
45
|
+
static DrawLine(pt0: Vec3, pt1: Vec3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
|
|
38
46
|
const obj = Internal.getLine(duration);
|
|
39
47
|
|
|
40
48
|
const positions = obj.geometry.getAttribute("position");
|
|
@@ -45,19 +53,37 @@ export class Gizmos {
|
|
|
45
53
|
obj.material["depthTest"] = depthTest;
|
|
46
54
|
}
|
|
47
55
|
|
|
48
|
-
static DrawWireSphere(center:
|
|
56
|
+
static DrawWireSphere(center: Vec3, radius: number, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
|
|
49
57
|
const obj = Internal.getSphere(radius, duration, true);
|
|
50
58
|
setWorldPositionXYZ(obj, center.x, center.y, center.z);
|
|
51
59
|
obj.material["color"].set(color);
|
|
52
60
|
obj.material["depthTest"] = depthTest;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
static DrawSphere(center:
|
|
63
|
+
static DrawSphere(center: Vec3, radius: number, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
|
|
56
64
|
const obj = Internal.getSphere(radius, duration, false);
|
|
57
65
|
setWorldPositionXYZ(obj, center.x, center.y, center.z);
|
|
58
66
|
obj.material["color"].set(color);
|
|
59
67
|
obj.material["depthTest"] = depthTest;
|
|
60
68
|
}
|
|
69
|
+
|
|
70
|
+
static DrawBox(center: Vec3, size: Vec3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
|
|
71
|
+
const obj = Internal.getBox(duration);
|
|
72
|
+
obj.position.set(center.x, center.y, center.z);
|
|
73
|
+
obj.scale.set(size.x, size.y, size.z);
|
|
74
|
+
obj.material["color"].set(color);
|
|
75
|
+
obj.material["depthTest"] = depthTest;
|
|
76
|
+
obj.material["wireframe"] = true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static DrawBox3(box:Box3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
|
|
80
|
+
const obj = Internal.getBox(duration);
|
|
81
|
+
obj.position.copy(box.getCenter(_tmp));
|
|
82
|
+
obj.scale.copy(box.getSize(_tmp));
|
|
83
|
+
obj.material["color"].set(color);
|
|
84
|
+
obj.material["depthTest"] = depthTest;
|
|
85
|
+
obj.material["wireframe"] = true;
|
|
86
|
+
}
|
|
61
87
|
}
|
|
62
88
|
|
|
63
89
|
const box: BoxGeometry = new BoxGeometry(1, 1, 1);
|
|
@@ -79,6 +105,16 @@ const $cacheSymbol = Symbol("GizmoCache");
|
|
|
79
105
|
class Internal {
|
|
80
106
|
// private static createdLines: number = 0;
|
|
81
107
|
|
|
108
|
+
static getBox(duration: number): Mesh {
|
|
109
|
+
let box = this.boxesCache.pop();
|
|
110
|
+
if (!box) {
|
|
111
|
+
const geo: BoxGeometry = new BoxGeometry(1, 1, 1);
|
|
112
|
+
box = new Mesh(geo);
|
|
113
|
+
}
|
|
114
|
+
this.registerTimedObject(Context.Current, box, duration, this.boxesCache);
|
|
115
|
+
return box;
|
|
116
|
+
}
|
|
117
|
+
|
|
82
118
|
static getLine(duration: number): Line {
|
|
83
119
|
let line = this.linesCache.pop();
|
|
84
120
|
if (!line) {
|
|
@@ -107,6 +143,7 @@ class Internal {
|
|
|
107
143
|
|
|
108
144
|
private static linesCache: Array<Line> = [];
|
|
109
145
|
private static spheresCache: Mesh[] = [];
|
|
146
|
+
private static boxesCache: Mesh[] = [];
|
|
110
147
|
|
|
111
148
|
private static registerTimedObject(context: Context, object: Object3D, duration: number, cache: Array<Object3D>) {
|
|
112
149
|
if (!this.contextPostRenderCallbacks.get(context)) {
|
|
@@ -139,6 +139,11 @@ export class Context {
|
|
|
139
139
|
return el.getAROverlayContainer();
|
|
140
140
|
return this.domElement;
|
|
141
141
|
}
|
|
142
|
+
/** Current event of the update cycle */
|
|
143
|
+
get currentFrameEvent(): FrameEvent {
|
|
144
|
+
return this._currentFrameEvent;
|
|
145
|
+
}
|
|
146
|
+
private _currentFrameEvent: FrameEvent = -1;
|
|
142
147
|
|
|
143
148
|
scene: THREE.Scene;
|
|
144
149
|
renderer: THREE.WebGLRenderer;
|
|
@@ -517,6 +522,9 @@ export class Context {
|
|
|
517
522
|
}
|
|
518
523
|
|
|
519
524
|
private render(_, frame) {
|
|
525
|
+
|
|
526
|
+
this._currentFrameEvent = -1;
|
|
527
|
+
|
|
520
528
|
this._stats?.begin();
|
|
521
529
|
|
|
522
530
|
Context._current = this;
|
|
@@ -538,6 +546,8 @@ export class Context {
|
|
|
538
546
|
}
|
|
539
547
|
}
|
|
540
548
|
|
|
549
|
+
this._currentFrameEvent = FrameEvent.EarlyUpdate;
|
|
550
|
+
|
|
541
551
|
for (let i = 0; i < this.scripts_earlyUpdate.length; i++) {
|
|
542
552
|
const script = this.scripts_earlyUpdate[i];
|
|
543
553
|
if (!script.activeAndEnabled) continue;
|
|
@@ -546,9 +556,10 @@ export class Context {
|
|
|
546
556
|
script.earlyUpdate();
|
|
547
557
|
}
|
|
548
558
|
}
|
|
549
|
-
|
|
550
559
|
this.executeCoroutines(FrameEvent.EarlyUpdate);
|
|
551
560
|
|
|
561
|
+
this._currentFrameEvent = FrameEvent.Update;
|
|
562
|
+
|
|
552
563
|
for (let i = 0; i < this.scripts_update.length; i++) {
|
|
553
564
|
const script = this.scripts_update[i];
|
|
554
565
|
if (!script.activeAndEnabled) continue;
|
|
@@ -557,9 +568,10 @@ export class Context {
|
|
|
557
568
|
script.update();
|
|
558
569
|
}
|
|
559
570
|
}
|
|
560
|
-
|
|
561
571
|
this.executeCoroutines(FrameEvent.Update);
|
|
562
572
|
|
|
573
|
+
this._currentFrameEvent = FrameEvent.LateUpdate;
|
|
574
|
+
|
|
563
575
|
for (let i = 0; i < this.scripts_lateUpdate.length; i++) {
|
|
564
576
|
const script = this.scripts_lateUpdate[i];
|
|
565
577
|
if (!script.activeAndEnabled) continue;
|
|
@@ -572,12 +584,15 @@ export class Context {
|
|
|
572
584
|
// this.mainLight = null;
|
|
573
585
|
this.executeCoroutines(FrameEvent.LateUpdate);
|
|
574
586
|
|
|
587
|
+
|
|
575
588
|
try {
|
|
576
589
|
const physicsSteps = 1;
|
|
577
590
|
const dt = this.time.deltaTime / physicsSteps;
|
|
578
591
|
for (let i = 0; i < physicsSteps; i++) {
|
|
592
|
+
this._currentFrameEvent = FrameEvent.PrePhysicsStep;
|
|
579
593
|
this.executeCoroutines(FrameEvent.PrePhysicsStep);
|
|
580
594
|
this.physics.step(dt);
|
|
595
|
+
this._currentFrameEvent = FrameEvent.PostPhysicsStep;
|
|
581
596
|
this.executeCoroutines(FrameEvent.PostPhysicsStep);
|
|
582
597
|
}
|
|
583
598
|
}
|
|
@@ -586,6 +601,8 @@ export class Context {
|
|
|
586
601
|
}
|
|
587
602
|
this.physics.postStep();
|
|
588
603
|
|
|
604
|
+
this._currentFrameEvent = FrameEvent.OnBeforeRender;
|
|
605
|
+
|
|
589
606
|
// should we move these callbacks in the regular three onBeforeRender events?
|
|
590
607
|
for (let i = 0; i < this.scripts_onBeforeRender.length; i++) {
|
|
591
608
|
const script = this.scripts_onBeforeRender[i];
|
|
@@ -609,6 +626,8 @@ export class Context {
|
|
|
609
626
|
}
|
|
610
627
|
}
|
|
611
628
|
|
|
629
|
+
this._currentFrameEvent = -10;
|
|
630
|
+
|
|
612
631
|
this._isRendering = true;
|
|
613
632
|
this.renderRequiredTextures();
|
|
614
633
|
if (!this.isManagedExternally) {
|
|
@@ -621,6 +640,8 @@ export class Context {
|
|
|
621
640
|
}
|
|
622
641
|
this._isRendering = false;
|
|
623
642
|
|
|
643
|
+
this._currentFrameEvent = FrameEvent.OnAfterRender;
|
|
644
|
+
|
|
624
645
|
for (let i = 0; i < this.scripts_onAfterRender.length; i++) {
|
|
625
646
|
const script = this.scripts_onAfterRender[i];
|
|
626
647
|
if (!script.activeAndEnabled) continue;
|
|
@@ -638,6 +659,8 @@ export class Context {
|
|
|
638
659
|
}
|
|
639
660
|
}
|
|
640
661
|
|
|
662
|
+
this._currentFrameEvent = -1;
|
|
663
|
+
|
|
641
664
|
this.connection.sendBufferedMessagesNow();
|
|
642
665
|
|
|
643
666
|
this._stats?.end();
|