[Bf-blender-cvs] [c5d6b049864] temp-alembic-exporter-T73363-ms2: Alembic: added Curve writing to new Alembic exporter

Sybren A. Stüvel noreply at git.blender.org
Tue Apr 28 11:51:07 CEST 2020


Commit: c5d6b0498644ce64cd653bbb45ef3db0cef8c78e
Author: Sybren A. Stüvel
Date:   Fri Apr 24 13:46:20 2020 +0200
Branches: temp-alembic-exporter-T73363-ms2
https://developer.blender.org/rBc5d6b0498644ce64cd653bbb45ef3db0cef8c78e

Alembic: added Curve writing to new Alembic exporter

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

M	source/blender/io/alembic/CMakeLists.txt
M	source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
A	source/blender/io/alembic/intern/export/abc_writer_curve.cc
A	source/blender/io/alembic/intern/export/abc_writer_curve.h

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

diff --git a/source/blender/io/alembic/CMakeLists.txt b/source/blender/io/alembic/CMakeLists.txt
index 61ba4c4b009..4757825dd5d 100644
--- a/source/blender/io/alembic/CMakeLists.txt
+++ b/source/blender/io/alembic/CMakeLists.txt
@@ -97,6 +97,7 @@ set(SRC
   intern/export/abc_subdiv_disabler.cc
   intern/export/abc_writer_abstract.cc
   intern/export/abc_writer_camera.cc
+  intern/export/abc_writer_curve.cc
   intern/export/abc_writer_mesh.cc
   intern/export/abc_writer_metaball.cc
   intern/export/abc_writer_transform.cc
@@ -106,6 +107,7 @@ set(SRC
   intern/export/abc_subdiv_disabler.h
   intern/export/abc_writer_abstract.h
   intern/export/abc_writer_camera.h
+  intern/export/abc_writer_curve.h
   intern/export/abc_writer_mesh.h
   intern/export/abc_writer_metaball.h
   intern/export/abc_writer_transform.h
diff --git a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
index 087d9995cfd..c2e5df1ac7d 100644
--- a/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
+++ b/source/blender/io/alembic/intern/export/abc_hierarchy_iterator.cc
@@ -20,8 +20,7 @@
 #include "abc_hierarchy_iterator.h"
 #include "abc_writer_abstract.h"
 #include "abc_writer_camera.h"
-// #include "abc_writer_hair.h"
-// #include "abc_writer_light.h"
+#include "abc_writer_curve.h"
 #include "abc_writer_mesh.h"
 #include "abc_writer_metaball.h"
 #include "abc_writer_transform.h"
@@ -124,16 +123,20 @@ AbstractHierarchyWriter *ABCHierarchyIterator::create_data_writer(const Hierarch
     case OB_CAMERA:
       data_writer = new ABCCameraWriter(writer_args);
       break;
-    case OB_LAMP:
-      // data_writer = new ABCLightWriter(writer_args);
-      return nullptr;
+    case OB_CURVE:
+      if (params_.curves_as_mesh) {
+        data_writer = new ABCCurveMeshWriter(writer_args);
+      }
+      else {
+        data_writer = new ABCCurveWriter(writer_args);
+      }
       break;
     case OB_MBALL:
       data_writer = new ABCMetaballWriter(writer_args);
       break;
 
     case OB_EMPTY:
-    case OB_CURVE:
+    case OB_LAMP:
     case OB_SURF:
     case OB_FONT:
     case OB_SPEAKER:
diff --git a/source/blender/io/alembic/intern/export/abc_writer_curve.cc b/source/blender/io/alembic/intern/export/abc_writer_curve.cc
new file mode 100644
index 00000000000..9abc10efd31
--- /dev/null
+++ b/source/blender/io/alembic/intern/export/abc_writer_curve.cc
@@ -0,0 +1,198 @@
+/*
+ * 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 & 2020 Blender Foundation.
+ * All rights reserved.
+ */
+
+#include "abc_writer_curve.h"
+#include "intern/abc_axis_conversion.h"
+
+extern "C" {
+#include "DNA_curve_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_curve.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+}
+
+#include "CLG_log.h"
+static CLG_LogRef LOG = {"io.alembic"};
+
+using Alembic::AbcGeom::OCompoundProperty;
+using Alembic::AbcGeom::OCurves;
+using Alembic::AbcGeom::OCurvesSchema;
+using Alembic::AbcGeom::OInt16Property;
+using Alembic::AbcGeom::ON3fGeomParam;
+using Alembic::AbcGeom::OV2fGeomParam;
+
+namespace ABC {
+
+const std::string ABC_CURVE_RESOLUTION_U_PROPNAME("blender:resolution");
+
+ABCCurveWriter::ABCCurveWriter(const ABCWriterConstructorArgs &args) : ABCAbstractWriter(args)
+{
+}
+
+void ABCCurveWriter::create_alembic_objects()
+{
+  /* If the object is static, use the default static time sampling. */
+  uint32_t timesample_index = is_animated_ ? timesample_index_geometry_ : 0;
+
+  CLOG_INFO(&LOG, 2, "exporting %s", args_.abc_path.c_str());
+  abc_curve_ = OCurves(args_.abc_parent, args_.abc_name, timesample_index);
+  abc_curve_schema_ = abc_curve_.getSchema();
+
+  Curve *cu = static_cast<Curve *>(args_.object->data);
+  OCompoundProperty user_props = abc_curve_schema_.getUserProperties();
+  OInt16Property user_prop_resolu(user_props, ABC_CURVE_RESOLUTION_U_PROPNAME);
+  user_prop_resolu.set(cu->resolu);
+}
+
+const Alembic::Abc::OObject ABCCurveWriter::get_alembic_object() const
+{
+  return abc_curve_;
+}
+
+void ABCCurveWriter::do_write(HierarchyContext &context)
+{
+  Curve *curve = static_cast<Curve *>(context.object->data);
+
+  std::vector<Imath::V3f> verts;
+  std::vector<int32_t> vert_counts;
+  std::vector<float> widths;
+  std::vector<float> weights;
+  std::vector<float> knots;
+  std::vector<uint8_t> orders;
+  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->bp) {
+      curve_basis = Alembic::AbcGeom::kNoBasis;
+      curve_type = Alembic::AbcGeom::kVariableOrder;
+
+      const int totpoint = nurbs->pntsu * nurbs->pntsv;
+
+      const BPoint *point = nurbs->bp;
+
+      for (int i = 0; i < totpoint; i++, point++) {
+        copy_yup_from_zup(temp_vert.getValue(), point->vec);
+        verts.push_back(temp_vert);
+        weights.push_back(point->vec[3]);
+        widths.push_back(point->radius);
+      }
+    }
+    else if (nurbs->bezt) {
+      curve_basis = Alembic::AbcGeom::kBezierBasis;
+      curve_type = Alembic::AbcGeom::kCubic;
+
+      const int totpoint = nurbs->pntsu;
+
+      const BezTriple *bezier = nurbs->bezt;
+
+      /* TODO(kevin): store info about handles, Alembic doesn't have this. */
+      for (int i = 0; i < totpoint; i++, bezier++) {
+        copy_yup_from_zup(temp_vert.getValue(), bezier->vec[1]);
+        verts.push_back(temp_vert);
+        widths.push_back(bezier->radius);
+      }
+    }
+
+    if ((nurbs->flagu & CU_NURB_ENDPOINT) != 0) {
+      periodicity = Alembic::AbcGeom::kNonPeriodic;
+    }
+    else if ((nurbs->flagu & CU_NURB_CYCLIC) != 0) {
+      periodicity = Alembic::AbcGeom::kPeriodic;
+
+      /* Duplicate the start points to indicate that the curve is actually
+       * cyclic since other software need those.
+       */
+
+      for (int i = 0; i < nurbs->orderu; i++) {
+        verts.push_back(verts[i]);
+      }
+    }
+
+    if (nurbs->knotsu != NULL) {
+      const size_t num_knots = KNOTSU(nurbs);
+
+      /* Add an extra knot at the beginning and end of the array since most apps
+       * require/expect them. */
+      knots.resize(num_knots + 2);
+
+      for (int i = 0; i < num_knots; i++) {
+        knots[i + 1] = nurbs->knotsu[i];
+      }
+
+      if ((nurbs->flagu & CU_NURB_CYCLIC) != 0) {
+        knots[0] = nurbs->knotsu[0];
+        knots[num_knots - 1] = nurbs->knotsu[num_knots - 1];
+      }
+      else {
+        knots[0] = (2.0f * nurbs->knotsu[0] - nurbs->knotsu[1]);
+        knots[num_knots - 1] = (2.0f * nurbs->knotsu[num_knots - 1] -
+                                nurbs->knotsu[num_knots - 2]);
+      }
+    }
+
+    orders.push_back(nurbs->orderu);
+    vert_counts.push_back(verts.size());
+  }
+
+  Alembic::AbcGeom::OFloatGeomParam::Sample width_sample;
+  width_sample.setVals(widths);
+
+  OCurvesSchema::Sample sample(verts,
+                               vert_counts,
+                               curve_type,
+                               periodicity,
+                               width_sample,
+                               OV2fGeomParam::Sample(), /* UVs */
+                               ON3fGeomParam::Sample(), /* normals */
+                               curve_basis,
+                               weights,
+                               orders,
+                               knots);
+
+  update_bounding_box(context.object);
+  sample.setSelfBounds(bounding_box_);
+  abc_curve_schema_.set(sample);
+}
+
+ABCCurveMeshWriter::ABCCurveMeshWriter(const ABCWriterConstructorArgs &args)
+    : ABCGenericMeshWriter(args)
+{
+}
+
+Mesh *ABCCurveMeshWriter::get_export_mesh(Object *object_eval, bool &r_needsfree)
+{
+  Mesh *mesh_eval = BKE_object_get_evaluated_mesh(object_eval);
+  if (mesh_eval != NULL) {
+    /* Mesh_eval only exists when generative modifiers are in use. */
+    r_needsfree = false;
+    return mesh_eval;
+  }
+
+  r_needsfree = true;
+  return BKE_mesh_new_nomain_from_curve(object_eval);
+}
+
+}  // namespace ABC
\ No newline at end of file
diff --git a/source/blender/io/alembic/intern/export/abc_writer_curve.h b/source/blender/io/alembic/intern/export/abc_writer_curve.h
new file mode 100644
index 00000000000..829091d13fc
--- /dev/null
+++ b/source/blender/io/alembic/intern/export/abc_writer_curve.h
@@ -0,0 +1,53 @@
+/*
+ * 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 & 2020 Blender Foundation.
+ * All rights reserved.
+ */
+#pragma once
+
+#include "abc_writer_abstract.h"
+#include "abc_writer_mesh.h"
+
+#include <Alembic/AbcGeom/CurveType.h>
+
+namespace AB

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list