@equinor/esv-intersection 3.1.8 → 4.0.0
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/datautils/schematicShapeGenerator.d.ts +5 -5
- package/dist/datautils/schematicShapeGenerator.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1386 -1381
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/layers/CustomDisplayObjects/ComplexRope.d.ts +2 -3
- package/dist/layers/CustomDisplayObjects/ComplexRope.d.ts.map +1 -1
- package/dist/layers/CustomDisplayObjects/ComplexRopeGeometry.d.ts.map +1 -1
- package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRope.d.ts +3 -4
- package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRope.d.ts.map +1 -1
- package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.d.ts +4 -4
- package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.d.ts.map +1 -1
- package/dist/layers/CustomDisplayObjects/UniformTextureStretchRope.d.ts +3 -4
- package/dist/layers/CustomDisplayObjects/UniformTextureStretchRope.d.ts.map +1 -1
- package/dist/layers/CustomDisplayObjects/UniformTextureStretchRopeGeometry.d.ts +4 -4
- package/dist/layers/CustomDisplayObjects/UniformTextureStretchRopeGeometry.d.ts.map +1 -1
- package/dist/layers/GeomodelLayerV2.d.ts.map +1 -1
- package/dist/layers/SchematicLayer.d.ts +6 -6
- package/dist/layers/SchematicLayer.d.ts.map +1 -1
- package/dist/layers/base/PixiLayer.d.ts +7 -8
- package/dist/layers/base/PixiLayer.d.ts.map +1 -1
- package/dist/utils/vectorUtils.d.ts +6 -6
- package/dist/utils/vectorUtils.d.ts.map +1 -1
- package/dist/vendor/pixi-dashed-line/index.d.ts +13 -13
- package/dist/vendor/pixi-dashed-line/index.d.ts.map +1 -1
- package/package.json +3 -6
- package/src/datautils/schematicShapeGenerator.ts +23 -21
- package/src/layers/CustomDisplayObjects/ComplexRope.ts +10 -13
- package/src/layers/CustomDisplayObjects/ComplexRopeGeometry.ts +9 -8
- package/src/layers/CustomDisplayObjects/FixedWidthSimpleRope.ts +11 -14
- package/src/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.ts +13 -12
- package/src/layers/CustomDisplayObjects/UniformTextureStretchRope.ts +11 -16
- package/src/layers/CustomDisplayObjects/UniformTextureStretchRopeGeometry.ts +11 -11
- package/src/layers/GeomodelLayerV2.ts +4 -5
- package/src/layers/SchematicLayer.ts +42 -31
- package/src/layers/base/PixiLayer.ts +11 -38
- package/src/utils/vectorUtils.ts +6 -6
- package/src/vendor/pixi-dashed-line/index.ts +33 -32
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Point, MeshGeometry } from 'pixi.js';
|
|
2
2
|
|
|
3
3
|
export class FixedWidthSimpleRopeGeometry extends MeshGeometry {
|
|
4
|
-
public points:
|
|
4
|
+
public points: Point[];
|
|
5
5
|
_width: number;
|
|
6
6
|
/**
|
|
7
7
|
* @param {number} [width=200] - The width (i.e., thickness) of the rope.
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {Point[]} [points] - An array of Point objects to construct this rope.
|
|
9
9
|
*/
|
|
10
|
-
constructor(points:
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
constructor(points: Point[], width = 200) {
|
|
11
|
+
super({
|
|
12
|
+
positions: new Float32Array(points.length * 4),
|
|
13
|
+
uvs: new Float32Array(points.length * 4),
|
|
14
|
+
indices: new Uint32Array((points.length - 1) * 6),
|
|
15
|
+
});
|
|
13
16
|
/**
|
|
14
17
|
* An array of points that determine the rope
|
|
15
|
-
* @member {
|
|
18
|
+
* @member {Point[]}
|
|
16
19
|
*/
|
|
17
20
|
this.points = points;
|
|
18
21
|
/**
|
|
@@ -45,20 +48,18 @@ export class FixedWidthSimpleRopeGeometry extends MeshGeometry {
|
|
|
45
48
|
if (!points) {
|
|
46
49
|
return;
|
|
47
50
|
}
|
|
48
|
-
const vertexBuffer = this.getBuffer('
|
|
49
|
-
const uvBuffer = this.getBuffer('
|
|
51
|
+
const vertexBuffer = this.getBuffer('aPosition');
|
|
52
|
+
const uvBuffer = this.getBuffer('aUV');
|
|
50
53
|
const indexBuffer = this.getIndex();
|
|
54
|
+
|
|
51
55
|
// if too little points, or texture hasn't got UVs set yet just move on.
|
|
52
56
|
if (points.length < 1) {
|
|
53
57
|
return;
|
|
54
58
|
}
|
|
55
59
|
// if the number of points has changed we will need to recreate the arraybuffers
|
|
56
60
|
if (vertexBuffer.data.length / 4 !== points.length) {
|
|
57
|
-
// @ts-expect-error Temporary fix until pixi.js is updated
|
|
58
61
|
vertexBuffer.data = new Float32Array(points.length * 4);
|
|
59
|
-
// @ts-expect-error Temporary fix until pixi.js is updated
|
|
60
62
|
uvBuffer.data = new Float32Array(points.length * 4);
|
|
61
|
-
// @ts-expect-error Temporary fix until pixi.js is updated
|
|
62
63
|
indexBuffer.data = new Uint16Array((points.length - 1) * 6);
|
|
63
64
|
}
|
|
64
65
|
const uvs = uvBuffer.data;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Point, Mesh, Texture } from 'pixi.js';
|
|
2
2
|
import { UniformTextureStretchRopeGeometry } from './UniformTextureStretchRopeGeometry';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -13,27 +13,22 @@ export class UniformTextureStretchRope extends Mesh {
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @param texture - The texture to use on the rope.
|
|
16
|
-
* @param points - An array of {@link
|
|
16
|
+
* @param points - An array of {@link Point} objects to construct this rope.
|
|
17
17
|
*/
|
|
18
|
-
constructor(texture: Texture, points:
|
|
18
|
+
constructor(texture: Texture, points: Point[]) {
|
|
19
19
|
const ropeGeometry = new UniformTextureStretchRopeGeometry(points, texture.height);
|
|
20
|
-
const meshMaterial = new MeshMaterial(texture);
|
|
21
20
|
|
|
22
|
-
super(ropeGeometry,
|
|
21
|
+
super({ geometry: ropeGeometry, texture });
|
|
23
22
|
|
|
24
23
|
this.autoUpdate = true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
override _render(renderer: Renderer): void {
|
|
28
|
-
const geometry: UniformTextureStretchRopeGeometry = this.geometry as UniformTextureStretchRopeGeometry;
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (this.autoUpdate || geometry._width !== this.shader.texture.height) {
|
|
33
|
-
geometry._width = this.shader.texture.height;
|
|
34
|
-
geometry.update();
|
|
35
|
-
}
|
|
25
|
+
this.onRender = () => {
|
|
26
|
+
const geometry: UniformTextureStretchRopeGeometry = this.geometry as UniformTextureStretchRopeGeometry;
|
|
36
27
|
|
|
37
|
-
|
|
28
|
+
if (this.autoUpdate || geometry._width !== this.shader?.texture.height) {
|
|
29
|
+
geometry._width = this.shader?.texture.height ?? 0;
|
|
30
|
+
geometry.update();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
38
33
|
}
|
|
39
34
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { MeshGeometry } from 'pixi.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Point } from 'pixi.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* UniformTextureStretchRopeGeometry allows you to draw a geometry across several points and then manipulate these points.
|
|
6
6
|
*/
|
|
7
7
|
export class UniformTextureStretchRopeGeometry extends MeshGeometry {
|
|
8
8
|
/** An array of points that determine the rope. */
|
|
9
|
-
public points:
|
|
9
|
+
public points: Point[];
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The width (i.e., thickness) of the rope.
|
|
@@ -16,11 +16,14 @@ export class UniformTextureStretchRopeGeometry extends MeshGeometry {
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @param width - The width (i.e., thickness) of the rope.
|
|
19
|
-
* @param points - An array of
|
|
19
|
+
* @param points - An array of Point objects to construct this rope.
|
|
20
20
|
*/
|
|
21
|
-
constructor(points:
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
constructor(points: Point[], width = 200) {
|
|
22
|
+
super({
|
|
23
|
+
positions: new Float32Array(points.length * 4),
|
|
24
|
+
uvs: new Float32Array(points.length * 4),
|
|
25
|
+
indices: new Uint32Array((points.length - 1) * 6),
|
|
26
|
+
});
|
|
24
27
|
|
|
25
28
|
this.points = points;
|
|
26
29
|
this._width = width;
|
|
@@ -36,8 +39,8 @@ export class UniformTextureStretchRopeGeometry extends MeshGeometry {
|
|
|
36
39
|
return;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
|
-
const vertexBuffer = this.getBuffer('
|
|
40
|
-
const uvBuffer = this.getBuffer('
|
|
42
|
+
const vertexBuffer = this.getBuffer('aPosition');
|
|
43
|
+
const uvBuffer = this.getBuffer('aUV');
|
|
41
44
|
const indexBuffer = this.getIndex();
|
|
42
45
|
|
|
43
46
|
// if too few points, or texture hasn't got UVs set yet just move on.
|
|
@@ -47,11 +50,8 @@ export class UniformTextureStretchRopeGeometry extends MeshGeometry {
|
|
|
47
50
|
|
|
48
51
|
// if the number of points has changed we will need to recreate the arraybuffers
|
|
49
52
|
if (vertexBuffer.data.length / 4 !== points.length) {
|
|
50
|
-
// @ts-expect-error Temporary fix until pixi.js is updated
|
|
51
53
|
vertexBuffer.data = new Float32Array(points.length * 4);
|
|
52
|
-
// @ts-expect-error Temporary fix until pixi.js is updated
|
|
53
54
|
uvBuffer.data = new Float32Array(points.length * 4);
|
|
54
|
-
// @ts-expect-error Temporary fix until pixi.js is updated
|
|
55
55
|
indexBuffer.data = new Uint16Array((points.length - 1) * 6);
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -77,11 +77,10 @@ export class GeomodelLayerV2<T extends SurfaceData> extends PixiLayer<T> {
|
|
|
77
77
|
|
|
78
78
|
generateAreaPolygon = (s: SurfaceArea): void => {
|
|
79
79
|
const g = new Graphics();
|
|
80
|
-
g.lineStyle(1, s.color as number, 1);
|
|
81
|
-
g.beginFill(s.color as number);
|
|
82
80
|
const polygons = this.createPolygons(s.data);
|
|
83
|
-
polygons.forEach((polygon: number[]) => g.
|
|
84
|
-
g.
|
|
81
|
+
polygons.forEach((polygon: number[]) => g.poly(polygon));
|
|
82
|
+
g.setStrokeStyle({ width: 1, color: s.color as number, alpha: 1 });
|
|
83
|
+
g.fill({ color: s.color as number });
|
|
85
84
|
this.addChild(g);
|
|
86
85
|
};
|
|
87
86
|
|
|
@@ -90,7 +89,7 @@ export class GeomodelLayerV2<T extends SurfaceData> extends PixiLayer<T> {
|
|
|
90
89
|
const { data: d } = s;
|
|
91
90
|
|
|
92
91
|
const alignment = 0.5;
|
|
93
|
-
g.
|
|
92
|
+
g.setStrokeStyle({ width: SURFACE_LINE_WIDTH, color: s.color as number, alpha: 1, alignment });
|
|
94
93
|
|
|
95
94
|
let penDown = false;
|
|
96
95
|
for (let i = 0; i < d.length; i++) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { max } from 'd3-array';
|
|
2
2
|
import { scaleLinear, ScaleLinear } from 'd3-scale';
|
|
3
|
-
import { Graphics, groupD8,
|
|
3
|
+
import { Assets, Graphics, groupD8, Point, Rectangle, MeshRope, Texture } from 'pixi.js';
|
|
4
4
|
import { DashLine } from '../vendor/pixi-dashed-line';
|
|
5
5
|
import { LayerOptions, PixiLayer, PixiRenderApplication } from '.';
|
|
6
6
|
import { DEFAULT_TEXTURE_SIZE, EXAGGERATED_DIAMETER, HOLE_OUTLINE, SCREEN_OUTLINE } from '../constants';
|
|
@@ -186,14 +186,14 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
186
186
|
this.textureSymbolCacheArray = null;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
public override onUpdate(event: OnUpdateEvent<T>): void {
|
|
189
|
+
public override async onUpdate(event: OnUpdateEvent<T>): Promise<void> {
|
|
190
190
|
super.onUpdate(event);
|
|
191
191
|
this.clearLayer();
|
|
192
|
-
this.preRender();
|
|
192
|
+
await this.preRender();
|
|
193
193
|
this.render();
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
public override onRescale(event: OnRescaleEvent): void {
|
|
196
|
+
public override async onRescale(event: OnRescaleEvent): Promise<void> {
|
|
197
197
|
const shouldRecalculate = this.scalingFactors.zFactor !== event.zFactor;
|
|
198
198
|
|
|
199
199
|
this.scalingFactors = { height: event.height, zFactor: event.zFactor, yScale: event.yScale };
|
|
@@ -205,13 +205,13 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
205
205
|
this.setContainerScale(event.xRatio * (flippedX ? -1 : 1), yRatio * (flippedY ? -1 : 1));
|
|
206
206
|
if (shouldRecalculate) {
|
|
207
207
|
this.clearLayer();
|
|
208
|
-
this.preRender();
|
|
208
|
+
await this.preRender();
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
this.render();
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
public override setVisibility(isVisible: boolean, layerId: string) {
|
|
214
|
+
public override async setVisibility(isVisible: boolean, layerId: string) {
|
|
215
215
|
if (layerId === this.id) {
|
|
216
216
|
super.setVisibility(isVisible, layerId);
|
|
217
217
|
return;
|
|
@@ -225,7 +225,7 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
225
225
|
if (keyFound) {
|
|
226
226
|
this.internalLayerVisibility[keyFound as keyof InternalLayerVisibility] = isVisible;
|
|
227
227
|
this.clearLayer();
|
|
228
|
-
this.preRender();
|
|
228
|
+
await this.preRender();
|
|
229
229
|
this.render();
|
|
230
230
|
}
|
|
231
231
|
}
|
|
@@ -254,11 +254,10 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
254
254
|
return path.map((p) => new Point(p.point[0], y(p.point[1]!)));
|
|
255
255
|
};
|
|
256
256
|
|
|
257
|
-
protected drawBigPolygon = (coords:
|
|
257
|
+
protected drawBigPolygon = (coords: Point[], color = 0x000000) => {
|
|
258
258
|
const polygon = new Graphics();
|
|
259
|
-
polygon.
|
|
260
|
-
polygon.
|
|
261
|
-
polygon.endFill();
|
|
259
|
+
polygon.poly(coords);
|
|
260
|
+
polygon.fill(color);
|
|
262
261
|
|
|
263
262
|
this.addChild(polygon);
|
|
264
263
|
};
|
|
@@ -268,7 +267,7 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
268
267
|
return undefined;
|
|
269
268
|
}
|
|
270
269
|
|
|
271
|
-
const rope:
|
|
270
|
+
const rope: MeshRope = new MeshRope({ texture, points: path, textureScale: 1 });
|
|
272
271
|
rope.tint = tint || rope.tint;
|
|
273
272
|
this.addChild(rope);
|
|
274
273
|
}
|
|
@@ -296,7 +295,6 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
296
295
|
const startPointLeft = leftPathReverse[0]!;
|
|
297
296
|
|
|
298
297
|
const line = new Graphics();
|
|
299
|
-
line.lineStyle(lineWidth, lineColor, undefined, lineAlignment);
|
|
300
298
|
line.moveTo(startPointRight.x, startPointRight.y);
|
|
301
299
|
rightPath.forEach((p: Point) => line.lineTo(p.x, p.y));
|
|
302
300
|
|
|
@@ -310,6 +308,8 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
310
308
|
line.lineTo(startPointRight.x, startPointRight.y);
|
|
311
309
|
}
|
|
312
310
|
|
|
311
|
+
line.stroke({ width: lineWidth, color: lineColor, alignment: lineAlignment });
|
|
312
|
+
|
|
313
313
|
this.addChild(line);
|
|
314
314
|
}
|
|
315
315
|
|
|
@@ -329,11 +329,11 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
329
329
|
const [dashedAlignment, solidAlignment] = flippedPaths ? [1, 0] : [0, 1];
|
|
330
330
|
|
|
331
331
|
const graphics = new Graphics();
|
|
332
|
-
graphics.lineStyle(lineWidth, convertColor(lineColor), undefined, solidAlignment);
|
|
333
332
|
|
|
334
333
|
const startPointLinePath = linePath[0]!;
|
|
335
334
|
graphics.moveTo(startPointLinePath.x, startPointLinePath.y);
|
|
336
335
|
linePath.forEach((p: Point) => graphics.lineTo(p.x, p.y));
|
|
336
|
+
graphics.setStrokeStyle({ width: lineWidth, color: convertColor(lineColor), alignment: solidAlignment });
|
|
337
337
|
|
|
338
338
|
const dashedLine = new DashLine(graphics, {
|
|
339
339
|
dash: [windowOptions.dashLength, windowOptions.spaceLength],
|
|
@@ -353,7 +353,7 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
353
353
|
|
|
354
354
|
private perforationRopeAndTextureReferences: { rope: ComplexRope; texture: Texture }[] = [];
|
|
355
355
|
|
|
356
|
-
public preRender(): void {
|
|
356
|
+
public async preRender(): Promise<void> {
|
|
357
357
|
if (!this.data || !this.referenceSystem) {
|
|
358
358
|
return;
|
|
359
359
|
}
|
|
@@ -361,7 +361,7 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
361
361
|
const { exaggerationFactor = 1 } = this.options as SchematicLayerOptions<T>;
|
|
362
362
|
const { holeSizes, casings, cements, completion, symbols, pAndA, perforations } = this.data;
|
|
363
363
|
|
|
364
|
-
this.updateSymbolCache(symbols);
|
|
364
|
+
await this.updateSymbolCache(symbols);
|
|
365
365
|
|
|
366
366
|
holeSizes.sort((a: HoleSize, b: HoleSize) => b.diameter - a.diameter);
|
|
367
367
|
const maxHoleDiameter =
|
|
@@ -420,12 +420,16 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
420
420
|
);
|
|
421
421
|
|
|
422
422
|
this.perforationRopeAndTextureReferences.forEach(({ rope, texture }) => {
|
|
423
|
-
rope.
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
423
|
+
if (!rope.destroyed) {
|
|
424
|
+
rope.destroy({
|
|
425
|
+
children: true,
|
|
426
|
+
texture: true,
|
|
427
|
+
textureSource: true,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
if (texture) {
|
|
431
|
+
texture.destroy(true);
|
|
432
|
+
}
|
|
429
433
|
});
|
|
430
434
|
this.perforationRopeAndTextureReferences = [];
|
|
431
435
|
|
|
@@ -524,7 +528,7 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
524
528
|
}
|
|
525
529
|
}
|
|
526
530
|
|
|
527
|
-
private updateSymbolCache(symbols: { [key: string]: string }) {
|
|
531
|
+
private async updateSymbolCache(symbols: { [key: string]: string }) {
|
|
528
532
|
if (!this.textureSymbolCacheArray) {
|
|
529
533
|
this.textureSymbolCacheArray = {};
|
|
530
534
|
}
|
|
@@ -533,11 +537,12 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
533
537
|
}
|
|
534
538
|
|
|
535
539
|
const existingKeys = Object.keys(this.textureSymbolCacheArray);
|
|
536
|
-
Object.entries(symbols).
|
|
540
|
+
const promises = Object.entries(symbols).map(async ([key, symbol]: [string, string]) => {
|
|
537
541
|
if (!existingKeys.includes(key) && this.textureSymbolCacheArray) {
|
|
538
|
-
this.textureSymbolCacheArray[key] =
|
|
542
|
+
this.textureSymbolCacheArray[key] = await Assets.load(symbol);
|
|
539
543
|
}
|
|
540
544
|
});
|
|
545
|
+
await Promise.all(promises);
|
|
541
546
|
}
|
|
542
547
|
|
|
543
548
|
private drawCementPlug(cementPlug: CementPlug, casings: Casing[], completion: Completion[], holes: HoleSize[]) {
|
|
@@ -610,8 +615,8 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
610
615
|
}
|
|
611
616
|
|
|
612
617
|
private getSymbolTexture(symbolKey: string, diameter: number): Texture | undefined {
|
|
613
|
-
const baseTexture = this.textureSymbolCacheArray?.[symbolKey]?.
|
|
614
|
-
return baseTexture ? new Texture(baseTexture,
|
|
618
|
+
const baseTexture = this.textureSymbolCacheArray?.[symbolKey]?.source;
|
|
619
|
+
return baseTexture ? new Texture({ source: baseTexture, orig: new Rectangle(0, 0, 0, diameter), rotate: groupD8.MAIN_DIAGONAL }) : undefined;
|
|
615
620
|
}
|
|
616
621
|
|
|
617
622
|
private drawHoleSize = (maxHoleDiameter: number, holeObject: HoleSize): void => {
|
|
@@ -639,7 +644,7 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
639
644
|
return undefined;
|
|
640
645
|
}
|
|
641
646
|
|
|
642
|
-
const rope:
|
|
647
|
+
const rope: MeshRope = new MeshRope({ texture, points: path, textureScale: maxHoleDiameter / DEFAULT_TEXTURE_SIZE });
|
|
643
648
|
|
|
644
649
|
this.addChild(rope);
|
|
645
650
|
}
|
|
@@ -655,10 +660,13 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
655
660
|
this.holeTextureCache = createHoleBaseTexture(holeOptions, width, height);
|
|
656
661
|
}
|
|
657
662
|
|
|
658
|
-
const baseTexture = this.holeTextureCache.
|
|
663
|
+
const baseTexture = this.holeTextureCache.source;
|
|
659
664
|
const sidePadding = (height - textureDiameter) / 2;
|
|
660
665
|
const frame = new Rectangle(0, sidePadding, width, textureDiameter);
|
|
661
|
-
const texture = new Texture(
|
|
666
|
+
const texture = new Texture({
|
|
667
|
+
source: baseTexture,
|
|
668
|
+
frame,
|
|
669
|
+
});
|
|
662
670
|
|
|
663
671
|
return texture;
|
|
664
672
|
}
|
|
@@ -761,7 +769,10 @@ export class SchematicLayer<T extends SchematicData> extends PixiLayer<T> {
|
|
|
761
769
|
|
|
762
770
|
private createCasingTexture(diameter: number): Texture {
|
|
763
771
|
const textureWidthPO2 = 16;
|
|
764
|
-
return new Texture(
|
|
772
|
+
return new Texture({
|
|
773
|
+
source: Texture.WHITE.source,
|
|
774
|
+
orig: new Rectangle(0, 0, textureWidthPO2, diameter),
|
|
775
|
+
});
|
|
765
776
|
}
|
|
766
777
|
|
|
767
778
|
private drawShoe(casingEnd: number, casingRadius: number): void {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { autoDetectRenderer, AutoDetectOptions, Container, ContainerChild, Renderer, RendererType } from 'pixi.js';
|
|
2
2
|
import { Layer, LayerOptions } from './Layer';
|
|
3
3
|
import { OnMountEvent, OnRescaleEvent, OnResizeEvent, OnUnmountEvent } from '../../interfaces';
|
|
4
4
|
import { DEFAULT_LAYER_HEIGHT, DEFAULT_LAYER_WIDTH } from '../../constants';
|
|
@@ -11,9 +11,9 @@ import { DEFAULT_LAYER_HEIGHT, DEFAULT_LAYER_WIDTH } from '../../constants';
|
|
|
11
11
|
export class PixiRenderApplication {
|
|
12
12
|
stage: Container | undefined;
|
|
13
13
|
|
|
14
|
-
renderer:
|
|
14
|
+
renderer: Renderer<HTMLCanvasElement> | undefined;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
async init(pixiRenderOptions?: Partial<AutoDetectOptions>) {
|
|
17
17
|
const options = {
|
|
18
18
|
width: DEFAULT_LAYER_WIDTH,
|
|
19
19
|
height: DEFAULT_LAYER_HEIGHT,
|
|
@@ -24,38 +24,12 @@ export class PixiRenderApplication {
|
|
|
24
24
|
preserveDrawingBuffer: true,
|
|
25
25
|
...pixiRenderOptions,
|
|
26
26
|
};
|
|
27
|
-
this.renderer = autoDetectRenderer
|
|
27
|
+
this.renderer = await autoDetectRenderer(options);
|
|
28
28
|
this.stage = new Container();
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
this.
|
|
33
|
-
children: true,
|
|
34
|
-
texture: true,
|
|
35
|
-
baseTexture: true,
|
|
36
|
-
});
|
|
37
|
-
this.stage = undefined;
|
|
38
|
-
|
|
39
|
-
// Get renderType and clContext before we destroy the renderer
|
|
40
|
-
const renderType = this.renderer?.type;
|
|
41
|
-
const glContext = this.renderer instanceof Renderer ? this.renderer?.gl : undefined;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* WebGL v2 does supposedly not have WEBGL_lose_context
|
|
45
|
-
* so Pixi.js does not use it to "clean up" on v2.
|
|
46
|
-
*
|
|
47
|
-
* Cleaning up our self since it still seems to work and fix issue with lingering context
|
|
48
|
-
*/
|
|
49
|
-
if (renderType === RENDERER_TYPE.WEBGL && glContext) {
|
|
50
|
-
glContext?.getExtension('WEBGL_lose_context')?.loseContext();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
this.renderer?.destroy(true);
|
|
54
|
-
this.renderer = undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
get view() {
|
|
58
|
-
return this.renderer?.view;
|
|
31
|
+
get canvas() {
|
|
32
|
+
return this.renderer?.canvas;
|
|
59
33
|
}
|
|
60
34
|
|
|
61
35
|
render() {
|
|
@@ -70,11 +44,10 @@ export abstract class PixiLayer<T> extends Layer<T> {
|
|
|
70
44
|
private ctx: PixiRenderApplication;
|
|
71
45
|
private container: Container;
|
|
72
46
|
|
|
73
|
-
constructor(ctx:
|
|
47
|
+
constructor(ctx: PixiRenderApplication, id?: string, options?: LayerOptions<T>) {
|
|
74
48
|
super(id, options);
|
|
75
49
|
|
|
76
50
|
this.ctx = ctx;
|
|
77
|
-
|
|
78
51
|
this.container = new Container();
|
|
79
52
|
this.ctx.stage?.addChild(this.container);
|
|
80
53
|
}
|
|
@@ -83,7 +56,7 @@ export abstract class PixiLayer<T> extends Layer<T> {
|
|
|
83
56
|
this.ctx.render();
|
|
84
57
|
}
|
|
85
58
|
|
|
86
|
-
addChild(child:
|
|
59
|
+
addChild(child: ContainerChild) {
|
|
87
60
|
this.container.addChild(child);
|
|
88
61
|
}
|
|
89
62
|
|
|
@@ -104,8 +77,8 @@ export abstract class PixiLayer<T> extends Layer<T> {
|
|
|
104
77
|
this.pixiViewContainer.setAttribute('id', `${this.id}`);
|
|
105
78
|
this.pixiViewContainer.setAttribute('class', 'webgl-layer');
|
|
106
79
|
|
|
107
|
-
if (this.ctx.
|
|
108
|
-
this.pixiViewContainer.appendChild(this.ctx.
|
|
80
|
+
if (this.ctx.canvas != null) {
|
|
81
|
+
this.pixiViewContainer.appendChild(this.ctx.canvas);
|
|
109
82
|
}
|
|
110
83
|
|
|
111
84
|
this.element?.appendChild(this.pixiViewContainer);
|
|
@@ -188,7 +161,7 @@ export abstract class PixiLayer<T> extends Layer<T> {
|
|
|
188
161
|
}
|
|
189
162
|
}
|
|
190
163
|
|
|
191
|
-
renderType():
|
|
164
|
+
renderType(): RendererType | undefined {
|
|
192
165
|
return this.ctx.renderer?.type;
|
|
193
166
|
}
|
|
194
167
|
}
|
package/src/utils/vectorUtils.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Point } from 'pixi.js';
|
|
2
2
|
import Vector2 from '@equinor/videx-vector2';
|
|
3
3
|
|
|
4
|
-
export const pointToVector = (p:
|
|
5
|
-
export const pointToArray = (p:
|
|
4
|
+
export const pointToVector = (p: Point): Vector2 => new Vector2(p.x, p.y);
|
|
5
|
+
export const pointToArray = (p: Point): [number, number] => [p.x, p.y];
|
|
6
6
|
export const vectorToPoint = (v: Vector2): Point => new Point(v[0], v[1]);
|
|
7
7
|
export const vectorToArray = (v: Vector2): [number, number] => [v[0] ?? 0, v[1] ?? 0];
|
|
8
8
|
export const arrayToPoint = (a: number[]): Point => new Point(a[0], a[1]);
|
|
@@ -27,7 +27,7 @@ export const convertToUnitVector = (p: Point): Point => {
|
|
|
27
27
|
return vectorToPoint(pointToVector(p).normalize());
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
export const createNormals = (points:
|
|
30
|
+
export const createNormals = (points: Point[]): Vector2[] => {
|
|
31
31
|
if (points.length < 2) {
|
|
32
32
|
return [new Vector2(0)];
|
|
33
33
|
}
|
|
@@ -53,12 +53,12 @@ export const createNormals = (points: IPoint[]): Vector2[] => {
|
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
// TODO check if this can be simplified and return Vector/number[]
|
|
56
|
-
export const offsetPoint = (point:
|
|
56
|
+
export const offsetPoint = (point: Point, vector: Vector2, offset: number): Point => {
|
|
57
57
|
const p = pointToVector(point);
|
|
58
58
|
return vectorToPoint(p.add(vector.scale(offset)));
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
export const offsetPoints = (points:
|
|
61
|
+
export const offsetPoints = (points: Point[], vectors: Vector2[], offset: number): Point[] => {
|
|
62
62
|
if (points.length !== vectors.length) {
|
|
63
63
|
throw new Error('Number of vectors does not match number of points');
|
|
64
64
|
}
|