-Better Collada now keeps mesh names properly from blender, makes the "overwrite existing, keep materials" import mode work properly.
This commit is contained in:
parent
b016f3898b
commit
e18c6ef63b
@ -2130,14 +2130,14 @@ void EditorSceneImportPlugin::_add_new_nodes(Node *p_node,Node *p_imported,Node
|
|||||||
Node *imported_node = p_imported->get_child(i);
|
Node *imported_node = p_imported->get_child(i);
|
||||||
|
|
||||||
if (imported_node->get_owner()!=p_imported_scene) {
|
if (imported_node->get_owner()!=p_imported_scene) {
|
||||||
print_line("skipping because not imported at "+String(imported_node->get_name()));
|
// print_line("skipping because not imported at "+String(imported_node->get_name()));
|
||||||
continue; //end of the road
|
continue; //end of the road
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<StringName> nn;
|
Vector<StringName> nn;
|
||||||
nn.push_back(imported_node->get_name());
|
nn.push_back(imported_node->get_name());
|
||||||
NodePath imported_path(nn,false);
|
NodePath imported_path(nn,false);
|
||||||
print_line("check for: "+String(imported_path));
|
//print_line("check for: "+String(imported_path));
|
||||||
|
|
||||||
if (!p_node->has_node(imported_path) && !checked_nodes.has(imported_node)) {
|
if (!p_node->has_node(imported_path) && !checked_nodes.has(imported_node)) {
|
||||||
//not there, re-add it
|
//not there, re-add it
|
||||||
@ -2147,11 +2147,11 @@ void EditorSceneImportPlugin::_add_new_nodes(Node *p_node,Node *p_imported,Node
|
|||||||
if (o)
|
if (o)
|
||||||
n=o->cast_to<Node>();
|
n=o->cast_to<Node>();
|
||||||
|
|
||||||
print_line("creating node of same type..");
|
//print_line("creating node of same type..");
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
|
|
||||||
print_line("copy props and add");
|
//print_line("copy props and add");
|
||||||
List<PropertyInfo> pl;
|
List<PropertyInfo> pl;
|
||||||
imported_node->get_property_list(&pl);
|
imported_node->get_property_list(&pl);
|
||||||
for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
|
for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
|
||||||
@ -2165,7 +2165,7 @@ void EditorSceneImportPlugin::_add_new_nodes(Node *p_node,Node *p_imported,Node
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print_line("already exists");
|
//print_line("already exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2223,27 +2223,33 @@ void EditorSceneImportPlugin::_scan_materials(Node*p_base,Node *p_node,Map<Strin
|
|||||||
|
|
||||||
void EditorSceneImportPlugin::_apply_materials(Node*p_base,Node *p_node,Map<String,Ref<Material> > &mesh_materials,Map<String,Ref<Material> >& override_materials,Set<Ref<Mesh> >& meshes_processed) {
|
void EditorSceneImportPlugin::_apply_materials(Node*p_base,Node *p_node,Map<String,Ref<Material> > &mesh_materials,Map<String,Ref<Material> >& override_materials,Set<Ref<Mesh> >& meshes_processed) {
|
||||||
|
|
||||||
if (!p_base && p_node->get_owner()!=p_base)
|
if (p_node!=p_base && p_node->get_owner()!=p_base)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MeshInstance *mi=p_node->cast_to<MeshInstance>();
|
MeshInstance *mi=p_node->cast_to<MeshInstance>();
|
||||||
|
|
||||||
if (mi) {
|
if (mi) {
|
||||||
|
|
||||||
|
print_line("is mesh "+String(p_node->get_name()));
|
||||||
String path = p_base->get_path_to(p_node);
|
String path = p_base->get_path_to(p_node);
|
||||||
if (override_materials.has(path))
|
if (override_materials.has(path)) {
|
||||||
|
print_line("is in material overrides");
|
||||||
mi->set_material_override(override_materials[path]);
|
mi->set_material_override(override_materials[path]);
|
||||||
|
}
|
||||||
|
|
||||||
Ref<Mesh> mesh = mi->get_mesh();
|
Ref<Mesh> mesh = mi->get_mesh();
|
||||||
if (mesh.is_valid() && !meshes_processed.has(mesh)) {
|
if (mesh.is_valid() && !meshes_processed.has(mesh)) {
|
||||||
|
print_line("mesh was not processed");
|
||||||
meshes_processed.insert(mesh);
|
meshes_processed.insert(mesh);
|
||||||
for(int i=0;i<mesh->get_surface_count();i++) {
|
for(int i=0;i<mesh->get_surface_count();i++) {
|
||||||
|
|
||||||
String name = mesh->get_name()+":"+mesh->surface_get_name(i);
|
String name = mesh->get_name()+":"+mesh->surface_get_name(i);
|
||||||
|
print_line("name for surface "+itos(i)+": "+name);
|
||||||
if (mesh_materials.has(name)) {
|
if (mesh_materials.has(name)) {
|
||||||
|
|
||||||
Ref<Material> mat = mesh_materials[name];
|
Ref<Material> mat = mesh_materials[name];
|
||||||
mesh->surface_set_material(i,mat);
|
mesh->surface_set_material(i,mat);
|
||||||
|
print_line("overriding!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2260,9 +2266,19 @@ void EditorSceneImportPlugin::_merge_materials(Node *p_node,Node *p_imported) {
|
|||||||
Map<String,Ref<Material> > override_materials;
|
Map<String,Ref<Material> > override_materials;
|
||||||
|
|
||||||
_scan_materials(p_node,p_node,mesh_materials,override_materials);
|
_scan_materials(p_node,p_node,mesh_materials,override_materials);
|
||||||
|
|
||||||
|
for (Map<String,Ref<Material> >::Element *E=mesh_materials.front();E;E=E->next()) {
|
||||||
|
print_line("Mats: "+String(E->key()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map<String,Ref<Material> >::Element *E=override_materials.front();E;E=E->next()) {
|
||||||
|
print_line("Overrides: "+String(E->key()));
|
||||||
|
}
|
||||||
|
|
||||||
Set<Ref<Mesh> > mp;
|
Set<Ref<Mesh> > mp;
|
||||||
_apply_materials(p_imported,p_imported,mesh_materials,override_materials,mp);
|
_apply_materials(p_imported,p_imported,mesh_materials,override_materials,mp);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -482,6 +482,11 @@ class DaeExporter:
|
|||||||
|
|
||||||
apply_modifiers = len(node.modifiers) and self.config["use_mesh_modifiers"]
|
apply_modifiers = len(node.modifiers) and self.config["use_mesh_modifiers"]
|
||||||
|
|
||||||
|
name_to_use = mesh.name
|
||||||
|
#print("name to use: "+mesh.name)
|
||||||
|
if (custom_name!=None and custom_name!=""):
|
||||||
|
name_to_use=custom_name
|
||||||
|
|
||||||
mesh=node.to_mesh(self.scene,apply_modifiers,"RENDER") #is this allright?
|
mesh=node.to_mesh(self.scene,apply_modifiers,"RENDER") #is this allright?
|
||||||
|
|
||||||
triangulate=self.config["use_triangles"]
|
triangulate=self.config["use_triangles"]
|
||||||
@ -635,10 +640,7 @@ class DaeExporter:
|
|||||||
|
|
||||||
|
|
||||||
meshid = self.new_id("mesh")
|
meshid = self.new_id("mesh")
|
||||||
if (custom_name!=None):
|
self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+name_to_use+'">')
|
||||||
self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+custom_name+'">')
|
|
||||||
else:
|
|
||||||
self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+mesh.name+'">')
|
|
||||||
|
|
||||||
self.writel(S_GEOM,2,'<mesh>')
|
self.writel(S_GEOM,2,'<mesh>')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user