Skip to content

Commit 2a6b170

Browse files
committed
Move to fullscreen and integrated UI
1 parent f519f58 commit 2a6b170

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

index.html

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
<body>
1212
<canvas id="renderCanvas"></canvas>
13-
<canvas id="controlCanvas"></canvas>
14-
<button id="addMarkerButton">+</button>
1513
<script type="module" src="/src/main.ts"></script>
1614
</body>
1715

src/colorMap.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,21 @@ export class ColorMap {
3030
// Canvas size is increased in order to encompass the markers
3131
this.positionOffset = 10;
3232
this.canvas = document.querySelector<HTMLCanvasElement>("#" + canvasId)!;
33+
this.canvas = document.createElement("canvas");
34+
this.canvas.setAttribute("id", "colorMap");
3335
this.canvas.setAttribute("width", String(width + this.positionOffset * 2));
3436
this.canvas.setAttribute("height", String(height + this.positionOffset * 2));
37+
this.canvas.style.top = "20px";
38+
this.canvas.style.right = "20px";
39+
this.canvas.style.position = "absolute";
40+
console.log(this.canvas.style);
3541
this.context = this.canvas.getContext("2d") as CanvasRenderingContext2D;
42+
document.body.append(this.canvas);
3643

3744
// Offscreen canvas is used for dynamic texture (full size, no markers)
3845
this.offscreenCanvas = document.createElement("canvas");
39-
this.offscreenCanvas.setAttribute("width", this.canvas.width.toString());
40-
this.offscreenCanvas.setAttribute("height", this.canvas.height.toString());
46+
this.offscreenCanvas.style.width = this.canvas.width.toString();
47+
this.offscreenCanvas.style.height = this.canvas.height.toString();
4148
this.offscreenContext = this.offscreenCanvas.getContext("2d") as CanvasRenderingContext2D;
4249
this.canvas.append(this.offscreenCanvas);
4350

@@ -135,7 +142,6 @@ export class ColorMap {
135142
// Draw gradient to offscreen canvas
136143
this.offscreenContext.fillStyle = this.gradient;
137144
this.offscreenContext.fillRect(0, 0, this.offscreenCanvas.width, this.offscreenCanvas.height);
138-
this.offscreenContext.strokeRect(0, 0, this.offscreenCanvas.width, this.offscreenCanvas.height);
139145

140146
// Copy it to visible canvas
141147
this.context.drawImage(this.offscreenCanvas, this.positionOffset, this.positionOffset, this.width, this.height);

src/main.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
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";
22
import "@babylonjs/inspector";
33
import { ColorMap } from "./colorMap";
44
import './shadersStore';
55
import './style.css';
66
import { VolumeRawSceneLoader } from "./volumeRawSceneLoader";
77

8+
/**
9+
* Entry point of the main application.
10+
*/
811
class App {
912

1013
private engine: Engine;
1114
private scene: Scene;
1215
private camera: ArcRotateCamera;
1316

17+
/**
18+
* Create the whole rendering pipeline.
19+
*/
1420
constructor() {
1521
let canvas: HTMLCanvasElement = document.querySelector<HTMLCanvasElement>('#renderCanvas')!;
1622

1723
this.engine = new Engine(canvas, true);
1824
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);
2026

2127
SceneLoader.RegisterPlugin(new VolumeRawSceneLoader());
2228

2329
this.camera = new ArcRotateCamera("camera", Math.PI / 2, Math.PI / 2, -2, new Vector3(0.5, 0.5, 0), this.scene);
2430
this.camera.attachControl(canvas, true);
2531
this.camera.wheelPrecision = 120;
32+
this.camera.minZ = 0.1;
2633

2734
const light: HemisphericLight = new HemisphericLight("light", new Vector3(0, 1, 0), this.scene);
2835
light.intensity = 0.7;
2936
}
3037

38+
/**
39+
* Create a simple box without any custom attributes.
40+
*/
3141
private createSimpleBox(): Mesh {
3242
const box: Mesh = new Mesh("box", this.scene);
3343

@@ -55,6 +65,11 @@ class App {
5565
return box;
5666
}
5767

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+
*/
5873
private createMaterial(volumeTexture: RawTexture3D, colorMapTexture: DynamicTexture): ShaderMaterial {
5974
const material: ShaderMaterial = new ShaderMaterial("volume", this.scene, { vertex: "volume", fragment: "volume", },
6075
{
@@ -69,6 +84,9 @@ class App {
6984
return material;
7085
}
7186

87+
/**
88+
* Load the asset then create the full scene.
89+
*/
7290
public start() {
7391
const bonsaiFilename: string = "bonsai_256x256x256_uint8.raw";
7492
SceneLoader.LoadAssetContainer("./", bonsaiFilename, this.scene, (container) => {
@@ -92,7 +110,6 @@ class App {
92110

93111
const material: ShaderMaterial = this.createMaterial(volumeTexture, colorMapTexture);
94112

95-
new AxesViewer(this.scene, 1.0);
96113
const box = this.createSimpleBox();
97114
box.material = material;
98115

src/style.css

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
html,
2+
body,
13
#renderCanvas {
2-
margin-top: 60px;
4+
margin: 0;
5+
padding: 0;
36
width: 100%;
4-
height: 600px;
7+
height: 100%;
8+
font-size: 0;
59
}
6-
7-
8-
canvas { border: 1px solid black; }
9-

src/volumeRawSceneLoader.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ISceneLoaderPlugin, Scene, AbstractMesh, IParticleSystem, Skeleton, RawTexture3D, Engine, Texture, AssetContainer, ISceneLoaderPluginExtensions } from "@babylonjs/core";
22

3+
/**
4+
* Scene loader for volume raw data.
5+
*/
36
export class VolumeRawSceneLoader implements ISceneLoaderPlugin {
47

58
public name = "Volume .raw scene loader";
@@ -20,6 +23,9 @@ export class VolumeRawSceneLoader implements ISceneLoaderPlugin {
2023
return container;
2124
}
2225

26+
/**
27+
* Create a 3D texture from the loaded volume data.
28+
*/
2329
private createTexture3D(scene: Scene, data: ArrayBuffer): RawTexture3D {
2430
const volumeDimensions: number[] = [256, 256, 256];
2531

0 commit comments

Comments
 (0)