Skip to content

Commit 83b1186

Browse files
authored
User new APIs to get preview URL for display. (#13)
1 parent 99fb5ca commit 83b1186

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

flask/gpuopen/MaterialXGPUOpenApp.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def handle_download_materialx(self, data):
9797
# Initialize the loader and fetch materials
9898
self.loader = gpuo.GPUOpenMaterialLoader()
9999
self.materials = self.loader.getMaterials()
100+
self.loader.getRenders()
100101
self.material_names = self.loader.getMaterialNames()
101102

102103
# Convert materials to JSON and get the count
@@ -159,10 +160,12 @@ def handle_extract_material(self, data):
159160
self._emit_status_message(f'- Image file {file_name}')
160161
image = item["data"]
161162
image_base64 = self.loader.convertPilImageToBase64(image)
162-
return_data[file_name] = image_base64
163+
return_data[file_name] = image_base64
163164

164165
if len(return_data) > 0:
165-
return_list.append({'title': title, 'data': return_data})
166+
url = self.loader.getMaterialPreviewURL(title)
167+
self._emit_status_message(f'Preview URL: {url}')
168+
return_list.append({'title': title, 'data': return_data, 'url': url})
166169

167170
if len(return_list) == 0:
168171
self._emit_status_message('No materials extracted')

flask/gpuopen/static/js/MaterialXGPUOpenClient.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
9292
const title = extractedData.title;
9393
console.log('Title:', title);
9494

95+
const preview_url = extractedData.url;
96+
console.log('URL:', preview_url);
97+
9598
const dataObj = extractedData.data;
9699
const imageDOM = document.getElementById('extracted_images');
97100
imageDOM.innerHTML = ''; // Clear existing images
@@ -103,6 +106,7 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
103106
// Optionally save zip of data to file.
104107
let save_extracted = document.getElementById('save_extracted').checked;
105108
let zip = save_extracted ? new JSZip() : null;
109+
106110
for (const key in dataObj) {
107111
if (key.endsWith('.mtlx')) {
108112
this.extractedEditor.setValue(dataObj[key]);
@@ -157,6 +161,26 @@ export class MaterialX_GPUOpen_Client extends WebSocketClient
157161
}
158162
}
159163

164+
if (preview_url) {
165+
// Create a container for the image and label
166+
const imageContainer = document.createElement('div');
167+
imageContainer.style.display = 'inline-block';
168+
imageContainer.style.margin = '10px';
169+
imageContainer.style.textAlign = 'center'; // Center the label under the image
170+
171+
// Create the image element
172+
const img = document.createElement('img');
173+
img.src = preview_url;
174+
img.width = 200;
175+
img.alt = "";
176+
177+
// Add the key as a tooltip
178+
img.title = "Preview render";
179+
180+
imageContainer.appendChild(img);
181+
imageDOM.appendChild(imageContainer);
182+
}
183+
160184
// Create the zip file asynchronously
161185
if (zip)
162186
{

0 commit comments

Comments
 (0)