Whitespace fix

This commit is contained in:
Nobody Really 2016-07-09 11:33:08 +02:00
parent ea108bed79
commit 7de55b86c1
3 changed files with 1623 additions and 1714 deletions

View file

@ -36,6 +36,7 @@ import os
from bpy.app.handlers import persistent
from mathutils import Vector, Matrix
class godot_export_manager(bpy.types.Panel):
bl_label = "Godot Export Manager"
bl_space_type = 'PROPERTIES'
@ -62,13 +63,10 @@ class godot_export_manager(bpy.types.Panel):
op = col.operator("scene.godot_delete_objects_from_group",text="Delete selected objects from Group",icon="PASTEDOWN")
row = layout.row()
col = row.column()
col.label(text="Export Groups:")
row = layout.row()
col = row.column()
@ -114,6 +112,7 @@ class godot_export_manager(bpy.types.Panel):
col.prop(group,"anim_optimize_precision")
col.prop(group,"use_metadata")
### Custom template_list look
class UI_List_Godot(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
@ -150,7 +149,6 @@ class add_objects_to_group(bpy.types.Operator):
else:
objects_str += ", "+object.name
self.report({'INFO'}, objects_str + " added to group." )
if self.undo:
bpy.ops.ed.undo_push(message="Objects added to group")
@ -178,14 +176,12 @@ class del_objects_from_group(bpy.types.Operator):
if node.name in selected_objects:
scene.godot_export_groups[scene.godot_export_groups_index].nodes.remove(i)
if j == 0:
objects_str += object.name
else:
objects_str += ", "+object.name
j+=1
self.report({'INFO'}, objects_str + " deleted from group." )
bpy.ops.ed.undo_push(message="Objects deleted from group")
else:
@ -209,6 +205,7 @@ class select_group_objects(bpy.types.Operator):
context.scene.objects.active = bpy.data.objects[node.name]
return{'FINISHED'}
class export_groups_autosave(bpy.types.Operator):
bl_idname = "scene.godot_export_groups_autosave"
bl_label = "Export All Groups"
@ -224,6 +221,7 @@ class export_groups_autosave(bpy.types.Operator):
bpy.ops.ed.undo_push(message="Export all Groups")
return{'FINISHED'}
class export_all_groups(bpy.types.Operator):
bl_idname = "scene.godot_export_all_groups"
bl_label = "Export All Groups"
@ -247,7 +245,6 @@ class export_group(bpy.types.Operator):
idx = IntProperty(default=0)
export_all = BoolProperty(default=False)
def copy_object_recursive(self,ob,parent,single_user = True):
new_ob = bpy.data.objects[ob.name].copy()
if single_user or ob.type=="ARMATURE":
@ -310,7 +307,6 @@ class export_group(bpy.types.Operator):
context.scene.layers = [True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True]
if group[self.idx].export_name.endswith(".dae"):
path = os.path.join(path,group[self.idx].export_name)
else:
@ -363,6 +359,7 @@ class export_group(bpy.types.Operator):
self.report({'INFO'}, "Define Export Name and Export Path." )
return{'FINISHED'}
class add_export_group(bpy.types.Operator):
bl_idname = "scene.godot_add_export_group"
bl_label = "Adds a new export Group"
@ -380,6 +377,7 @@ class add_export_group(bpy.types.Operator):
bpy.ops.ed.undo_push(message="Create New Export Group")
return{'FINISHED'}
class del_export_group(bpy.types.Operator):
bl_idname = "scene.godot_delete_export_group"
bl_label = "Delets the selected export Group"
@ -398,9 +396,11 @@ class del_export_group(bpy.types.Operator):
bpy.ops.ed.undo_push(message="Delete Export Group")
return{'FINISHED'}
class godot_node_list(bpy.types.PropertyGroup):
name = StringProperty()
class godot_export_groups(bpy.types.PropertyGroup):
name = StringProperty(name="Group Name")
export_name = StringProperty(name="scene_name")
@ -431,6 +431,7 @@ class godot_export_groups(bpy.types.PropertyGroup):
use_metadata = BoolProperty(name="Use Metadata",default=True,options={'HIDDEN'})
use_include_particle_duplicates = BoolProperty(name="Include Particle Duplicates",default=True)
def register():
bpy.utils.register_class(godot_export_manager)
bpy.utils.register_class(godot_node_list)
@ -448,6 +449,7 @@ def register():
bpy.types.Scene.godot_export_groups = CollectionProperty(type=godot_export_groups)
bpy.types.Scene.godot_export_groups_index = IntProperty(default=0,min=0)
def unregister():
bpy.utils.unregister_class(godot_export_manager)
bpy.utils.unregister_class(godot_node_list)
@ -462,6 +464,7 @@ def unregister():
bpy.utils.unregister_class(select_group_objects)
bpy.utils.unregister_class(UI_List_Godot)
@persistent
def auto_export(dummy):
bpy.ops.scene.godot_export_groups_autosave()

View file

@ -59,7 +59,6 @@ class ExportDAE(bpy.types.Operator, ExportHelper):
# List of operator properties, the attributes will be assigned
# to the class instance from the operator settings before calling.
object_types = EnumProperty(
name="Object Types",
options={'ENUM_FLAG'},
@ -93,7 +92,6 @@ class ExportDAE(bpy.types.Operator, ExportHelper):
description="Export Triangles instead of Polygons.",
default=False,
)
use_copy_images = BoolProperty(
name="Copy Images",
description="Copy Images (create images/ subfolder)",

View file

@ -87,6 +87,7 @@ def numarr(a,mult=1.0):
s+=" "
return s
def numarr_alpha(a,mult=1.0):
s=" "
for x in a:
@ -96,6 +97,7 @@ def numarr_alpha(a,mult=1.0):
s+=" "
return s
def strarr(arr):
s=" "
for x in arr:
@ -103,6 +105,7 @@ def strarr(arr):
s+=" "
return s
class DaeExporter:
def validate_id(self,d):
@ -110,7 +113,6 @@ class DaeExporter:
return "z"+d
return d
def new_id(self,t):
self.last_id+=1
return "id-"+t+"-"+str(self.last_id)
@ -157,7 +159,6 @@ class DaeExporter:
self.bones=[]
self.weights=[]
def writel(self,section,indent,text):
if (not (section in self.sections)):
self.sections[section]=[]
@ -167,7 +168,6 @@ class DaeExporter:
line+=text
self.sections[section].append(line)
def export_image(self,image):
if (image in self.image_cache):
return self.image_cache[image]
@ -178,7 +178,6 @@ class DaeExporter:
imgpath = bpy.path.abspath(imgpath)
#path is absolute, now do something!
if (self.config["use_copy_images"]):
#copy image
basedir = os.path.dirname(self.path)+"/images"
@ -215,7 +214,6 @@ class DaeExporter:
except:
pass #fails sometimes, not sure why
imgid = self.new_id("image")
print("FOR: "+imgpath)
@ -234,7 +232,6 @@ class DaeExporter:
return imgid
def export_material(self,material,double_sided_hint=True):
if (material in self.material_cache):
return self.material_cache[material]
@ -365,7 +362,6 @@ class DaeExporter:
# Also export blender material in all it's glory (if set as active)
# Material
matid = self.new_id("material")
self.writel(S_MATS,1,'<material id="'+matid+'" name="'+material.name+'">')
@ -375,12 +371,9 @@ class DaeExporter:
self.material_cache[material]=matid
return matid
def export_mesh(self,node,armature=None,skeyindex=-1,skel_source=None,custom_name=None):
mesh = node.data
if (node.data in self.mesh_cache):
return self.mesh_cache[mesh]
@ -428,7 +421,6 @@ class DaeExporter:
node.show_only_shape_key=False
node.active_shape_key_index = 0
self.writel(S_MORPH,1,'<controller id="'+mid+'" name="">')
#if ("skin_id" in morph_targets[0]):
# self.writel(S_MORPH,2,'<morph source="#'+morph_targets[0]["skin_id"]+'" method="NORMALIZED">')
@ -491,8 +483,6 @@ class DaeExporter:
meshdata["morph_id"]=mid
meshdata["material_assign"]=morph_targets[0]["material_assign"]
self.mesh_cache[node.data]=meshdata
return meshdata
@ -513,7 +503,6 @@ class DaeExporter:
bm.to_mesh(mesh)
bm.free()
mesh.update(calc_tessface=True)
vertices=[]
vertex_map={}
@ -547,7 +536,6 @@ class DaeExporter:
mesh.calc_normals_split()
has_tangents=False
for fi in range(len(mesh.polygons)):
f=mesh.polygons[fi]
@ -605,7 +593,6 @@ class DaeExporter:
v.tangent = Vector( ml.tangent )
v.bitangent = Vector( ml.bitangent )
# if (armature):
# v.vertex = node.matrix_world * v.vertex
@ -636,9 +623,6 @@ class DaeExporter:
v.bones.append(0)
v.weights.append(1)
tup = v.get_tup()
idx = 0
if (skeyindex==-1 and tup in vertex_map): #do not optmize if using shapekeys
@ -654,13 +638,11 @@ class DaeExporter:
#only triangles and above
indices.append(vi)
meshid = self.new_id("mesh")
self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+name_to_use+'">')
self.writel(S_GEOM,2,'<mesh>')
# Vertex Array
self.writel(S_GEOM,3,'<source id="'+meshid+'-positions">')
float_values=""
@ -721,10 +703,7 @@ class DaeExporter:
self.writel(S_GEOM,4,'</technique_common>')
self.writel(S_GEOM,3,'</source>')
# UV Arrays
for uvi in range(uv_layer_count):
self.writel(S_GEOM,3,'<source id="'+meshid+'-texcoord-'+str(uvi)+'">')
@ -773,7 +752,6 @@ class DaeExporter:
else:
prim_type="polygons"
for m in surface_indices:
indices = surface_indices[m]
mat = materials[m]
@ -785,7 +763,6 @@ class DaeExporter:
else:
self.writel(S_GEOM,3,'<'+prim_type+' count="'+str(int(len(indices)))+'">') # todo material
self.writel(S_GEOM,4,'<input semantic="VERTEX" source="#'+meshid+'-vertices" offset="0"/>')
self.writel(S_GEOM,4,'<input semantic="NORMAL" source="#'+meshid+'-normals" offset="0"/>')
@ -815,20 +792,16 @@ class DaeExporter:
self.writel(S_GEOM,3,'</'+prim_type+'>')
self.writel(S_GEOM,2,'</mesh>')
self.writel(S_GEOM,1,'</geometry>')
meshdata={}
meshdata["id"]=meshid
meshdata["material_assign"]=mat_assign
if (skeyindex==-1):
self.mesh_cache[node.data]=meshdata
# Export armature data (if armature exists)
if (armature!=None and (skel_source!=None or skeyindex==-1)):
contid = self.new_id("controller")
@ -883,7 +856,6 @@ class DaeExporter:
self.writel(S_SKIN,4,'</technique_common>')
self.writel(S_SKIN,3,'</source>')
self.writel(S_SKIN,3,'<joints>')
self.writel(S_SKIN,4,'<input semantic="JOINT" source="#'+contid+'-joints"/>')
self.writel(S_SKIN,4,'<input semantic="INV_BIND_MATRIX" source="#'+contid+'-bind_poses"/>')
@ -904,19 +876,16 @@ class DaeExporter:
self.writel(S_SKIN,4,'<v>'+vs+'</v>')
self.writel(S_SKIN,3,'</vertex_weights>')
self.writel(S_SKIN,2,'</skin>')
self.writel(S_SKIN,1,'</controller>')
meshdata["skin_id"]=contid
return meshdata
def export_mesh_node(self,node,il):
if (node.data==None):
return
armature=None
armcount=0
for n in node.modifiers:
@ -931,11 +900,9 @@ class DaeExporter:
if (armcount==0):
self.operator.report({'WARNING'},'Object "'+node.name+'" is child of an armature, but has no armature modifier.')
if (armcount>0 and not armature):
self.operator.report({'WARNING'},'Object "'+node.name+'" has armature modifier, but is not a child of an armature. This is unsupported.')
if (node.data.shape_keys!=None):
sk = node.data.shape_keys
if (sk.animation_data):
@ -949,7 +916,6 @@ class DaeExporter:
#print("LINKING "+str(node)+" WITH "+str(t.id.name))
self.armature_for_morph[node]=self.scene.objects[t.id.name]
meshdata = self.export_mesh(node,armature)
close_controller=False
@ -964,7 +930,6 @@ class DaeExporter:
elif (armature==None):
self.writel(S_NODES,il,'<instance_geometry url="#'+meshdata["id"]+'">')
if (len(meshdata["material_assign"])>0):
self.writel(S_NODES,il+1,'<bind_material>')
@ -980,7 +945,6 @@ class DaeExporter:
else:
self.writel(S_NODES,il,'</instance_geometry>')
def export_armature_bone(self,bone,il,si):
boneid = self.new_id("bone")
boneidx = si["bone_count"]
@ -1011,9 +975,7 @@ class DaeExporter:
il-=1
self.writel(S_NODES,il,'</node>')
def export_armature_node(self,node,il):
if (node.data==None):
return
@ -1022,8 +984,6 @@ class DaeExporter:
armature = node.data
self.skeleton_info[node]={ "bone_count":0, "id":self.new_id("skelbones"),"name":node.name, "bone_index":{},"bone_ids":{},"bone_names":[],"bone_bind_poses":[],"skeleton_nodes":[],"armature_xform":node.matrix_world }
for b in armature.bones:
if (b.parent!=None):
continue
@ -1035,9 +995,7 @@ class DaeExporter:
if (x.type=='ACTION'):
self.action_constraints.append(x.action)
def export_camera_node(self,node,il):
if (node.data==None):
return
@ -1065,11 +1023,9 @@ class DaeExporter:
self.writel(S_CAMS,2,'</optics>')
self.writel(S_CAMS,1,'</camera>')
self.writel(S_NODES,il,'<instance_camera url="#'+camid+'"/>')
def export_lamp_node(self,node,il):
if (node.data==None):
return
@ -1096,31 +1052,25 @@ class DaeExporter:
self.writel(S_LAMPS,5,'<falloff_angle>'+str(math.degrees(light.spot_size/2))+'</falloff_angle>')
self.writel(S_LAMPS,4,'</spot>')
else: #write a sun lamp for everything else (not supported)
self.writel(S_LAMPS,4,'<directional>')
self.writel(S_LAMPS,5,'<color>'+strarr(light.color)+'</color>')
self.writel(S_LAMPS,4,'</directional>')
self.writel(S_LAMPS,3,'</technique_common>')
#self.writel(S_LAMPS,2,'</optics>')
self.writel(S_LAMPS,1,'</light>')
self.writel(S_NODES,il,'<instance_light url="#'+lightid+'"/>')
def export_empty_node(self,node,il):
self.writel(S_NODES,4,'<extra>')
self.writel(S_NODES,5,'<technique profile="GODOT">')
self.writel(S_NODES,6,'<empty_draw_type>'+node.empty_draw_type+'</empty_draw_type>')
self.writel(S_NODES,5,'</technique>')
self.writel(S_NODES,4,'</extra>')
def export_curve(self,curve):
splineid = self.new_id("spline")
self.writel(S_GEOM,1,'<geometry id="'+splineid+'" name="'+curve.name+'">')
@ -1140,7 +1090,6 @@ class DaeExporter:
points.append(s.co[1])
points.append(s.co[2])
handles_in.append(s.handle_left[0])
handles_in.append(s.handle_left[1])
handles_in.append(s.handle_left[2])
@ -1149,7 +1098,6 @@ class DaeExporter:
handles_out.append(s.handle_right[1])
handles_out.append(s.handle_right[2])
tilts.append(s.tilt)
interps.append("BEZIER")
else:
@ -1167,9 +1115,6 @@ class DaeExporter:
tilts.append(s.tilt)
interps.append("LINEAR")
self.writel(S_GEOM,3,'<source id="'+splineid+'-positions">')
position_values=""
for x in points:
@ -1220,7 +1165,6 @@ class DaeExporter:
self.writel(S_GEOM,4,'</accessor>')
self.writel(S_GEOM,3,'</source>')
self.writel(S_GEOM,3,'<source id="'+splineid+'-tilts">')
tilt_values=""
for x in tilts:
@ -1240,26 +1184,24 @@ class DaeExporter:
self.writel(S_GEOM,4,'<input semantic="TILT" source="#'+splineid+'-tilts"/>')
self.writel(S_GEOM,3,'</control_vertices>')
self.writel(S_GEOM,2,'</spline>')
self.writel(S_GEOM,1,'</geometry>')
return splineid
def export_curve_node(self,node,il):
if (node.data==None):
return
curveid = self.export_curve(node.data)
self.writel(S_NODES,il,'<instance_geometry url="#'+curveid+'">')
self.writel(S_NODES,il,'</instance_geometry>')
def export_node(self,node,il):
if (not node in self.valid_nodes):
return
prev_node = bpy.context.scene.objects.active
bpy.context.scene.objects.active = node
@ -1291,6 +1233,7 @@ class DaeExporter:
def is_node_valid(self,node):
if (not node.type in self.config["object_types"]):
return False
if (self.config["use_active_layers"]):
valid=False
# print("NAME: "+node.name)
@ -1306,10 +1249,7 @@ class DaeExporter:
return True
def export_scene(self):
self.writel(S_NODES,0,'<library_visual_scenes>')
self.writel(S_NODES,1,'<visual_scene id="'+self.scene_name+'" name="scene">')
@ -1324,8 +1264,6 @@ class DaeExporter:
self.valid_nodes.append(n)
n=n.parent
for obj in self.scene.objects:
if (obj in self.valid_nodes and obj.parent==None):
self.export_node(obj,2)
@ -1334,8 +1272,6 @@ class DaeExporter:
self.writel(S_NODES,0,'</library_visual_scenes>')
def export_asset(self):
self.writel(S_ASSET,0,'<asset>')
# Why is this time stuff mandatory?, no one could care less...
self.writel(S_ASSET,1,'<contributor>')
@ -1348,9 +1284,7 @@ class DaeExporter:
self.writel(S_ASSET,1,'<up_axis>Z_UP</up_axis>')
self.writel(S_ASSET,0,'</asset>')
def export_animation_transform_channel(self,target,keys,matrices=True):
frame_total=len(keys)
anim_id=self.new_id("anim")
self.writel(S_ANIM,1,'<animation id="'+anim_id+'">')
@ -1367,7 +1301,6 @@ class DaeExporter:
source_interps +=" LINEAR"
# Time Source
self.writel(S_ANIM,2,'<source id="'+anim_id+'-input">')
self.writel(S_ANIM,3,'<float_array id="'+anim_id+'-input-array" count="'+str(frame_total)+'">'+source_frames+'</float_array>')
@ -1422,9 +1355,7 @@ class DaeExporter:
return [anim_id]
def export_animation(self,start,end,allowed=None):
# Blender -> Collada frames needs a little work
# Collada starts from 0, blender usually from 1
# The last frame must be included also
@ -1472,7 +1403,6 @@ class DaeExporter:
blend_cache[name].append( (key,node.data.shape_keys.key_blocks[i].value) )
if (node.type=="MESH" and node.parent and node.parent.type=="ARMATURE"):
continue #In Collada, nodes that have skin modifier must not export animation, animate the skin instead.
@ -1515,7 +1445,6 @@ class DaeExporter:
if (not parent_invisible):
mtx = parent_posebone.matrix.inverted() * mtx
xform_cache[bone_name].append( (key,mtx) )
self.scene.frame_set(frame_orig)
@ -1539,16 +1468,13 @@ class DaeExporter:
self.writel(S_ANIM,0,'<library_animations>')
if (self.config["use_anim_action_all"] and len(self.skeletons)):
cached_actions = {}
for s in self.skeletons:
if s.animation_data and s.animation_data.action:
cached_actions[s] = s.animation_data.action.name
self.writel(S_ANIM_CLIPS,0,'<library_animation_clips>')
for x in bpy.data.actions[:]:
@ -1582,7 +1508,6 @@ class DaeExporter:
for j,bone in enumerate(s.pose.bones):
bone.matrix_basis = Matrix()
# print("allowed skeletons "+str(allowed_skeletons))
# print(str(x))
@ -1599,11 +1524,8 @@ class DaeExporter:
if (len(tcn)==0):
self.operator.report({'WARNING'},'Animation clip "'+x.name+'" contains no tracks.')
self.writel(S_ANIM_CLIPS,0,'</library_animation_clips>')
for i,s in enumerate(self.skeletons):
if (s.animation_data==None):
continue
@ -1617,12 +1539,9 @@ class DaeExporter:
else:
self.export_animation(self.scene.frame_start,self.scene.frame_end)
self.writel(S_ANIM,0,'</library_animations>')
def export(self):
self.writel(S_GEOM,0,'<library_geometries>')
self.writel(S_CONT,0,'<library_controllers>')
self.writel(S_CAMS,0,'<library_cameras>')
@ -1631,7 +1550,6 @@ class DaeExporter:
self.writel(S_MATS,0,'<library_materials>')
self.writel(S_FX,0,'<library_effects>')
self.skeletons=[]
self.action_constraints=[]
self.export_asset()
@ -1669,7 +1587,6 @@ class DaeExporter:
f.write(bytes('<?xml version="1.0" encoding="utf-8"?>\n',"UTF-8"))
f.write(bytes('<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">\n',"UTF-8"))
s=[]
for x in self.sections.keys():
s.append(x)
@ -1703,11 +1620,6 @@ class DaeExporter:
self.wrongvtx_report=False
def save(operator, context,
filepath="",
use_selection=False,
@ -1717,8 +1629,4 @@ def save(operator, context,
exp = DaeExporter(filepath,kwargs,operator)
exp.export()
return {'FINISHED'} # so the script wont run after we have batch exported.