83 let references =
loader.getReferenceList();
86 if (filteredTags && filteredTags.length > 0) {
87 const lowerTags = filteredTags.map(tag => tag.toLowerCase());
88 references = references.filter(ref => {
89 const name = (ref.name ||
'').toLowerCase();
90 const tagsArr = (ref.tags && Array.isArray(ref.tags)) ? ref.tags.map(t => t.toLowerCase()) : [];
92 return lowerTags.some(tag => name.includes(tag) || tagsArr.some(t => t.includes(tag)));
97 display_references = []
100 if (!references.find(ref => ref.name === selName)) {
102 const fullRef =
loader.getReferenceList().find(ref => ref.name === selName);
104 display_references.push(fullRef);
108 for (let i = 0; i < references.length; i++) {
109 display_references.push(references[i]);
112 display_references.sort((a, b) => a.name.localeCompare(b.name));
114 if (display_references.length > 0) {
115 const referencesContainer = document.getElementById(
'PBReferencesImages');
116 referencesContainer.innerHTML =
'';
118 display_references.forEach(ref => {
119 const col = document.createElement(
'div');
120 col.className =
'rounded col-sm mx-auto ml-4 mb-2';
123 if (ref.tags && Array.isArray(ref.tags)) {
124 col.setAttribute(
'data-tags', ref.tags.join(
','));
126 col.setAttribute(
'data-tags',
'');
130 col.style.background =
'#0072B2';
132 col.style.background =
'';
134 col.addEventListener(
'click', (event) => {
136 let isMultiSelect =
event.shiftKey;
141 const name = document.createElement(
'p');
142 name.textContent = ref.name ||
'Reference Image';
143 name.style.marginBottom =
'2px';
144 col.appendChild(name);
147 const img = document.createElement(
'img');
148 img.src = ref.reference;
150 img.style.width =
'100%';
151 img.style.minWidth =
'128px';
152 img.style.display =
'block';
153 img.style.marginBottom =
'10px';
156 col.appendChild(img);
159 if (ref.tags && Array.isArray(ref.tags) && ref.tags.length > 0) {
160 const tagLine = document.createElement(
'div');
161 tagLine.style.marginBottom =
'0px';
162 ref.tags.forEach(tag => {
163 const pill = document.createElement(
'div');
164 pill.className =
'badge bg-white text-dark mt-1 me-1 mb-1';
165 pill.textContent = tag;
166 tagLine.appendChild(pill);
168 col.appendChild(tagLine);
172 referencesContainer.appendChild(col);
179 let shadingModel =
'standard_surface';
180 const shadingModelOption = document.getElementById(
'shadingModelButton').textContent;
181 if (shadingModelOption) {
182 if (shadingModelOption) {
183 shadingModel = shadingModelOption.toLowerCase().replace(/ /g,
'_');
184 console.log(
'>>>>>>>>>>>>>>>>>>> Selected shading model:', shadingModel);
188 console.log(
'> Generate for shading Model:', shadingModel);
190 let addAllInputs =
false;
192 let shaderPrefix =
'';
194 if (
loader.convertToMaterialX(shadingModel, references, addAllInputs,
195 materialNames, remapKeys, shaderPrefix)) {
197 let [validateDocument, errors] =
loader.validateDocument();
198 console.log(
'> MaterialX validation:', validateDocument, errors);
199 let docString =
loader.getMaterialXString();
200 if (docString.length > 0) {
232 const jsonTextArea = document.getElementById(
'jsonMaterials');
233 let cmeditor2 =
null;
235 cmeditor2 = CodeMirror.fromTextArea(jsonTextArea, {
236 mode:
'application/json',
243 const initialjson =
'';
244 jsonTextArea.value = initialjson;
245 cmeditor2.setValue(initialjson);
248 cmeditor2.on(
'change', (e) => {
249 jsonTextArea.value = cmeditor2.getValue();
257 const jsonTextArea3 = document.getElementById(
'jsonRemapping');
258 let cmeditor3 =
null;
260 cmeditor3 = CodeMirror.fromTextArea(jsonTextArea3, {
261 mode:
'application/json',
266 viewportMargin: Infinity
270 const initialjson3 =
'';
271 jsonTextArea3.value = initialjson3;
272 cmeditor3.setValue(initialjson3);
275 cmeditor3.on(
'change', (e) => {
276 jsonTextArea3.value = cmeditor3.getValue();
284 document.body.setAttribute(
'data-bs-theme',
'dark');
287 document.getElementById(
'materialFilter').addEventListener(
'input',
function (e) {
288 const filterValue = e.target.value.trim();
290 if (filterValue.length > 0) {
292 tags = filterValue.split(/[, ]+/).filter(Boolean);
298 document.getElementById(
'shadingModelOption').addEventListener(
'click', async (e) => {
302 document.getElementById(
'clearSelection').addEventListener(
'click', async () => {
306 document.getElementById(
'fetchData').addEventListener(
'click', async () => {
311 document.getElementById(
'genMaterialX').addEventListener(
'click', async () => {
315 let = viewer = document.getElementById(
"viewer");
316 let targetURL =
"https://kwokcb.github.io/MaterialXLab/javascript/shader_utilities/dist/index.html?viewerOnly=1";
317 viewer.src = targetURL;
319 let modalDialog =
null;
323 viewerButton = document.getElementById(
'openViewer');
324 viewerButton.removeAttribute(
'data-bs-toggle');
325 viewerButton.removeAttribute(
'data-bs-target');
327 function showModal() {
329 alert(
'No shaders to display.');
335 var modalEl = document.getElementById(
'viewPopup');
336 if (window.bootstrap && modalEl) {
338 modalDialog = window.bootstrap.Modal.getOrCreateInstance(modalEl);
342 viewer.style.display =
'block';
346 viewerButton.addEventListener(
'click', async (e) => {