[Bf-blender-cvs] [0955288] alembic_basic_io: AbcHairWriter: split write function in smaller ones.
Kévin Dietrich
noreply at git.blender.org
Wed Apr 6 20:42:06 CEST 2016
Commit: 09552885f932a6b0e4673881205a7d7291f8b1da
Author: Kévin Dietrich
Date: Wed Apr 6 19:56:23 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB09552885f932a6b0e4673881205a7d7291f8b1da
AbcHairWriter: split write function in smaller ones.
===================================================================
M source/blender/alembic/intern/abc_hair.cc
M source/blender/alembic/intern/abc_hair.h
===================================================================
diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc
index fccd90b..a489195 100644
--- a/source/blender/alembic/intern/abc_hair.cc
+++ b/source/blender/alembic/intern/abc_hair.cc
@@ -22,6 +22,8 @@
#include "abc_hair.h"
+#include <cstdio>
+
#include "abc_transform.h"
#include "abc_util.h"
@@ -39,6 +41,8 @@ using Alembic::AbcGeom::OCurvesSchema;
using Alembic::AbcGeom::ON3fGeomParam;
using Alembic::AbcGeom::OV2fGeomParam;
+static const float nscale = 1.0f / 32767.0f;
+
AbcHairWriter::AbcHairWriter(Scene *sce,
Object *obj,
AbcTransformWriter *parent,
@@ -77,177 +81,214 @@ void AbcHairWriter::do_write()
return;
}
- Object *ob = m_object;
-
- ParticleData * pa; int p, k;
- ParticleCacheKey **cache, *path;
+ DerivedMesh *dm = mesh_create_derived_view(m_scene, m_object, CD_MASK_MESH);
+ DM_ensure_tessface(dm);
+ DM_update_tessface_data(dm);
- /* Get untransformed vertices, there's a xform under the hair. */
- float inv_mat[4][4];
- invert_m4_m4_safe(inv_mat, ob->obmat);
+ std::vector<Imath::V3f> verts;
+ std::vector<int32_t> hvertices;
+ std::vector<Imath::V2f> uv_values;
+ std::vector<Imath::V3f> norm_values;
ParticleSettings *part = m_psys->part;
- DerivedMesh *dm = mesh_create_derived_view(m_scene, m_object, CD_MASK_MESH);
- DM_ensure_tessface(dm);
- DM_update_tessface_data(dm);
+ if (part->type == PART_HAIR && m_psys->pathcache) {
+ write_hair_sample(dm, part, verts, norm_values, uv_values, hvertices);
+
+ if (m_options.export_child_hairs && m_psys->childcache) {
+ write_hair_child_sample(dm, part, verts, norm_values, uv_values, hvertices);
+ }
+ }
+
+ dm->release(dm);
+
+ Alembic::Abc::P3fArraySample iPos(verts);
+ m_curves_schema_sample = OCurvesSchema::Sample(iPos, hvertices);
+
+ if (!uv_values.empty()) {
+ OV2fGeomParam::Sample uv_smp;
+ uv_smp.setVals(uv_values);
+ m_curves_schema_sample.setUVs(uv_smp);
+ }
+
+ if (!norm_values.empty()) {
+ ON3fGeomParam::Sample norm_smp;
+ norm_smp.setVals(norm_values);
+ m_curves_schema_sample.setNormals(norm_smp);
+ }
+
+ m_curves_schema_sample.setSelfBounds(bounds());
+ m_curves_schema.set(m_curves_schema_sample);
+}
+
+void AbcHairWriter::write_hair_sample(DerivedMesh *dm,
+ ParticleSettings *part,
+ std::vector<Imath::V3f> &verts,
+ std::vector<Imath::V3f> &norm_values,
+ std::vector<Imath::V2f> &uv_values,
+ std::vector<int32_t> &hvertices)
+{
+ /* Get untransformed vertices, there's a xform under the hair. */
+ float inv_mat[4][4];
+ invert_m4_m4_safe(inv_mat, m_object->obmat);
MTFace *mtface = static_cast<MTFace *>(CustomData_get_layer(&dm->faceData, CD_MTFACE));
MFace *mface = dm->getTessFaceArray(dm);
MVert *mverts = dm->getVertArray(dm);
if (!mtface || !mface) {
- printf("Warning, no UV set found for underlying geometry\n");
+ std::fprintf(stderr, "Warning, no UV set found for underlying geometry.\n");
}
- std::vector<Imath::V3f> verts;
- std::vector<int32_t> hvertices;
- std::vector<Imath::V2f> uv_values;
- std::vector<Imath::V3f> norm_values;
+ ParticleData * pa = m_psys->particles;
+ int k;
- const float nscale = 1.0f / 32767.0f;
+ ParticleCacheKey **cache = m_psys->pathcache;
+ ParticleCacheKey *path;
- if (part->type == PART_HAIR && m_psys->pathcache) {
- cache = m_psys->pathcache;
+ for (int p = 0; p < m_psys->totpart; ++p, ++pa) {
+ /* underlying info for faces-only emission */
+ path = cache[p];
- for (p = 0, pa = m_psys->particles; p < m_psys->totpart; p++, pa++) {
- /* We want underlying info for faces only emission */
- path = cache[p];
+ if (part->from == PART_FROM_FACE && mtface) {
+ float r_uv[2];
+ float tmpnor[3], mapfw[4], vec[3];
+ int num = pa->num_dmcache >= 0 ? pa->num_dmcache : pa->num;
- if (part->from == PART_FROM_FACE && mtface) {
- float r_uv[2];
- float tmpnor[3], mapfw[4], vec[3];
- int num = pa->num_dmcache >= 0 ? pa->num_dmcache : pa->num;
+ if (num < dm->getNumTessFaces(dm)) {
+ MFace *face = (MFace*)dm->getTessFaceData(dm, num, CD_MFACE);
+ MTFace *tface = mtface + num;
- if (num < dm->getNumTessFaces(dm)) {
- MFace *face = (MFace*)dm->getTessFaceData(dm, num, CD_MFACE);
- MTFace *tface = mtface + num;
+ if (mface) {
+ psys_interpolate_uvs(tface, face->v4, pa->fuv, r_uv);
+ uv_values.push_back(Imath::V2f(r_uv[0], r_uv[1]));
- if (mface) {
- psys_interpolate_uvs(tface, face->v4, pa->fuv, r_uv);
- uv_values.push_back(Imath::V2f(r_uv[0], r_uv[1]));
+ psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL, NULL);
- psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL, NULL);
- norm_values.push_back(Imath::V3f(tmpnor[0],tmpnor[2], -tmpnor[1]));
+ if (m_options.do_convert_axis) {
+ mul_m3_v3(m_options.convert_matrix, tmpnor);
}
+
+ norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[1], tmpnor[2]));
}
- else {
- printf("Particle to faces overflow (%d/%d)\n", num, dm->getNumTessFaces(dm));
- }
}
- else if (part->from == 0 && mtface) {
- /* num is the DM's vertex id */
- const int num = (pa->num_dmcache >= 0) ? pa->num_dmcache : pa->num;
-
- /* We will iterate over all faces to find a corresponding underlying UV */
- for (int n = 0; n < dm->getNumTessFaces(dm); ++n) {
- MFace * face = (MFace*)dm->getTessFaceData(dm, n, CD_MFACE);
- MTFace *tface = mtface + n;
- unsigned int vtx[4];
- vtx[0] = face->v1;
- vtx[1] = face->v2;
- vtx[2] = face->v3;
- vtx[3] = face->v4;
- bool found = false;
- for (int o = 0; o < 4; ++o) {
- if (o > 2 && vtx[o] == 0) {
- break;
- }
-
- if (vtx[o] == num) {
- uv_values.push_back(Imath::V2f(tface->uv[o][0], tface->uv[o][1]));
- MVert *mv = mverts + vtx[o];
- norm_values.push_back(Imath::V3f(mv->no[0] * nscale,
- mv->no[1] * nscale, mv->no[2] * nscale));
- found = true;
- break;
- }
+ else {
+ std::fprintf(stderr, "Particle to faces overflow (%d/%d)\n", num, dm->getNumTessFaces(dm));
+ }
+ }
+ else if (part->from == PART_FROM_VERT && mtface) {
+ /* vertex id */
+ const int num = (pa->num_dmcache >= 0) ? pa->num_dmcache : pa->num;
+
+ /* iterate over all faces to find a corresponding underlying UV */
+ for (int n = 0; n < dm->getNumTessFaces(dm); ++n) {
+ MFace *face = (MFace*)dm->getTessFaceData(dm, n, CD_MFACE);
+ MTFace *tface = mtface + n;
+ unsigned int vtx[4];
+ vtx[0] = face->v1;
+ vtx[1] = face->v2;
+ vtx[2] = face->v3;
+ vtx[3] = face->v4;
+ bool found = false;
+
+ for (int o = 0; o < 4; ++o) {
+ if (o > 2 && vtx[o] == 0) {
+ break;
}
- if (found) {
+ if (vtx[o] == num) {
+ uv_values.push_back(Imath::V2f(tface->uv[o][0], tface->uv[o][1]));
+ MVert *mv = mverts + vtx[o];
+ norm_values.push_back(Imath::V3f(mv->no[0] * nscale,
+ mv->no[1] * nscale, mv->no[2] * nscale));
+ found = true;
break;
}
}
+
+ if (found) {
+ break;
+ }
}
+ }
- int steps = path->segments + 1;
- hvertices.push_back(steps);
+ int steps = path->segments + 1;
+ hvertices.push_back(steps);
- for (k = 0; k < steps; ++k) {
- float vert[3];
- copy_v3_v3(vert, path->co);
- mul_m4_v3(inv_mat, vert);
+ for (k = 0; k < steps; ++k) {
+ float vert[3];
+ copy_v3_v3(vert, path->co);
+ mul_m4_v3(inv_mat, vert);
- if (m_options.do_convert_axis) {
- mul_m3_v3(m_options.convert_matrix, vert);
- }
+ if (m_options.do_convert_axis) {
+ mul_m3_v3(m_options.convert_matrix, vert);
+ }
- verts.push_back(Imath::V3f(vert[0], vert[1], vert[2]));
+ verts.push_back(Imath::V3f(vert[0], vert[1], vert[2]));
- ++path;
- }
+ ++path;
}
+ }
+}
- if (m_options.export_child_hairs && m_psys->childcache) {
- /* Children part */
- cache = m_psys->childcache;
- ChildParticle *pc;
- for (p = 0, pc = m_psys->child; p < m_psys->totchild; p++, pc++) {
- path = cache[p];
+void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm,
+ ParticleSettings *part,
+ std::vector<Imath::V3f> &verts,
+ std::vector<Imath::V3f> &norm_values,
+ std::vector<Imath::V2f> &uv_values,
+ std::vector<int32_t> &hvertices)
+{
+ /* Get untransformed vertices, there's a xform under the hair. */
+ float inv_mat[4][4];
+ invert_m4_m4_safe(inv_mat, m_object->obmat);
- if (part->from == PART_FROM_FACE) {
- float r_uv[2];
- float tmpnor[3], mapfw[4], vec[3];
- int num = pc->num;
+ MTFace *mtface = static_cast<MTFace *>(CustomData_get_layer(&dm->faceData, CD_MTFACE));
+ MFace *mface = dm->getTessFaceArray(dm);
+ MVert *mverts = dm->getVertArray(dm);
- MFace *face = (MFace *)dm->getTessFaceData(dm, num, CD_MFACE);
- MTFace *tface = mtface + num;
+ if (!mtface || !mface) {
+ std::fprintf(stderr, "Warning, no UV set found for underlying geometry.\n");
+ }
- if (mface && mtface) {
- psys_interpolate_uvs(tface, face->v4, pc->fuv, r_uv);
- uv_values.push_back(Imath::V2f(r_uv[0], r_uv[1]));
+ ParticleCacheKey **cache = m_psys->childcache;
+ ParticleCacheKey *path;
- psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL, NULL);
+ ChildParticle *pc = m_psys->child;
- if (m_options.do_convert_axis) {
- mul_m3_v3(m_options.convert_matrix, tmpnor);
- }
+ for (int p = 0; p < m_psys->totchild; ++p, ++pc) {
+ path = cache[p];
- norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[1], tmpnor[2]));
- }
- }
+ if (part->from == PART_FROM_FACE) {
+ float r_uv[2];
+ float tmpnor[3], mapfw[4], vec[3];
+ int num = pc->num;
+
+ MFace *face = (MF
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list