[Bf-blender-cvs] [c7f135f] alembic_basic_io: Split curves reader/writer in a separate file.
Kévin Dietrich
noreply at git.blender.org
Thu Jun 23 21:18:26 CEST 2016
Commit: c7f135ffbc857a4b3ef8cde7ff3f0d4329cf930d
Author: Kévin Dietrich
Date: Thu Jun 23 18:39:17 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rBc7f135ffbc857a4b3ef8cde7ff3f0d4329cf930d
Split curves reader/writer in a separate file.
===================================================================
M source/blender/alembic/CMakeLists.txt
A source/blender/alembic/intern/abc_curves.cc
A source/blender/alembic/intern/abc_curves.h
M source/blender/alembic/intern/abc_exporter.cc
M source/blender/alembic/intern/abc_hair.cc
M source/blender/alembic/intern/abc_hair.h
M source/blender/alembic/intern/alembic_capi.cc
===================================================================
diff --git a/source/blender/alembic/CMakeLists.txt b/source/blender/alembic/CMakeLists.txt
index 58f4366..03a6f50 100644
--- a/source/blender/alembic/CMakeLists.txt
+++ b/source/blender/alembic/CMakeLists.txt
@@ -44,6 +44,7 @@ set(INC_SYS
set(SRC
intern/abc_camera.cc
intern/abc_customdata.cc
+ intern/abc_curves.cc
intern/abc_exporter.cc
intern/abc_export_options.cc
intern/abc_hair.cc
@@ -58,6 +59,7 @@ set(SRC
ABC_alembic.h
intern/abc_camera.h
intern/abc_customdata.h
+ intern/abc_curves.h
intern/abc_exporter.h
intern/abc_export_options.h
intern/abc_hair.h
diff --git a/source/blender/alembic/intern/abc_curves.cc b/source/blender/alembic/intern/abc_curves.cc
new file mode 100644
index 0000000..09b75ed
--- /dev/null
+++ b/source/blender/alembic/intern/abc_curves.cc
@@ -0,0 +1,211 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Kévin Dietrich.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+#include "abc_curves.h"
+
+#include <cstdio>
+
+#include "abc_transform.h"
+#include "abc_util.h"
+
+extern "C" {
+#include "MEM_guardedalloc.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_object_types.h"
+
+#include "BLI_listbase.h"
+
+#include "BKE_curve.h"
+#include "BKE_object.h"
+
+#include "ED_curve.h"
+}
+
+using Alembic::Abc::IInt32ArrayProperty;
+using Alembic::Abc::Int32ArraySamplePtr;
+using Alembic::Abc::P3fArraySamplePtr;
+
+using Alembic::AbcGeom::ICurves;
+using Alembic::AbcGeom::ICurvesSchema;
+using Alembic::AbcGeom::ISampleSelector;
+using Alembic::AbcGeom::kWrapExisting;
+
+using Alembic::AbcGeom::OCurves;
+using Alembic::AbcGeom::OCurvesSchema;
+using Alembic::AbcGeom::ON3fGeomParam;
+using Alembic::AbcGeom::OV2fGeomParam;
+
+/* ************************************************************************** */
+
+AbcCurveWriter::AbcCurveWriter(Scene *scene,
+ Object *ob,
+ AbcTransformWriter *parent,
+ uint32_t time_sampling,
+ ExportSettings &settings)
+ : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+{
+ OCurves curves(parent->alembicXform(), m_name, m_time_sampling);
+ m_schema = curves.getSchema();
+}
+
+void AbcCurveWriter::do_write()
+{
+ Curve *curve = static_cast<Curve *>(m_object->data);
+
+ std::vector<Imath::V3f> verts;
+ std::vector<int32_t> vert_counts;
+ std::vector<float> widths;
+ Imath::V3f temp_vert;
+
+ Alembic::AbcGeom::BasisType curve_basis;
+ Alembic::AbcGeom::CurveType curve_type;
+ Alembic::AbcGeom::CurvePeriodicity periodicity;
+
+ Nurb *nurbs = static_cast<Nurb *>(curve->nurb.first);
+ for (; nurbs; nurbs = nurbs->next) {
+ if ((nurbs->flagu & CU_NURB_ENDPOINT) != 0) {
+ periodicity = Alembic::AbcGeom::kNonPeriodic;
+ }
+ else if ((nurbs->flagu & CU_NURB_CYCLIC) != 0) {
+ periodicity = Alembic::AbcGeom::kPeriodic;
+ }
+
+ if (nurbs->bp) {
+ curve_basis = Alembic::AbcGeom::kNoBasis;
+ curve_type = Alembic::AbcGeom::kLinear;
+
+ const int totpoint = nurbs->pntsu * nurbs->pntsv;
+ vert_counts.push_back(totpoint);
+
+ const BPoint *point = nurbs->bp;
+
+ for (int i = 0; i < totpoint; ++i, ++point) {
+ copy_zup_yup(temp_vert.getValue(), point->vec);
+ verts.push_back(temp_vert);
+ widths.push_back(point->radius);
+ }
+ }
+ else if (nurbs->bezt) {
+ curve_basis = Alembic::AbcGeom::kBezierBasis;
+ curve_type = Alembic::AbcGeom::kCubic;
+
+ const int totpoint = nurbs->pntsu;
+ vert_counts.push_back(totpoint);
+
+ const BezTriple *bezier = nurbs->bezt;
+
+ /* TODO: how does Alembic store info about handles, if applicable? */
+ for (int i = 0; i < totpoint; ++i, ++bezier) {
+ copy_zup_yup(temp_vert.getValue(), bezier->vec[1]);
+ verts.push_back(temp_vert);
+ }
+ }
+ }
+
+ Alembic::Abc::P3fArraySample pos(verts);
+ m_sample = OCurvesSchema::Sample(pos, vert_counts);
+ m_sample.setBasis(curve_basis);
+ m_sample.setType(curve_type);
+ m_sample.setWrap(periodicity);
+
+ if (!widths.empty()) {
+ Alembic::AbcGeom::OFloatGeomParam::Sample width_sample;
+ width_sample.setVals(widths);
+
+ m_sample.setWidths(width_sample);
+ }
+
+ m_sample.setSelfBounds(bounds());
+ m_schema.set(m_sample);
+}
+
+/* ************************************************************************** */
+
+AbcCurveReader::AbcCurveReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
+ : AbcObjectReader(object, settings)
+{
+ ICurves abc_curves(object, kWrapExisting);
+ m_curves_schema = abc_curves.getSchema();
+
+ get_min_max_time(m_curves_schema, m_min_time, m_max_time);
+}
+
+bool AbcCurveReader::valid() const
+{
+ return m_curves_schema.valid();
+}
+
+void AbcCurveReader::readObjectData(Main *bmain, Scene *scene, float time)
+{
+ Curve *cu = BKE_curve_add(bmain, m_data_name.c_str(), OB_CURVE);
+ cu->flag |= CU_PATH | CU_3D;
+
+ const ISampleSelector sample_sel(time);
+
+ const ICurvesSchema::Sample smp = m_curves_schema.getValue(sample_sel);
+ const Int32ArraySamplePtr hvertices = smp.getCurvesNumVertices();
+ const P3fArraySamplePtr positions = smp.getPositions();
+
+ m_object = BKE_object_add(bmain, scene, OB_CURVE, m_object_name.c_str());
+ m_object->data = cu;
+
+ size_t idx = 0;
+ for (size_t i = 0; i < hvertices->size(); ++i) {
+ const int steps = (*hvertices)[i];
+
+ Nurb *nu = static_cast<Nurb *>(MEM_callocN(sizeof(Nurb), "abc_getnurb"));
+ nu->bp = static_cast<BPoint *>(MEM_callocN(sizeof(BPoint) * steps, "abc_getnurb"));
+ nu->type = CU_NURBS;
+ nu->resolu = cu->resolu;
+ nu->resolv = cu->resolv;
+ nu->pntsu = steps;
+ nu->pntsv = 1;
+ nu->orderu = steps;
+ nu->flagu = CU_NURB_ENDPOINT;
+ nu->flagv = CU_NURB_ENDPOINT;
+
+ BPoint *bp = nu->bp;
+
+ for (int j = 0; j < steps; ++j, ++bp) {
+ Imath::V3f pos = (*positions)[idx++];
+
+ copy_yup_zup(bp->vec, pos.getValue());
+ bp->vec[3] = 1.0;
+
+ bp->radius = bp->weight = 1.0;
+ }
+
+ nu->flag |= CU_SMOOTH;
+
+ BLI_addtail(&cu->nurb, nu);
+ }
+
+ cu->actnu = hvertices->size();
+ cu->actvert = CU_ACT_NONE;
+
+ if (m_settings->is_sequence || !m_curves_schema.isConstant()) {
+ addDefaultModifier(bmain);
+ }
+}
diff --git a/source/blender/alembic/intern/abc_hair.h b/source/blender/alembic/intern/abc_curves.h
similarity index 52%
copy from source/blender/alembic/intern/abc_hair.h
copy to source/blender/alembic/intern/abc_curves.h
index 5b160d9..8c754db 100644
--- a/source/blender/alembic/intern/abc_hair.h
+++ b/source/blender/alembic/intern/abc_curves.h
@@ -12,56 +12,20 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
+ * along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * Contributor(s): Esteban Tovagliari, Cedric Paille, Kevin Dietrich
+ * The Original Code is Copyright (C) 2016 Kévin Dietrich.
+ * All rights reserved.
*
* ***** END GPL LICENSE BLOCK *****
+ *
*/
#pragma once
#include "abc_object.h"
-struct DerivedMesh;
-struct ParticleSettings;
-struct ParticleSystem;
-
-/* ************************************************************************** */
-
-class AbcHairWriter : public AbcObjectWriter {
- ParticleSystem *m_psys;
-
- Alembic::AbcGeom::OCurvesSchema m_schema;
- Alembic::AbcGeom::OCurvesSchema::Sample m_sample;
-
-public:
- AbcHairWriter(Scene *scene,
- Object *ob,
- AbcTransformWriter *parent,
- uint32_t time_sampling,
- ExportSettings &settings,
- ParticleSystem *psys);
-
-private:
- virtual void do_write();
-
- void 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);
-
- void 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);
-};
-
/* ************************************************************************** */
class AbcCurveWriter : public AbcObjectWriter {
diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc
index 201cb2e..253e752 100644
--- a/source/blender/alembic/intern/abc_exporter.cc
+++ b/source/blender/alembic/intern/abc_exporter.cc
@@ -28,6 +28,7 @@
#include <Alembic/AbcCoreOgawa/All.h>
#include "abc_camera.h"
+#include "abc_curves.h"
#include "abc_hair.h"
#include "abc_mesh.h"
#include "abc_nurbs.h"
diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc
index f5053d6..7e2b63b 100644
--- a/source/blender/alembic/intern/abc_hair.cc
+++ b/source/blender/alembic/intern/abc_hair.cc
@@ -30,29 +30,18 @@
extern "C" {
#include "MEM_guardedalloc.h"
-#include "DNA_curve_types.h"
#include "DNA_modifier_types.h"
#include "BLI_listbase.h"
#include "BLI_math_geom.h"
-#include "BKE_curve.h"
#include "BKE_DerivedMesh.h"
#incl
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list