Skip to content

Commit 78ee55f

Browse files
committed
Fix details area for GPU open flask.
1 parent e36120b commit 78ee55f

3 files changed

Lines changed: 139 additions & 131 deletions

File tree

flask/gpuopen/MaterialXGPUOpenApp.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,20 @@ def handle_download_materialx(self, data):
129129

130130
# Convert materials to JSON and add preview URLs
131131
materials_list = []
132+
merged_results = { "results": [] }
132133
for mat_json in self.loader.getMaterialsAsJsonString():
133134
mat_obj = json.loads(mat_json)
134135
# Add preview URL for each result
135-
for result in mat_obj.get('results', []):
136+
results = mat_obj.get('results', [])
137+
for result in results:
136138
title = result.get('title')
137139
result['url'] = self.loader.getMaterialPreviewURL(title)
138-
materials_list.append(json.dumps(mat_obj))
140+
merged_results["results"].append(result)
141+
139142
# Sort list by title
143+
merged_results["results"].sort(key=lambda x: x.get('title', ''))
144+
materials_list.append(json.dumps(merged_results, indent=2))
145+
140146
self.material_count = len(self.material_names)
141147

142148
# Emit a status message
@@ -156,8 +162,11 @@ def handle_extract_material(self, data):
156162
@param data The data received from the client, expected to contain:
157163
{ 'expression': string, 'update_materialx': bool }
158164
'''
165+
return_list = []
166+
159167
if self.loader is None:
160168
self._emit_status_message('Loader is not initialized. Download materials first.')
169+
emit('materialx_extracted', {'extractedData': return_list}, broadcast=True)
161170
return
162171

163172
self._emit_status_message('Extracting materials...')
@@ -166,7 +175,6 @@ def handle_extract_material(self, data):
166175
if not have_mx:
167176
update_mtlx = False
168177
data_items = self.loader.downloadPackageByExpression(expression)
169-
return_list = []
170178

171179
for data_item in data_items:
172180
status_message = f'Extracting material: {data_item[1]}'
@@ -206,6 +214,7 @@ def handle_extract_material(self, data):
206214

207215
if len(return_list) == 0:
208216
self._emit_status_message('No materials extracted')
217+
emit('materialx_extracted', {'extractedData': return_list}, broadcast=True)
209218
else:
210219
status_message = f'Extracted {len(return_list)} materials'
211220
self._emit_status_message(status_message)

flask/gpuopen/static/js/MaterialXGPUOpenClient.js

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
3232
for (const result of resultsArray) {
3333
if (result.title === name) {
3434
foundMaterial = result;
35-
//console.log('>>>>>>>>>> Found Material:', result.title);
35+
console.log('>>>>>>>>>> Popultate form:', result.title);
3636
this.populateForm(result);
3737
return foundMaterial;
3838
}
@@ -79,6 +79,7 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
7979
card.classList.remove('selected');
8080
}
8181
}
82+
this.findMaterialByName(name);
8283
}
8384

8485
handleMaterialXDownLoad(data)
@@ -121,6 +122,7 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
121122
// Render preview images in gallery using preview URL from backend
122123
const gallery = document.getElementById('material_gallery');
123124
gallery.innerHTML = '';
125+
let firstTitle = '';
124126
for (const element of this.materialsList) {
125127
let materials = JSON.parse(element).results;
126128
if (materials) {
@@ -129,6 +131,9 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
129131
for (const material of materials)
130132
{
131133
if (material.url) {
134+
if (!firstTitle)
135+
firstTitle = material.title;
136+
132137
const col = document.createElement('div');
133138
col.className = 'col-sm-4 col-md-3 col-lg-2 mb-4';
134139

@@ -151,6 +156,11 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
151156
}
152157
}
153158
}
159+
160+
if (firstTitle) {
161+
this.highlightSelectedMaterialInGallery(firstTitle);
162+
this.selectMaterialByName(firstTitle);
163+
}
154164
}
155165
}
156166

@@ -163,6 +173,10 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
163173

164174
console.log('WEB: materialx extracted event:', data.extractedData);
165175
const extractedData = data.extractedData[0];
176+
if (!extractedData) {
177+
console.log('No extracted data received');
178+
return;
179+
}
166180
const title = extractedData.title;
167181
console.log('Title:', title);
168182

@@ -181,6 +195,30 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
181195
let save_extracted = document.getElementById('save_extracted').checked;
182196
let zip = save_extracted ? new JSZip() : null;
183197

198+
199+
if (preview_url) {
200+
const imageContainer = document.createElement('div');
201+
imageContainer.className = 'col-sm-4 col-md-3 col-lg-2 mb-4';
202+
let key = "Preview Render";
203+
imageContainer.innerHTML = `
204+
<div class="card material-card" data-material-id="${key}">
205+
<img loading="lazy" src="${preview_url}" id="${key} Image" class="card-img-top material-img" alt="${key}">
206+
<div class="card-body">
207+
<div style="font-size: 10px;" class="card-title">${key}</div>
208+
</div>
209+
</div>
210+
`;
211+
212+
// Add "url.txt" file to zip where "url" is the preview URL, for reference
213+
if (zip)
214+
{
215+
const urlFile = new File([preview_url], "url.txt", { type: 'text/plain' });
216+
zip.file("url.txt", urlFile);
217+
}
218+
219+
imageDOM.appendChild(imageContainer);
220+
}
221+
184222
for (const key in dataObj) {
185223
if (key.endsWith('.mtlx')) {
186224
this.extractedEditor.setValue(dataObj[key]);
@@ -200,29 +238,15 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
200238

201239
// Create a container for the image and label
202240
const imageContainer = document.createElement('div');
203-
imageContainer.classList.add('col-sm');
204-
//imageContainer.style.display = 'inline-block';
205-
//imageContainer.style.margin = '10px';
206-
//imageContainer.style.textAlign = 'center'; // Center the label under the image
207-
208-
// Create the image element
209-
const img = document.createElement('img');
210-
img.src = url;
211-
img.style.width = "256px";
212-
img.alt = key;
213-
214-
// Add the key as a tooltip
215-
img.title = key;
216-
217-
// Create a label for the image
218-
const label = document.createElement('div');
219-
label.innerText = key;
220-
label.style.fontSize = '0.8rem';
221-
//label.style.color = '#FFF'; //
222-
223-
// Append the image and label to the container
224-
imageContainer.appendChild(img);
225-
imageContainer.appendChild(label);
241+
imageContainer.className = 'col-sm-4 col-md-3 col-lg-2 mb-4';
242+
imageContainer.innerHTML = `
243+
<div class="card material-card" data-material-id="${key}">
244+
<img src="${url}" id="${key} Image" class="card-img-top material-img" alt="${key}">
245+
<div class="card-body">
246+
<div style="font-size: 10px;" class="card-title">${key}</div>
247+
</div>
248+
</div>
249+
`;
226250

227251
// Append the container to the image DOM
228252
imageDOM.appendChild(imageContainer);
@@ -236,32 +260,6 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
236260
}
237261
}
238262

239-
if (preview_url) {
240-
// Create a container for the image and label
241-
const imageContainer = document.createElement('div');
242-
imageContainer.classList.add('col-sm');
243-
//imageContainer.style.margin = '10px';
244-
//imageContainer.style.textAlign = 'center'; // Center the label under the image
245-
246-
// Create the image element
247-
const img = document.createElement('img');
248-
img.src = preview_url;
249-
img.style.width = "256px";
250-
img.alt = "";
251-
252-
// Add the key as a tooltip
253-
img.title = "Preview render";
254-
255-
// Add "url.txt" file to zip where "url" is the preview URL, for reference
256-
if (zip)
257-
{
258-
const urlFile = new File([preview_url], "url.txt", { type: 'text/plain' });
259-
zip.file("url.txt", urlFile);
260-
}
261-
262-
imageContainer.appendChild(img);
263-
imageDOM.appendChild(imageContainer);
264-
}
265263

266264
// Create the zip file asynchronously
267265
if (zip)

0 commit comments

Comments
 (0)