simulationjsv2 0.7.2 → 0.7.3
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/TODO.md +2 -0
- package/dist/graphics.d.ts +1 -0
- package/dist/graphics.js +17 -1
- package/dist/simulation.js +8 -5
- package/package.json +1 -1
package/TODO.md
CHANGED
package/dist/graphics.d.ts
CHANGED
|
@@ -200,6 +200,7 @@ export declare class Instance<T extends AnySimulationElement> extends Simulation
|
|
|
200
200
|
private matrixBuffer;
|
|
201
201
|
private baseMat;
|
|
202
202
|
private maxInstances;
|
|
203
|
+
private hasMapped;
|
|
203
204
|
isInstance: boolean;
|
|
204
205
|
constructor(obj: T, numInstances: number);
|
|
205
206
|
setNumInstances(numInstances: number): void;
|
package/dist/graphics.js
CHANGED
|
@@ -979,6 +979,7 @@ export class Instance extends SimulationElement3d {
|
|
|
979
979
|
matrixBuffer;
|
|
980
980
|
baseMat;
|
|
981
981
|
maxInstances;
|
|
982
|
+
hasMapped;
|
|
982
983
|
isInstance = true;
|
|
983
984
|
constructor(obj, numInstances) {
|
|
984
985
|
super(vector3(), vector3());
|
|
@@ -990,6 +991,7 @@ export class Instance extends SimulationElement3d {
|
|
|
990
991
|
this.instanceMatrix = [];
|
|
991
992
|
this.is3d = obj.is3d;
|
|
992
993
|
this.geometry = new BlankGeometry();
|
|
994
|
+
this.hasMapped = false;
|
|
993
995
|
this.baseMat = matrix4();
|
|
994
996
|
for (let i = 0; i < numInstances; i++) {
|
|
995
997
|
const clone = cloneBuf(this.baseMat);
|
|
@@ -1024,6 +1026,17 @@ export class Instance extends SimulationElement3d {
|
|
|
1024
1026
|
if (instance >= this.instanceMatrix.length || instance < 0)
|
|
1025
1027
|
return;
|
|
1026
1028
|
this.instanceMatrix[instance] = transformation;
|
|
1029
|
+
const device = globalInfo.getDevice();
|
|
1030
|
+
if (!device)
|
|
1031
|
+
return;
|
|
1032
|
+
if (!this.matrixBuffer) {
|
|
1033
|
+
const minSize = this.maxInstances * mat4ByteLength;
|
|
1034
|
+
const size = Math.max(minSize, this.instanceMatrix.length);
|
|
1035
|
+
this.allocBuffer(size);
|
|
1036
|
+
}
|
|
1037
|
+
const buf = new Float32Array(transformation);
|
|
1038
|
+
device.queue.writeBuffer(this.matrixBuffer, instance * mat4ByteLength, buf.buffer, buf.byteOffset, buf.byteLength);
|
|
1039
|
+
this.matrixBuffer.unmap();
|
|
1027
1040
|
}
|
|
1028
1041
|
allocBuffer(size) {
|
|
1029
1042
|
const device = globalInfo.getDevice();
|
|
@@ -1047,6 +1060,7 @@ export class Instance extends SimulationElement3d {
|
|
|
1047
1060
|
const buf = new Float32Array(this.instanceMatrix.map((mat) => [...mat]).flat());
|
|
1048
1061
|
device.queue.writeBuffer(this.matrixBuffer, 0, buf.buffer, buf.byteOffset, buf.byteLength);
|
|
1049
1062
|
this.matrixBuffer.unmap();
|
|
1063
|
+
this.hasMapped = true;
|
|
1050
1064
|
}
|
|
1051
1065
|
getInstances() {
|
|
1052
1066
|
return this.instanceMatrix;
|
|
@@ -1055,7 +1069,9 @@ export class Instance extends SimulationElement3d {
|
|
|
1055
1069
|
return this.instanceMatrix.length;
|
|
1056
1070
|
}
|
|
1057
1071
|
getMatrixBuffer() {
|
|
1058
|
-
this.
|
|
1072
|
+
if (!this.hasMapped) {
|
|
1073
|
+
this.mapBuffer();
|
|
1074
|
+
}
|
|
1059
1075
|
return this.matrixBuffer;
|
|
1060
1076
|
}
|
|
1061
1077
|
getVertexCount() {
|
package/dist/simulation.js
CHANGED
|
@@ -69,16 +69,21 @@ class FrameRateView {
|
|
|
69
69
|
fpsBuffer = [];
|
|
70
70
|
maxFpsBufferLength = 8;
|
|
71
71
|
prevAvg = 0;
|
|
72
|
+
showing;
|
|
72
73
|
constructor(show) {
|
|
73
74
|
this.el = document.createElement('div');
|
|
74
75
|
this.el.classList.add('simjs-frame-rate');
|
|
76
|
+
this.showing = show;
|
|
75
77
|
const style = document.createElement('style');
|
|
76
78
|
style.innerHTML = simjsFrameRateCss;
|
|
77
|
-
if (
|
|
79
|
+
if (this.showing) {
|
|
78
80
|
document.head.appendChild(style);
|
|
79
81
|
document.body.appendChild(this.el);
|
|
80
82
|
}
|
|
81
83
|
}
|
|
84
|
+
isActive() {
|
|
85
|
+
return this.showing;
|
|
86
|
+
}
|
|
82
87
|
updateFrameRate(num) {
|
|
83
88
|
if (this.fpsBuffer.length < this.maxFpsBufferLength) {
|
|
84
89
|
this.fpsBuffer.push(num);
|
|
@@ -400,9 +405,7 @@ export class Simulation extends Settings {
|
|
|
400
405
|
let prev = Date.now() - 10;
|
|
401
406
|
let prevFps = 0;
|
|
402
407
|
const frame = async () => {
|
|
403
|
-
if (!canvas)
|
|
404
|
-
return;
|
|
405
|
-
if (!this.renderInfo)
|
|
408
|
+
if (!canvas || !this.renderInfo)
|
|
406
409
|
return;
|
|
407
410
|
requestAnimationFrame(frame);
|
|
408
411
|
if (!this.running)
|
|
@@ -411,7 +414,7 @@ export class Simulation extends Settings {
|
|
|
411
414
|
const diff = Math.max(now - prev, 1);
|
|
412
415
|
prev = now;
|
|
413
416
|
const fps = 1000 / diff;
|
|
414
|
-
if (fps === prevFps) {
|
|
417
|
+
if (fps === prevFps && this.frameRateView.isActive()) {
|
|
415
418
|
this.frameRateView.updateFrameRate(fps);
|
|
416
419
|
}
|
|
417
420
|
prevFps = fps;
|