@soonspacejs/plugin-drawing-shape 2.5.0-rc.4 → 2.5.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.
Files changed (34) hide show
  1. package/package.json +2 -2
  2. package/example/changjing02/FileInfo.xml +0 -1
  3. package/example/changjing02/Maps/1_board_t01.png +0 -0
  4. package/example/changjing02/Maps/AirconStand01_t01.jpg +0 -0
  5. package/example/changjing02/Maps/AirconStand01_t02.jpg +0 -0
  6. package/example/changjing02/Maps/AirconWall01_t01.jpg +0 -0
  7. package/example/changjing02/Maps/CCTV_01_t.jpg +0 -0
  8. package/example/changjing02/Maps/COPPWIR01.jpg +0 -0
  9. package/example/changjing02/Maps/Cabinet02_t01.jpg +0 -0
  10. package/example/changjing02/Maps/CeilingDefault.jpg +0 -0
  11. package/example/changjing02/Maps/ExCon02.jpg +0 -0
  12. package/example/changjing02/Maps/Fa_06.jpg +0 -0
  13. package/example/changjing02/Maps/FireT_t01.jpg +0 -0
  14. package/example/changjing02/Maps/Keyborad01_t01.jpg +0 -0
  15. package/example/changjing02/Maps/MattTile01.jpg +0 -0
  16. package/example/changjing02/Maps/Stone_TileColumn2.jpg +0 -0
  17. package/example/changjing02/Maps/VinylT_Plan01.jpg +0 -0
  18. package/example/changjing02/Maps/Wall_Gradient.jpg +0 -0
  19. package/example/changjing02/Maps/Wood_Maple.jpg +0 -0
  20. package/example/changjing02/Maps/Wood_Maple_Door.jpg +0 -0
  21. package/example/changjing02/Maps/Wood_Maple_DoorFR.jpg +0 -0
  22. package/example/changjing02/Maps/fj0001.jpg +0 -0
  23. package/example/changjing02/Maps/sk0002.jpg +0 -0
  24. package/example/changjing02/Mobile.zip +0 -0
  25. package/example/changjing02/changjing02.gpl +0 -0
  26. package/example/changjing02/changjing02.jpg +0 -0
  27. package/example/changjing02/changjing02.xml +0 -69
  28. package/example/changjing02/changjing02_1F_0.sbm +0 -0
  29. package/example/ground/001.jpg +0 -0
  30. package/example/ground/002.jpg +0 -0
  31. package/example/ground/003.jpg +0 -0
  32. package/example/ground/004.jpg +0 -0
  33. package/example/index.html +0 -134
  34. package/src/index.ts +0 -500
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-drawing-shape",
3
3
  "pluginName": "DrawingShapePlugin",
4
- "version": "2.5.0-rc.4",
4
+ "version": "2.5.0",
5
5
  "description": "DrawingShapePlugin plugin for SoonSpace.js",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,5 +13,5 @@
13
13
  ],
14
14
  "author": "xuek",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "408fbc280a73b3557b5f9a62be3c2365c963fa4f"
16
+ "gitHead": "61b7ed6ce3e0d761a30fb65d64a4eeb22acbfef9"
17
17
  }
@@ -1 +0,0 @@
1
- <?xml version="1.0" standalone="yes"?><folder name="changjing02"><file name="changjing02.gpl" Extension=".gpl" /><file name="changjing02.jpg" Extension=".jpg" /><file name="changjing02.xml" Extension=".xml" /><file name="changjing02_1F_0.sbm" Extension=".sbm" /><file name="Mobile.zip" Extension=".zip" /><folder name="Maps"><file name="1_board_t01.png" Extension=".png" /><file name="AirconStand01_t01.jpg" Extension=".jpg" /><file name="AirconStand01_t02.jpg" Extension=".jpg" /><file name="AirconWall01_t01.jpg" Extension=".jpg" /><file name="Cabinet02_t01.jpg" Extension=".jpg" /><file name="CCTV_01_t.jpg" Extension=".jpg" /><file name="CeilingDefault.jpg" Extension=".jpg" /><file name="COPPWIR01.jpg" Extension=".jpg" /><file name="ExCon02.jpg" Extension=".jpg" /><file name="Fa_06.jpg" Extension=".jpg" /><file name="FireT_t01.jpg" Extension=".jpg" /><file name="fj0001.jpg" Extension=".jpg" /><file name="Keyborad01_t01.jpg" Extension=".jpg" /><file name="MattTile01.jpg" Extension=".jpg" /><file name="sk0002.jpg" Extension=".jpg" /><file name="Stone_TileColumn2.jpg" Extension=".jpg" /><file name="VinylT_Plan01.jpg" Extension=".jpg" /><file name="Wall_Gradient.jpg" Extension=".jpg" /><file name="Wood_Maple.jpg" Extension=".jpg" /><file name="Wood_Maple_Door.jpg" Extension=".jpg" /><file name="Wood_Maple_DoorFR.jpg" Extension=".jpg" /></folder></folder>
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,69 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Project>
3
- <ProjectInfo gkxmlVersion="1.2">
4
- <Title>changjing02</Title>
5
- </ProjectInfo>
6
- <Building sourceType="GPL" northAxis="0.000000">
7
- <EarthReferenceSystem type="WGS84">
8
- <altitudeMode>relativeToGround</altitudeMode>
9
- <Location>
10
- <longitude>30</longitude>
11
- <latitude>119</latitude>
12
- <altitude>0</altitude>
13
- </Location>
14
- <Orientation>
15
- <heading>0</heading>
16
- <tilt>0.0</tilt>
17
- <roll>0.0</roll>
18
- </Orientation>
19
- </EarthReferenceSystem>
20
- <ExportOptions>
21
- <Item name="floorMerge" value="false"/>
22
- <Item name="wallMerge" value="true">
23
- <MergeObjectTypes>WALL,CEILING,COLUMN,SLAB,SPACE,DOOR,WINDOW,STAIR,ELEVATOR,FACILITY</MergeObjectTypes>
24
- </Item>
25
- </ExportOptions>
26
- <Unit>centimeter</Unit>
27
- <DefaultBuilding>false</DefaultBuilding>
28
- <DefaultFloor>0</DefaultFloor>
29
- <Floors>
30
- <Floor id="0" name="1F" baseFloor="1" groupID="0" isMain="True">
31
- <FileSource name=".\changjing02_1F_0.sbm" type="SBM"/>
32
- <BoundingBox minimum="-1147.500000, -377.599487, -536.307251" maximum="1147.500000, 2121.000000, 594.959839"/>
33
- </Floor>
34
- </Floors>
35
- <SpaceInfo>
36
- <Floor id="0" name="1F" longname="2030925431" baseFloor="1" level="0.000000"/>
37
- </SpaceInfo>
38
- <ObjectHierarchy>
39
- <Entity id="0" name="1F" type="Floor" longname="2030925431">
40
- <Entity id="25" name="MERGED_0_1_Board_0" longname="" type="MERGED" visible="True"/>
41
- <Entity id="9" name="MERGED_0_AirconStand01/AirconStand01_01_0" longname="" type="MERGED" visible="True"/>
42
- <Entity id="10" name="MERGED_0_AirconStand01/AirconStand01_02_0" longname="" type="MERGED" visible="True"/>
43
- <Entity id="22" name="MERGED_0_AirconWall01/AirconWall01_01_0" longname="" type="MERGED" visible="True"/>
44
- <Entity id="23" name="MERGED_0_AirconWall01/AirconWall01_02_0" longname="" type="MERGED" visible="True"/>
45
- <Entity id="24" name="MERGED_0_CCTV_01/07-Default_0" longname="" type="MERGED" visible="True"/>
46
- <Entity id="26" name="MERGED_0_Cabinet02/Cabinet02_0" longname="" type="MERGED" visible="True"/>
47
- <Entity id="11" name="MERGED_0_Chair_CM01/Chair_CM0111_0" longname="" type="MERGED" visible="True"/>
48
- <Entity id="12" name="MERGED_0_Chair_CM01/Chair_CM0112_0" longname="" type="MERGED" visible="True"/>
49
- <Entity id="13" name="MERGED_0_Chair_CM01/Chair_CM0113_0" longname="" type="MERGED" visible="True"/>
50
- <Entity id="14" name="MERGED_0_Chair_CM01/Chair_CM0114_0" longname="" type="MERGED" visible="True"/>
51
- <Entity id="15" name="MERGED_0_Chair_CM01/Chair_CM0115_0" longname="" type="MERGED" visible="True"/>
52
- <Entity id="18" name="MERGED_0_DeskOffice_01/DeskOffice_01Gray_0" longname="" type="MERGED" visible="True"/>
53
- <Entity id="17" name="MERGED_0_DeskOffice_01/DeskOffice_01Green_0" longname="" type="MERGED" visible="True"/>
54
- <Entity id="16" name="MERGED_0_FireT/FireT_0" longname="" type="MERGED" visible="True"/>
55
- <Entity id="19" name="MERGED_0_Keyborad01/Keyborad01_01_0" longname="" type="MERGED" visible="True"/>
56
- <Entity id="20" name="MERGED_0_Keyborad01/Keyborad01_02_0" longname="" type="MERGED" visible="True"/>
57
- <Entity id="5" name="MERGED_0_LIBENT10_0" longname="" type="MERGED" visible="True"/>
58
- <Entity id="6" name="MERGED_0_LIBENT15_0" longname="" type="MERGED" visible="True"/>
59
- <Entity id="3" name="MERGED_0_LIBENT16_0" longname="" type="MERGED" visible="True"/>
60
- <Entity id="1" name="MERGED_0_LIBENT1_0" longname="" type="MERGED" visible="True"/>
61
- <Entity id="2" name="MERGED_0_LIBENT2_0" longname="" type="MERGED" visible="True"/>
62
- <Entity id="4" name="MERGED_0_LIBENT3_0" longname="" type="MERGED" visible="True"/>
63
- <Entity id="7" name="MERGED_0_LIBENT4_0" longname="" type="MERGED" visible="True"/>
64
- <Entity id="8" name="MERGED_0_LIBENT5_0" longname="" type="MERGED" visible="True"/>
65
- <Entity id="21" name="MERGED_0_PDP_003/Material#122_0" longname="" type="MERGED" visible="True"/>
66
- </Entity>
67
- </ObjectHierarchy>
68
- <GLBFShells><GLBFShell><FileSource name=".\changjing02_1F_0.json" type="GLBF"/><BoundingBox/></GLBFShell></GLBFShells></Building>
69
- </Project>
Binary file
Binary file
Binary file
Binary file
@@ -1,134 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
- <title>Document</title>
9
- <style>
10
- * {
11
- margin: 0;
12
- }
13
- </style>
14
- </head>
15
-
16
- <body>
17
- <div id="view" style="width: 100vw; height: 100vh;"></div>
18
-
19
- <script type="module">
20
- import SoonSpace from '../../../soonspacejs/dist/index.esm.js'
21
- import DrawingShapePlugin from '../dist/index.esm.js'
22
- import { GUI } from '../../../../libs/gui.js'
23
-
24
- const ssp = window.ssp = new SoonSpace({
25
- el: '#view',
26
- options: {
27
- showInfo: true,
28
- showGrid: false
29
- },
30
- events: {
31
- // selectPosition(position) {
32
- // console.log(position)
33
- // }
34
- }
35
- })
36
-
37
- ssp.loadSbm({
38
- id: 'room',
39
- url: './changjing02/changjing02_1F_0.sbm',
40
- position: {
41
- x: 100,
42
- y: 120,
43
- z: 100
44
- }
45
- })
46
- .then(sbm => {
47
- return ssp.flyToObj(sbm, "leftFrontTop", { padding: 100 })
48
- })
49
- .then(sbm => {
50
- const drawingShapePlugin = ssp.registerPlugin(DrawingShapePlugin, 'drawingShapePlugin')
51
-
52
- const gui = new GUI()
53
-
54
- const fns = {
55
- 绘制点: function () {
56
- drawingShapePlugin.drawingPoint(
57
- {
58
- color: 'blue',
59
- opacity: 1
60
- },
61
- {
62
- onCancel() {
63
- console.log('drawPoint onCancel')
64
- }
65
- }
66
- )
67
- .then(res => console.log('drawPoint done', res))
68
- },
69
- 绘制线: function () {
70
- drawingShapePlugin.drawingLine(
71
- {
72
- color: 'green',
73
- opacity: 0.8
74
- },
75
- {
76
- onCancel() {
77
- console.log('drawingLine onCancel')
78
- },
79
- onCancelPrev() {
80
- console.log('drawingLine onCancelPrev')
81
- },
82
- }
83
- )
84
- .then(res => console.log('drawLine done', res))
85
- },
86
- 绘制面: function () {
87
- drawingShapePlugin.drawingPolygon(
88
- {
89
- yHeight: 200,
90
- color: 'blue',
91
- opacity: 0.5
92
- },
93
- {
94
- onCancel() {
95
- console.log('drawingPolygon onCancel')
96
- },
97
- onCancelPrev() {
98
- console.log('drawingPolygon onCancelPrev')
99
- },
100
- }
101
- )
102
- .then(res => console.log('drawPolygon done', res))
103
- },
104
- 绘制圆: function () {
105
- drawingShapePlugin.drawingCircle(
106
- {
107
- color: 'blue',
108
- opacity: 0.5
109
- },
110
- {
111
- onCancel() {
112
- console.log('drawingCircle onCancel')
113
- }
114
- }
115
- )
116
- .then(res => console.log('drawingCircle done', res))
117
- }
118
- }
119
-
120
- for (let i in fns) gui.add(fns, i)
121
-
122
- })
123
-
124
- ssp.addGroundHelper({
125
- id: 'ground',
126
- imgUrl: './ground/001.jpg',
127
- width: 10000,
128
- height: 10000
129
- })
130
-
131
- </script>
132
- </body>
133
-
134
- </html>
package/src/index.ts DELETED
@@ -1,500 +0,0 @@
1
- import SoonSpace, { Position, } from 'soonspacejs'
2
- import { SetOptionsPointInfo, SetOptionsLineInfo, SetOptionsPolygonInfo, SetOptionsCircleInfo, } from 'soonspacejs/types/Library'
3
- import { Vector3, } from 'three'
4
-
5
- export type DrawingPointInfo = SetOptionsPointInfo
6
- export interface DrawingPointEvents {
7
- onCancel?: () => void;
8
- }
9
-
10
- export type DrawingLineInfo = Omit<SetOptionsLineInfo, 'points'>
11
- export interface DrawingLineEvents {
12
- onCancel?: () => void;
13
- onCancelPrev?: () => void;
14
- }
15
-
16
- export type DrawingPolygonInfo = Omit<SetOptionsPolygonInfo, 'points' | 'yHeight'>
17
- export interface DrawingPolygonEvents {
18
- onCancel?: () => void;
19
- onCancelPrev?: () => void;
20
- }
21
-
22
- export type DrawingCircleInfo = Omit<SetOptionsCircleInfo, 'radius'>
23
- export interface DrawingCircleEvents {
24
- onCancel?: () => void;
25
- }
26
-
27
-
28
- const DrawingIds = {
29
- canvas: 'drawingCanvas',
30
- point: 'drawingPoint',
31
- line: 'drawingLine',
32
- polygon: 'drawingPolygon',
33
- circle: 'drawingCircle',
34
- }
35
-
36
- export default class DrawIngShapePlugin {
37
-
38
- readonly viewport: SoonSpace['viewport']
39
-
40
- constructor ( readonly ssp: SoonSpace ) {
41
-
42
- this.viewport = ssp.viewport
43
-
44
- }
45
-
46
- drawingPoint ( options: DrawingPointInfo, events?: DrawingPointEvents ): Promise<SetOptionsPointInfo> {
47
-
48
- return new Promise( ( resolve ) => {
49
-
50
- this.clearDrawingCanvas3D()
51
-
52
- const canvas = new this.ssp.library.Canvas3D( {
53
- id: DrawingIds.canvas,
54
- points: [ {
55
- ...options,
56
- id: DrawingIds.point,
57
- } ],
58
- } )
59
-
60
- this.ssp.manager.store.canvas3DManager.scene.add( canvas )
61
-
62
- const point = canvas.getPoint( DrawingIds.point )
63
-
64
- const onMouseMove = ( event: MouseEvent ) => {
65
-
66
- if ( !point ) return
67
-
68
- const intersects = this.ssp.viewport.getIntersects( event )
69
- const position = intersects.length > 0 ? intersects[ 0 ].point.clone() : this.ssp.getPositionByOffset( event )
70
-
71
- point.setOptions( {
72
- position,
73
- } )
74
-
75
- }
76
-
77
- const onClick = ( event: MouseEvent ) => {
78
-
79
- removeSignals()
80
-
81
- if ( !point ) return
82
-
83
- const intersects = this.ssp.viewport.getIntersects( event )
84
- const position = intersects.length > 0 ? intersects[ 0 ].point.clone() : this.ssp.getPositionByOffset( event )
85
-
86
- point.setOptions( {
87
- position,
88
- } )
89
-
90
- resolve( {
91
- ...options,
92
- position: position.clone(),
93
- } )
94
-
95
- }
96
-
97
- const onRightClick = () => {
98
-
99
- this.clearDrawingCanvas3D()
100
- removeSignals()
101
-
102
- events?.onCancel?.()
103
-
104
- }
105
-
106
- const onKeyUp = ( event: KeyboardEvent ) => {
107
-
108
- switch ( event.code ) {
109
-
110
- case 'Escape':
111
- onRightClick()
112
- break
113
-
114
- }
115
-
116
- }
117
-
118
- const removeSignals = () => {
119
-
120
- this.ssp.signals.mouseMove.remove( onMouseMove )
121
- this.ssp.signals.click.remove( onClick )
122
- this.ssp.signals.rightClick.remove( onRightClick )
123
- this.ssp.signals.keyUp.remove( onKeyUp )
124
-
125
- }
126
-
127
- this.ssp.signals.mouseMove.add( onMouseMove )
128
- this.ssp.signals.click.add( onClick )
129
- this.ssp.signals.rightClick.add( onRightClick )
130
- this.ssp.signals.keyUp.add( onKeyUp )
131
-
132
- } )
133
-
134
- }
135
-
136
- drawingLine ( options: DrawingLineInfo, events?: DrawingLineEvents ): Promise<SetOptionsLineInfo> {
137
-
138
- return new Promise( ( resolve ) => {
139
-
140
- this.clearDrawingCanvas3D()
141
-
142
- const canvas = new this.ssp.library.Canvas3D( {
143
- id: DrawingIds.canvas,
144
- lines: [ {
145
- ...options,
146
- points: [],
147
- id: DrawingIds.line,
148
- } ],
149
- } )
150
-
151
- this.ssp.manager.store.canvas3DManager.scene.add( canvas )
152
-
153
- const line = canvas.getLine( DrawingIds.line )
154
- const linePoints: Position[] = []
155
-
156
- const onMouseMove = ( event: MouseEvent ) => {
157
-
158
- const intersects = this.ssp.viewport.getIntersects( event )
159
- const position = intersects.length > 0 ? intersects[ 0 ].point.clone() : this.ssp.getPositionByOffset( event )
160
-
161
- if ( !line ) return
162
-
163
- line.setOptions( {
164
- ...options,
165
- points: [ ...linePoints, position.clone().setY( position.y + 1 ) ],
166
- } )
167
-
168
- }
169
-
170
- const onClick = ( event: MouseEvent ) => {
171
-
172
- const intersects = this.ssp.viewport.getIntersects( event )
173
- const position = intersects.length > 0 ? intersects[ 0 ].point.clone() : this.ssp.getPositionByOffset( event )
174
-
175
- linePoints.push( position.clone().setY( position.y + 1 ) )
176
-
177
- if ( !line ) return
178
-
179
- line.setOptions( {
180
- ...options,
181
- points: linePoints,
182
- } )
183
-
184
- }
185
-
186
- const onRightClick = () => {
187
-
188
- linePoints.pop()
189
-
190
- if ( !line ) return
191
-
192
- line.setOptions( {
193
- ...options,
194
- points: linePoints,
195
- } )
196
-
197
- events?.onCancelPrev?.()
198
-
199
- }
200
-
201
- const onDblClick = () => {
202
-
203
- removeSignals()
204
-
205
- resolve( {
206
- ...options,
207
- points: linePoints,
208
- } )
209
-
210
- }
211
-
212
- const onKeyUp = ( event: KeyboardEvent ) => {
213
-
214
- switch ( event.code ) {
215
-
216
- case 'Backspace':
217
- onRightClick()
218
- break
219
- case 'Escape':
220
- this.clearDrawingCanvas3D()
221
- removeSignals()
222
-
223
- events?.onCancel?.()
224
- break
225
-
226
- }
227
-
228
- }
229
-
230
- const removeSignals = () => {
231
-
232
- this.ssp.signals.mouseMove.remove( onMouseMove )
233
- this.ssp.signals.click.remove( onClick )
234
- this.ssp.signals.rightClick.remove( onRightClick )
235
- this.ssp.signals.dblClick.remove( onDblClick )
236
- this.ssp.signals.keyUp.remove( onKeyUp )
237
-
238
- }
239
-
240
- this.ssp.signals.mouseMove.add( onMouseMove )
241
- this.ssp.signals.click.add( onClick )
242
- this.ssp.signals.rightClick.add( onRightClick )
243
- this.ssp.signals.dblClick.add( onDblClick )
244
- this.ssp.signals.keyUp.add( onKeyUp )
245
-
246
- } )
247
-
248
- }
249
-
250
- drawingPolygon ( options: DrawingPolygonInfo, events?: DrawingPolygonEvents ): Promise<SetOptionsPolygonInfo> {
251
-
252
- return new Promise( ( resolve ) => {
253
-
254
- this.clearDrawingCanvas3D()
255
-
256
- const canvas = new this.ssp.library.Canvas3D( {
257
- id: DrawingIds.canvas,
258
- polygons: [ {
259
- ...options,
260
- points: [],
261
- yHeight: 0,
262
- id: DrawingIds.polygon,
263
- } ],
264
- lines: [ {
265
- ...options,
266
- points: [],
267
- id: DrawingIds.line,
268
- width: 2,
269
- } ],
270
- } )
271
-
272
- this.ssp.manager.store.canvas3DManager.scene.add( canvas )
273
-
274
- const polygon = canvas.getPolygon( DrawingIds.polygon )
275
- const line = canvas.getLine( DrawingIds.line )
276
- const polygonPoints: Position[] = []
277
-
278
- const omMouseMove = ( event: MouseEvent ) => {
279
-
280
- const intersects = this.ssp.viewport.getIntersects( event )
281
- const position = intersects.length > 0 ? intersects[ 0 ].point.clone() : this.ssp.getPositionByOffset( event )
282
-
283
- if ( !polygon ) return
284
-
285
- const movingPolygonPoints = [ ...polygonPoints, position ]
286
-
287
- if ( movingPolygonPoints.length > 2 ) {
288
-
289
- canvas.removeLine( DrawingIds.line )
290
-
291
- } else {
292
-
293
- line?.setOptions( {
294
- points: movingPolygonPoints,
295
- } )
296
-
297
- }
298
-
299
- polygon.setOptions( {
300
- yHeight: ( polygonPoints[ 0 ]?.y || position.y ) + 1,
301
- points: movingPolygonPoints,
302
- } )
303
-
304
- }
305
-
306
- const onClick = ( event: MouseEvent ) => {
307
-
308
- const intersects = this.ssp.viewport.getIntersects( event )
309
- const position = intersects.length > 0 ? intersects[ 0 ].point.clone() : this.ssp.getPositionByOffset( event )
310
-
311
- polygonPoints.push( position.clone().setY( position.y + 1 ) )
312
-
313
- if ( !polygon ) return
314
-
315
- polygon.setOptions( {
316
- ...options,
317
- yHeight: ( polygonPoints[ 0 ]?.y || 0 ) + 1,
318
- points: polygonPoints,
319
- } )
320
-
321
- }
322
-
323
- const onRightClick = () => {
324
-
325
- polygonPoints.pop()
326
-
327
- if ( !polygon ) return
328
-
329
- polygon.setOptions( {
330
- ...options,
331
- yHeight: ( polygonPoints[ 0 ]?.y || 0 ) + 1,
332
- points: polygonPoints,
333
- } )
334
-
335
- events?.onCancelPrev?.()
336
-
337
- }
338
-
339
- const onDblClick = () => {
340
-
341
- removeSignals()
342
-
343
- resolve( {
344
- ...options,
345
- yHeight: ( polygonPoints[ 0 ]?.y || 0 ) + 1,
346
- points: polygonPoints,
347
- } )
348
-
349
- }
350
-
351
- const onKeyUp = ( event: KeyboardEvent ) => {
352
-
353
- switch ( event.code ) {
354
-
355
- case 'Backspace':
356
- onRightClick()
357
- break
358
- case 'Escape':
359
- this.clearDrawingCanvas3D()
360
- removeSignals()
361
-
362
- events?.onCancel?.()
363
- break
364
-
365
- }
366
-
367
- }
368
-
369
- const removeSignals = () => {
370
-
371
- this.ssp.signals.mouseMove.remove( omMouseMove )
372
- this.ssp.signals.click.remove( onClick )
373
- this.ssp.signals.rightClick.remove( onRightClick )
374
- this.ssp.signals.dblClick.remove( onDblClick )
375
- this.ssp.signals.keyUp.remove( onKeyUp )
376
-
377
- }
378
-
379
- this.ssp.signals.mouseMove.add( omMouseMove )
380
- this.ssp.signals.click.add( onClick )
381
- this.ssp.signals.rightClick.add( onRightClick )
382
- this.ssp.signals.dblClick.add( onDblClick )
383
- this.ssp.signals.keyUp.add( onKeyUp )
384
-
385
- } )
386
-
387
- }
388
-
389
- drawingCircle ( options: DrawingCircleInfo, events?: DrawingCircleEvents ): Promise<SetOptionsCircleInfo> {
390
-
391
- return new Promise( ( resolve ) => {
392
-
393
- this.clearDrawingCanvas3D()
394
-
395
- const canvas = new this.ssp.library.Canvas3D( {
396
- id: DrawingIds.canvas,
397
- circles: [ {
398
- ...options,
399
- id: DrawingIds.circle,
400
- } ],
401
- } )
402
-
403
- this.ssp.manager.store.canvas3DManager.scene.add( canvas )
404
-
405
- const circle = canvas.getCircle( DrawingIds.circle )
406
-
407
- let position: Vector3 | null
408
- let radius = 100
409
-
410
- const onMouseMove = ( event: MouseEvent ) => {
411
-
412
- if ( !circle || !position ) return
413
-
414
- const intersects = this.ssp.viewport.getIntersects( event )
415
- const mouseMovePosition = intersects.length > 0 ? intersects[ 0 ].point.clone() : this.ssp.getPositionByOffset( event )
416
-
417
- radius = mouseMovePosition.distanceTo( position )
418
-
419
- circle.setOptions( {
420
- position,
421
- radius,
422
- } )
423
-
424
- }
425
-
426
- const onClick = ( event: MouseEvent ) => {
427
-
428
- if ( !circle ) return
429
-
430
- const intersects = this.ssp.viewport.getIntersects( event )
431
- const mouseMovePosition = intersects.length > 0 ? intersects[ 0 ].point.clone() : this.ssp.getPositionByOffset( event )
432
-
433
- if ( !position ) position = mouseMovePosition.clone().setY( mouseMovePosition.y + 1 )
434
- else {
435
-
436
- removeSignals()
437
-
438
- radius = mouseMovePosition.distanceTo( this.ssp.utils.IVector3ToVector3( position ) )
439
-
440
- circle.setOptions( {
441
- position,
442
- radius,
443
- } )
444
-
445
- resolve( {
446
- ...options,
447
- position,
448
- radius,
449
- } )
450
-
451
- }
452
-
453
- }
454
-
455
- const onRightClick = () => {
456
-
457
- this.clearDrawingCanvas3D()
458
- removeSignals()
459
-
460
- events?.onCancel?.()
461
-
462
- }
463
-
464
- const onKeyUp = ( event: KeyboardEvent ) => {
465
-
466
- switch ( event.code ) {
467
-
468
- case 'Escape':
469
- onRightClick()
470
- break
471
-
472
- }
473
-
474
- }
475
-
476
- const removeSignals = () => {
477
-
478
- this.ssp.signals.mouseMove.remove( onMouseMove )
479
- this.ssp.signals.click.remove( onClick )
480
- this.ssp.signals.rightClick.remove( onRightClick )
481
- this.ssp.signals.keyUp.remove( onKeyUp )
482
-
483
- }
484
-
485
- this.ssp.signals.mouseMove.add( onMouseMove )
486
- this.ssp.signals.click.add( onClick )
487
- this.ssp.signals.rightClick.add( onRightClick )
488
- this.ssp.signals.keyUp.add( onKeyUp )
489
-
490
- } )
491
-
492
- }
493
-
494
- clearDrawingCanvas3D (): void {
495
-
496
- this.ssp.removeObjectById( DrawingIds.canvas )
497
-
498
- }
499
-
500
- }