@@ -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