@@ -23,19 +23,14 @@ import { CSS2DRenderer, CSS2DObject } from 'three/addons/renderers/CSS2DRenderer
23
23
24
24
export function showGraph3D ( tag , graph , width , height , show_labels ) {
25
25
const scene = new THREE . Scene ( ) ;
26
- const aspect = height / width ;
27
- const scale = 20 ;
28
- const camera = new THREE . OrthographicCamera ( - scale , scale , scale * aspect , - scale * aspect ) ;
29
26
const renderer = new THREE . WebGLRenderer ( { antialias : true } ) ;
30
27
const labelRenderer = new CSS2DRenderer ( ) ;
31
28
const light = new THREE . DirectionalLight ( 0xffffff , 2 ) ;
32
29
33
30
scene . background = new THREE . Color ( 0xffffff ) ;
34
- camera . layers . enableAll ( ) ;
35
31
scene . add ( new THREE . AmbientLight ( 0xffffff , 1.5 ) ) ;
36
32
light . position . set ( 1 , 1 , 1 ) . normalize ( ) ;
37
33
scene . add ( light ) ;
38
- camera . position . z = 10 ;
39
34
renderer . setSize ( width , height ) ;
40
35
labelRenderer . setSize ( width , height ) ;
41
36
labelRenderer . domElement . style . position = 'absolute' ;
@@ -61,35 +56,29 @@ export function showGraph3D(tag, graph, width, height, show_labels) {
61
56
rightButton . innerHTML = '🡆' ;
62
57
buttons . appendChild ( rightButton ) ;
63
58
64
- const controls = new OrbitControls ( camera , labelRenderer . domElement ) ;
65
- const raycaster = new THREE . Raycaster ( ) ;
66
- const mouse = new THREE . Vector2 ( ) ;
67
- let highlightRow = - 1 ;
68
- controls . minDistance = 1 ;
69
- controls . maxDistance = 100 ;
70
-
71
-
72
59
var ntab = { } ;
73
60
74
61
const rows = new Set ( ) ;
75
- let minY = null , maxY = null , minZ = null , maxZ = null ;
62
+ let minX = null , maxX = null , minY = null , maxY = null , minZ = null , maxZ = null ;
76
63
77
64
graph . nodes . forEach ( function ( d ) {
78
65
ntab [ d . name ] = d ;
79
66
d . nhd = [ ] ;
80
67
rows . add ( d . x ) ;
68
+ minX = ( minX == null ) ? d . x : Math . min ( d . x , minX ) ;
81
69
minY = ( minY == null ) ? d . y : Math . min ( d . y , minY ) ;
82
70
minZ = ( minZ == null ) ? d . z : Math . min ( d . z , minZ ) ;
71
+ maxX = ( maxX == null ) ? d . x : Math . max ( d . x , maxX ) ;
83
72
maxY = ( maxY == null ) ? d . y : Math . max ( d . y , maxY ) ;
84
73
maxZ = ( maxZ == null ) ? d . z : Math . max ( d . z , maxZ ) ;
85
74
86
- let color = 0x000000 , radius = 0.1 ;
75
+ let color = 0x000000 , radius = 0.05 ;
87
76
if ( d . t == 1 ) {
88
77
color = Number ( '0x' + '#99dd99' . substring ( 1 ) ) ;
89
- radius = 0.15 ;
78
+ radius = 0.1 ;
90
79
} else if ( d . t == 2 ) {
91
80
color = Number ( '0x' + '#ff8888' . substring ( 1 ) ) ;
92
- radius = 0.15 ;
81
+ radius = 0.1 ;
93
82
}
94
83
95
84
const geometry = new THREE . SphereGeometry ( radius , 48 , 24 ) ;
@@ -98,7 +87,7 @@ export function showGraph3D(tag, graph, width, height, show_labels) {
98
87
d . sphere . name = d . name ;
99
88
d . sphere . position . set ( d . x , d . y , d . z ) ;
100
89
d . sphere . layers . enableAll ( ) ;
101
- d . sphere . renderOrder = 0.0 ;
90
+ d . sphere . renderOrder = 0.5 ;
102
91
scene . add ( d . sphere ) ;
103
92
104
93
if ( d . phase != '' ) {
@@ -139,7 +128,7 @@ export function showGraph3D(tag, graph, width, height, show_labels) {
139
128
new THREE . Vector3 ( t . x , t . y , t . z )
140
129
] ) ;
141
130
d . line = new Line2 ( geometry , material ) ;
142
- d . line . renderOrder = 0.5 ;
131
+ d . line . renderOrder = 0.6 ;
143
132
scene . add ( d . line ) ;
144
133
} ) ;
145
134
@@ -152,24 +141,43 @@ export function showGraph3D(tag, graph, width, height, show_labels) {
152
141
highlightPlane . renderOrder = 1.0 ;
153
142
scene . add ( highlightPlane ) ;
154
143
144
+ const aspect = height / width ;
145
+ let scale = 20 ;
146
+ if ( minX != null ) {
147
+ scale = Math . max ( ( maxX - minX ) / 2 , ( maxY - minY ) / ( 2 * aspect ) ) + 2 ;
148
+ }
149
+ const camera = new THREE . OrthographicCamera ( - scale , scale , scale * aspect , - scale * aspect ) ;
150
+ camera . layers . enableAll ( ) ;
151
+ camera . position . z = 5 ;
152
+ if ( minX != null ) {
153
+ camera . position . z = 2 * Math . max ( maxX , maxY , maxZ ) ;
154
+ }
155
+
156
+ const controls = new OrbitControls ( camera , labelRenderer . domElement ) ;
157
+ const raycaster = new THREE . Raycaster ( ) ;
158
+ const mouse = new THREE . Vector2 ( ) ;
159
+ let highlightRow = - 1 ;
160
+ controls . minDistance = 1 ;
161
+ controls . maxDistance = 100 ;
162
+
163
+
164
+
155
165
function checkIntersection ( ) {
156
166
raycaster . setFromCamera ( mouse , camera ) ;
157
167
const intersects = raycaster . intersectObject ( scene , true ) ;
158
- if ( intersects . length > 0 ) {
159
- const selectedObject = intersects [ 0 ] . object ;
168
+ highlightRow = - 1 ;
169
+ for ( let obj of intersects ) {
170
+ const selectedObject = obj . object ;
160
171
if ( Object . hasOwn ( selectedObject , 'name' ) && selectedObject . name != '' ) {
161
172
const d = ntab [ selectedObject . name ] ;
162
173
highlightRow = rowList . indexOf ( d . x ) ;
163
- } else {
164
- highlightRow = - 1 ;
174
+ break ;
165
175
}
166
- } else {
167
- highlightRow = - 1 ;
168
176
}
169
-
170
177
update ( ) ;
171
178
}
172
179
180
+
173
181
function update ( ) {
174
182
if ( highlightRow == - 1 ) {
175
183
highlightPlane . material . opacity = 0.0 ;
@@ -181,8 +189,10 @@ export function showGraph3D(tag, graph, width, height, show_labels) {
181
189
graph . nodes . forEach ( function ( d ) {
182
190
if ( highlightRow == - 1 || rowList [ highlightRow ] == d . x ) {
183
191
d . sphere . material . opacity = 1.0 ;
192
+ d . sphere . renderOrder = 0.5 ;
184
193
} else {
185
194
d . sphere . material . opacity = 0.4 ;
195
+ d . sphere . renderOrder = 0.7 ;
186
196
}
187
197
} ) ;
188
198
@@ -193,8 +203,10 @@ export function showGraph3D(tag, graph, width, height, show_labels) {
193
203
} else {
194
204
d . line . material . opacity = 1.0 ;
195
205
}
206
+ d . line . renderOrder = 0.6 ;
196
207
} else {
197
208
d . line . material . opacity = 0.25 ;
209
+ d . line . renderOrder = 0.8 ;
198
210
}
199
211
} ) ;
200
212
}
0 commit comments