[Bf-blender-cvs] [9f9d0ea] alembic_basic_io: Add support to export particles.

Kévin Dietrich noreply at git.blender.org
Tue May 31 01:51:13 CEST 2016


Commit: 9f9d0eae6f5d12fb2128af9737ec130fb6b6e4cb
Author: Kévin Dietrich
Date:   Tue May 31 01:19:03 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB9f9d0eae6f5d12fb2128af9737ec130fb6b6e4cb

Add support to export particles.

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

M	source/blender/alembic/CMakeLists.txt
M	source/blender/alembic/intern/abc_exporter.cc
A	source/blender/alembic/intern/abc_points.cc
A	source/blender/alembic/intern/abc_points.h

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

diff --git a/source/blender/alembic/CMakeLists.txt b/source/blender/alembic/CMakeLists.txt
index b7843a0..59264c7 100644
--- a/source/blender/alembic/CMakeLists.txt
+++ b/source/blender/alembic/CMakeLists.txt
@@ -53,6 +53,7 @@ set(SRC
 	intern/abc_mesh.cc
 	intern/abc_nurbs.cc
 	intern/abc_object.cc
+	intern/abc_points.cc
 	intern/abc_shape.cc
 	intern/abc_transform.cc
 	intern/abc_util.cc
@@ -66,6 +67,7 @@ set(SRC
 	intern/abc_mesh.h
 	intern/abc_nurbs.h
 	intern/abc_object.h
+	intern/abc_points.h
 	intern/abc_shape.h
 	intern/abc_transform.h
 	intern/abc_util.h
diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc
index 07a2aea..75ac85e 100644
--- a/source/blender/alembic/intern/abc_exporter.cc
+++ b/source/blender/alembic/intern/abc_exporter.cc
@@ -28,9 +28,10 @@
 #include <Alembic/AbcCoreOgawa/All.h>
 
 #include "abc_camera.h"
+#include "abc_hair.h"
 #include "abc_mesh.h"
 #include "abc_nurbs.h"
-#include "abc_hair.h"
+#include "abc_points.h"
 #include "abc_util.h"
 
 extern "C" {
@@ -453,10 +454,13 @@ void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
 		if (!psys_check_enabled(ob, psys))
 			continue;
 
-		if (enable_hair && psys->part && (psys->part->type == PART_HAIR)) {
+		if ((psys->part->type == PART_HAIR) && enable_hair && psys->part) {
 			m_settings.export_child_hairs = enable_hair_child;
 			m_shapes.push_back(new AbcHairWriter(m_scene, ob, xform, m_shape_sampling_index, m_settings, psys));
 		}
+		else if (psys->part->type == PART_EMITTER) {
+			m_shapes.push_back(new AbcPointsWriter(m_scene, ob, xform, m_shape_sampling_index, m_settings, psys));
+		}
 	}
 
 	switch(ob->type) {
diff --git a/source/blender/alembic/intern/abc_points.cc b/source/blender/alembic/intern/abc_points.cc
new file mode 100644
index 0000000..b47fcb6
--- /dev/null
+++ b/source/blender/alembic/intern/abc_points.cc
@@ -0,0 +1,120 @@
+/*
+ * ***** 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_points.h"
+
+#include <Alembic/Abc/All.h>
+
+#include "abc_transform.h"
+
+extern "C" {
+#include "BKE_lattice.h"
+#include "BKE_particle.h"
+#include "BKE_scene.h"
+
+#include "BLI_math.h"
+}
+
+using Alembic::AbcGeom::kVertexScope;
+
+using Alembic::AbcGeom::OPoints;
+using Alembic::AbcGeom::OPointsSchema;
+
+AbcPointsWriter::AbcPointsWriter(Scene *scene,
+                                 Object *ob,
+	                             AbcTransformWriter *parent,
+	                             uint32_t timeSampling,
+	                             ExportSettings &settings,
+	                             ParticleSystem *psys)
+    : AbcShapeWriter(scene, ob, parent, timeSampling, settings)
+{
+	m_psys = psys;
+
+	OPoints points(parent->alembicXform(), m_name, m_time_sampling);
+	m_schema = points.getSchema();
+}
+
+void AbcPointsWriter::do_write()
+{
+	if (!m_psys) {
+		return;
+	}
+
+	std::vector<Imath::V3f> points;
+	std::vector<Imath::V3f> velocities;
+	std::vector<float> widths;
+	std::vector<uint64_t> ids;
+
+	ParticleKey state;
+
+	ParticleSimulationData sim;
+	sim.scene = m_scene;
+	sim.ob = m_object;
+	sim.psys = m_psys;
+
+	m_psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
+
+	uint64_t index = 0;
+	for (int p = 0; p < m_psys->totpart; p++) {
+		float pos[3], vel[3];
+
+		if (m_psys->particles[p].flag & (PARS_NO_DISP | PARS_UNEXIST)) {
+			continue;
+		}
+
+		state.time = BKE_scene_frame_get(m_scene);
+
+		if (psys_get_particle_state(&sim, p, &state, 0) == 0) {
+			continue;
+		}
+
+		/* location */
+		mul_v3_m4v3(pos, m_object->imat, state.co);
+
+		/* velocity */
+		sub_v3_v3v3(vel, state.co, m_psys->particles[p].prev_state.co);
+
+		/* Convert Z-up to Y-up. */
+		points.push_back(Imath::V3f(pos[0], pos[2], -pos[1]));
+		velocities.push_back(Imath::V3f(vel[0], vel[2], -vel[1]));
+		widths.push_back(m_psys->particles[p].size);
+		ids.push_back(index++);
+	}
+
+	if (m_psys->lattice_deform_data) {
+		end_latt_deform(m_psys->lattice_deform_data);
+		m_psys->lattice_deform_data = NULL;
+	}
+
+	Alembic::Abc::P3fArraySample psample(points);
+	Alembic::Abc::UInt64ArraySample idsample(ids);
+	Alembic::Abc::V3fArraySample vsample(velocities);
+	Alembic::Abc::FloatArraySample wsample_array(widths);
+	Alembic::AbcGeom::OFloatGeomParam::Sample wsample(wsample_array, kVertexScope);
+
+	m_sample = OPointsSchema::Sample(psample, idsample, vsample, wsample);
+	m_sample.setSelfBounds(bounds());
+
+	m_schema.set(m_sample);
+}
diff --git a/source/blender/alembic/intern/abc_points.h b/source/blender/alembic/intern/abc_points.h
new file mode 100644
index 0000000..ad8a49f
--- /dev/null
+++ b/source/blender/alembic/intern/abc_points.h
@@ -0,0 +1,45 @@
+/*
+ * ***** 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 *****
+ *
+ */
+
+#pragma once
+
+#include "abc_shape.h"
+
+class ParticleSystem;
+
+class AbcPointsWriter : public AbcShapeWriter {
+	Alembic::AbcGeom::OPointsSchema m_schema;
+	Alembic::AbcGeom::OPointsSchema::Sample m_sample;
+	ParticleSystem *m_psys;
+
+public:
+	AbcPointsWriter(Scene *scene,
+	                Object *ob,
+                    AbcTransformWriter *parent,
+                    uint32_t timeSampling,
+                    ExportSettings &settings,
+                    ParticleSystem *psys);
+
+	void do_write();
+};




More information about the Bf-blender-cvs mailing list