Automatic sharp-edge-marking using Retro's normals for reference

This commit is contained in:
Jack Andersen 2016-03-28 16:24:47 -10:00
parent 9a96d4025d
commit e11588aa66
2 changed files with 77 additions and 7 deletions

View File

@ -420,7 +420,10 @@ public:
void InitGeomBlenderContext(hecl::BlenderConnection::PyOutStream& os,
const hecl::ProjectPath& masterShaderPath)
{
os << "# Using 'Blender Game'\n"
os << "import math\n"
"from mathutils import Vector\n"
"\n"
"# Using 'Blender Game'\n"
"bpy.context.scene.render.engine = 'BLENDER_GAME'\n"
"\n"
"# Clear Scene\n"
@ -434,6 +437,14 @@ void InitGeomBlenderContext(hecl::BlenderConnection::PyOutStream& os,
" if loop.vert[bm.verts.layers.int['CMDLOriginalPosIdxs']] == vert_idx:\n"
" return loop\n"
"\n"
"def loops_from_edgevert(bm, edge, vert):\n"
" ret = []\n"
" for face in edge.link_faces:\n"
" for loop in face.loops:\n"
" if loop.vert == vert:\n"
" ret.append(loop)\n"
" return ret\n"
"\n"
"def add_triangle(bm, vert_seq, vert_indices, norm_seq, norm_indices, mat_nr, od_list):\n"
" if len(set(vert_indices)) != 3:\n"
" return None, None\n"
@ -516,6 +527,7 @@ void FinishBlenderMesh(hecl::BlenderConnection::PyOutStream& os,
"mesh.hecl_material_count = %u\n", meshIdx, matSetCount);
os << "mesh.use_auto_smooth = True\n"
"mesh.auto_smooth_angle = math.pi\n"
"\n"
"for material in materials:\n"
" mesh.materials.append(material)\n"
@ -546,14 +558,26 @@ void FinishBlenderMesh(hecl::BlenderConnection::PyOutStream& os,
"\n"
" od_entry['bm'].free()\n"
"\n"
"for edge in bm.edges:\n"
" if edge.is_manifold:\n"
" pass_count = 0\n"
" for vert in edge.verts:\n"
" loops = loops_from_edgevert(bm, edge, vert)\n"
" norm0 = Vector(norm_list[loops[0][orig_nidx_lay]])\n"
" norm1 = Vector(norm_list[loops[1][orig_nidx_lay]])\n"
" if norm0.dot(norm1) < 0.9:\n"
" pass_count += 1\n"
" if pass_count > 0:\n"
" edge.smooth = False\n"
"\n"
"bm.to_mesh(mesh)\n"
"\n"
"# Load split normal data\n"
"split_normals = []\n"
"for face in bm.faces:\n"
" for loop in face.loops:\n"
" split_normals.append(norm_list[loop[orig_nidx_lay]])\n"
"mesh.normals_split_custom_set(split_normals)\n"
"# Resolve split normal data\n"
"#split_normals = []\n"
"#for face in bm.faces:\n"
"# for loop in face.loops:\n"
"# split_normals.append(norm_list[loop[orig_nidx_lay]])\n"
"#mesh.normals_split_custom_set(split_normals)\n"
"\n"
"bm.free()\n"
"\n"

View File

@ -10,6 +10,11 @@
#include "DNAMP1/CMDL.hpp"
#include "DNAMP1/ANCS.hpp"
#include "DNACommon/PART.hpp"
#include "DNACommon/SWHC.hpp"
#include "DNACommon/ELSC.hpp"
#include "DNACommon/WPSC.hpp"
#include "DNACommon/CRSC.hpp"
#include "DNACommon/DPSC.hpp"
namespace DataSpec
{
@ -297,6 +302,16 @@ struct SpecMP1 : SpecBase
return true;
else if (!strcmp(classType, DNAParticle::GPSM<UniqueID32>::DNAType()))
return true;
else if (!strcmp(classType, DNAParticle::SWSH<UniqueID32>::DNAType()))
return true;
else if (!strcmp(classType, DNAParticle::ELSM<UniqueID32>::DNAType()))
return true;
else if (!strcmp(classType, DNAParticle::WPSM<UniqueID32>::DNAType()))
return true;
else if (!strcmp(classType, DNAParticle::CRSM<UniqueID32>::DNAType()))
return true;
else if (!strcmp(classType, DNAParticle::DPSM<UniqueID32>::DNAType()))
return true;
return false;
});
}
@ -347,7 +362,38 @@ struct SpecMP1 : SpecBase
gpsm.read(reader);
DNAParticle::WriteGPSM(gpsm, out);
}
else if (!classStr.compare(DNAParticle::SWSH<UniqueID32>::DNAType()))
{
DNAParticle::SWSH<UniqueID32> swsh;
swsh.read(reader);
DNAParticle::WriteSWSH(swsh, out);
}
else if (!classStr.compare(DNAParticle::ELSM<UniqueID32>::DNAType()))
{
DNAParticle::ELSM<UniqueID32> elsm;
elsm.read(reader);
DNAParticle::WriteELSM(elsm, out);
}
else if (!classStr.compare(DNAParticle::WPSM<UniqueID32>::DNAType()))
{
DNAParticle::WPSM<UniqueID32> wpsm;
wpsm.read(reader);
DNAParticle::WriteWPSM(wpsm, out);
}
else if (!classStr.compare(DNAParticle::CRSM<UniqueID32>::DNAType()))
{
DNAParticle::CRSM<UniqueID32> crsm;
crsm.read(reader);
DNAParticle::WriteCRSM(crsm, out);
}
else if (!classStr.compare(DNAParticle::DPSM<UniqueID32>::DNAType()))
{
DNAParticle::DPSM<UniqueID32> dpsm;
dpsm.read(reader);
DNAParticle::WriteDPSM(dpsm, out);
}
}
progress(_S("Done"));
}
};