From 144494600620dbaeee454fb454b84f2388d6fe25 Mon Sep 17 00:00:00 2001 From: cheece <666mon@gmail.com> Date: Tue, 24 Feb 2015 20:13:21 -0430 Subject: COLLADA load normals from morph target if the file has normals use them! --- tools/editor/io_plugins/editor_import_collada.cpp | 54 ++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'tools/editor') diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp index 529ed3374b..36d412d66c 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/io_plugins/editor_import_collada.cpp @@ -1354,8 +1354,60 @@ Error ColladaImport::_create_mesh_surfaces(Ref& p_mesh,const Map::Write(); DVector normals; DVector tangents; + if(md.vertices[vertex_src_id].sources.has("NORMAL")){ + //has normals + normals.resize(vlen); + std::cout << "has normals" << std::endl; + String normal_src_id = md.vertices[vertex_src_id].sources["NORMAL"]; + std::cout << "normals source: "<< normal_src_id.utf8().get_data() <array.size() != vertex_src->array.size(), ERR_INVALID_DATA); + int stride=m->stride; + if (stride==0) + stride=3; + + + //read normals from morph target + DVector::Write vertw = normals.write(); + + for(int m_i=0;m_iarray.size()/stride;m_i++) { + + int pos = m_i*stride; + Vector3 vtx( m->array[pos+0], m->array[pos+1], m->array[pos+2] ); + + #ifndef NO_UP_AXIS_SWAP + if (collada.state.up_axis==Vector3::AXIS_Z) { + + SWAP( vtx.z, vtx.y ); + vtx.z = -vtx.z; + + } + #endif + + Collada::Vertex vertex; + vertex.vertex=vtx; + vertex.fix_unit_scale(collada); + vtx=vertex.vertex; + + vtx = p_local_xform.xform(vtx); + + + if (vertex_map.has(m_i)) { //vertex may no longer be here, don't bother converting + + + for (Set ::Element *E=vertex_map[m_i].front() ; E; E=E->next() ) { + + vertw[E->get()]=vtx; + } + } + } + + }else{ + _generate_normals(index_array,vertices,normals);//no normals + } if (final_tangent_array.size() && final_uv_array.size()) { _generate_tangents_and_binormals(index_array,vertices,final_uv_array,normals,tangents); -- cgit v1.2.3