summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/collada/collada.cpp37
-rw-r--r--tools/collada/collada.h2
-rw-r--r--tools/editor/io_plugins/editor_import_collada.cpp66
-rw-r--r--tools/export/blender25/io_scene_dae/export_dae.py19
4 files changed, 95 insertions, 29 deletions
diff --git a/tools/collada/collada.cpp b/tools/collada/collada.cpp
index 7a842391a4..97e9f5c36d 100644
--- a/tools/collada/collada.cpp
+++ b/tools/collada/collada.cpp
@@ -2250,29 +2250,35 @@ void Collada::_joint_set_owner(Collada::Node *p_node, NodeSkeleton *p_owner) {
}
}
-void Collada::_create_skeletons(Collada::Node **p_node) {
+void Collada::_create_skeletons(Collada::Node **p_node,NodeSkeleton *p_skeleton) {
Node *node = *p_node;
-
-
if (node->type==Node::TYPE_JOINT) {
- // ohohohoohoo it's a joint node, time to work!
+ if (!p_skeleton) {
+
+ // ohohohoohoo it's a joint node, time to work!
+ NodeSkeleton *sk = memnew( NodeSkeleton );
+ *p_node=sk;
+ sk->children.push_back(node);
+ sk->parent=node->parent;
+ node->parent=sk;
+ p_skeleton=sk;
+ }
- NodeSkeleton *sk = memnew( NodeSkeleton );
- *p_node=sk;
- sk->children.push_back(node);
- sk->parent=node->parent;
- node->parent=sk;
- _joint_set_owner(node,sk);
+ NodeJoint *nj = static_cast<NodeJoint*>(node);
+ nj->owner=p_skeleton;
} else {
+ p_skeleton=NULL;
+ }
- for(int i=0;i<node->children.size();i++) {
- _create_skeletons(&node->children[i]);
- }
+
+ for(int i=0;i<node->children.size();i++) {
+ _create_skeletons(&node->children[i],p_skeleton);
}
+
}
bool Collada::_remove_node(Node *p_parent,Node *p_node) {
@@ -2325,6 +2331,9 @@ void Collada::_merge_skeletons(VisualScene *p_vscene,Node *p_node) {
NodeJoint *nj = SAFE_CAST<NodeJoint*>(state.scene_map[nodeid]);
+ if (!nj->owner) {
+ print_line("no owner for: "+String(nodeid));
+ }
ERR_CONTINUE( !nj->owner ); //weird, node should have a skeleton owner
skeletons.insert(nj->owner);
@@ -2626,6 +2635,7 @@ void Collada::_optimize() {
_create_skeletons(&vs.root_nodes[i]);
}
+#if 1
for(int i=0;i<vs.root_nodes.size();i++) {
_merge_skeletons(&vs,vs.root_nodes[i]);
}
@@ -2653,6 +2663,7 @@ void Collada::_optimize() {
}
}
+#endif
for(int i=0;i<vs.root_nodes.size();i++) {
_find_morph_nodes(&vs,vs.root_nodes[i]);
}
diff --git a/tools/collada/collada.h b/tools/collada/collada.h
index c5e5705105..f523d24e02 100644
--- a/tools/collada/collada.h
+++ b/tools/collada/collada.h
@@ -619,7 +619,7 @@ private: // private stuff
Transform _read_transform(XMLParser& parser);
void _joint_set_owner(Collada::Node *p_node, NodeSkeleton *p_owner);
- void _create_skeletons(Collada::Node **p_node);
+ void _create_skeletons(Collada::Node **p_node, NodeSkeleton *p_skeleton=NULL);
void _find_morph_nodes(VisualScene *p_vscene,Node *p_node);
bool _remove_node(Node *p_parent,Node *p_node);
void _remove_node(VisualScene *p_vscene,Node *p_node);
diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp
index 8fe7010760..529ed3374b 100644
--- a/tools/editor/io_plugins/editor_import_collada.cpp
+++ b/tools/editor/io_plugins/editor_import_collada.cpp
@@ -61,6 +61,7 @@ struct ColladaImport {
Color ambient;
bool found_directional;
bool force_make_tangents;
+ bool apply_mesh_xform_to_vertices;
float bake_fps;
@@ -69,6 +70,7 @@ struct ColladaImport {
Map<String, Ref<Mesh> > mesh_cache;
Map<String, Ref<Curve3D> > curve_cache;
Map<String, Ref<Material> > material_cache;
+ Map<Collada::Node*,Skeleton*> skeleton_map;
Map< Skeleton*, Map< String, int> > skeleton_bone_map;
@@ -77,6 +79,7 @@ struct ColladaImport {
Map<String,bool> bones_with_animation;
Error _populate_skeleton(Skeleton *p_skeleton,Collada::Node *p_node, int &r_bone, int p_parent);
+ Error _create_scene_skeletons(Collada::Node *p_node);
Error _create_scene(Collada::Node *p_node, Spatial *p_parent);
Error _create_resources(Collada::Node *p_node);
Error _create_material(const String& p_material);
@@ -96,6 +99,7 @@ struct ColladaImport {
found_ambient=false;
found_directional=false;
force_make_tangents=false;
+ apply_mesh_xform_to_vertices=true;
bake_fps=15;
}
@@ -110,7 +114,7 @@ Error ColladaImport::_populate_skeleton(Skeleton *p_skeleton,Collada::Node *p_no
Collada::NodeJoint *joint = static_cast<Collada::NodeJoint*>(p_node);
-
+ print_line("populating joint "+joint->name);
p_skeleton->add_bone(p_node->name);
if (p_parent>=0)
p_skeleton->set_bone_parent(r_bone,p_parent);
@@ -170,6 +174,34 @@ void ColladaImport::_pre_process_lights(Collada::Node *p_node) {
_pre_process_lights(p_node->children[i]);
}
+Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) {
+
+
+ if (p_node->type==Collada::Node::TYPE_SKELETON) {
+
+ Skeleton *sk = memnew( Skeleton );
+ int bone = 0;
+
+ for(int i=0;i<p_node->children.size();i++) {
+
+ _populate_skeleton(sk,p_node->children[i],bone,-1);
+ }
+ sk->localize_rests(); //after creating skeleton, rests must be localized...!
+ skeleton_map[p_node]=sk;
+ }
+
+
+ for(int i=0;i<p_node->children.size();i++) {
+
+ Error err = _create_scene_skeletons(p_node->children[i]);
+ if (err)
+ return err;
+ }
+ return OK;
+
+}
+
+
Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
Spatial * node=NULL;
@@ -297,15 +329,8 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) {
} break;
case Collada::Node::TYPE_SKELETON: {
- Skeleton *sk = memnew( Skeleton );
- int bone = 0;
-
- for(int i=0;i<p_node->children.size();i++) {
-
- _populate_skeleton(sk,p_node->children[i],bone,-1);
- }
- sk->localize_rests(); //after creating skeleton, rests must be localized...!
-
+ ERR_FAIL_COND_V(!skeleton_map.has(p_node),ERR_CANT_CREATE);
+ Skeleton *sk = skeleton_map[p_node];
node=sk;
} break;
@@ -1502,6 +1527,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) {
ERR_FAIL_COND_V( skeletons.empty(), ERR_INVALID_DATA );
String skname = skeletons[0];
+ if (!node_map.has(skname)) {
+ print_line("no node for skeleton "+skname);
+ }
ERR_FAIL_COND_V( !node_map.has(skname), ERR_INVALID_DATA );
NodeMap nmsk = node_map[skname];
Skeleton *sk = nmsk.node->cast_to<Skeleton>();
@@ -1518,8 +1546,12 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) {
meshid=morph->mesh;
}
- apply_xform=collada.fix_transform(p_node->default_transform);
- node->set_transform(Transform());
+ if (apply_mesh_xform_to_vertices) {
+ apply_xform=collada.fix_transform(p_node->default_transform);
+ node->set_transform(Transform());
+ } else {
+ apply_xform=Transform();
+ }
Collada::SkinControllerData::Source *joint_src=NULL;
@@ -1615,6 +1647,16 @@ Error ColladaImport::load(const String& p_path,int p_flags,bool p_force_make_tan
}
//import scene
+
+ for(int i=0;i<vs.root_nodes.size();i++) {
+
+ Error err = _create_scene_skeletons(vs.root_nodes[i]);
+ if (err!=OK) {
+ memdelete(scene);
+ ERR_FAIL_COND_V(err,err);
+ }
+ }
+
for(int i=0;i<vs.root_nodes.size();i++) {
Error err = _create_scene(vs.root_nodes[i],scene);
diff --git a/tools/export/blender25/io_scene_dae/export_dae.py b/tools/export/blender25/io_scene_dae/export_dae.py
index f8e64452db..8b1d2e296a 100644
--- a/tools/export/blender25/io_scene_dae/export_dae.py
+++ b/tools/export/blender25/io_scene_dae/export_dae.py
@@ -1171,7 +1171,7 @@ class DaeExporter:
def export_node(self,node,il):
- if (not self.is_node_valid(node)):
+ if (not node in self.valid_nodes):
return
bpy.context.scene.objects.active = node
@@ -1191,7 +1191,6 @@ class DaeExporter:
elif (node.type=="LAMP"):
self.export_lamp_node(node,il)
- self.valid_nodes.append(node)
for x in node.children:
self.export_node(x,il)
@@ -1203,6 +1202,7 @@ class DaeExporter:
return False
if (self.config["use_active_layers"]):
valid=False
+ print("NAME: "+node.name)
for i in range(20):
if (node.layers[i] and self.scene.layers[i]):
valid=True
@@ -1222,8 +1222,21 @@ class DaeExporter:
self.writel(S_NODES,0,'<library_visual_scenes>')
self.writel(S_NODES,1,'<visual_scene id="'+self.scene_name+'" name="scene">')
+ #validate nodes
for obj in self.scene.objects:
- if (obj.parent==None):
+ if (obj in self.valid_nodes):
+ continue
+ if (self.is_node_valid(obj)):
+ n = obj
+ while (n!=None):
+ if (not n in self.valid_nodes):
+ 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)
self.writel(S_NODES,1,'</visual_scene>')