summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/collada/collada.cpp2
-rw-r--r--tools/collada/collada.h18
-rw-r--r--tools/editor/editor_import_export.cpp30
-rw-r--r--tools/editor/editor_import_export.h3
-rw-r--r--tools/editor/io_plugins/editor_import_collada.cpp11
-rw-r--r--tools/export/blender25/io_scene_dae/export_dae.py67
6 files changed, 109 insertions, 22 deletions
diff --git a/tools/collada/collada.cpp b/tools/collada/collada.cpp
index 97e9f5c36d..b55edde801 100644
--- a/tools/collada/collada.cpp
+++ b/tools/collada/collada.cpp
@@ -817,7 +817,7 @@ void Collada::_parse_camera(XMLParser& parser) {
if (name=="perspective") {
camera.mode=CameraData::MODE_PERSPECTIVE;
- } else if (name=="orthogonal") {
+ } else if (name=="orthographic") {
camera.mode=CameraData::MODE_ORTHOGONAL;
} else if (name=="xfov") {
diff --git a/tools/collada/collada.h b/tools/collada/collada.h
index f523d24e02..7691d90c0a 100644
--- a/tools/collada/collada.h
+++ b/tools/collada/collada.h
@@ -337,6 +337,24 @@ public:
if(normal==p_vert.normal) {
if(uv==p_vert.uv) {
if(uv2==p_vert.uv2) {
+
+ if (!weights.empty() || !p_vert.weights.empty()) {
+
+ if (weights.size()==p_vert.weights.size()) {
+
+ for(int i=0;i<weights.size();i++) {
+ if (weights[i].bone_idx!=p_vert.weights[i].bone_idx)
+ return weights[i].bone_idx<p_vert.weights[i].bone_idx;
+
+ if (weights[i].weight!=p_vert.weights[i].weight)
+ return weights[i].weight<p_vert.weights[i].weight;
+ }
+ } else {
+ return weights.size() < p_vert.weights.size();
+ }
+
+ }
+
return (color<p_vert.color);
} else
return (uv2<p_vert.uv2);
diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp
index 6399d0f909..e6ec11e9d3 100644
--- a/tools/editor/editor_import_export.cpp
+++ b/tools/editor/editor_import_export.cpp
@@ -904,6 +904,16 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func
return OK;
}
+static int _get_pad(int p_alignment, int p_n) {
+
+ int rest = p_n % p_alignment;
+ int pad = 0;
+ if (rest > 0) {
+ pad = p_alignment - rest;
+ };
+
+ return pad;
+};
Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total) {
@@ -930,11 +940,19 @@ Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path
pd->ep->step("Storing File: "+p_path,2+p_file*100/p_total);
pd->count++;
pd->ftmp->store_buffer(p_data.ptr(),p_data.size());
+ if (pd->alignment > 1) {
+
+ int pad = _get_pad(pd->alignment, pd->ftmp->get_pos());
+ for (int i=0; i<pad; i++) {
+
+ pd->ftmp->store_8(0);
+ };
+ };
return OK;
}
-Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles) {
+Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles, int p_alignment) {
EditorProgress ep("savepack","Packing",102);
@@ -952,7 +970,6 @@ Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles) {
dst->store_32(0);
}
-
size_t fcountpos = dst->get_pos();
dst->store_32(0);
@@ -961,11 +978,20 @@ Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles) {
pd.f=dst;
pd.ftmp=tmp;
pd.count=0;
+ pd.alignment = p_alignment;
Error err = export_project_files(save_pack_file,&pd,p_make_bundles);
memdelete(tmp);
if (err)
return err;
+ if (p_alignment > 1) {
+ int pad = _get_pad(p_alignment, dst->get_pos());
+ for (int i=0; i<pad; i++) {
+
+ dst->store_8(0);
+ };
+ };
+
size_t ofsplus = dst->get_pos();
//append file
diff --git a/tools/editor/editor_import_export.h b/tools/editor/editor_import_export.h
index cd24fa076b..a4723f41d0 100644
--- a/tools/editor/editor_import_export.h
+++ b/tools/editor/editor_import_export.h
@@ -100,6 +100,7 @@ protected:
Vector<TempData> file_ofs;
EditorProgress *ep;
int count;
+ int alignment;
};
@@ -121,7 +122,7 @@ public:
Error export_project_files(EditorExportSaveFunction p_func, void* p_udata,bool p_make_bundles);
- Error save_pack(FileAccess *p_where, bool p_make_bundles=false);
+ Error save_pack(FileAccess *p_where, bool p_make_bundles=false, int p_alignment = 1);
virtual String get_name() const =0;
virtual ImageCompression get_image_compression() const=0;
virtual Ref<Texture> get_logo() const =0;
diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp
index 529ed3374b..6dd46843cc 100644
--- a/tools/editor/io_plugins/editor_import_collada.cpp
+++ b/tools/editor/io_plugins/editor_import_collada.cpp
@@ -285,13 +285,16 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
case Collada::CameraData::MODE_ORTHOGONAL: {
- if (cd.orthogonal.x_mag) {
+ if (cd.orthogonal.y_mag) {
- camera->set_orthogonal(cd.orthogonal.x_mag,cd.z_near,cd.z_far);
+ camera->set_keep_aspect_mode(Camera::KEEP_HEIGHT);
+ camera->set_orthogonal(cd.orthogonal.y_mag*2.0 ,cd.z_near,cd.z_far);
- } else if (!cd.orthogonal.x_mag && cd.orthogonal.y_mag) {
+ } else if (!cd.orthogonal.y_mag && cd.orthogonal.x_mag) {
- camera->set_orthogonal(cd.orthogonal.y_mag * cd.aspect,cd.z_near,cd.z_far);
+
+ camera->set_keep_aspect_mode(Camera::KEEP_WIDTH);
+ camera->set_orthogonal(cd.orthogonal.x_mag*2.0,cd.z_near,cd.z_far);
}
} break;
diff --git a/tools/export/blender25/io_scene_dae/export_dae.py b/tools/export/blender25/io_scene_dae/export_dae.py
index 8e751fc33c..5e5febfb1f 100644
--- a/tools/export/blender25/io_scene_dae/export_dae.py
+++ b/tools/export/blender25/io_scene_dae/export_dae.py
@@ -94,8 +94,6 @@ def strarr(arr):
s+=" "
return s
-
-
class DaeExporter:
def validate_id(self,d):
@@ -132,10 +130,10 @@ class DaeExporter:
tup = tup + (self.tangent.x,self.tangent.y,self.tangent.z)
if (self.bitangent!=None):
tup = tup + (self.bitangent.x,self.bitangent.y,self.bitangent.z)
- #for t in self.bones:
- # tup = tup + (t)
- #for t in self.weights:
- # tup = tup + (t)
+ for t in self.bones:
+ tup = tup + (float(t),)
+ for t in self.weights:
+ tup = tup + (float(t),)
return tup
@@ -512,12 +510,12 @@ class DaeExporter:
mat_assign=[]
uv_layer_count=len(mesh.uv_textures)
- if (len(mesh.uv_textures)):
+ if (has_tangents and len(mesh.uv_textures)):
try:
mesh.calc_tangents()
except:
- print("Warning, blender API is fucked up, not exporting UVs for this object.")
- uv_layer_count=0
+ self.operator.report({'WARNING'},'CalcTangets failed for mesh "'+mesh.name+'", no tangets will be exported.')
+ #uv_layer_count=0
mesh.calc_normals_split()
has_tangents=False
@@ -591,16 +589,30 @@ class DaeExporter:
if (armature!=None):
wsum=0.0
+ zero_bones=[]
+
for vg in mv.groups:
if vg.group >= len(node.vertex_groups):
continue;
name = node.vertex_groups[vg.group].name
+
if (name in si["bone_index"]):
#could still put the weight as 0.0001 maybe
if (vg.weight>0.001): #blender has a lot of zero weight stuff
v.bones.append(si["bone_index"][name])
v.weights.append(vg.weight)
wsum+=vg.weight
+ if (wsum==0.0):
+ if not self.wrongvtx_report:
+ self.operator.report({'WARNING'},'Mesh for object "'+node.name+'" has unassigned weights. This may look wrong in exported model.')
+ self.wrongvtx_report=True
+
+ #blender can have bones assigned that weight zero so they remain local
+ #this is the best it can be done?
+ v.bones.append(0)
+ v.weights.append(1)
+
+
tup = v.get_tup()
@@ -889,6 +901,15 @@ class DaeExporter:
if (node.parent!=None):
if (node.parent.type=="ARMATURE"):
armature=node.parent
+ armcount=0
+ for n in node.modifiers:
+ if (n.type=="ARMATURE"):
+ armcount+=1
+ if (armcount>1):
+ self.operator.report({'WARNING'},'Object "'+node.name+'" refers to more than one armature! This is unsopported.')
+
+
+
if (node.data.shape_keys!=None):
sk = node.data.shape_keys
@@ -940,6 +961,12 @@ class DaeExporter:
boneidx = si["bone_count"]
si["bone_count"]+=1
bonesid = si["id"]+"-"+str(boneidx)
+ if (bone.name in self.used_bones):
+ if (self.config["use_anim_action_all"]):
+ self.operator.report({'WARNING'},'Bone name "'+bone.name+'" used in more than one skeleton. Actions might export wrong.')
+ else:
+ self.used_bones.append(bone.name)
+
si["bone_index"][bone.name]=boneidx
si["bone_ids"][bone]=boneid
si["bone_names"].append(bonesid)
@@ -1002,12 +1029,12 @@ class DaeExporter:
self.writel(S_CAMS,5,'<zfar> '+str(camera.clip_end)+' </zfar>')
self.writel(S_CAMS,4,'</perspective>')
else:
- self.writel(S_CAMS,4,'<orthografic>')
- self.writel(S_CAMS,5,'<xmag> '+str(camera.ortho_scale)+' </xmag>') # I think?
+ self.writel(S_CAMS,4,'<orthographic>')
+ self.writel(S_CAMS,5,'<xmag> '+str(camera.ortho_scale*0.5)+' </xmag>') # I think?
self.writel(S_CAMS,5,'<aspect_ratio> '+str(self.scene.render.resolution_x / self.scene.render.resolution_y)+' </aspect_ratio>')
self.writel(S_CAMS,5,'<znear> '+str(camera.clip_start)+' </znear>')
self.writel(S_CAMS,5,'<zfar> '+str(camera.clip_end)+' </zfar>')
- self.writel(S_CAMS,4,'</orthografic>')
+ self.writel(S_CAMS,4,'</orthographic>')
self.writel(S_CAMS,3,'</technique_common>')
self.writel(S_CAMS,2,'</optics>')
@@ -1534,10 +1561,14 @@ class DaeExporter:
for z in tcn:
self.writel(S_ANIM_CLIPS,2,'<instance_animation url="#'+z+'"/>')
self.writel(S_ANIM_CLIPS,1,'</animation_clip>')
+ 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
@@ -1547,6 +1578,7 @@ class DaeExporter:
s.animation_data.action = None
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)
@@ -1617,7 +1649,8 @@ class DaeExporter:
f.write(bytes('</COLLADA>\n',"UTF-8"))
return True
- def __init__(self,path,kwargs):
+ def __init__(self,path,kwargs,operator):
+ self.operator=operator
self.scene=bpy.context.scene
self.last_id=0
self.scene_name=self.new_id("scene")
@@ -1631,6 +1664,10 @@ class DaeExporter:
self.config=kwargs
self.valid_nodes=[]
self.armature_for_morph={}
+ self.used_bones=[]
+ self.wrongvtx_report=False
+
+
@@ -1642,9 +1679,11 @@ def save(operator, context,
**kwargs
):
- exp = DaeExporter(filepath,kwargs)
+ exp = DaeExporter(filepath,kwargs,operator)
exp.export()
+
+
return {'FINISHED'} # so the script wont run after we have batch exported.