-
Notifications
You must be signed in to change notification settings - Fork 0
/
param-viewer.html
253 lines (234 loc) · 9.58 KB
/
param-viewer.html
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<title>Parameters of the Enterprise PBR Shading Model</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<div class="row">
<h1 class="mt-5">Enterprise PBR Shading Model</h1>
<h2 class="mt-1">Parameters</h2>
</div>
<div class="row">
<div class="col">
<p>
This page lists all parameters of the Enterprise PBR Shading Model and its subtypes.
</p>
<p>
Each parameter is of a certain type, and has a default, minimum and maximum value. We recommend
that a UI displays the parameters in the order given in the following table, grouped
by the string in the "Group" property.
</p>
<p>
Subtypes provide defaults for certain classes of materials, like metal, textile, or glass.
Subtypes significantly reduce the amount of parameters presented to the user. The "Hidden"
property of a parameter indicates that a parameter must not be visible in the UI.
</p>
<p class="needs-data d-none">
The data on this page is generated from <a id="dataLink" href=""></a>. The file format is
described in the
<a href="spec-2022x.md.html#appendix/parameterjsonfileformat">
appendix to the Enterprise PBR 2022x specification
</a>.
</p>
</div>
</div>
<div class="row needs-data d-none">
<div class="col col-form-label">
<label for="materialList">Subtype</label>
</div>
<div class="col-10">
<select id="materialList" onchange="materialSelectionChanged(event);" class="form-select" >
<template id="materialItem">
<option></option>
</template>
</select>
</div>
</div>
</div>
<div class="col-3 align-self-end">
<img id="previewImage" alt="Preview Image" width="200px" class="img-fluid float-end needs-data d-none" />
</div>
</div>
<div class="row needs-data d-none">
<table class="table table-sm table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Minimum</th>
<th>Maximum</th>
<th>Hidden</th>
<th>Group</th>
</tr>
</thead>
<tbody id="paramTableBody">
<template id="param">
<tr>
<td class="uiOrder fade-if-hidden"></td>
<td class="name fade-if-hidden"></td>
<td class="type fade-if-hidden"></td>
<td class="default fade-if-hidden"></td>
<td class="min empty-if-hidden fade-if-hidden"></td>
<td class="max empty-if-hidden fade-if-hidden"></td>
<td class="hidden fade-if-hidden"></td>
<td class="group empty-if-hidden fade-if-hidden"></td>
</tr>
</template>
</tbody>
</table>
</div>
<div class="row fetch-instructions">
<div id="dropZone" class="border border-3 rounded text-center p-5 mt-5" style="border-style: dashed !important; cursor: hand;" onclick="openFile(event);" ondrop="dropHandler(event);" ondragover="dragOverHandler(event);">
<p class="lead">Drop JSON file here or click to load.</p>
<p>Due to security restrictions in the browser we cannot automatically load files from local disk.</p>
<p>Please drag&drop <span class="font-monospace">params-<version>.json</span> to open the file.</p>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js" integrity="sha256-qXBd/EfAdjOA2FGrGAG+b3YBn2tn5A6bhz+LSgYD96k=" crossorigin="anonymous"></script>
<script type="text/javascript">
function create(templateId) {
const c = document.getElementById(templateId).content
return c.cloneNode(true).children[0]
};
function setElement(element, className, value) {
element.getElementsByClassName(className)[0].innerText = value
}
function mergeMaterials(materialId) {
let cur = materialId
let inheritedMaterials = []
do {
inheritedMaterials.push(data.materials[cur])
cur = data.materials[cur].inherits || ''
} while (cur != '')
return inheritedMaterials.reduceRight(_.merge, {})
}
function get(value, def) {
if (value === undefined) {
return def;
} else if (Array.isArray(value)) {
return value.join(', ')
} else {
return value;
}
};
function formatMinMaxDefault(p) {
if (p.type == 'color') {
return [
get(p.min, '0, 0, 0'),
get(p.max, '+inf, +inf, +inf'),
get(p.default, '')]
} else if (p.type == 'float') {
return [
p.min === undefined ? '-inf' : p.min,
p.max === undefined ? '+inf' : p.max,
typeof p.default === 'object' && p.default.infinity === true ? '+inf' : (get(p.default, ''))]
} else if (p.type == 'vector') {
return [
get(p.min, '-inf, -inf, -inf'),
get(p.max, '+inf, +inf, +inf'),
get(p.default, '0, 0, 0')]
}
return [ get(p.min, ''), get(p.max, ''), get(p.default, '')]
}
function formatType(p) {
if (p.uniform) {
return 'uniform ' + (p.type || '');
} else {
return (p.type || '');
}
}
function updateParamTable(materialId) {
const table = document.getElementById('paramTableBody')
table.querySelectorAll('tr').forEach(el => el.remove())
const material = mergeMaterials(materialId);
const parameters = Object.entries(material.parameters).sort((a, b) => {
return a[1].uiOrder - b[1].uiOrder
})
for (const param of parameters) {
let row = create('param')
setElement(row, 'uiOrder', get(param[1].uiOrder, -1))
setElement(row, 'name', param[1].name || '')
setElement(row, 'type', formatType(param[1]))
const [min, max, def] = formatMinMaxDefault(param[1])
setElement(row, 'default', def)
const hidden = param[1].hidden || false
setElement(row, 'min', min)
setElement(row, 'max', max)
setElement(row, 'hidden', hidden)
setElement(row, 'group', param[1].group || '')
if (hidden) {
row.querySelectorAll('.fade-if-hidden').forEach(el => el.classList.add('text-muted'));
row.querySelectorAll('.empty-if-hidden').forEach(el => el.style = 'color: rgb(0, 0, 0, 0) !important;');
}
table.insertBefore(row, null)
}
document.getElementById('previewImage').src = material.preview
}
function materialSelectionChanged(event) {
updateParamTable(event.target.value)
window.location.hash = '#' + event.target.value
}
function dataReceived(d) {
data = d
document.querySelectorAll('.fetch-instructions').forEach(el => el.classList.add('d-none'))
document.querySelectorAll('.needs-data').forEach(el => el.classList.remove('d-none'))
let materialList = document.getElementById('materialList')
for (const id in data.materials) {
let option = create('materialItem')
option.text = data.materials[id].name
option.value = id
materialList.insertBefore(option, null)
}
materialList.value = (window.location.hash || 'generic').replace('#', '')
updateParamTable(materialList.value)
}
async function loadFile(file) {
const text = await file.text()
dataReceived(JSON.parse(text))
document.getElementById('dataLink').innerText = file.name
document.getElementById('dataLink').href = file.name
}
function openFile(event) {
let input = document.createElement('input');
input.type = 'file';
input.onchange = _ => {
let files = Array.from(input.files);
loadFile(files[0])
};
input.click();
}
async function dropHandler(event) {
event.preventDefault()
if (event.dataTransfer.items.length < 1) {
return
}
if (event.dataTransfer.items[0].kind !== 'file') {
return
}
loadFile(event.dataTransfer.items[0].getAsFile())
}
function dragOverHandler(event) {
event.preventDefault()
}
let data = null
const defaultFilename = 'params-2022x.json'
fetch(defaultFilename)
.then(response => response.json())
.then(data => {
dataReceived(data)
document.getElementById('dataLink').innerText = defaultFilename
document.getElementById('dataLink').href = defaultFilename
})
.catch(err => console.log(err))
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
</body>
</html>