1
- import { ArcRotateCamera , AxesViewer , DynamicTexture , Engine , HemisphericLight , Mesh , MeshBuilder , RawTexture3D , Scene , SceneLoader , ShaderMaterial , StandardMaterial , Vector2 , Vector3 , VertexData } from "@babylonjs/core" ;
1
+ import { ArcRotateCamera , Color4 , DynamicTexture , Engine , HemisphericLight , Mesh , RawTexture3D , Scene , SceneLoader , ShaderMaterial , Vector3 , VertexData } from "@babylonjs/core" ;
2
2
import "@babylonjs/inspector" ;
3
3
import { ColorMap } from "./colorMap" ;
4
4
import './shadersStore' ;
5
5
import './style.css' ;
6
6
import { VolumeRawSceneLoader } from "./volumeRawSceneLoader" ;
7
7
8
+ /**
9
+ * Entry point of the main application.
10
+ */
8
11
class App {
9
12
10
13
private engine : Engine ;
11
14
private scene : Scene ;
12
15
private camera : ArcRotateCamera ;
13
16
17
+ /**
18
+ * Create the whole rendering pipeline.
19
+ */
14
20
constructor ( ) {
15
21
let canvas : HTMLCanvasElement = document . querySelector < HTMLCanvasElement > ( '#renderCanvas' ) ! ;
16
22
17
23
this . engine = new Engine ( canvas , true ) ;
18
24
this . scene = new Scene ( this . engine ) ;
19
- this . scene . debugLayer . show ( ) ;
25
+ this . scene . clearColor = new Color4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
20
26
21
27
SceneLoader . RegisterPlugin ( new VolumeRawSceneLoader ( ) ) ;
22
28
23
29
this . camera = new ArcRotateCamera ( "camera" , Math . PI / 2 , Math . PI / 2 , - 2 , new Vector3 ( 0.5 , 0.5 , 0 ) , this . scene ) ;
24
30
this . camera . attachControl ( canvas , true ) ;
25
31
this . camera . wheelPrecision = 120 ;
32
+ this . camera . minZ = 0.1 ;
26
33
27
34
const light : HemisphericLight = new HemisphericLight ( "light" , new Vector3 ( 0 , 1 , 0 ) , this . scene ) ;
28
35
light . intensity = 0.7 ;
29
36
}
30
37
38
+ /**
39
+ * Create a simple box without any custom attributes.
40
+ */
31
41
private createSimpleBox ( ) : Mesh {
32
42
const box : Mesh = new Mesh ( "box" , this . scene ) ;
33
43
@@ -55,6 +65,11 @@ class App {
55
65
return box ;
56
66
}
57
67
68
+ /**
69
+ * Create the material for the volume rendering.
70
+ * @param volumeTexture texture to gather volume data
71
+ * @param colorMapTexture texture for transfert function
72
+ */
58
73
private createMaterial ( volumeTexture : RawTexture3D , colorMapTexture : DynamicTexture ) : ShaderMaterial {
59
74
const material : ShaderMaterial = new ShaderMaterial ( "volume" , this . scene , { vertex : "volume" , fragment : "volume" , } ,
60
75
{
@@ -69,6 +84,9 @@ class App {
69
84
return material ;
70
85
}
71
86
87
+ /**
88
+ * Load the asset then create the full scene.
89
+ */
72
90
public start ( ) {
73
91
const bonsaiFilename : string = "bonsai_256x256x256_uint8.raw" ;
74
92
SceneLoader . LoadAssetContainer ( "./" , bonsaiFilename , this . scene , ( container ) => {
@@ -92,7 +110,6 @@ class App {
92
110
93
111
const material : ShaderMaterial = this . createMaterial ( volumeTexture , colorMapTexture ) ;
94
112
95
- new AxesViewer ( this . scene , 1.0 ) ;
96
113
const box = this . createSimpleBox ( ) ;
97
114
box . material = material ;
98
115
0 commit comments