-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExperiment.razor
More file actions
108 lines (89 loc) · 3.33 KB
/
Experiment.razor
File metadata and controls
108 lines (89 loc) · 3.33 KB
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
@using SeeSharp.Experiments
@using SeeSharp
@using SeeSharp.Blazor
@inject IJSRuntime JS
@page "/Experiment"
<h1>Experiment Config</h1>
<SceneSelector @ref=sceneSelector OnSceneLoaded="@OnSceneLoaded"></SceneSelector>
<div style="display: flex; align-items: flex-start; gap: 1.5em;">
<div style="display: flex; flex-direction: column; gap: 1.5em; width: 250px; flex-shrink: 0;">
<IntegratorSelector
@ref="integratorSelector"
scene="@scene"
OnRunIntegrator="OnRunIntegrator"
OnDeleteIntegrator="OnDeleteIntegrator"
OnRunAllIntegrators="OnRunAllIntegrators"/>
</div>
@if (resultsAvailable)
{
<button @onclick="OnDownloadClick">Download results</button>
}
@if (!running)
{
@if (resultsAvailable)
{
<div class="experiment-results">
<FlipViewer Flip="@flip" OnClick="@OnFlipClick"></FlipViewer>
@if (selected.HasValue && selected.Value)
{
<table>
<tr><th>Mesh</th><td>@(selected.Value.Mesh.Name)</td></tr>
<tr><th>Material</th><td>@(selected.Value.Mesh.Material.Name) (roughness: @(selected.Value.Mesh.Material.GetRoughness(selected.Value)), transmissive: @(selected.Value.Mesh.Material.IsTransmissive(selected.Value)))</td></tr>
<tr><th>Distance</th><td>@(selected.Value.Distance)</td></tr>
<tr><th>Position</th><td>@(selected.Value.Position)</td></tr>
</table>
}
</div>
}
}
else
{
<p>Rendering...</p>
}
</div>
@code {
SceneSelector sceneSelector;
Scene scene;
bool running = false;
bool resultsAvailable = false;
SimpleImageIO.FlipBook flip;
IntegratorSelector integratorSelector;
async Task OnSceneLoaded(SceneDirectory sceneDir)
{
await Task.Run(() => scene = sceneDir.SceneLoader.Scene);
flip = null;
resultsAvailable = false;
}
async Task OnRunIntegrator(Integrator integrator)
{
running = true;
resultsAvailable = false;
integratorSelector.Names.TryGetValue(integrator, out string customName);
await Task.Run(() => RunSingleIntegrator(integrator, customName));
running = false;
resultsAvailable = true;
}
void OnDeleteIntegrator(Integrator integrator)
{
if (integrator == null || flip == null) return;
integratorSelector.Names.TryGetValue(integrator, out string customName);
string name = customName ?? IntegratorUtils.FormatClassName(integrator.GetType());
flip.Remove(name);
}
async Task OnRunAllIntegrators()
{
running = true;
resultsAvailable = false;
flip = new FlipBook(660, 580)
.SetZoom(FlipBook.InitialZoom.FillWidth)
.SetToneMapper(FlipBook.InitialTMO.Exposure(scene.RecommendedExposure))
.SetToolVisibility(false);
foreach (var integrator in integratorSelector.addedIntegrators)
{
integratorSelector.Names.TryGetValue(integrator, out string customName);
await Task.Run(() => RunSingleIntegrator(integrator, customName));
}
running = false;
resultsAvailable = true;
}
}