[Bf-blender-cvs] [6382dbf] alembic_basic_io: Initial support to import hair systems.

Kévin Dietrich noreply at git.blender.org
Thu May 26 17:29:56 CEST 2016


Commit: 6382dbfb5ab27b6f7990a40d1c3f28de42116e60
Author: Kévin Dietrich
Date:   Thu May 26 17:27:41 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB6382dbfb5ab27b6f7990a40d1c3f28de42116e60

Initial support to import hair systems.

For the time being, hair are read as curves since this is how alembic
stores them. And since there is no real way to know if an ICurves object
exported from another software is a hair system or not, it will probably
stay like so.

===================================================================

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/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc
index b830b7c..acaa21a 100644
--- a/source/blender/alembic/intern/abc_hair.cc
+++ b/source/blender/alembic/intern/abc_hair.cc
@@ -28,14 +28,31 @@
 #include "abc_util.h"
 
 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"
+#include "BKE_object.h"
 #include "BKE_particle.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;
@@ -280,3 +297,73 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm,
 		}
 	}
 }
+
+AbcHairReader::AbcHairReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
+    : AbcObjectReader(object, settings)
+{
+	ICurves abc_curves(object, kWrapExisting);
+	m_curves_schema = abc_curves.getSchema();
+}
+
+bool AbcHairReader::valid() const
+{
+	return m_curves_schema.valid();
+}
+
+void AbcHairReader::readObjectData(Main *bmain, Scene *scene, float time)
+{
+	Curve *cu = BKE_curve_add(bmain, "abc_hair", OB_CURVE);
+	cu->editnurb = (EditNurb *)MEM_callocN(sizeof(EditNurb), "editnurb");
+	cu->flag |= CU_DEFORM_FILL | 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;
+
+	ListBase *editnurb = object_editcurve_get(m_object);
+
+	size_t idx = 0;
+	for (size_t i = 0; i < hvertices->size(); ++i) {
+		const int steps = (*hvertices)[i];
+
+		Nurb *nu = (Nurb *)MEM_callocN(sizeof(Nurb), "abc_getnurb");
+		nu->bp = (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; /* endpoint */
+
+		BPoint *bp = nu->bp;
+
+		for (int j = 0; j < steps; ++j, ++bp) {
+			Imath::V3f pos = (*positions)[idx++];
+
+			/* Convert Y-up to Z-up. */
+			bp->vec[0] = pos.x;
+			bp->vec[1] = -pos.z;
+			bp->vec[2] = pos.y;
+			bp->vec[3] = 1.0;
+
+	//		bp->f1 = SELECT;
+			bp->radius = bp->weight = 1.0;
+		}
+
+		nu->knotsu = NULL; /* nurbs_knot_calc_u allocates */
+		BKE_nurb_knot_calc_u(nu);
+
+		nu->flag |= CU_SMOOTH;
+
+		BLI_addtail(editnurb, nu);
+	}
+
+	cu->actnu = hvertices->size() - 1;
+	cu->actvert = CU_ACT_NONE;
+}
diff --git a/source/blender/alembic/intern/abc_hair.h b/source/blender/alembic/intern/abc_hair.h
index 080615c..68ad644 100644
--- a/source/blender/alembic/intern/abc_hair.h
+++ b/source/blender/alembic/intern/abc_hair.h
@@ -23,6 +23,7 @@
 #ifndef __ABC_HAIR_WRITER_H__
 #define __ABC_HAIR_WRITER_H__
 
+#include "abc_object.h"
 #include "abc_shape.h"
 
 struct CustomDataLayer;
@@ -66,4 +67,15 @@ private:
                                  std::vector<int32_t> &hvertices);
 };
 
+class AbcHairReader : public AbcObjectReader {
+	Alembic::AbcGeom::ICurvesSchema m_curves_schema;
+
+public:
+	AbcHairReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
+
+	bool valid() const;
+
+	void readObjectData(Main *bmain, Scene *scene, float time);
+};
+
 #endif  /* __ABC_HAIR_WRITER_H__ */
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 748d733..c9fa39b 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -28,6 +28,7 @@
 
 #include "abc_exporter.h"
 #include "abc_camera.h"
+#include "abc_hair.h"
 #include "abc_mesh.h"
 #include "abc_nurbs.h"
 #include "abc_util.h"
@@ -402,7 +403,7 @@ static void visit_object(const IObject &object,
 			/* Pass, those are handled in the mesh reader. */
 		}
 		else if (ICurves::matches(md)) {
-			/* Pass for now. */
+			reader = new AbcHairReader(child, settings);
 		}
 		else {
 			assert(false);




More information about the Bf-blender-cvs mailing list