@@ -297,21 +297,27 @@ def execute(self, context):
297297
298298
299299class SplashExportNodeTree (Operator ):
300- """Exports the Splash configuration (following the tree starting from this node)"""
300+ """Exports the Splash configuration or project (following the tree starting from this node)"""
301301 bl_idname = "splash.export_node_tree"
302302 bl_label = "Exports the node tree"
303303
304+
304305 filepath = bpy .props .StringProperty (subtype = 'FILE_PATH' )
305306 filter_glob = bpy .props .StringProperty (
306307 default = "*.json" ,
307308 options = {'HIDDEN' },
308309 )
309310
310311 node_name = StringProperty (name = 'Node name' , description = 'Name of the calling node' , default = '' )
312+ export_project = BoolProperty (name = 'export_project' )
313+
311314 world_node = None
312315 scene_order = []
313316 scene_lists = {}
314317 node_links = {}
318+ project_accepted_types = ['SplashImageNodeType' ,
319+ 'SplashMeshNodeType' ,
320+ 'SplashObjectNodeType' ]
315321
316322 def execute (self , context ):
317323 self .scene_order .clear ()
@@ -330,72 +336,91 @@ def execute(self, context):
330336 for scene in connectedScenes :
331337 scene_list = {}
332338 node_links = []
333- self .parseTree (scene , scene_list , node_links )
339+ self .parseTree (scene , scene_list , node_links , self . export_project )
334340
335341 self .scene_order .append (scene .name )
336342 self .scene_lists [scene .name ] = scene_list
337343 self .node_links [scene .name ] = node_links
338344
339- print (self .scene_order )
340- return self .export ()
345+ # Merge scenes info if exporting a project
346+ if self .export_project and len (self .scene_order ) > 0 :
347+ masterSceneName = self .scene_order [0 ]
348+ for sceneId in range (1 , len (self .scene_order )):
349+ sceneName = self .scene_order [sceneId ]
350+
351+ for node in self .scene_lists [sceneName ]:
352+ if node not in self .scene_lists [masterSceneName ]:
353+ self .scene_lists [masterSceneName ][node ] = self .scene_lists [sceneName ][node ]
354+ for link in self .node_links [sceneName ]:
355+ self .node_links [masterSceneName ].append (link )
356+
357+ self .scene_order = [self .scene_order [0 ]]
358+ self .scene_lists = {masterSceneName : self .scene_lists [masterSceneName ]}
359+
360+ return self .export (self .export_project )
341361
342- def parseTree (self , node , scene_list , node_links ):
343- scene_list [node .name ] = node
362+ def parseTree (self , node , scene_list , node_links , export_project = False ):
363+ if not export_project or node .bl_idname in self .project_accepted_types :
364+ scene_list [node .name ] = node
344365
345366 connectedNodes = [socket .links [0 ].from_node for socket in node .inputs if socket .is_linked ]
346367 for connectedNode in connectedNodes :
347368 newLink = [connectedNode .name , node .name ]
348369 if newLink not in node_links :
349370 node_links .append ([connectedNode .name , node .name ])
350- self .parseTree (connectedNode , scene_list , node_links )
371+ self .parseTree (connectedNode , scene_list , node_links , export_project )
351372
352- def export (self ):
373+ def export (self , export_project = False ):
353374 file = open (self .filepath , "w" , encoding = "utf8" , newline = "\n " )
354375 fw = file .write
355376
356- # World informations
357377 worldArgs = self .world_node .exportProperties (self .filepath )
358378 fw ("// Splash configuration file\n "
359379 "// Exported with Blender Splash add-on\n "
360- "{\n "
361- " \" encoding\" : \" UTF-8\" ,\n "
362- " \" description\" : \" splashConfiguration\" ,\n "
363- "\n "
364- " \" world\" : {\n "
365- " \" framerate\" : %i\n "
366- " },\n " % (worldArgs ['framerate' ]))
367-
368- # Scenes list
369- fw (" \" scenes\" : [\n " )
370- sceneIndex = 0
371- for scene in self .scene_order :
372- # Find the Scene nodes
373- for node in self .scene_lists [scene ]:
374- if self .scene_lists [scene ][node ].bl_idname == "SplashSceneNodeType" :
375- args = self .scene_lists [scene ][node ].exportProperties (self .filepath )
376- fw (" {\n " )
377- valueIndex = 0
378- for values in args :
379- fw (" \" %s\" : %s" % (values , args [values ]))
380+ "{\n " )
380381
381- if valueIndex < len (args ) - 1 :
382+ if export_project :
383+ fw (" \" description\" : \" splashProject\" ,\n " )
384+ else :
385+ fw (" \" description\" : \" splashConfiguration\" ,\n " )
386+ # World informations
387+ fw (" \" world\" : {\n "
388+ " \" framerate\" : %i\n "
389+ " },\n " % (worldArgs ['framerate' ]))
390+
391+ # Scenes list
392+ fw (" \" scenes\" : [\n " )
393+ sceneIndex = 0
394+ for scene in self .scene_order :
395+ # Find the Scene nodes
396+ for node in self .scene_lists [scene ]:
397+ if self .scene_lists [scene ][node ].bl_idname == "SplashSceneNodeType" :
398+ args = self .scene_lists [scene ][node ].exportProperties (self .filepath )
399+ fw (" {\n " )
400+ valueIndex = 0
401+ for values in args :
402+ fw (" \" %s\" : %s" % (values , args [values ]))
403+
404+ if valueIndex < len (args ) - 1 :
405+ fw (",\n " )
406+ else :
407+ fw ("\n " )
408+ valueIndex = valueIndex + 1
409+ fw (" }" )
410+
411+ if sceneIndex < len (self .scene_lists ) - 1 :
382412 fw (",\n " )
383413 else :
384414 fw ("\n " )
385- valueIndex = valueIndex + 1
386- fw (" }" )
387-
388- if sceneIndex < len (self .scene_lists ) - 1 :
389- fw (",\n " )
390- else :
391- fw ("\n " )
392- sceneIndex = sceneIndex + 1
393- fw (" ],\n " )
415+ sceneIndex = sceneIndex + 1
416+ fw (" ],\n " )
394417
395418 # Scenes information
396419 sceneIndex = 0
397420 for scene in self .scene_order :
398- fw (" \" %s\" : {\n " % scene )
421+ if not export_project :
422+ fw (" \" %s\" : {\n " % scene )
423+
399424 for node in self .scene_lists [scene ]:
400425 if self .scene_lists [scene ][node ].bl_idname != "SplashSceneNodeType" :
401426 args = self .scene_lists [scene ][node ].exportProperties (self .filepath )
@@ -429,7 +454,8 @@ def export(self):
429454 fw (" }\n " )
430455 sceneIndex = sceneIndex + 1
431456
432- fw ("}" )
457+ if not export_project :
458+ fw ("}" )
433459
434460 return {'FINISHED' }
435461
0 commit comments