simulationjsv2 0.10.1 → 0.10.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/dist/graphics.d.ts +1 -1
- package/dist/graphics.js +53 -6
- package/dist/materials.d.ts +3 -1
- package/dist/materials.js +12 -1
- package/package.json +1 -1
package/dist/graphics.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export declare abstract class SimulationElement3d {
|
|
|
27
27
|
is3d: boolean;
|
|
28
28
|
isEmpty: boolean;
|
|
29
29
|
constructor(pos: Vector3, rotation: Vector3, color?: Color);
|
|
30
|
+
empty(): void;
|
|
30
31
|
getId(): string | null;
|
|
31
32
|
setId(id: string): void;
|
|
32
33
|
getColor(): Color;
|
|
@@ -52,7 +53,6 @@ export declare abstract class SimulationElement3d {
|
|
|
52
53
|
resetCenterOffset(): void;
|
|
53
54
|
getModelMatrix(): Mat4;
|
|
54
55
|
isTransparent(): boolean;
|
|
55
|
-
setMaterial(material: Material): void;
|
|
56
56
|
getObjectInfo(): string;
|
|
57
57
|
getUniformBuffer(): GPUBuffer;
|
|
58
58
|
getPipeline(): GPURenderPipeline;
|
package/dist/graphics.js
CHANGED
|
@@ -44,6 +44,9 @@ export class SimulationElement3d {
|
|
|
44
44
|
this.cullMode = 'none';
|
|
45
45
|
this.id = null;
|
|
46
46
|
}
|
|
47
|
+
empty() {
|
|
48
|
+
this.children = [];
|
|
49
|
+
}
|
|
47
50
|
getId() {
|
|
48
51
|
return this.id;
|
|
49
52
|
}
|
|
@@ -146,9 +149,6 @@ export class SimulationElement3d {
|
|
|
146
149
|
isTransparent() {
|
|
147
150
|
return this.material.isTransparent();
|
|
148
151
|
}
|
|
149
|
-
setMaterial(material) {
|
|
150
|
-
this.material = material;
|
|
151
|
-
}
|
|
152
152
|
getObjectInfo() {
|
|
153
153
|
const topologyString = this.isWireframe() ? 'line-strip' : 'triangle-' + this.getGeometryTopology();
|
|
154
154
|
return `{ "topology": "${topologyString}", "transparent": ${this.isTransparent()}, "cullMode": "${this.cullMode}" }`;
|
|
@@ -267,6 +267,53 @@ export class SimulationElement3d {
|
|
|
267
267
|
this.vertexCache.updated();
|
|
268
268
|
}, t, f);
|
|
269
269
|
}
|
|
270
|
+
// setMaterial(material: Material, t = 0, f?: LerpFunc) {
|
|
271
|
+
// let colorDiff: Color | Color[];
|
|
272
|
+
// if (material.hasVertexColors()) {
|
|
273
|
+
// const diffs = material.getVertexColors().map((color) => color.clone());
|
|
274
|
+
// const initialColor = this.material.getColor();
|
|
275
|
+
// const colorArr = this.material.hasVertexColors()
|
|
276
|
+
// ? this.material.getVertexColors()
|
|
277
|
+
// : Array(diffs.length).map(() => initialColor.clone());
|
|
278
|
+
// if (!this.material.hasVertexColors()) {
|
|
279
|
+
// this.material.setVertexColors(colorArr);
|
|
280
|
+
// this.material.setHasVertexColors(true);
|
|
281
|
+
// }
|
|
282
|
+
// colorDiff = diffs.map((diff, index) => diff.diff(colorArr[index]));
|
|
283
|
+
// } else if (this.material.hasVertexColors()) {
|
|
284
|
+
// const initialColor = material.getColor();
|
|
285
|
+
// const currentColors = this.material.getVertexColors();
|
|
286
|
+
// const colorArr = Array(currentColors.length).map(() => initialColor.clone());
|
|
287
|
+
// colorDiff = colorArr.map((color, index) => color.diff(currentColors[index]));
|
|
288
|
+
// } else {
|
|
289
|
+
// colorDiff = material.getColor().diff(this.material.getColor());
|
|
290
|
+
// }
|
|
291
|
+
// // TODO finish this
|
|
292
|
+
// return transitionValues(
|
|
293
|
+
// (p) => {
|
|
294
|
+
// if (Array.isArray(colorDiff)) {
|
|
295
|
+
// const colors = this.material.getVertexColors();
|
|
296
|
+
// for (let i = 0; i < colors.length; i++) {
|
|
297
|
+
// colors[i].r += colorDiff[i].r * p;
|
|
298
|
+
// colors[i].g += colorDiff[i].g * p;
|
|
299
|
+
// colors[i].b += colorDiff[i].b * p;
|
|
300
|
+
// colors[i].a += colorDiff[i].a * p;
|
|
301
|
+
// }
|
|
302
|
+
// } else {
|
|
303
|
+
// const currentColor = this.material.getColor();
|
|
304
|
+
// currentColor.r += colorDiff.r * p;
|
|
305
|
+
// currentColor.g += colorDiff.g * p;
|
|
306
|
+
// currentColor.b += colorDiff.b * p;
|
|
307
|
+
// currentColor.a += colorDiff.a * p;
|
|
308
|
+
// }
|
|
309
|
+
// },
|
|
310
|
+
// () => {
|
|
311
|
+
// this.material = material;
|
|
312
|
+
// },
|
|
313
|
+
// t,
|
|
314
|
+
// f
|
|
315
|
+
// );
|
|
316
|
+
// }
|
|
270
317
|
move(amount, t = 0, f) {
|
|
271
318
|
const tempAmount = cloneBuf(amount);
|
|
272
319
|
const finalPos = cloneBuf(this.pos);
|
|
@@ -552,7 +599,7 @@ export class Polygon extends SimulationElement2d {
|
|
|
552
599
|
const prevColor = this.getColor();
|
|
553
600
|
this.shader = vertexColorShader;
|
|
554
601
|
this.geometry = new PolygonGeometry(vectors);
|
|
555
|
-
this.material = new VertexColorMaterial();
|
|
602
|
+
this.material = new VertexColorMaterial([]);
|
|
556
603
|
this.material.setColor(prevColor);
|
|
557
604
|
const colors = vertices.map((vert) => vert.getColor() ?? this.material.getColor());
|
|
558
605
|
this.material.setVertexColors(colors);
|
|
@@ -913,7 +960,7 @@ export class Spline2d extends SimulationElement2d {
|
|
|
913
960
|
this.interpolateLimit = 1;
|
|
914
961
|
this.length = 0;
|
|
915
962
|
this.geometry = new Spline2dGeometry(points, this.thickness, this.detail);
|
|
916
|
-
this.material = new VertexColorMaterial();
|
|
963
|
+
this.material = new VertexColorMaterial([]);
|
|
917
964
|
this.material.setColor(pos.getColor() ?? globalInfo.getDefaultColor());
|
|
918
965
|
this.setVertexColors();
|
|
919
966
|
this.shader = vertexColorShader;
|
|
@@ -1153,7 +1200,7 @@ export class TraceLines2d extends SimulationElement2d {
|
|
|
1153
1200
|
constructor(color, maxLen) {
|
|
1154
1201
|
super(vector2(), vector3(), color);
|
|
1155
1202
|
this.geometry = new TraceLinesGeometry(maxLen);
|
|
1156
|
-
this.material = new VertexColorMaterial();
|
|
1203
|
+
this.material = new VertexColorMaterial([]);
|
|
1157
1204
|
if (color)
|
|
1158
1205
|
this.material.setColor(color);
|
|
1159
1206
|
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
|
}
|