simulationjsv2 0.4.6 → 0.4.8
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/dist/graphics.d.ts +1 -0
- package/dist/graphics.js +7 -3
- package/dist/simulation.js +1 -1
- package/package.json +1 -1
package/dist/graphics.d.ts
CHANGED
|
@@ -184,6 +184,7 @@ export declare class Instance<T extends SimulationElement2d | SimulationElement3
|
|
|
184
184
|
private matrixBuffer;
|
|
185
185
|
private device;
|
|
186
186
|
private baseMat;
|
|
187
|
+
private needsRemap;
|
|
187
188
|
constructor(obj: T, numInstances: number);
|
|
188
189
|
setNumInstances(numInstances: number): void;
|
|
189
190
|
setInstance(instance: number, transformation: Mat4): void;
|
package/dist/graphics.js
CHANGED
|
@@ -895,6 +895,7 @@ export class Instance extends SimulationElement3d {
|
|
|
895
895
|
matrixBuffer;
|
|
896
896
|
device;
|
|
897
897
|
baseMat;
|
|
898
|
+
needsRemap = false;
|
|
898
899
|
constructor(obj, numInstances) {
|
|
899
900
|
super(vector3());
|
|
900
901
|
this.device = null;
|
|
@@ -937,14 +938,14 @@ export class Instance extends SimulationElement3d {
|
|
|
937
938
|
}
|
|
938
939
|
if (this.device) {
|
|
939
940
|
this.setMatrixBuffer();
|
|
940
|
-
this.
|
|
941
|
+
this.needsRemap = true;
|
|
941
942
|
}
|
|
942
943
|
}
|
|
943
944
|
setInstance(instance, transformation) {
|
|
944
945
|
if (instance >= this.instanceMatrix.length || instance < 0)
|
|
945
946
|
return;
|
|
946
947
|
this.instanceMatrix[instance] = transformation;
|
|
947
|
-
this.
|
|
948
|
+
this.needsRemap = true;
|
|
948
949
|
}
|
|
949
950
|
mapBuffer() {
|
|
950
951
|
if (!this.device || this.matrixBuffer === null)
|
|
@@ -952,6 +953,7 @@ export class Instance extends SimulationElement3d {
|
|
|
952
953
|
const buf = new Float32Array(this.instanceMatrix.map((mat) => [...mat]).flat());
|
|
953
954
|
this.device.queue.writeBuffer(this.matrixBuffer, 0, buf.buffer, buf.byteOffset, buf.byteLength);
|
|
954
955
|
this.matrixBuffer.unmap();
|
|
956
|
+
this.needsRemap = false;
|
|
955
957
|
}
|
|
956
958
|
setMatrixBuffer() {
|
|
957
959
|
if (!this.device || this.instanceMatrix.length === 0)
|
|
@@ -962,7 +964,7 @@ export class Instance extends SimulationElement3d {
|
|
|
962
964
|
size,
|
|
963
965
|
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
|
|
964
966
|
});
|
|
965
|
-
this.
|
|
967
|
+
this.needsRemap = true;
|
|
966
968
|
}
|
|
967
969
|
getInstances() {
|
|
968
970
|
return this.instanceMatrix;
|
|
@@ -987,6 +989,8 @@ export class Instance extends SimulationElement3d {
|
|
|
987
989
|
}
|
|
988
990
|
updateMatrix(_) { }
|
|
989
991
|
getBuffer(camera) {
|
|
992
|
+
if (this.needsRemap)
|
|
993
|
+
this.mapBuffer();
|
|
990
994
|
return this.obj.getBuffer(camera);
|
|
991
995
|
}
|
|
992
996
|
}
|
package/dist/simulation.js
CHANGED
|
@@ -12,7 +12,7 @@ struct Uniforms {
|
|
|
12
12
|
|
|
13
13
|
@group(0) @binding(0) var<uniform> uniforms : Uniforms;
|
|
14
14
|
|
|
15
|
-
@group(0) @binding(1) var<storage, read> instanceMatrices : array<mat4x4f
|
|
15
|
+
@group(0) @binding(1) var<storage, read> instanceMatrices : array<mat4x4f>;
|
|
16
16
|
|
|
17
17
|
struct VertexOutput {
|
|
18
18
|
@builtin(position) Position : vec4<f32>,
|