@@ -3,11 +3,84 @@ import Earcut from 'earcut';
3
3
import { FEATURE_TYPES } from 'Core/Feature' ;
4
4
import ReferLayerProperties from 'Layer/ReferencingLayerProperties' ;
5
5
import { deprecatedFeature2MeshOptions } from 'Core/Deprecated/Undeprecator' ;
6
+ import Extent from 'Core/Geographic/Extent' ;
7
+ import Crs from 'Core/Geographic/Crs' ;
8
+ import OrientationUtils from 'Utils/OrientationUtils' ;
9
+ import Coordinates from 'Core/Geographic/Coordinates' ;
10
+
11
+ const coord = new Coordinates ( 'EPSG:4326' , 0 , 0 , 0 ) ;
12
+ const dim_ref = new THREE . Vector2 ( ) ;
13
+ const dim = new THREE . Vector2 ( ) ;
14
+ const extent = new Extent ( 'EPSG:4326' , 0 , 0 , 0 , 0 ) ;
6
15
7
16
const _color = new THREE . Color ( ) ;
8
17
const maxValueUint8 = 2 ** 8 - 1 ;
9
18
const maxValueUint16 = 2 ** 16 - 1 ;
10
19
const maxValueUint32 = 2 ** 32 - 1 ;
20
+ const crsWGS84 = 'EPSG:4326' ;
21
+
22
+ class FeatureMesh extends THREE . Group {
23
+ #currentCrs;
24
+ #originalCrs;
25
+ constructor ( meshes , collection ) {
26
+ super ( ) ;
27
+ this . meshesCollection = new THREE . Group ( ) . add ( ...meshes ) ;
28
+ this . meshesCollection . quaternion . copy ( collection . quaternion ) ;
29
+ this . meshesCollection . position . copy ( collection . position ) ;
30
+ this . meshesCollection . scale . copy ( collection . scale ) ;
31
+ this . meshesCollection . updateMatrix ( ) ;
32
+
33
+ this . #originalCrs = collection . crs ;
34
+ this . #currentCrs = this . #originalCrs;
35
+ this . extent = collection . extent ;
36
+ this . place = new THREE . Group ( ) ;
37
+ this . geoid = new THREE . Group ( ) ;
38
+
39
+ this . add ( this . place . add ( this . geoid . add ( this . meshesCollection ) ) ) ;
40
+ }
41
+
42
+ as ( crs ) {
43
+ if ( this . #currentCrs !== crs ) {
44
+ this . #currentCrs = crs ;
45
+ if ( crs == this . #originalCrs) {
46
+ // reset transformation
47
+ this . place . position . set ( 0 , 0 , 0 ) ;
48
+ this . position . set ( 0 , 0 , 0 ) ;
49
+ this . scale . set ( 1 , 1 , 1 ) ;
50
+ this . quaternion . identity ( ) ;
51
+ } else {
52
+ // calculate the scale transformation to transform the feature.extent
53
+ // to feature.extent.as(crs)
54
+ coord . crs = Crs . formatToEPSG ( this . #originalCrs) ;
55
+ extent . copy ( this . extent ) . applyMatrix4 ( this . meshesCollection . matrix ) ;
56
+ extent . as ( coord . crs , extent ) ;
57
+ extent . spatialEuclideanDimensions ( dim_ref ) ;
58
+ extent . planarDimensions ( dim ) ;
59
+ if ( dim . x && dim . y ) {
60
+ this . scale . copy ( dim_ref ) . divide ( dim ) . setZ ( 1 ) ;
61
+ }
62
+
63
+ // Position and orientation
64
+ // remove original position
65
+ this . place . position . copy ( this . meshesCollection . position ) . negate ( ) ;
66
+
67
+ // get mesh coordinate
68
+ coord . setFromVector3 ( this . meshesCollection . position ) ;
69
+
70
+ // get method to calculate orientation
71
+ const crsInput = this . #originalCrs == 'EPSG:3857' ? crsWGS84 : this . #originalCrs;
72
+ const crs2crs = OrientationUtils . quaternionFromCRSToCRS ( crsInput , crs ) ;
73
+ // calculate orientation to crs
74
+ crs2crs ( coord . as ( crsWGS84 ) , this . quaternion ) ;
75
+
76
+ // transform position to crs
77
+ coord . as ( crs , coord ) . toVector3 ( this . position ) ;
78
+ }
79
+ }
80
+
81
+ return this ;
82
+ }
83
+ }
11
84
12
85
function toColor ( color ) {
13
86
if ( color ) {
@@ -507,18 +580,12 @@ export default {
507
580
508
581
if ( ! features || features . length == 0 ) { return ; }
509
582
510
- const group = new THREE . Group ( ) ;
511
583
options . GlobalZTrans = collection . center . z ;
512
584
513
- group . layer = options . layer ;
514
-
515
- features . forEach ( feature => group . add ( featureToMesh ( feature , options ) ) ) ;
516
-
517
- group . quaternion . copy ( collection . quaternion ) ;
518
- group . position . copy ( collection . position ) ;
519
- group . scale . copy ( collection . scale ) ;
585
+ const meshes = features . map ( feature => featureToMesh ( feature , options ) ) ;
586
+ const featureNode = new FeatureMesh ( meshes , collection ) ;
520
587
521
- return group ;
588
+ return featureNode ;
522
589
} ;
523
590
} ,
524
591
} ;
0 commit comments