summaryrefslogtreecommitdiff
path: root/tools/export/blender25/io_scene_dae
diff options
context:
space:
mode:
authorDana Olson <dana@shineuponthee.com>2015-01-09 01:36:38 -0500
committerDana Olson <dana@shineuponthee.com>2015-01-09 01:36:38 -0500
commit66a2adbf4badc7f97923e9e2c02d8f1b807d560e (patch)
tree63bf46b77b02f725bd13b99db570af636079a66f /tools/export/blender25/io_scene_dae
parent0c2222188e7d9b9c2bcae8186c7a164b50000dc3 (diff)
mergable version of ndee's pull request
Diffstat (limited to 'tools/export/blender25/io_scene_dae')
-rw-r--r--tools/export/blender25/io_scene_dae/export_dae.py71
1 files changed, 49 insertions, 22 deletions
diff --git a/tools/export/blender25/io_scene_dae/export_dae.py b/tools/export/blender25/io_scene_dae/export_dae.py
index 4e1635429b..8161f05bf8 100644
--- a/tools/export/blender25/io_scene_dae/export_dae.py
+++ b/tools/export/blender25/io_scene_dae/export_dae.py
@@ -162,37 +162,61 @@ class DaeExporter:
def export_image(self,image):
-
if (image in self.image_cache):
return self.image_cache[image]
-
+
imgpath = image.filepath
if (imgpath.find("//")==0 or imgpath.find("\\\\")==0):
#if relative, convert to absolute
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"
if (not os.path.isdir(basedir)):
os.makedirs(basedir)
- dstfile=basedir+"/"+os.path.basename(imgpath)
- if (not os.path.isfile(dstfile)):
- shutil.copy(imgpath,dstfile)
- imgpath="images/"+os.path.basename(imgpath)
+
+ if os.path.isfile(imgpath):
+ dstfile=basedir+"/"+os.path.basename(imgpath)
+
+ if (not os.path.isfile(dstfile)):
+ shutil.copy(imgpath,dstfile)
+ imgpath="images/"+os.path.basename(imgpath)
+ else:
+ ### if file is not found save it as png file in the destination folder
+ img_tmp_path = image.filepath
+ if img_tmp_path.endswith((".bmp",".rgb",".png",".jpeg",".jpg",".jp2",".tga",".cin",".dpx",".exr",".hdr",".tif")):
+ image.filepath = basedir+"/"+os.path.basename(img_tmp_path)
+ else:
+ image.filepath = basedir+"/"+image.name+".png"
+
+ dstfile=basedir+"/"+os.path.basename(image.filepath)
+
+ if (not os.path.isfile(dstfile)):
+
+ image.save()
+ imgpath="images/"+os.path.basename(image.filepath)
+ image.filepath = img_tmp_path
else:
#export relative, always, no one wants absolute paths.
try:
imgpath = os.path.relpath(imgpath,os.path.dirname(self.path)).replace("\\","/") # export unix compatible always
+
except:
pass #fails sometimes, not sure why
-
-
+
imgid = self.new_id("image")
+
+ if (not os.path.isfile(imgpath)):
+ if img_tmp_path.endswith((".bmp",".rgb",".png",".jpeg",".jpg",".jp2",".tga",".cin",".dpx",".exr",".hdr",".tif")):
+ imgpath="images/"+os.path.basename(img_tmp_path)
+ else:
+ imgpath="images/"+image.name+".png"
+
self.writel(S_IMGS,1,'<image id="'+imgid+'" name="'+image.name+'">')
self.writel(S_IMGS,2,'<init_from>'+imgpath+'</init_from>"/>')
self.writel(S_IMGS,1,'</image>')
@@ -1176,6 +1200,7 @@ class DaeExporter:
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
self.writel(S_NODES,il,'<node id="'+self.validate_id(node.name)+'" name="'+node.name+'" type="NODE">')
@@ -1199,6 +1224,7 @@ class DaeExporter:
il-=1
self.writel(S_NODES,il,'</node>')
+ bpy.context.scene.objects.active = prev_node #make previous node active again
def is_node_valid(self,node):
if (not node.type in self.config["object_types"]):
@@ -1441,12 +1467,13 @@ class DaeExporter:
return tcn
def export_animations(self):
- tmp_mat = [] # workaround by ndee
- for s in self.skeletons: # workaround by ndee
- tmp_bone_mat = [] # workaround by ndee
- for bone in s.pose.bones: # workaround by ndee
- tmp_bone_mat.append(Matrix(bone.matrix_basis)) # workaround by ndee
- tmp_mat.append([Matrix(s.matrix_local),tmp_bone_mat]) # workaround by ndee -> stores skeleton and bone transformations
+ tmp_mat = []
+ for s in self.skeletons:
+ tmp_bone_mat = []
+ for bone in s.pose.bones:
+ tmp_bone_mat.append(Matrix(bone.matrix_basis))
+ bone.matrix_basis = Matrix()
+ tmp_mat.append([Matrix(s.matrix_local),tmp_bone_mat])
self.writel(S_ANIM,0,'<library_animations>')
@@ -1481,7 +1508,7 @@ class DaeExporter:
bones.append(dp)
allowed_skeletons=[]
- for i,y in enumerate(self.skeletons): # workaround by ndee
+ for i,y in enumerate(self.skeletons):
if (y.animation_data):
for z in y.pose.bones:
if (z.bone.name in bones):
@@ -1489,9 +1516,9 @@ class DaeExporter:
allowed_skeletons.append(y)
y.animation_data.action=x;
- y.matrix_local = tmp_mat[i][0] # workaround by ndee -> resets the skeleton transformation.
- for j,bone in enumerate(s.pose.bones): # workaround by ndee
- bone.matrix_basis = Matrix() # workaround by ndee -> resets the bone transformations. Important if bones in follwing actions miss keyframes
+ y.matrix_local = tmp_mat[i][0]
+ for j,bone in enumerate(s.pose.bones):
+ bone.matrix_basis = Matrix()
print("allowed skeletons "+str(allowed_skeletons))
@@ -1511,15 +1538,15 @@ class DaeExporter:
self.writel(S_ANIM_CLIPS,0,'</library_animation_clips>')
- for i,s in enumerate(self.skeletons): # workaround by ndee
+ for i,s in enumerate(self.skeletons):
if (s.animation_data==None):
continue
if s in cached_actions:
s.animation_data.action = bpy.data.actions[cached_actions[s]]
else:
s.animation_data.action = None
- for j,bone in enumerate(s.pose.bones): # workaround by ndee
- bone.matrix_basis = tmp_mat[i][1][j] # workaround by ndee -> resets the bone transformation to what they were before exporting.
+ for j,bone in enumerate(s.pose.bones):
+ bone.matrix_basis = tmp_mat[i][1][j]
else:
self.export_animation(self.scene.frame_start,self.scene.frame_end)