Advertisement
PlanetKiller

RecExBuild

Mar 8th, 2016
1,470
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.53 KB | None
  1. extends Object
  2. # for Godot
  3. # March-7-2016
  4. # PlanetKiller exporter script
  5. # computer-aided game creation enrichment
  6. # Place on a node, set the apropriate function, run scene
  7. # should automate most of the more obnoxious tasks
  8.  
  9. # ver 1.0
  10. # checks for existing resources
  11. # minor opimizations planned
  12.  
  13. # member variables here, example:
  14. # var a=2
  15. # var b="textvar"
  16.  
  17. func save_meshes(folder, ext): # needs top-level parent node
  18.     var mesh
  19.     var path
  20.     for i in get_children():
  21.         if i.is_type("MeshInstance"):
  22.             mesh = i.get_mesh()
  23.             path = "res://"+folder+"/"+i.get_name()+"."+ext
  24.             if(!check_file(path)):
  25.                 print(mesh.get_path())
  26.                 ResourceSaver.save(path, mesh)
  27.                 #print(ResourceSaver.save(path, mesh, 1))
  28.            
  29. func get_dir(Folder):
  30.     var newDir = Directory.new()
  31.     var openDir = newDir.open("res://"+Folder+"/")
  32.     var dirStart = newDir.list_dir_begin()
  33.     return newDir
  34.     pass
  35.    
  36. func check_file(fileDir):
  37.     var d2 = Directory.new()
  38.     return d2.file_exists(fileDir)
  39.     pass
  40.  
  41.  
  42. # should have mesh node with a default material
  43. func fixedmat_gen(TexFolder, outFolder, imgExt, exportExt):
  44.    
  45.     var newDir = get_dir(TexFolder)
  46.     var file = newDir.get_next()
  47.     while(file!=""):
  48.         var fileExt = file.extension()
  49.         var fileName = file.split( ".")[0]
  50.         var matOver = self.get_material_override()
  51.         var fullPath = "res://"+TexFolder+"/"+file
  52.         var exPath = "res://"+outFolder+"/"+fileName+"."+exportExt
  53.         if(fileExt == imgExt):
  54.             if(!check_file(exPath)):
  55.                 print(file)
  56.                 matOver.set_texture(0,ResourceLoader.load(fullPath))
  57.                 matOver.set_path(exPath)
  58.                 ResourceSaver.save(exPath, matOver)
  59.         file = newDir.get_next()
  60.     pass
  61.    
  62.  
  63. func scene_exporter(sceneTop, meshFile, fileName, outputFolder, exportExt):
  64.     #var exPath = "res://"+outputFolder+"/"+file
  65.     var packed_scene = PackedScene.new()
  66.     #var fileName = meshFile.split( ".")[0]
  67.     print(fileName)
  68.     var exPath = "res://"+outputFolder+"/"+fileName+"."+exportExt
  69.     print(exPath)
  70.    
  71.     for i in sceneTop.get_children():
  72.         i.set_owner(sceneTop)
  73.         if i.is_type("MeshInstance"):
  74.             #var name = i.get_mesh().get_name()
  75.             #print(i.get_mesh().get_name())
  76.             sceneTop.set_name(fileName+"Body")
  77.             i.set_name(fileName)
  78.             i.set_mesh(ResourceLoader.load(meshFile))
  79.         elif i.is_type("CollisionShape"):
  80.             i.set_name(fileName+"CS")
  81.        
  82.     var newChild = self.get_child(0)
  83.     print(self.get_child(0))
  84.     print(sceneTop)
  85.     if(!check_file(exPath)):
  86.         packed_scene.pack(sceneTop)
  87.         packed_scene.set_path(exPath)
  88.         ResourceSaver.save(exPath, packed_scene)
  89.     pass
  90.    
  91. # put on top-level node, exports first child and children
  92. func scene_save(meshFolder, outputFolder, exportExt):
  93.    
  94.     var newDir = get_dir(meshFolder)
  95.     var file = newDir.get_next()
  96.     var sceneTop = get_tree().get_current_scene().get_child(0)
  97.     while(file!=""):
  98.         var fullPath = "res://"+meshFolder+"/"+file
  99.         var fileName = file.split( ".")[0]
  100.         scene_exporter(sceneTop, fullPath, fileName, outputFolder,exportExt)
  101.         file = newDir.get_next()
  102.     pass
  103.    
  104. # put on an animation player node
  105. func save_anims(folder, ext):
  106.     #anm
  107.     var path
  108.     var animList = self.get_animation_list()
  109.     for i in animList:
  110.         var anim = self.get_animation(i)
  111.         #print(i)
  112.         #print(anim)
  113.         path = "res://"+folder+"/"+i+"."+ext
  114.         if(!check_file(path)):
  115.             ResourceSaver.save(path, anim)
  116.             print(i)
  117.             print(anim)
  118.    
  119.     pass
  120.  
  121.  
  122.  
  123. func _ready():
  124.     #save_meshes("Mesh", "msh")
  125.     #fixedmat_gen("Textures", "Mats", "png", "mtl")
  126.     #scene_save("Mesh", "test", "scn")
  127.     #save_anims("Anims", "anm")
  128.     # Called every time the node is added to the scene.
  129.     # Initialization here
  130.     pass
Advertisement
RAW Paste Data Copied
Advertisement