simulationjsv2 0.4.3 → 0.4.4
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.js +1 -0
- package/dist/internalUtils.js +0 -2
- package/dist/simulation.d.ts +1 -0
- package/dist/simulation.js +25 -11
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/graphics.js
CHANGED
|
@@ -373,6 +373,7 @@ export class Circle extends SimulationElement2d {
|
|
|
373
373
|
detail;
|
|
374
374
|
constructor(pos, radius, color, detail = 50) {
|
|
375
375
|
super(pos, 0, color);
|
|
376
|
+
vector2ToPixelRatio(this.pos);
|
|
376
377
|
this.radius = radius;
|
|
377
378
|
this.detail = detail;
|
|
378
379
|
this.geometry = new CircleGeometry(this.radius, this.detail);
|
package/dist/internalUtils.js
CHANGED
package/dist/simulation.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export declare class SceneCollection extends SimulationElement3d {
|
|
|
44
44
|
setWireframe(_: boolean): void;
|
|
45
45
|
getName(): string;
|
|
46
46
|
getScene(): SimSceneObjInfo[];
|
|
47
|
+
getVertexCount(): number;
|
|
47
48
|
getSceneObjects(): SimulationElement<Vector3 | Vector2>[];
|
|
48
49
|
setSceneObjects(newScene: SimulationElement<any>[]): void;
|
|
49
50
|
setScene(newScene: SimSceneObjInfo[]): void;
|
package/dist/simulation.js
CHANGED
|
@@ -266,7 +266,8 @@ export class Simulation {
|
|
|
266
266
|
this.renderInfo = {
|
|
267
267
|
uniformBuffer,
|
|
268
268
|
bindGroupLayout,
|
|
269
|
-
instanceBuffer
|
|
269
|
+
instanceBuffer,
|
|
270
|
+
vertexBuffer: null
|
|
270
271
|
};
|
|
271
272
|
this.pipelines = {
|
|
272
273
|
triangleList2d: createPipeline(device, shaderModule, bindGroupLayout, presentationFormat, 'vertex_main_2d', 'triangle-list'),
|
|
@@ -329,6 +330,8 @@ export class Simulation {
|
|
|
329
330
|
const frame = async () => {
|
|
330
331
|
if (!canvas)
|
|
331
332
|
return;
|
|
333
|
+
if (!this.renderInfo)
|
|
334
|
+
return;
|
|
332
335
|
requestAnimationFrame(frame);
|
|
333
336
|
if (!this.running)
|
|
334
337
|
return;
|
|
@@ -369,22 +372,25 @@ export class Simulation {
|
|
|
369
372
|
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
|
|
370
373
|
passEncoder.setPipeline(this.pipelines.triangleList3d);
|
|
371
374
|
passEncoder.setBindGroup(0, uniformBindGroup);
|
|
372
|
-
|
|
375
|
+
const totalVertices = getTotalVertices(this.scene);
|
|
376
|
+
if (this.renderInfo.vertexBuffer === null ||
|
|
377
|
+
this.renderInfo.vertexBuffer.size / (4 * BUF_LEN) < totalVertices) {
|
|
378
|
+
this.renderInfo.vertexBuffer = device.createBuffer({
|
|
379
|
+
size: totalVertices * 4 * BUF_LEN,
|
|
380
|
+
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
this.renderScene(device, passEncoder, this.renderInfo.vertexBuffer, this.scene, 0, diff);
|
|
373
384
|
this.camera.updateConsumed();
|
|
374
385
|
passEncoder.end();
|
|
375
386
|
device.queue.submit([commandEncoder.finish()]);
|
|
376
387
|
};
|
|
377
388
|
requestAnimationFrame(frame);
|
|
378
389
|
}
|
|
379
|
-
|
|
390
|
+
renderScene(device, passEncoder, vertexBuffer, scene, startOffset, diff) {
|
|
380
391
|
if (this.pipelines === null)
|
|
381
|
-
return;
|
|
382
|
-
let
|
|
383
|
-
const vertexBuffer = device.createBuffer({
|
|
384
|
-
size: totalVertices * 4 * BUF_LEN,
|
|
385
|
-
usage: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST
|
|
386
|
-
});
|
|
387
|
-
let currentOffset = 0;
|
|
392
|
+
return 0;
|
|
393
|
+
let currentOffset = startOffset;
|
|
388
394
|
let toRemove = [];
|
|
389
395
|
for (let i = 0; i < scene.length; i++) {
|
|
390
396
|
const lifetime = scene[i].getLifetime();
|
|
@@ -398,7 +404,7 @@ export class Simulation {
|
|
|
398
404
|
}
|
|
399
405
|
const obj = scene[i].getObj();
|
|
400
406
|
if (obj.isCollection) {
|
|
401
|
-
this.renderScene(device, passEncoder, obj.getScene(), diff);
|
|
407
|
+
currentOffset += this.renderScene(device, passEncoder, vertexBuffer, obj.getScene(), currentOffset, diff);
|
|
402
408
|
continue;
|
|
403
409
|
}
|
|
404
410
|
const buffer = new Float32Array(obj.getBuffer(this.camera));
|
|
@@ -465,6 +471,7 @@ export class Simulation {
|
|
|
465
471
|
for (let i = toRemove.length - 1; i >= 0; i--) {
|
|
466
472
|
removeObject(scene, scene[i].getObj());
|
|
467
473
|
}
|
|
474
|
+
return currentOffset - startOffset;
|
|
468
475
|
}
|
|
469
476
|
fitElement() {
|
|
470
477
|
this.assertHasCanvas();
|
|
@@ -501,6 +508,13 @@ export class SceneCollection extends SimulationElement3d {
|
|
|
501
508
|
getScene() {
|
|
502
509
|
return this.scene;
|
|
503
510
|
}
|
|
511
|
+
getVertexCount() {
|
|
512
|
+
let total = 0;
|
|
513
|
+
for (let i = 0; i < this.scene.length; i++) {
|
|
514
|
+
total += this.scene[i].getObj().getVertexCount();
|
|
515
|
+
}
|
|
516
|
+
return total;
|
|
517
|
+
}
|
|
504
518
|
getSceneObjects() {
|
|
505
519
|
return this.scene.map((item) => item.getObj());
|
|
506
520
|
}
|
package/dist/types.d.ts
CHANGED