@@ -112,7 +112,7 @@ useExtensionService().registerExtension({
112112 LOAD_3D ( node ) {
113113 const fileInput = document . createElement ( 'input' )
114114 fileInput . type = 'file'
115- fileInput . accept = '.gltf,.glb,.obj,.mtl,. fbx,.stl'
115+ fileInput . accept = '.gltf,.glb,.obj,.fbx,.stl'
116116 fileInput . style . display = 'none'
117117
118118 fileInput . onchange = async ( ) => {
@@ -195,9 +195,7 @@ useExtensionService().registerExtension({
195195
196196 await nextTick ( )
197197
198- const load3d = useLoad3dService ( ) . getLoad3d ( node )
199-
200- if ( load3d ) {
198+ useLoad3dService ( ) . waitForLoad3d ( node , ( load3d ) => {
201199 let cameraState = node . properties [ 'Camera Info' ]
202200
203201 const config = new Load3DConfiguration ( load3d )
@@ -256,7 +254,7 @@ useExtensionService().registerExtension({
256254 return returnVal
257255 }
258256 }
259- }
257+ } )
260258 }
261259} )
262260
@@ -346,67 +344,65 @@ useExtensionService().registerExtension({
346344
347345 await nextTick ( )
348346
349- const sceneWidget = node . widgets ?. find ( ( w ) => w . name === 'image' )
347+ useLoad3dService ( ) . waitForLoad3d ( node , ( load3d ) => {
348+ const sceneWidget = node . widgets ?. find ( ( w ) => w . name === 'image' )
349+ const modelWidget = node . widgets ?. find ( ( w ) => w . name === 'model_file' )
350+ let cameraState = node . properties [ 'Camera Info' ]
351+ const width = node . widgets ?. find ( ( w ) => w . name === 'width' )
352+ const height = node . widgets ?. find ( ( w ) => w . name === 'height' )
350353
351- const load3d = useLoad3dService ( ) . getLoad3d ( node ) as Load3dAnimation
354+ if ( modelWidget && width && height && sceneWidget && load3d ) {
355+ const config = new Load3DConfiguration ( load3d )
352356
353- const modelWidget = node . widgets ?. find ( ( w ) => w . name === 'model_file' )
357+ config . configure ( 'input' , modelWidget , cameraState , width , height )
354358
355- let cameraState = node . properties [ 'Camera Info' ]
359+ sceneWidget . serializeValue = async ( ) => {
360+ node . properties [ 'Camera Info' ] = load3d . getCameraState ( )
356361
357- const width = node . widgets ?. find ( ( w ) => w . name === 'width' )
358- const height = node . widgets ?. find ( ( w ) => w . name === 'height' )
362+ const load3dAnimation = load3d as Load3dAnimation
363+ load3dAnimation . toggleAnimation ( false )
359364
360- if ( modelWidget && width && height && sceneWidget && load3d ) {
361- const config = new Load3DConfiguration ( load3d )
365+ if ( load3dAnimation . isRecording ( ) ) {
366+ load3dAnimation . stopRecording ( )
367+ }
362368
363- config . configure ( 'input' , modelWidget , cameraState , width , height )
369+ const {
370+ scene : imageData ,
371+ mask : maskData ,
372+ normal : normalData
373+ } = await load3dAnimation . captureScene (
374+ width . value as number ,
375+ height . value as number
376+ )
364377
365- sceneWidget . serializeValue = async ( ) => {
366- node . properties [ 'Camera Info' ] = load3d . getCameraState ( )
378+ const [ data , dataMask , dataNormal ] = await Promise . all ( [
379+ Load3dUtils . uploadTempImage ( imageData , 'scene' ) ,
380+ Load3dUtils . uploadTempImage ( maskData , 'scene_mask' ) ,
381+ Load3dUtils . uploadTempImage ( normalData , 'scene_normal' )
382+ ] )
367383
368- load3d . toggleAnimation ( false )
384+ load3dAnimation . handleResize ( )
369385
370- if ( load3d . isRecording ( ) ) {
371- load3d . stopRecording ( )
372- }
386+ const returnVal = {
387+ image : `threed/${ data . name } [temp]` ,
388+ mask : `threed/${ dataMask . name } [temp]` ,
389+ normal : `threed/${ dataNormal . name } [temp]` ,
390+ camera_info : node . properties [ 'Camera Info' ] ,
391+ recording : ''
392+ }
373393
374- const {
375- scene : imageData ,
376- mask : maskData ,
377- normal : normalData
378- } = await load3d . captureScene (
379- width . value as number ,
380- height . value as number
381- )
382-
383- const [ data , dataMask , dataNormal ] = await Promise . all ( [
384- Load3dUtils . uploadTempImage ( imageData , 'scene' ) ,
385- Load3dUtils . uploadTempImage ( maskData , 'scene_mask' ) ,
386- Load3dUtils . uploadTempImage ( normalData , 'scene_normal' )
387- ] )
388-
389- load3d . handleResize ( )
390-
391- const returnVal = {
392- image : `threed/${ data . name } [temp]` ,
393- mask : `threed/${ dataMask . name } [temp]` ,
394- normal : `threed/${ dataNormal . name } [temp]` ,
395- camera_info : node . properties [ 'Camera Info' ] ,
396- recording : ''
397- }
394+ const recordingData = load3dAnimation . getRecordingData ( )
395+ if ( recordingData ) {
396+ const [ recording ] = await Promise . all ( [
397+ Load3dUtils . uploadTempImage ( recordingData , 'recording' , 'mp4' )
398+ ] )
399+ returnVal [ 'recording' ] = `threed/${ recording . name } [temp]`
400+ }
398401
399- const recordingData = load3d . getRecordingData ( )
400- if ( recordingData ) {
401- const [ recording ] = await Promise . all ( [
402- Load3dUtils . uploadTempImage ( recordingData , 'recording' , 'mp4' )
403- ] )
404- returnVal [ 'recording' ] = `threed/${ recording . name } [temp]`
402+ return returnVal
405403 }
406-
407- return returnVal
408404 }
409- }
405+ } )
410406 }
411407} )
412408
@@ -467,19 +463,19 @@ useExtensionService().registerExtension({
467463 useToastStore ( ) . addAlert ( msg )
468464 }
469465
470- const load3d = useLoad3dService ( ) . getLoad3d ( node )
471-
472466 let cameraState = message . result [ 1 ]
473467
474- const modelWidget = node . widgets ?. find ( ( w ) => w . name === 'model_file' )
468+ useLoad3dService ( ) . waitForLoad3d ( node , ( load3d ) => {
469+ const modelWidget = node . widgets ?. find ( ( w ) => w . name === 'model_file' )
475470
476- if ( load3d && modelWidget ) {
477- modelWidget . value = filePath . replaceAll ( '\\' , '/' )
471+ if ( modelWidget ) {
472+ modelWidget . value = filePath . replaceAll ( '\\' , '/' )
478473
479- const config = new Load3DConfiguration ( load3d )
474+ const config = new Load3DConfiguration ( load3d )
480475
481- config . configure ( 'output' , modelWidget , cameraState )
482- }
476+ config . configure ( 'output' , modelWidget , cameraState )
477+ }
478+ } )
483479 }
484480 }
485481} )
@@ -543,16 +539,16 @@ useExtensionService().registerExtension({
543539
544540 let cameraState = message . result [ 1 ]
545541
546- const load3d = useLoad3dService ( ) . getLoad3d ( node )
547-
548- const modelWidget = node . widgets ?. find ( ( w ) => w . name === 'model_file' )
549- if ( load3d && modelWidget ) {
550- modelWidget . value = filePath . replaceAll ( '\\' , '/' )
542+ useLoad3dService ( ) . waitForLoad3d ( node , ( load3d ) => {
543+ const modelWidget = node . widgets ?. find ( ( w ) => w . name === 'model_file' )
544+ if ( modelWidget ) {
545+ modelWidget . value = filePath . replaceAll ( '\\' , '/' )
551546
552- const config = new Load3DConfiguration ( load3d )
547+ const config = new Load3DConfiguration ( load3d )
553548
554- config . configure ( 'output' , modelWidget , cameraState )
555- }
549+ config . configure ( 'output' , modelWidget , cameraState )
550+ }
551+ } )
556552 }
557553 }
558554} )
0 commit comments