[Bf-blender-cvs] [8f4d982] alembic_pointcache: Only poly and vertex normals are mandatory for a valid normals, loop normals may not exist.
Lukas Tönne
noreply at git.blender.org
Thu Nov 13 12:54:00 CET 2014
Commit: 8f4d98283d3a4d6e23e9024e95974486015170d1
Author: Lukas Tönne
Date: Thu Nov 13 12:52:24 2014 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB8f4d98283d3a4d6e23e9024e95974486015170d1
Only poly and vertex normals are mandatory for a valid normals, loop
normals may not exist.
Note: Currently we cannot create poly normals explicitly from a modifier,
they have to be recalculated every time ...
===================================================================
M source/blender/pointcache/intern/mesh.cpp
===================================================================
diff --git a/source/blender/pointcache/intern/mesh.cpp b/source/blender/pointcache/intern/mesh.cpp
index 2853bc2..facf8e0 100644
--- a/source/blender/pointcache/intern/mesh.cpp
+++ b/source/blender/pointcache/intern/mesh.cpp
@@ -28,6 +28,7 @@ extern "C" {
#include "BKE_DerivedMesh.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_mesh.h"
#include "PIL_time.h"
}
@@ -68,6 +69,30 @@ PointCacheWriter::~PointCacheWriter()
{
}
+/* XXX modifiers are not allowed to generate poly normals on their own!
+ * see assert in DerivedMesh.c : dm_ensure_display_normals
+ */
+#if 0
+static void ensure_normal_data(DerivedMesh *dm)
+{
+ MVert *mverts = dm->getVertArray(dm);
+ MLoop *mloops = dm->getLoopArray(dm);
+ MPoly *mpolys = dm->getPolyArray(dm);
+ CustomData *cdata = dm->getPolyDataLayout(dm);
+ float (*polynors)[3];
+ int totvert = dm->getNumVerts(dm);
+ int totloop = dm->getNumLoops(dm);
+ int totpoly = dm->getNumPolys(dm);
+
+ if (CustomData_has_layer(cdata, CD_NORMAL))
+ polynors = (float (*)[3])CustomData_get_layer(cdata, CD_NORMAL);
+ else
+ polynors = (float (*)[3])CustomData_add_layer(cdata, CD_NORMAL, CD_CALLOC, NULL, totpoly);
+
+ BKE_mesh_calc_normals_poly(mverts, totvert, mloops, mpolys, totloop, totpoly, polynors, false);
+}
+#endif
+
static P3fArraySample create_sample_positions(DerivedMesh *dm, std::vector<V3f> &data)
{
MVert *mv, *mverts = dm->getVertArray(dm);
@@ -213,6 +238,10 @@ void PointCacheWriter::write_sample()
if (!output_dm)
return;
+ /* TODO make this optional by a flag? */
+ /* XXX does not work atm, see comment above */
+ /*ensure_normal_data(output_dm);*/
+
OPolyMeshSchema &schema = m_mesh.getSchema();
std::vector<V3f> positions_buffer;
@@ -466,17 +495,22 @@ PTCReadSampleResult PointCacheReader::read_sample(float frame)
Int32ArraySamplePtr indices = sample.getFaceIndices();
Int32ArraySamplePtr counts = sample.getFaceCounts();
N3fArraySamplePtr lnormals, pnormals, vnormals;
- if (m_param_loop_normals && m_param_poly_normals && m_param_vertex_normals) {
- lnormals = m_param_loop_normals.getExpandedValue(ss).getVals();
+ if (m_param_poly_normals && m_param_poly_normals.getNumSamples() > 0
+ && m_param_vertex_normals && m_param_vertex_normals.getNumSamples() > 0) {
pnormals = m_param_poly_normals.getExpandedValue(ss).getVals();
vnormals = m_param_vertex_normals.getExpandedValue(ss).getVals();
/* we need all normal properties defined, otherwise have to recalculate */
- has_normals = lnormals->valid() && pnormals->valid() && vnormals->valid();
+ has_normals = pnormals->valid() && vnormals->valid();
+ }
+ if (has_normals) {
+ /* note: loop normals are not mandatory, but if poly/vertex normals don't exist they get recalculated anyway */
+ if (m_param_loop_normals && m_param_loop_normals.getNumSamples() > 0)
+ lnormals = m_param_loop_normals.getExpandedValue(ss).getVals();
}
BoolArraySamplePtr smooth;
- if (m_param_smooth) {
+ if (m_param_smooth && m_param_smooth.getNumSamples() > 0) {
IBoolGeomParam::Sample sample_smooth;
m_param_smooth.getExpanded(sample_smooth, ss);
smooth = sample_smooth.getVals();
@@ -484,7 +518,8 @@ PTCReadSampleResult PointCacheReader::read_sample(float frame)
bool has_edges = false;
Int32ArraySamplePtr edges, edges_index;
- if (m_prop_edges && m_prop_edges_index) {
+ if (m_prop_edges && m_prop_edges.getNumSamples() > 0
+ && m_prop_edges_index && m_prop_edges_index.getNumSamples() > 0) {
m_prop_edges.get(edges, ss);
m_prop_edges_index.get(edges_index, ss);
BLI_assert(edges->size() % 2 == 0); /* 2 vertex indices per edge */
@@ -504,9 +539,11 @@ PTCReadSampleResult PointCacheReader::read_sample(float frame)
apply_sample_vertex_indices(m_result, indices);
apply_sample_loop_counts(m_result, counts);
if (has_normals) {
- apply_sample_loop_normals(m_result, pnormals);
apply_sample_poly_normals(m_result, lnormals);
apply_sample_vertex_normals(m_result, vnormals);
+
+ if (lnormals->valid())
+ apply_sample_loop_normals(m_result, pnormals);
}
else {
/* make sure normals are recalculated if there is no sample data */
More information about the Bf-blender-cvs
mailing list