-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnimbus_3D.js
115 lines (91 loc) · 3.68 KB
/
nimbus_3D.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { getColor } from './nimbus_common.js';
//import { TrackballControls } from './TrackballControls.js';
class Nimbus3DRender {
constructor(element) {
this.element = element;
this.renderer = new THREE.WebGLRenderer();
element.appendChild( this.renderer.domElement );
//this.renderer.setSize(element.innerWidth, element.clientHeight);
this.scene = new THREE.Scene();
var numPixels = 352 * 288;
var material = new THREE.PointsMaterial( {
side: THREE.DoubleSide,
size: 1,
color: 0xFFFFFF,
vertexColors: THREE.VertexColors
});
var geometry = new THREE.BufferGeometry();
this.points = new THREE.Points( geometry, material );
this.scene.add( this.points );
this.setupCamera();
var positions = new Int16Array( 101376 * 3 );
var lutColors = new Float32Array( 101376 * 3 );
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
geometry.addAttribute( 'color', new THREE.BufferAttribute( lutColors , 3 ) );
geometry.setDrawRange( 0, numPixels );
}
resize(width, height){
this.camera.aspect = width/height;
this.camera.updateProjectionMatrix();
this.renderer.setSize( width, height);
console.log("resize!", width, height);
}
render3Dscene(x_arr, y_arr, z_arr, dist_arr, conf, distMin, distMax) {
var positions = this.points.geometry.attributes.position.array;
var lutColors = this.points.geometry.attributes.color.array;
var posIndex = 0;
for( var index = 0; index < dist_arr.length; index++ ) {
var colorVal = dist_arr[index];
var color = getColor(colorVal, distMin, distMax);
if(conf[index] == 0 || conf[index] == 4)
{
positions[posIndex++] = x_arr[index];
positions[posIndex++] = y_arr[index];
positions[posIndex++] = z_arr[index];
lutColors[ 3 * index ] = color[0];
lutColors[ 3 * index + 1 ] = color[1];
lutColors[ 3 * index + 2 ] = color[2];
}
else
{
positions[posIndex++] = 0;
positions[posIndex++] = 0;
positions[posIndex++] = -30000;
lutColors[ 3 * index ] = 0;
lutColors[ 3 * index + 1 ] = 0;
lutColors[ 3 * index + 2 ] = 0;
}
}
this.points.geometry.attributes.position.needsUpdate = true;
this.points.geometry.attributes.color.needsUpdate = true;
this.controls.update();
this.renderer.render( this.scene, this.camera );
}
setupCamera() {
this.camera = new THREE.PerspectiveCamera( 100, window.innerWidth/window.innerHeight, 0.1, 100000 );
this.camera.position.x = 0;
this.camera.position.y = 0;
this.camera.position.z = 30000;
//this.camera.up = new THREE.Vector3( 0, 1, 0 );
this.camera.lookAt( new THREE.Vector3( 0, 0, 1 ) );
this.controls = new THREE.TrackballControls(this.camera, this.renderer.domElement);
this.controls.target.set( 0, 0, 0 );
this.controls.update();
}
} /* Nimbus3DRender */
var Nimbus3DRenderSingle = (function () {
var instance;
function createInstance(element) {
var object = new Nimbus3DRender(element);
return object;
}
return {
getInstance: function (element) {
if (!instance) {
instance = createInstance(element);
}
return instance;
}
};
})();
export { Nimbus3DRenderSingle };