simulationjsv2 0.10.2 → 0.10.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/TODO.md +1 -0
- package/dist/graphics.d.ts +2 -1
- package/dist/graphics.js +59 -6
- package/dist/materials.d.ts +3 -1
- package/dist/materials.js +12 -1
- package/dist/simulation.d.ts +1 -0
- package/dist/simulation.js +6 -0
- package/package.json +1 -1
package/TODO.md
CHANGED
package/dist/graphics.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export declare abstract class SimulationElement3d {
|
|
|
27
27
|
is3d: boolean;
|
|
28
28
|
isEmpty: boolean;
|
|
29
29
|
constructor(pos: Vector3, rotation: Vector3, color?: Color);
|
|
30
|
+
emptyShallow(): void;
|
|
31
|
+
empty(): void;
|
|
30
32
|
getId(): string | null;
|
|
31
33
|
setId(id: string): void;
|
|
32
34
|
getColor(): Color;
|
|
@@ -52,7 +54,6 @@ export declare abstract class SimulationElement3d {
|
|
|
52
54
|
resetCenterOffset(): void;
|
|
53
55
|
getModelMatrix(): Mat4;
|
|
54
56
|
isTransparent(): boolean;
|
|
55
|
-
setMaterial(material: Material): void;
|
|
56
57
|
getObjectInfo(): string;
|
|
57
58
|
getUniformBuffer(): GPUBuffer;
|
|
58
59
|
getPipeline(): GPURenderPipeline;
|
package/dist/graphics.js
CHANGED
|
@@ -44,6 +44,15 @@ export class SimulationElement3d {
|
|
|
44
44
|
this.cullMode = 'none';
|
|
45
45
|
this.id = null;
|
|
46
46
|
}
|
|
47
|
+
emptyShallow() {
|
|
48
|
+
this.children = [];
|
|
49
|
+
}
|
|
50
|
+
empty() {
|
|
51
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
52
|
+
this.children[i].empty();
|
|
53
|
+
}
|
|
54
|
+
this.children = [];
|
|
55
|
+
}
|
|
47
56
|
getId() {
|
|
48
57
|
return this.id;
|
|
49
58
|
}
|
|
@@ -146,9 +155,6 @@ export class SimulationElement3d {
|
|
|
146
155
|
isTransparent() {
|
|
147
156
|
return this.material.isTransparent();
|
|
148
157
|
}
|
|
149
|
-
setMaterial(material) {
|
|
150
|
-
this.material = material;
|
|
151
|
-
}
|
|
152
158
|
getObjectInfo() {
|
|
153
159
|
const topologyString = this.isWireframe() ? 'line-strip' : 'triangle-' + this.getGeometryTopology();
|
|
154
160
|
return `{ "topology": "${topologyString}", "transparent": ${this.isTransparent()}, "cullMode": "${this.cullMode}" }`;
|
|
@@ -267,6 +273,53 @@ export class SimulationElement3d {
|
|
|
267
273
|
this.vertexCache.updated();
|
|
268
274
|
}, t, f);
|
|
269
275
|
}
|
|
276
|
+
// setMaterial(material: Material, t = 0, f?: LerpFunc) {
|
|
277
|
+
// let colorDiff: Color | Color[];
|
|
278
|
+
// if (material.hasVertexColors()) {
|
|
279
|
+
// const diffs = material.getVertexColors().map((color) => color.clone());
|
|
280
|
+
// const initialColor = this.material.getColor();
|
|
281
|
+
// const colorArr = this.material.hasVertexColors()
|
|
282
|
+
// ? this.material.getVertexColors()
|
|
283
|
+
// : Array(diffs.length).map(() => initialColor.clone());
|
|
284
|
+
// if (!this.material.hasVertexColors()) {
|
|
285
|
+
// this.material.setVertexColors(colorArr);
|
|
286
|
+
// this.material.setHasVertexColors(true);
|
|
287
|
+
// }
|
|
288
|
+
// colorDiff = diffs.map((diff, index) => diff.diff(colorArr[index]));
|
|
289
|
+
// } else if (this.material.hasVertexColors()) {
|
|
290
|
+
// const initialColor = material.getColor();
|
|
291
|
+
// const currentColors = this.material.getVertexColors();
|
|
292
|
+
// const colorArr = Array(currentColors.length).map(() => initialColor.clone());
|
|
293
|
+
// colorDiff = colorArr.map((color, index) => color.diff(currentColors[index]));
|
|
294
|
+
// } else {
|
|
295
|
+
// colorDiff = material.getColor().diff(this.material.getColor());
|
|
296
|
+
// }
|
|
297
|
+
// // TODO finish this
|
|
298
|
+
// return transitionValues(
|
|
299
|
+
// (p) => {
|
|
300
|
+
// if (Array.isArray(colorDiff)) {
|
|
301
|
+
// const colors = this.material.getVertexColors();
|
|
302
|
+
// for (let i = 0; i < colors.length; i++) {
|
|
303
|
+
// colors[i].r += colorDiff[i].r * p;
|
|
304
|
+
// colors[i].g += colorDiff[i].g * p;
|
|
305
|
+
// colors[i].b += colorDiff[i].b * p;
|
|
306
|
+
// colors[i].a += colorDiff[i].a * p;
|
|
307
|
+
// }
|
|
308
|
+
// } else {
|
|
309
|
+
// const currentColor = this.material.getColor();
|
|
310
|
+
// currentColor.r += colorDiff.r * p;
|
|
311
|
+
// currentColor.g += colorDiff.g * p;
|
|
312
|
+
// currentColor.b += colorDiff.b * p;
|
|
313
|
+
// currentColor.a += colorDiff.a * p;
|
|
314
|
+
// }
|
|
315
|
+
// },
|
|
316
|
+
// () => {
|
|
317
|
+
// this.material = material;
|
|
318
|
+
// },
|
|
319
|
+
// t,
|
|
320
|
+
// f
|
|
321
|
+
// );
|
|
322
|
+
// }
|
|
270
323
|
move(amount, t = 0, f) {
|
|
271
324
|
const tempAmount = cloneBuf(amount);
|
|
272
325
|
const finalPos = cloneBuf(this.pos);
|
|
@@ -552,7 +605,7 @@ export class Polygon extends SimulationElement2d {
|
|
|
552
605
|
const prevColor = this.getColor();
|
|
553
606
|
this.shader = vertexColorShader;
|
|
554
607
|
this.geometry = new PolygonGeometry(vectors);
|
|
555
|
-
this.material = new VertexColorMaterial();
|
|
608
|
+
this.material = new VertexColorMaterial([]);
|
|
556
609
|
this.material.setColor(prevColor);
|
|
557
610
|
const colors = vertices.map((vert) => vert.getColor() ?? this.material.getColor());
|
|
558
611
|
this.material.setVertexColors(colors);
|
|
@@ -913,7 +966,7 @@ export class Spline2d extends SimulationElement2d {
|
|
|
913
966
|
this.interpolateLimit = 1;
|
|
914
967
|
this.length = 0;
|
|
915
968
|
this.geometry = new Spline2dGeometry(points, this.thickness, this.detail);
|
|
916
|
-
this.material = new VertexColorMaterial();
|
|
969
|
+
this.material = new VertexColorMaterial([]);
|
|
917
970
|
this.material.setColor(pos.getColor() ?? globalInfo.getDefaultColor());
|
|
918
971
|
this.setVertexColors();
|
|
919
972
|
this.shader = vertexColorShader;
|
|
@@ -1153,7 +1206,7 @@ export class TraceLines2d extends SimulationElement2d {
|
|
|
1153
1206
|
constructor(color, maxLen) {
|
|
1154
1207
|
super(vector2(), vector3(), color);
|
|
1155
1208
|
this.geometry = new TraceLinesGeometry(maxLen);
|
|
1156
|
-
this.material = new VertexColorMaterial();
|
|
1209
|
+
this.material = new VertexColorMaterial([]);
|
|
1157
1210
|
if (color)
|
|
1158
1211
|
this.material.setColor(color);
|
|
1159
1212
|
this.shader = vertexColorShader;
|
package/dist/materials.d.ts
CHANGED
|
@@ -5,16 +5,18 @@ export declare class Material {
|
|
|
5
5
|
protected isVertexColors: boolean;
|
|
6
6
|
constructor();
|
|
7
7
|
hasVertexColors(): boolean;
|
|
8
|
+
setHasVertexColors(hasColors: boolean): void;
|
|
8
9
|
getVertexColors(): Color[];
|
|
9
10
|
getColor(): Color;
|
|
10
11
|
addVertexColor(color: Color): void;
|
|
11
12
|
setVertexColors(colors: Color[]): void;
|
|
12
13
|
isTransparent(): boolean;
|
|
13
14
|
setColor(color: Color): void;
|
|
15
|
+
clone(): Material;
|
|
14
16
|
}
|
|
15
17
|
export declare class BasicMaterial extends Material {
|
|
16
18
|
constructor(color: Color);
|
|
17
19
|
}
|
|
18
20
|
export declare class VertexColorMaterial extends Material {
|
|
19
|
-
constructor();
|
|
21
|
+
constructor(colors: Color[]);
|
|
20
22
|
}
|
package/dist/materials.js
CHANGED
|
@@ -11,6 +11,9 @@ export class Material {
|
|
|
11
11
|
hasVertexColors() {
|
|
12
12
|
return this.isVertexColors;
|
|
13
13
|
}
|
|
14
|
+
setHasVertexColors(hasColors) {
|
|
15
|
+
this.isVertexColors = hasColors;
|
|
16
|
+
}
|
|
14
17
|
getVertexColors() {
|
|
15
18
|
return this.vertexColors;
|
|
16
19
|
}
|
|
@@ -36,6 +39,13 @@ export class Material {
|
|
|
36
39
|
setColor(color) {
|
|
37
40
|
this.color = color;
|
|
38
41
|
}
|
|
42
|
+
clone() {
|
|
43
|
+
const res = new Material();
|
|
44
|
+
res.setColor(this.color.clone());
|
|
45
|
+
res.setVertexColors(this.vertexColors.map((color) => color.clone()));
|
|
46
|
+
res.setHasVertexColors(this.isVertexColors);
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
39
49
|
}
|
|
40
50
|
export class BasicMaterial extends Material {
|
|
41
51
|
constructor(color) {
|
|
@@ -44,8 +54,9 @@ export class BasicMaterial extends Material {
|
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
export class VertexColorMaterial extends Material {
|
|
47
|
-
constructor() {
|
|
57
|
+
constructor(colors) {
|
|
48
58
|
super();
|
|
59
|
+
this.vertexColors = colors;
|
|
49
60
|
this.isVertexColors = true;
|
|
50
61
|
}
|
|
51
62
|
}
|
package/dist/simulation.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export declare class Simulation extends Settings {
|
|
|
45
45
|
add(el: SimulationElement3d, id?: string): void;
|
|
46
46
|
remove(el: SimulationElement3d): void;
|
|
47
47
|
removeId(id: string): void;
|
|
48
|
+
empty(): void;
|
|
48
49
|
private applyCanvasSize;
|
|
49
50
|
setCanvasSize(width: number, height: number): void;
|
|
50
51
|
start(): void;
|
package/dist/simulation.js
CHANGED
|
@@ -214,6 +214,12 @@ export class Simulation extends Settings {
|
|
|
214
214
|
removeId(id) {
|
|
215
215
|
removeSceneId(this.scene, id);
|
|
216
216
|
}
|
|
217
|
+
empty() {
|
|
218
|
+
for (let i = 0; i < this.scene.length; i++) {
|
|
219
|
+
this.scene[i].empty();
|
|
220
|
+
}
|
|
221
|
+
this.scene = [];
|
|
222
|
+
}
|
|
217
223
|
applyCanvasSize(width, height) {
|
|
218
224
|
if (this.canvasRef === null)
|
|
219
225
|
return;
|