@threepipe/plugin-svg-renderer 0.1.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/LICENSE +674 -0
- package/dist/BasicSVGRendererPlugin.d.ts +26 -0
- package/dist/BasicSVGRendererPlugin.d.ts.map +1 -0
- package/dist/ThreeSVGRendererPlugin.d.ts +100 -0
- package/dist/ThreeSVGRendererPlugin.d.ts.map +1 -0
- package/dist/basic/BasicSVGRenderer.d.ts +10 -0
- package/dist/basic/BasicSVGRenderer.d.ts.map +1 -0
- package/dist/dependencies.txt +315 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16798 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +16798 -0
- package/dist/index.mjs.map +1 -0
- package/dist/three-mesh-halfedge/augments.d.ts +8 -0
- package/dist/three-mesh-halfedge/augments.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/core/Face.d.ts +39 -0
- package/dist/three-mesh-halfedge/core/Face.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/core/Halfedge.d.ts +40 -0
- package/dist/three-mesh-halfedge/core/Halfedge.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/core/HalfedgeDS.d.ts +109 -0
- package/dist/three-mesh-halfedge/core/HalfedgeDS.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/core/Vertex.d.ts +69 -0
- package/dist/three-mesh-halfedge/core/Vertex.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/core/Vertex.test.d.ts +1 -0
- package/dist/three-mesh-halfedge/core/Vertex.test.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/index.d.ts +5 -0
- package/dist/three-mesh-halfedge/index.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/addEdge.d.ts +5 -0
- package/dist/three-mesh-halfedge/operations/addEdge.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/addEdge.test.d.ts +1 -0
- package/dist/three-mesh-halfedge/operations/addEdge.test.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/addFace.d.ts +5 -0
- package/dist/three-mesh-halfedge/operations/addFace.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/addVertex.d.ts +5 -0
- package/dist/three-mesh-halfedge/operations/addVertex.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/addVertex.test.d.ts +1 -0
- package/dist/three-mesh-halfedge/operations/addVertex.test.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/cutFace.d.ts +6 -0
- package/dist/three-mesh-halfedge/operations/cutFace.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/cutFace.test.d.ts +1 -0
- package/dist/three-mesh-halfedge/operations/cutFace.test.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/removeEdge.d.ts +4 -0
- package/dist/three-mesh-halfedge/operations/removeEdge.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/removeFace.d.ts +4 -0
- package/dist/three-mesh-halfedge/operations/removeFace.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/removeVertex.d.ts +4 -0
- package/dist/three-mesh-halfedge/operations/removeVertex.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/setFromGeometry.d.ts +13 -0
- package/dist/three-mesh-halfedge/operations/setFromGeometry.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/setFromGeometry.test.d.ts +1 -0
- package/dist/three-mesh-halfedge/operations/setFromGeometry.test.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/operations/splitEdge.d.ts +6 -0
- package/dist/three-mesh-halfedge/operations/splitEdge.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/setuptests.d.ts +1 -0
- package/dist/three-mesh-halfedge/setuptests.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/utils/geometry.d.ts +5 -0
- package/dist/three-mesh-halfedge/utils/geometry.d.ts.map +1 -0
- package/dist/three-mesh-halfedge/utils/testutils.d.ts +3 -0
- package/dist/three-mesh-halfedge/utils/testutils.d.ts.map +1 -0
- package/dist/three-svg-renderer/SVGRenderer.d.ts +58 -0
- package/dist/three-svg-renderer/SVGRenderer.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/SVGMesh.d.ts +57 -0
- package/dist/three-svg-renderer/core/SVGMesh.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/index.d.ts +4 -0
- package/dist/three-svg-renderer/core/index.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/SVGDrawHandler.d.ts +23 -0
- package/dist/three-svg-renderer/core/svg/SVGDrawHandler.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/index.d.ts +3 -0
- package/dist/three-svg-renderer/core/svg/index.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/passes/ChainPass.d.ts +112 -0
- package/dist/three-svg-renderer/core/svg/passes/ChainPass.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/passes/DrawPass.d.ts +22 -0
- package/dist/three-svg-renderer/core/svg/passes/DrawPass.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/passes/FillPass.d.ts +46 -0
- package/dist/three-svg-renderer/core/svg/passes/FillPass.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/passes/SingularityPointPass.d.ts +16 -0
- package/dist/three-svg-renderer/core/svg/passes/SingularityPointPass.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/passes/TexturePass.d.ts +1 -0
- package/dist/three-svg-renderer/core/svg/passes/TexturePass.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/passes/index.d.ts +5 -0
- package/dist/three-svg-renderer/core/svg/passes/index.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/svg/svgutils.d.ts +10 -0
- package/dist/three-svg-renderer/core/svg/svgutils.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/Chain.d.ts +26 -0
- package/dist/three-svg-renderer/core/viewmap/Chain.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/Polygon.d.ts +12 -0
- package/dist/three-svg-renderer/core/viewmap/Polygon.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/ViewEdge.d.ts +67 -0
- package/dist/three-svg-renderer/core/viewmap/ViewEdge.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/ViewVertex.d.ts +27 -0
- package/dist/three-svg-renderer/core/viewmap/ViewVertex.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/Viewmap.d.ts +83 -0
- package/dist/three-svg-renderer/core/viewmap/Viewmap.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/index.d.ts +6 -0
- package/dist/three-svg-renderer/core/viewmap/index.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/assignPolygons.d.ts +11 -0
- package/dist/three-svg-renderer/core/viewmap/operations/assignPolygons.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/computeChainsVisibility.d.ts +19 -0
- package/dist/three-svg-renderer/core/viewmap/operations/computeChainsVisibility.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/computeMeshIntersections.d.ts +11 -0
- package/dist/three-svg-renderer/core/viewmap/operations/computeMeshIntersections.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/computePolygons.d.ts +17 -0
- package/dist/three-svg-renderer/core/viewmap/operations/computePolygons.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/createChains.d.ts +7 -0
- package/dist/three-svg-renderer/core/viewmap/operations/createChains.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/createViewVertex.d.ts +11 -0
- package/dist/three-svg-renderer/core/viewmap/operations/createViewVertex.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/find2dSingularities.d.ts +9 -0
- package/dist/three-svg-renderer/core/viewmap/operations/find2dSingularities.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/find3dSingularities.d.ts +26 -0
- package/dist/three-svg-renderer/core/viewmap/operations/find3dSingularities.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/meshIntersectionCb.d.ts +18 -0
- package/dist/three-svg-renderer/core/viewmap/operations/meshIntersectionCb.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/setupEdges.d.ts +25 -0
- package/dist/three-svg-renderer/core/viewmap/operations/setupEdges.d.ts.map +1 -0
- package/dist/three-svg-renderer/core/viewmap/operations/splitEdge.d.ts +20 -0
- package/dist/three-svg-renderer/core/viewmap/operations/splitEdge.d.ts.map +1 -0
- package/dist/three-svg-renderer/index.d.ts +4 -0
- package/dist/three-svg-renderer/index.d.ts.map +1 -0
- package/dist/three-svg-renderer/setuptests.d.ts +1 -0
- package/dist/three-svg-renderer/setuptests.d.ts.map +1 -0
- package/dist/three-svg-renderer/utils/buffergeometry.d.ts +17 -0
- package/dist/three-svg-renderer/utils/buffergeometry.d.ts.map +1 -0
- package/dist/three-svg-renderer/utils/geometry.d.ts +45 -0
- package/dist/three-svg-renderer/utils/geometry.d.ts.map +1 -0
- package/dist/three-svg-renderer/utils/geometry.test.d.ts +1 -0
- package/dist/three-svg-renderer/utils/geometry.test.d.ts.map +1 -0
- package/dist/three-svg-renderer/utils/index.d.ts +4 -0
- package/dist/three-svg-renderer/utils/index.d.ts.map +1 -0
- package/dist/three-svg-renderer/utils/objects.d.ts +2 -0
- package/dist/three-svg-renderer/utils/objects.d.ts.map +1 -0
- package/dist/three-svg-renderer/utils/orientationtests.d.ts +65 -0
- package/dist/three-svg-renderer/utils/orientationtests.d.ts.map +1 -0
- package/dist/three-svg-renderer/utils/testutils.d.ts +1 -0
- package/dist/three-svg-renderer/utils/testutils.d.ts.map +1 -0
- package/package.json +34 -0
- package/src/BasicSVGRendererPlugin.ts +110 -0
- package/src/ThreeSVGRendererPlugin.ts +405 -0
- package/src/basic/BasicSVGRenderer.ts +23 -0
- package/src/global.d.ts +40 -0
- package/src/index.ts +5 -0
- package/src/three-mesh-halfedge/LICENSE +21 -0
- package/src/three-mesh-halfedge/augments.ts +35 -0
- package/src/three-mesh-halfedge/core/Face.ts +122 -0
- package/src/three-mesh-halfedge/core/Halfedge.ts +109 -0
- package/src/three-mesh-halfedge/core/HalfedgeDS.ts +192 -0
- package/src/three-mesh-halfedge/core/Vertex.test.ts +185 -0
- package/src/three-mesh-halfedge/core/Vertex.ts +192 -0
- package/src/three-mesh-halfedge/index.ts +6 -0
- package/src/three-mesh-halfedge/operations/addEdge.test.ts +119 -0
- package/src/three-mesh-halfedge/operations/addEdge.ts +100 -0
- package/src/three-mesh-halfedge/operations/addFace.ts +108 -0
- package/src/three-mesh-halfedge/operations/addVertex.test.ts +60 -0
- package/src/three-mesh-halfedge/operations/addVertex.ts +38 -0
- package/src/three-mesh-halfedge/operations/cutFace.test.ts +157 -0
- package/src/three-mesh-halfedge/operations/cutFace.ts +162 -0
- package/src/three-mesh-halfedge/operations/removeEdge.ts +84 -0
- package/src/three-mesh-halfedge/operations/removeFace.ts +30 -0
- package/src/three-mesh-halfedge/operations/removeVertex.ts +53 -0
- package/src/three-mesh-halfedge/operations/setFromGeometry.test.ts +216 -0
- package/src/three-mesh-halfedge/operations/setFromGeometry.ts +174 -0
- package/src/three-mesh-halfedge/operations/splitEdge.ts +80 -0
- package/src/three-mesh-halfedge/setuptests.ts +16 -0
- package/src/three-mesh-halfedge/utils/geometry.ts +44 -0
- package/src/three-mesh-halfedge/utils/testutils.ts +83 -0
- package/src/three-svg-renderer/LICENSE +674 -0
- package/src/three-svg-renderer/SVGRenderer.ts +141 -0
- package/src/three-svg-renderer/core/SVGMesh.ts +172 -0
- package/src/three-svg-renderer/core/index.ts +17 -0
- package/src/three-svg-renderer/core/svg/SVGDrawHandler.ts +78 -0
- package/src/three-svg-renderer/core/svg/index.ts +21 -0
- package/src/three-svg-renderer/core/svg/passes/ChainPass.ts +303 -0
- package/src/three-svg-renderer/core/svg/passes/DrawPass.ts +37 -0
- package/src/three-svg-renderer/core/svg/passes/FillPass.ts +227 -0
- package/src/three-svg-renderer/core/svg/passes/SingularityPointPass.ts +126 -0
- package/src/three-svg-renderer/core/svg/passes/TexturePass.ts +440 -0
- package/src/three-svg-renderer/core/svg/passes/index.ts +19 -0
- package/src/three-svg-renderer/core/svg/svgutils.ts +152 -0
- package/src/three-svg-renderer/core/viewmap/Chain.ts +82 -0
- package/src/three-svg-renderer/core/viewmap/Polygon.ts +34 -0
- package/src/three-svg-renderer/core/viewmap/ViewEdge.ts +143 -0
- package/src/three-svg-renderer/core/viewmap/ViewVertex.ts +74 -0
- package/src/three-svg-renderer/core/viewmap/Viewmap.ts +389 -0
- package/src/three-svg-renderer/core/viewmap/index.ts +24 -0
- package/src/three-svg-renderer/core/viewmap/operations/assignPolygons.ts +85 -0
- package/src/three-svg-renderer/core/viewmap/operations/computeChainsVisibility.ts +147 -0
- package/src/three-svg-renderer/core/viewmap/operations/computeMeshIntersections.ts +129 -0
- package/src/three-svg-renderer/core/viewmap/operations/computePolygons.ts +112 -0
- package/src/three-svg-renderer/core/viewmap/operations/createChains.ts +82 -0
- package/src/three-svg-renderer/core/viewmap/operations/createViewVertex.ts +42 -0
- package/src/three-svg-renderer/core/viewmap/operations/find2dSingularities.ts +126 -0
- package/src/three-svg-renderer/core/viewmap/operations/find3dSingularities.ts +176 -0
- package/src/three-svg-renderer/core/viewmap/operations/meshIntersectionCb.ts +86 -0
- package/src/three-svg-renderer/core/viewmap/operations/setupEdges.ts +152 -0
- package/src/three-svg-renderer/core/viewmap/operations/splitEdge.ts +197 -0
- package/src/three-svg-renderer/index.ts +15 -0
- package/src/three-svg-renderer/setuptests.ts +15 -0
- package/src/three-svg-renderer/types/isect/index.d.ts +65 -0
- package/src/three-svg-renderer/utils/buffergeometry.ts +66 -0
- package/src/three-svg-renderer/utils/geometry.test.ts +95 -0
- package/src/three-svg-renderer/utils/geometry.ts +156 -0
- package/src/three-svg-renderer/utils/index.ts +17 -0
- package/src/three-svg-renderer/utils/objects.ts +24 -0
- package/src/three-svg-renderer/utils/orientationtests.ts +108 -0
- package/src/three-svg-renderer/utils/testutils.ts +64 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// Author: Axel Antoine
|
|
2
|
+
// mail: ax.antoine@gmail.com
|
|
3
|
+
// website: https://axantoine.com
|
|
4
|
+
// 16/06/2022
|
|
5
|
+
|
|
6
|
+
// Loki, Inria project-team with Université de Lille
|
|
7
|
+
// within the Joint Research Unit UMR 9189 CNRS-Centrale
|
|
8
|
+
// Lille-Université de Lille, CRIStAL.
|
|
9
|
+
// https://loki.lille.inria.fr
|
|
10
|
+
|
|
11
|
+
// LICENCE: Licence.md
|
|
12
|
+
|
|
13
|
+
import {DrawPass} from './DrawPass';
|
|
14
|
+
import {Viewmap} from '../../viewmap/Viewmap';
|
|
15
|
+
import {Svg, G as SVGGroup, Element as SVGElement, Color as SVGColor,
|
|
16
|
+
} from '@svgdotjs/svg.js';
|
|
17
|
+
import {Chain, ChainVisibility} from '../../viewmap/Chain';
|
|
18
|
+
import {ViewEdgeNature} from '../../viewmap/ViewEdge';
|
|
19
|
+
import {getSVGPath, getSVGCircle, getSVGText} from '../svgutils';
|
|
20
|
+
import { SVGMesh } from '../../SVGMesh';
|
|
21
|
+
import { mergeOptions } from '../../../utils/objects';
|
|
22
|
+
|
|
23
|
+
const ViewEdgesNatures = Object.values(ViewEdgeNature);
|
|
24
|
+
|
|
25
|
+
export interface StrokeNatureOptions {
|
|
26
|
+
enable?: boolean;
|
|
27
|
+
|
|
28
|
+
renderOrder?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ChainPassOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Draw each chains in the svg with random colors.
|
|
34
|
+
* @defaultValue `false`
|
|
35
|
+
*/
|
|
36
|
+
useRandomColors?: boolean;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Draw the raycasting point used to determine visibility in the svg.
|
|
40
|
+
* @defaultValue `false`
|
|
41
|
+
*/
|
|
42
|
+
drawRaycastPoint?: boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Draw the legend showing the mapping between color and nature for chains.
|
|
46
|
+
* Useful only if {@link colorByNature} is true.
|
|
47
|
+
*/
|
|
48
|
+
drawLegend?: boolean;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Default style applied to strokes
|
|
52
|
+
*/
|
|
53
|
+
defaultStyle?: StrokeStyle,
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Customize stroke styles depending on their nature, if value are set,
|
|
57
|
+
* they overide default style
|
|
58
|
+
*/
|
|
59
|
+
styles?: {
|
|
60
|
+
[ViewEdgeNature.Silhouette]: PassStrokeStyle,
|
|
61
|
+
[ViewEdgeNature.MeshIntersection]: PassStrokeStyle,
|
|
62
|
+
[ViewEdgeNature.Crease]: PassStrokeStyle,
|
|
63
|
+
[ViewEdgeNature.Boundary]: PassStrokeStyle,
|
|
64
|
+
[ViewEdgeNature.Material]: PassStrokeStyle,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface StrokeStyle {
|
|
69
|
+
/**
|
|
70
|
+
* Color of the stroke in hex format.
|
|
71
|
+
* @defaultValue `"#000000"'
|
|
72
|
+
*/
|
|
73
|
+
color?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Width of the stroke
|
|
76
|
+
* @defaultValue `1`
|
|
77
|
+
*/
|
|
78
|
+
width?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Opacity of the stroke
|
|
81
|
+
* @defaultValue `1`
|
|
82
|
+
*/
|
|
83
|
+
opacity?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Pattern of dashes and gaps used for the stroke e.g. `"2,2"`
|
|
86
|
+
* @defaultValue `""`
|
|
87
|
+
*/
|
|
88
|
+
dasharray?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Shape to be used at the ends of stroke
|
|
91
|
+
* @defaultValue `"butt"`
|
|
92
|
+
*/
|
|
93
|
+
linecap?: 'butt' | 'round' | 'square';
|
|
94
|
+
/**
|
|
95
|
+
* Shape to use at the corners of stroke
|
|
96
|
+
* @defaultValue `"miter"`
|
|
97
|
+
*/
|
|
98
|
+
linejoin?: 'arcs' | 'bevel' | 'miter' | 'miter-clip' | 'round';
|
|
99
|
+
/**
|
|
100
|
+
* Offset to use before starting dash-array
|
|
101
|
+
* @defaultValue `0`
|
|
102
|
+
*/
|
|
103
|
+
dashoffset?: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Stroke Style interface with options specific to the Chain Pass
|
|
108
|
+
*/
|
|
109
|
+
export interface PassStrokeStyle extends StrokeStyle {
|
|
110
|
+
/**
|
|
111
|
+
* Draw order of the stroke in the svg. High order are drawn on top
|
|
112
|
+
* @defaultValue Silhouette 5, Boundary 4, MeshIntersection 3, Crease 2, Material 1
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
115
|
+
drawOrder?: number;
|
|
116
|
+
/**
|
|
117
|
+
* Enable the edge nature type to be drawn in the svg
|
|
118
|
+
*/
|
|
119
|
+
enabled?: boolean;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
export abstract class ChainPass extends DrawPass {
|
|
125
|
+
/** Options of the draw pass */
|
|
126
|
+
readonly options : Required<ChainPassOptions> = {
|
|
127
|
+
drawRaycastPoint: false,
|
|
128
|
+
useRandomColors: false,
|
|
129
|
+
drawLegend: false,
|
|
130
|
+
|
|
131
|
+
defaultStyle: {
|
|
132
|
+
color: "#000000",
|
|
133
|
+
width: 1,
|
|
134
|
+
dasharray: "",
|
|
135
|
+
linecap: "butt",
|
|
136
|
+
linejoin: "miter",
|
|
137
|
+
opacity: 1,
|
|
138
|
+
dashoffset: 0,
|
|
139
|
+
},
|
|
140
|
+
styles: {
|
|
141
|
+
[ViewEdgeNature.Silhouette]: {enabled: true, drawOrder: 5},
|
|
142
|
+
[ViewEdgeNature.Boundary]: {enabled: true, drawOrder: 4},
|
|
143
|
+
[ViewEdgeNature.MeshIntersection]: {enabled: true, drawOrder: 3},
|
|
144
|
+
[ViewEdgeNature.Crease]: {enabled: true, drawOrder: 2},
|
|
145
|
+
[ViewEdgeNature.Material]: {enabled: true, drawOrder: 1}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
*
|
|
151
|
+
* @param strokeStyle Default style applied to the strokes
|
|
152
|
+
* @param options
|
|
153
|
+
*/
|
|
154
|
+
constructor(options: ChainPassOptions = {}) {
|
|
155
|
+
super();
|
|
156
|
+
|
|
157
|
+
mergeOptions(this.options, options);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export class VisibleChainPass extends ChainPass {
|
|
162
|
+
|
|
163
|
+
constructor(options: Partial<ChainPassOptions> = {}) {
|
|
164
|
+
super(options);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async draw(svg: Svg, viewmap: Viewmap) {
|
|
168
|
+
|
|
169
|
+
const chains = viewmap.chains
|
|
170
|
+
.filter(c => c.visibility === ChainVisibility.Visible);
|
|
171
|
+
|
|
172
|
+
const meshes = Array.from(viewmap.meshes).filter(m => m.drawVisibleContours);
|
|
173
|
+
|
|
174
|
+
const group = new SVGGroup({id: "visible-contours"});
|
|
175
|
+
drawChains(group, meshes, chains, this.options);
|
|
176
|
+
svg.add(group);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export class HiddenChainPass extends ChainPass {
|
|
181
|
+
|
|
182
|
+
constructor(options: Partial<ChainPassOptions> = {}) {
|
|
183
|
+
|
|
184
|
+
const {defaultStyle, ...otherOptions} = options;
|
|
185
|
+
|
|
186
|
+
options = {
|
|
187
|
+
defaultStyle: {
|
|
188
|
+
color: "#FF0000",
|
|
189
|
+
dasharray: "2,2",
|
|
190
|
+
...defaultStyle,
|
|
191
|
+
},
|
|
192
|
+
...otherOptions
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
super(options);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async draw(svg: Svg, viewmap: Viewmap) {
|
|
199
|
+
|
|
200
|
+
const chains = viewmap.chains.filter(
|
|
201
|
+
c => c.visibility === ChainVisibility.Hidden
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const meshes = Array.from(viewmap.meshes).filter(m => m.drawHiddenContours);
|
|
205
|
+
|
|
206
|
+
const group = new SVGGroup({id: "hidden-contours"});
|
|
207
|
+
svg.add(group);
|
|
208
|
+
|
|
209
|
+
drawChains(group, meshes, chains, this.options);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function drawChains(
|
|
214
|
+
parent: SVGElement,
|
|
215
|
+
meshes: SVGMesh[],
|
|
216
|
+
chains: Chain[],
|
|
217
|
+
options: Required<ChainPassOptions>) {
|
|
218
|
+
|
|
219
|
+
const {defaultStyle, styles} = options;
|
|
220
|
+
|
|
221
|
+
// Order natures depending on the draw order
|
|
222
|
+
ViewEdgesNatures.sort(
|
|
223
|
+
(n1, n2) => (styles[n1].drawOrder ?? 0) - (styles[n2].drawOrder ?? 0)
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
// Group the contours by mesh
|
|
227
|
+
for (const mesh of meshes) {
|
|
228
|
+
const objectChains = chains.filter(c => c.object === mesh);
|
|
229
|
+
const objectGroup = new SVGGroup({id: mesh.name});
|
|
230
|
+
parent.add(objectGroup);
|
|
231
|
+
|
|
232
|
+
for (const nature of ViewEdgesNatures) {
|
|
233
|
+
|
|
234
|
+
if (styles[nature]?.enabled) {
|
|
235
|
+
|
|
236
|
+
const strokeStyle = {...defaultStyle, ...styles[nature]};
|
|
237
|
+
|
|
238
|
+
const natureChains = objectChains.filter(c => c.nature === nature);
|
|
239
|
+
const natureGroup = new SVGGroup({id: nature});
|
|
240
|
+
objectGroup.add(natureGroup);
|
|
241
|
+
|
|
242
|
+
for (const chain of natureChains) {
|
|
243
|
+
drawChain(natureGroup, chain, options, strokeStyle);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (options.drawLegend) {
|
|
250
|
+
parent.add(getLegend(options));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function drawChain(
|
|
256
|
+
parent: SVGElement,
|
|
257
|
+
chain: Chain,
|
|
258
|
+
options: Required<ChainPassOptions>,
|
|
259
|
+
style: StrokeStyle = {}
|
|
260
|
+
) {
|
|
261
|
+
|
|
262
|
+
// Make a copy of the style so we can modify it
|
|
263
|
+
style = {...style};
|
|
264
|
+
|
|
265
|
+
if (options.useRandomColors) {
|
|
266
|
+
style.color = SVGColor.random().toString();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const path = getSVGPath(chain.vertices, [], false, style);
|
|
270
|
+
parent.add(path);
|
|
271
|
+
|
|
272
|
+
if (options.drawRaycastPoint) {
|
|
273
|
+
drawContourRaycastPoint(parent, chain);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function drawContourRaycastPoint(parent: SVGElement, chain: Chain) {
|
|
278
|
+
const strokeStyle = {color: "black"};
|
|
279
|
+
const fillStyle = {color: "white"};
|
|
280
|
+
const cx = chain.raycastPoint.x;
|
|
281
|
+
const cy = chain.raycastPoint.y;
|
|
282
|
+
const point = getSVGCircle(cx, cy, 2, strokeStyle, fillStyle);
|
|
283
|
+
point.id('raycast-point');
|
|
284
|
+
parent.add(point);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function getLegend(options: Required<ChainPassOptions>) {
|
|
288
|
+
const legend = new SVGGroup({id: "edges-nature-legend"});
|
|
289
|
+
|
|
290
|
+
legend.add(getSVGText("Natures", 10, 140, {size: 15, anchor: 'start'}))
|
|
291
|
+
|
|
292
|
+
let y = 170;
|
|
293
|
+
for (const nature of ViewEdgesNatures) {
|
|
294
|
+
const fillColor = options.styles[nature].color ?? 'black';
|
|
295
|
+
|
|
296
|
+
legend.add(getSVGCircle(15, y, 8, {color: "black"}, {color: fillColor}));
|
|
297
|
+
legend.add(getSVGText(nature, 30, y-10, {size: 15, anchor: 'start'}));
|
|
298
|
+
|
|
299
|
+
y += 20;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return legend;
|
|
303
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Author: Axel Antoine
|
|
2
|
+
// mail: ax.antoine@gmail.com
|
|
3
|
+
// website: https://axantoine.com
|
|
4
|
+
// 16/06/2022
|
|
5
|
+
|
|
6
|
+
// Loki, Inria project-team with Université de Lille
|
|
7
|
+
// within the Joint Research Unit UMR 9189 CNRS-Centrale
|
|
8
|
+
// Lille-Université de Lille, CRIStAL.
|
|
9
|
+
// https://loki.lille.inria.fr
|
|
10
|
+
|
|
11
|
+
// LICENCE: Licence.md
|
|
12
|
+
|
|
13
|
+
import {Svg} from '@svgdotjs/svg.js';
|
|
14
|
+
import {Viewmap} from '../../viewmap/Viewmap';
|
|
15
|
+
|
|
16
|
+
export abstract class DrawPass {
|
|
17
|
+
/**
|
|
18
|
+
* Name of the draw pass
|
|
19
|
+
*/
|
|
20
|
+
readonly name: string;
|
|
21
|
+
/**
|
|
22
|
+
* Enables/Disables draw pass.
|
|
23
|
+
* @defaultValue `true`
|
|
24
|
+
*/
|
|
25
|
+
enabled = true;
|
|
26
|
+
|
|
27
|
+
constructor() {
|
|
28
|
+
this.name = this.constructor.name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Function automatically called by the `SVGDrawHandler`
|
|
33
|
+
* @param svg The svg tree being built
|
|
34
|
+
* @param viewmap The viewmap data structure
|
|
35
|
+
*/
|
|
36
|
+
abstract draw(svg: Svg, viewmap: Viewmap): Promise<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Author: Axel Antoine
|
|
2
|
+
// mail: ax.antoine@gmail.com
|
|
3
|
+
// website: https://axantoine.com
|
|
4
|
+
// 16/06/2022
|
|
5
|
+
|
|
6
|
+
// Loki, Inria project-team with Université de Lille
|
|
7
|
+
// within the Joint Research Unit UMR 9189 CNRS-Centrale
|
|
8
|
+
// Lille-Université de Lille, CRIStAL.
|
|
9
|
+
// https://loki.lille.inria.fr
|
|
10
|
+
|
|
11
|
+
// LICENCE: Licence.md
|
|
12
|
+
|
|
13
|
+
// Modified by repalash <palash@shaders.app>. Added support for cropping and overlaying rendered image, added parameters and other small changes.
|
|
14
|
+
|
|
15
|
+
import {DrawPass} from './DrawPass';
|
|
16
|
+
import {Viewmap} from '../../viewmap/Viewmap';
|
|
17
|
+
import {Color as SVGColor, Element as SVGElement, G as SVGGroup, Image, Pattern, Svg} from '@svgdotjs/svg.js';
|
|
18
|
+
import {getSVGCircle, getSVGPath} from '../svgutils';
|
|
19
|
+
import {Polygon} from '../../viewmap/Polygon';
|
|
20
|
+
import {mergeOptions} from '../../../utils/objects';
|
|
21
|
+
import {Box2, Vector2} from 'three'
|
|
22
|
+
|
|
23
|
+
export interface FillPassOptions {
|
|
24
|
+
drawRaycastPoint?: boolean;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Use a random color for each polygon in the svg. Overwrites
|
|
28
|
+
* {@link useFixedStyle} if `true`.
|
|
29
|
+
* @defaultValue `false`
|
|
30
|
+
*/
|
|
31
|
+
useRandomColors?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Use a fixed style ()`color` and/or `opacity`) provided by {@link fillStyle}
|
|
34
|
+
* instead of mesh material.
|
|
35
|
+
* @defaultValue `false`
|
|
36
|
+
*/
|
|
37
|
+
useFixedStyle?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Fixed style to apply to polygons
|
|
40
|
+
*/
|
|
41
|
+
fillStyle?: FillStyle;
|
|
42
|
+
strokeStyle?: FillStyle;
|
|
43
|
+
fillImage?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface FillStyle {
|
|
47
|
+
/**
|
|
48
|
+
* Color of the polygons.
|
|
49
|
+
* @defaultValue `"#333333"`
|
|
50
|
+
*/
|
|
51
|
+
color?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Opacity of the polygons.
|
|
54
|
+
* @defaultValue `1`
|
|
55
|
+
*/
|
|
56
|
+
opacity?: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class FillPass extends DrawPass {
|
|
60
|
+
drawFills = true;
|
|
61
|
+
drawStrokes = true;
|
|
62
|
+
drawImageFills = false;
|
|
63
|
+
|
|
64
|
+
readonly options: Required<FillPassOptions> = {
|
|
65
|
+
drawRaycastPoint: false,
|
|
66
|
+
useRandomColors: false,
|
|
67
|
+
useFixedStyle: false,
|
|
68
|
+
fillStyle: {
|
|
69
|
+
color: "#333333",
|
|
70
|
+
opacity: 1,
|
|
71
|
+
},
|
|
72
|
+
strokeStyle: {
|
|
73
|
+
color: "#111111",
|
|
74
|
+
opacity: 1,
|
|
75
|
+
},
|
|
76
|
+
fillImage: '',
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
constructor(options: FillPassOptions = {}) {
|
|
80
|
+
super();
|
|
81
|
+
mergeOptions(this.options, options);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async draw(svg: Svg, viewmap: Viewmap) {
|
|
85
|
+
let img = this.options.fillImage && this.drawImageFills ? new window.Image() : undefined
|
|
86
|
+
if(img) {
|
|
87
|
+
await new Promise<void>((res, rej) => {
|
|
88
|
+
img!.onload = () => {
|
|
89
|
+
res()
|
|
90
|
+
}
|
|
91
|
+
img!.onerror = (e) => {
|
|
92
|
+
console.error('error loading image', e)
|
|
93
|
+
rej()
|
|
94
|
+
}
|
|
95
|
+
img!.src = this.options.fillImage!
|
|
96
|
+
}).catch((e) => {
|
|
97
|
+
img = undefined
|
|
98
|
+
console.error('error loading image', e)
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
// debugger
|
|
102
|
+
const group = new SVGGroup({id: "fills"});
|
|
103
|
+
svg.add(group);
|
|
104
|
+
|
|
105
|
+
for (const mesh of viewmap.meshes) {
|
|
106
|
+
|
|
107
|
+
if (mesh.drawFills) {
|
|
108
|
+
const polygons = viewmap.polygons.filter(p => p.mesh === mesh);
|
|
109
|
+
const objectGroup = new SVGGroup({id: mesh.name});
|
|
110
|
+
group.add(objectGroup);
|
|
111
|
+
|
|
112
|
+
for (const polygon of polygons) {
|
|
113
|
+
|
|
114
|
+
let img1 = undefined
|
|
115
|
+
if(this.options.fillImage && img){ // todo this can be optimized
|
|
116
|
+
const polygonBounds = new Box2().setFromPoints(polygon.contour);
|
|
117
|
+
const rootSize = new Vector2(svg.width() as number, svg.height() as number)
|
|
118
|
+
const polygonSize = polygonBounds.getSize(new Vector2())
|
|
119
|
+
const polygonCenter = polygonBounds.getCenter(new Vector2())
|
|
120
|
+
if(polygonSize.length() > rootSize.length()){
|
|
121
|
+
// use the full image directly.
|
|
122
|
+
await new Promise<void>((res) => {
|
|
123
|
+
img1 = svg.image(img!.src, () => {
|
|
124
|
+
// this._svgFillImage?.size(20, 20)
|
|
125
|
+
res();
|
|
126
|
+
// debugger
|
|
127
|
+
});
|
|
128
|
+
})
|
|
129
|
+
}else {
|
|
130
|
+
if (img.width !== rootSize.x || img.height !== rootSize.y) {
|
|
131
|
+
console.error('image size does not match svg size')
|
|
132
|
+
} else {
|
|
133
|
+
const canvas = document.createElement('canvas')
|
|
134
|
+
canvas.width = Math.floor(polygonSize.width)
|
|
135
|
+
canvas.height = Math.floor(polygonSize.height)
|
|
136
|
+
const context = canvas.getContext('2d')
|
|
137
|
+
if (context && canvas.width > 0 && canvas.height > 0) {
|
|
138
|
+
context.drawImage(img,
|
|
139
|
+
Math.floor(polygonCenter.x - polygonSize.width / 2),
|
|
140
|
+
Math.floor(polygonCenter.y - polygonSize.height / 2),
|
|
141
|
+
Math.floor(polygonSize.width), Math.floor(polygonSize.height),
|
|
142
|
+
0, 0, Math.floor(polygonSize.width), Math.floor(polygonSize.height),
|
|
143
|
+
)
|
|
144
|
+
// canvas.style.position = 'absolute'
|
|
145
|
+
// canvas.style.top = '0'
|
|
146
|
+
// canvas.style.left = '0'
|
|
147
|
+
// document.body.appendChild(canvas)
|
|
148
|
+
const croppedImgData = canvas.toDataURL('image/png') // use jpeg if not transparent?
|
|
149
|
+
await new Promise<void>((res) => {
|
|
150
|
+
img1 = svg.image(croppedImgData, () => {
|
|
151
|
+
// this._svgFillImage?.size(20, 20)
|
|
152
|
+
res();
|
|
153
|
+
// debugger
|
|
154
|
+
});
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
drawPolygon(group, polygon, this.options, img1, this.drawFills, this.drawStrokes);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if(img){
|
|
168
|
+
// loop through defs
|
|
169
|
+
// size w, h for all patterns.
|
|
170
|
+
// move image out of the pattern
|
|
171
|
+
// <use xlink:href="#SvgjsImage1000"/>
|
|
172
|
+
|
|
173
|
+
const patternAndImages = svg.defs().children().filter(c=>c instanceof Pattern && c.children().length === 1).map(c=>[c,c.children()[0]])
|
|
174
|
+
// console.log(patternAndImages)
|
|
175
|
+
patternAndImages.forEach(([pattern, image])=>{
|
|
176
|
+
pattern.x(0)
|
|
177
|
+
pattern.y(0)
|
|
178
|
+
pattern.width(1)
|
|
179
|
+
pattern.height(1)
|
|
180
|
+
pattern.attr('patternUnits', 'objectBoundingBox')
|
|
181
|
+
svg.defs().add(image)
|
|
182
|
+
pattern.add(svg.use(image))
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
// this._svgFillImage = undefined
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function drawPolygon(
|
|
190
|
+
parent: SVGElement,
|
|
191
|
+
polygon: Polygon,
|
|
192
|
+
options: FillPassOptions,
|
|
193
|
+
fillImage?: Image, drawFills = true, drawStroke = true) {
|
|
194
|
+
|
|
195
|
+
// Make a copy of the style so we can modify it
|
|
196
|
+
const style = {...options.fillStyle};
|
|
197
|
+
const strokeStyle = {...options.strokeStyle};
|
|
198
|
+
|
|
199
|
+
// If not using fixed color through the style, use the object color
|
|
200
|
+
if (!options.useFixedStyle) {
|
|
201
|
+
style.color = '#'+polygon.color.getHexString();
|
|
202
|
+
strokeStyle.color = '#'+polygon.color.getHexString();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (options.useRandomColors) {
|
|
206
|
+
style.color = SVGColor.random().toString();
|
|
207
|
+
strokeStyle.color = SVGColor.random().toString();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const path = getSVGPath(polygon.contour, polygon.holes, true, drawStroke ? strokeStyle : undefined, drawFills ? style : undefined, fillImage, parent);
|
|
211
|
+
path.id("fill-"+polygon.id);
|
|
212
|
+
// parent.add(path);
|
|
213
|
+
|
|
214
|
+
if (options.drawRaycastPoint) {
|
|
215
|
+
drawPolygonRaycastPoint(parent, polygon);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function drawPolygonRaycastPoint(parent: SVGElement, polygon: Polygon) {
|
|
220
|
+
const strokeStyle = {color: "black"};
|
|
221
|
+
const fillStyle = {color: "white"};
|
|
222
|
+
const cx = polygon.insidePoint.x;
|
|
223
|
+
const cy = polygon.insidePoint.y;
|
|
224
|
+
const point = getSVGCircle(cx, cy, 2, strokeStyle, fillStyle);
|
|
225
|
+
point.id('raycast-point');
|
|
226
|
+
parent.add(point);
|
|
227
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Author: Axel Antoine
|
|
2
|
+
// mail: ax.antoine@gmail.com
|
|
3
|
+
// website: https://axantoine.com
|
|
4
|
+
// 16/06/2022
|
|
5
|
+
|
|
6
|
+
// Loki, Inria project-team with Université de Lille
|
|
7
|
+
// within the Joint Research Unit UMR 9189 CNRS-Centrale
|
|
8
|
+
// Lille-Université de Lille, CRIStAL.
|
|
9
|
+
// https://loki.lille.inria.fr
|
|
10
|
+
|
|
11
|
+
// LICENCE: Licence.md
|
|
12
|
+
|
|
13
|
+
import {DrawPass} from './DrawPass';
|
|
14
|
+
import {Viewmap} from '../../viewmap/Viewmap';
|
|
15
|
+
import {Svg, G as SVGGroup} from '@svgdotjs/svg.js';
|
|
16
|
+
import {ChainVisibility} from '../../viewmap/Chain';
|
|
17
|
+
import {getSVGCircle, getSVGText} from '../svgutils';
|
|
18
|
+
import { ViewVertexSingularity } from '../../viewmap/ViewVertex';
|
|
19
|
+
|
|
20
|
+
const ViewVertexSingularities = Object.values(ViewVertexSingularity)
|
|
21
|
+
.filter(singularity => singularity !== ViewVertexSingularity.None);
|
|
22
|
+
|
|
23
|
+
const ViewVertexSingularityColor = {
|
|
24
|
+
[ViewVertexSingularity.None]: "",
|
|
25
|
+
[ViewVertexSingularity.ImageIntersection]: "green",
|
|
26
|
+
[ViewVertexSingularity.MeshIntersection]: "red",
|
|
27
|
+
[ViewVertexSingularity.CurtainFold]: "blue",
|
|
28
|
+
[ViewVertexSingularity.Bifurcation]: "orange",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface SingularityPointPassOptions {
|
|
32
|
+
drawLegend?: boolean;
|
|
33
|
+
pointSize?: number;
|
|
34
|
+
drawVisiblePoints?: boolean;
|
|
35
|
+
drawHiddenPoints?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class SingularityPointPass extends DrawPass {
|
|
39
|
+
readonly options: Required<SingularityPointPassOptions> = {
|
|
40
|
+
drawVisiblePoints: true,
|
|
41
|
+
drawHiddenPoints: false,
|
|
42
|
+
drawLegend: true,
|
|
43
|
+
pointSize: 2,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
constructor(options: SingularityPointPassOptions = {}) {
|
|
47
|
+
super();
|
|
48
|
+
Object.assign(this.options, options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async draw(svg: Svg, viewmap: Viewmap) {
|
|
52
|
+
// Update point visibility to avoid drawing point on hidden chains if only
|
|
53
|
+
// visible chains are drawn
|
|
54
|
+
|
|
55
|
+
for (const chain of viewmap.chains) {
|
|
56
|
+
for (const p of chain.vertices) {
|
|
57
|
+
p.visible = p.visible || chain.visibility === ChainVisibility.Visible;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const visibilities = [];
|
|
62
|
+
if (this.options.drawVisiblePoints) {
|
|
63
|
+
visibilities.push(true);
|
|
64
|
+
}
|
|
65
|
+
if (this.options.drawHiddenPoints) {
|
|
66
|
+
visibilities.push(false);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const group = new SVGGroup({id: "singularity-points"});
|
|
70
|
+
svg.add(group);
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
const strokeStyle = {
|
|
74
|
+
color: 'black'
|
|
75
|
+
};
|
|
76
|
+
const fillStyle = {
|
|
77
|
+
color: "",
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const singularityPoints = Array.from(viewmap.viewVertexMap.values())
|
|
81
|
+
.filter(p => p.singularity != ViewVertexSingularity.None);
|
|
82
|
+
|
|
83
|
+
for (const visibility of visibilities) {
|
|
84
|
+
|
|
85
|
+
const visibilityGroup = new SVGGroup({id: visibility? "visible" : "hidden"})
|
|
86
|
+
group.add(visibilityGroup);
|
|
87
|
+
|
|
88
|
+
for (const singularity of ViewVertexSingularities) {
|
|
89
|
+
|
|
90
|
+
const points = singularityPoints
|
|
91
|
+
.filter(p => p.singularity === singularity && p.visible === visibility);
|
|
92
|
+
|
|
93
|
+
const singularityGroup = new SVGGroup({id: singularity});
|
|
94
|
+
visibilityGroup.add(singularityGroup);
|
|
95
|
+
|
|
96
|
+
fillStyle.color = ViewVertexSingularityColor[singularity];
|
|
97
|
+
for (const p of points) {
|
|
98
|
+
const svgPoint = getSVGCircle(p.pos2d.x, p.pos2d.y, this.options.pointSize, strokeStyle, fillStyle);
|
|
99
|
+
singularityGroup.add(svgPoint);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (this.options.drawLegend) {
|
|
105
|
+
group.add(getLegend());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getLegend() {
|
|
111
|
+
const legend = new SVGGroup({id: "singularity-legend"});
|
|
112
|
+
|
|
113
|
+
legend.add(getSVGText("Singularities", 10, 10, {size: 15, anchor: 'start'}))
|
|
114
|
+
|
|
115
|
+
let y = 40;
|
|
116
|
+
for (const singularity of ViewVertexSingularities) {
|
|
117
|
+
const fillColor = ViewVertexSingularityColor[singularity];
|
|
118
|
+
|
|
119
|
+
legend.add(getSVGCircle(15, y, 8, {color: "black"}, {color: fillColor}));
|
|
120
|
+
legend.add(getSVGText(singularity, 30, y-10, {size: 15, anchor: 'start'}));
|
|
121
|
+
|
|
122
|
+
y += 20;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return legend;
|
|
126
|
+
}
|