|
193 | 193 |
|
194 | 194 |
|
195 | 195 | JSROOT.GEO.createSphere = function( shape ) { |
196 | | - |
197 | 196 | var outerRadius = shape.fRmax; |
198 | 197 | var innerRadius = shape.fRmin; |
199 | 198 | var phiStart = shape.fPhi1 + 180; |
200 | 199 | var phiLength = shape.fPhi2 - shape.fPhi1; |
201 | 200 | var thetaStart = shape.fTheta1; |
202 | 201 | var thetaLength = shape.fTheta2 - shape.fTheta1; |
203 | | - |
204 | | - var widthSegments = Math.floor(phiLength / 6); |
205 | | - if (widthSegments < 8) widthSegments = 8; |
206 | | - |
207 | | - var heightSegments = Math.floor(thetaLength / 6); |
208 | | - if (heightSegments < 8) heightSegments = 8; |
| 202 | + var widthSegments = shape.fNseg; |
| 203 | + var heightSegments = shape.fNz; |
209 | 204 |
|
210 | 205 | var sphere = new THREE.SphereGeometry( outerRadius, widthSegments, heightSegments, |
211 | 206 | phiStart*Math.PI/180, phiLength*Math.PI/180, thetaStart*Math.PI/180, thetaLength*Math.PI/180); |
212 | 207 | sphere.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI / 2 ) ); |
213 | 208 |
|
214 | | - // simple sphere without inner cut |
215 | | - if ((innerRadius <= 0) && (thetaLength === 180) && (phiLength === 360)) return sphere; |
216 | | - |
217 | | - if (innerRadius <= 0) innerRadius = 0.0000001; |
218 | | - |
219 | 209 | var geometry = new THREE.Geometry(); |
220 | 210 | var color = new THREE.Color(); |
221 | 211 |
|
222 | | - // add inner sphere |
| 212 | + // add outer sphere |
223 | 213 | for (var n=0; n < sphere.vertices.length; ++n) |
224 | 214 | geometry.vertices.push(sphere.vertices[n]); |
225 | 215 |
|
| 216 | + // add faces |
226 | 217 | for (var n=0; n < sphere.faces.length; ++n) { |
227 | 218 | var face = sphere.faces[n]; |
228 | 219 | geometry.faces.push(new THREE.Face3( face.a, face.b, face.c, null, color, 0 ) ); |
229 | 220 | } |
230 | 221 |
|
231 | 222 | var shift = geometry.vertices.length; |
232 | | - var k = innerRadius / outerRadius; |
| 223 | + var noInside = (innerRadius <= 0); |
233 | 224 |
|
234 | | - // add outer sphere |
235 | | - for (var n=0; n < sphere.vertices.length; ++n) { |
236 | | - var v = sphere.vertices[n]; |
237 | | - geometry.vertices.push(new THREE.Vector3(k*v.x, k*v.y, k*v.z)); |
238 | | - } |
| 225 | + if (noInside) { |
| 226 | + // simple sphere without inner cut |
| 227 | + if ((thetaLength === 180) && (phiLength === 360)) { |
| 228 | + geometry.computeFaceNormals(); |
| 229 | + return geometry; |
| 230 | + } |
239 | 231 |
|
240 | | - for (var n=0; n < sphere.faces.length; ++n) { |
241 | | - var face = sphere.faces[n]; |
242 | | - geometry.faces.push(new THREE.Face3( shift+face.a, shift+face.b, shift+face.c, null, color, 0 ) ); |
| 232 | + geometry.vertices.push(new THREE.Vector3(0, 0, 0)); |
| 233 | + } else { |
| 234 | + var k = innerRadius / outerRadius; |
| 235 | + |
| 236 | + // add inner sphere |
| 237 | + for (var n=0; n < sphere.vertices.length; ++n) { |
| 238 | + var v = sphere.vertices[n]; |
| 239 | + geometry.vertices.push(new THREE.Vector3(k*v.x, k*v.y, k*v.z)); |
| 240 | + } |
| 241 | + for (var n=0; n < sphere.faces.length; ++n) { |
| 242 | + var face = sphere.faces[n]; |
| 243 | + geometry.faces.push(new THREE.Face3( shift+face.a, shift+face.b, shift+face.c, null, color, 0 ) ); |
| 244 | + } |
243 | 245 | } |
244 | 246 |
|
245 | 247 | if (thetaLength !== 180) { |
246 | 248 | // add top cap |
247 | 249 | for (var i = 0; i < widthSegments; ++i) { |
248 | | - geometry.faces.push( new THREE.Face3( i+0, i+1, i+shift, null, color, 0 ) ); |
249 | | - geometry.faces.push( new THREE.Face3( i+1, i+shift+1, i+shift, null, color, 0 ) ); |
| 250 | + if (noInside) { |
| 251 | + geometry.faces.push( new THREE.Face3( i+0, i+1, shift, null, color, 0 ) ); |
| 252 | + } else { |
| 253 | + geometry.faces.push( new THREE.Face3( i+0, i+1, i+shift, null, color, 0 ) ); |
| 254 | + geometry.faces.push( new THREE.Face3( i+1, i+shift+1, i+shift, null, color, 0 ) ); |
| 255 | + } |
250 | 256 | } |
251 | 257 |
|
252 | 258 | var dshift = sphere.vertices.length - widthSegments - 1; |
253 | 259 |
|
254 | 260 | // add bottom cap |
255 | 261 | for (var i = dshift; i < dshift + widthSegments; ++i) { |
256 | | - geometry.faces.push( new THREE.Face3( i+0, i+1, i+shift, null, color, 0 ) ); |
257 | | - geometry.faces.push( new THREE.Face3( i+1, i+shift+1, i+shift, null, color, 0 ) ); |
| 262 | + if (noInside) { |
| 263 | + geometry.faces.push( new THREE.Face3( i+0, i+1, shift, null, color, 0 ) ); |
| 264 | + } else { |
| 265 | + geometry.faces.push( new THREE.Face3( i+0, i+1, i+shift, null, color, 0 ) ); |
| 266 | + geometry.faces.push( new THREE.Face3( i+1, i+shift+1, i+shift, null, color, 0 ) ); |
| 267 | + } |
258 | 268 | } |
259 | 269 | } |
260 | 270 |
|
|
263 | 273 | for (var j=0; j<heightSegments; j++) { |
264 | 274 | var i1 = j*(widthSegments+1); |
265 | 275 | var i2 = (j+1)*(widthSegments+1); |
266 | | - geometry.faces.push( new THREE.Face3( i1, i2, i1+shift, null, color, 0 ) ); |
267 | | - geometry.faces.push( new THREE.Face3( i2, i2+shift, i1+shift, null, color, 0 )); |
| 276 | + if (noInside) { |
| 277 | + geometry.faces.push( new THREE.Face3( i1, i2, shift, null, color, 0 ) ); |
| 278 | + } else { |
| 279 | + geometry.faces.push( new THREE.Face3( i1, i2, i1+shift, null, color, 0 ) ); |
| 280 | + geometry.faces.push( new THREE.Face3( i2, i2+shift, i1+shift, null, color, 0 )); |
| 281 | + } |
268 | 282 | } |
269 | 283 | // another cuted side |
270 | 284 | for (var j=0;j<heightSegments;j++) { |
271 | 285 | var i1 = (j+1)*(widthSegments+1) - 1; |
272 | 286 | var i2 = (j+2)*(widthSegments+1) - 1; |
273 | | - geometry.faces.push( new THREE.Face3( i1, i2, i1+shift, null, color, 0 ) ); |
274 | | - geometry.faces.push( new THREE.Face3( i2, i2+shift, i1+shift, null, color, 0)); |
| 287 | + if (noInside) { |
| 288 | + geometry.faces.push( new THREE.Face3( i1, i2, shift, null, color, 0 ) ); |
| 289 | + } else { |
| 290 | + geometry.faces.push( new THREE.Face3( i1, i2, i1+shift, null, color, 0 ) ); |
| 291 | + geometry.faces.push( new THREE.Face3( i2, i2+shift, i1+shift, null, color, 0)); |
| 292 | + } |
275 | 293 | } |
276 | 294 | } |
277 | 295 |
|
|
0 commit comments