Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2020-08-07 14:04:31 +0300
committerJulian Eisel <julian@blender.org>2020-08-07 14:04:31 +0300
commit0d2d4a6d4a75ac38c41f872c88255eab70e88ab7 (patch)
treeb7a7518af86dddba48e05a98b3c2be55e8804721 /source/blender/io/alembic
parent9b416c66fb714bdfd15a481489dbf650d0f389ea (diff)
parentcfc6f9eb18e701f5be601b95c45004e8cf7fbc81 (diff)
Merge branch 'master' into temp-ui-button-type-refactortemp-ui-button-type-refactor
Diffstat (limited to 'source/blender/io/alembic')
-rw-r--r--source/blender/io/alembic/ABC_alembic.h10
-rw-r--r--source/blender/io/alembic/CMakeLists.txt4
-rw-r--r--source/blender/io/alembic/exporter/abc_export_capi.cc44
-rw-r--r--source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc13
-rw-r--r--source/blender/io/alembic/exporter/abc_hierarchy_iterator.h6
-rw-r--r--source/blender/io/alembic/exporter/abc_writer_curves.cc6
-rw-r--r--source/blender/io/alembic/exporter/abc_writer_nurbs.cc2
-rw-r--r--source/blender/io/alembic/exporter/abc_writer_transform.cc3
-rw-r--r--source/blender/io/alembic/intern/abc_axis_conversion.cc2
-rw-r--r--source/blender/io/alembic/intern/abc_axis_conversion.h2
-rw-r--r--source/blender/io/alembic/intern/abc_reader_mesh.cc2
-rw-r--r--source/blender/io/alembic/intern/abc_reader_object.cc2
-rw-r--r--source/blender/io/alembic/intern/alembic_capi.cc146
13 files changed, 212 insertions, 30 deletions
diff --git a/source/blender/io/alembic/ABC_alembic.h b/source/blender/io/alembic/ABC_alembic.h
index ddf75aa3258..67f8aeb0a67 100644
--- a/source/blender/io/alembic/ABC_alembic.h
+++ b/source/blender/io/alembic/ABC_alembic.h
@@ -128,6 +128,16 @@ struct CacheReader *CacheReader_open_alembic_object(struct AbcArchiveHandle *han
struct Object *object,
const char *object_path);
+bool ABC_has_vec3_array_property_named(struct CacheReader *reader, const char *name);
+
+/* r_vertex_velocities should point to a preallocated array of num_vertices floats */
+int ABC_read_velocity_cache(struct CacheReader *reader,
+ const char *velocity_name,
+ float time,
+ float fps,
+ int num_vertices,
+ float *r_vertex_velocities);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/io/alembic/CMakeLists.txt b/source/blender/io/alembic/CMakeLists.txt
index da36272b850..681d6d04acd 100644
--- a/source/blender/io/alembic/CMakeLists.txt
+++ b/source/blender/io/alembic/CMakeLists.txt
@@ -63,8 +63,8 @@ set(SRC
exporter/abc_writer_camera.cc
exporter/abc_writer_curves.cc
exporter/abc_writer_hair.cc
- exporter/abc_writer_mesh.cc
exporter/abc_writer_mball.cc
+ exporter/abc_writer_mesh.cc
exporter/abc_writer_nurbs.cc
exporter/abc_writer_points.cc
exporter/abc_writer_transform.cc
@@ -89,8 +89,8 @@ set(SRC
exporter/abc_writer_camera.h
exporter/abc_writer_curves.h
exporter/abc_writer_hair.h
- exporter/abc_writer_mesh.h
exporter/abc_writer_mball.h
+ exporter/abc_writer_mesh.h
exporter/abc_writer_nurbs.h
exporter/abc_writer_points.h
exporter/abc_writer_transform.h
diff --git a/source/blender/io/alembic/exporter/abc_export_capi.cc b/source/blender/io/alembic/exporter/abc_export_capi.cc
index fbc5b2d5c02..8c5f3d89870 100644
--- a/source/blender/io/alembic/exporter/abc_export_capi.cc
+++ b/source/blender/io/alembic/exporter/abc_export_capi.cc
@@ -48,6 +48,7 @@
static CLG_LogRef LOG = {"io.alembic"};
#include <algorithm>
+#include <memory>
struct ExportJobData {
Main *bmain;
@@ -73,7 +74,12 @@ static void build_depsgraph(Depsgraph *depsgraph, Main *bmain)
DEG_graph_build_from_view_layer(depsgraph, bmain, scene, view_layer);
}
-static void export_startjob(void *customdata, short *stop, short *do_update, float *progress)
+static void export_startjob(void *customdata,
+ /* Cannot be const, this function implements wm_jobs_start_callback.
+ * NOLINTNEXTLINE: readability-non-const-parameter. */
+ short *stop,
+ short *do_update,
+ float *progress)
{
ExportJobData *data = static_cast<ExportJobData *>(customdata);
data->was_canceled = false;
@@ -98,17 +104,41 @@ static void export_startjob(void *customdata, short *stop, short *do_update, flo
const bool export_animation = (data->params.frame_start != data->params.frame_end);
// Create the Alembic archive.
- ABCArchive abc_archive(data->bmain, scene, data->params, std::string(data->filename));
+ std::unique_ptr<ABCArchive> abc_archive;
+ try {
+ abc_archive = std::make_unique<ABCArchive>(
+ data->bmain, scene, data->params, std::string(data->filename));
+ }
+ catch (const std::exception &ex) {
+ std::stringstream error_message_stream;
+ error_message_stream << "Error writing to " << data->filename;
+ const std::string &error_message = error_message_stream.str();
+
+ // The exception message can be very cryptic (just "iostream error" on Linux, for example), so
+ // better not to include it in the report.
+ CLOG_ERROR(&LOG, "%s: %s", error_message.c_str(), ex.what());
+ WM_report(RPT_ERROR, error_message.c_str());
+ data->export_ok = false;
+ return;
+ }
+ catch (...) {
+ // Unknown exception class, so we cannot include its message.
+ std::stringstream error_message_stream;
+ error_message_stream << "Unknown error writing to " << data->filename;
+ WM_report(RPT_ERROR, error_message_stream.str().c_str());
+ data->export_ok = false;
+ return;
+ }
- ABCHierarchyIterator iter(data->depsgraph, &abc_archive, data->params);
+ ABCHierarchyIterator iter(data->depsgraph, abc_archive.get(), data->params);
if (export_animation) {
CLOG_INFO(&LOG, 2, "Exporting animation");
// Writing the animated frames is not 100% of the work, but it's our best guess.
- const float progress_per_frame = 1.0f / std::max(size_t(1), abc_archive.total_frame_count());
- ABCArchive::Frames::const_iterator frame_it = abc_archive.frames_begin();
- const ABCArchive::Frames::const_iterator frames_end = abc_archive.frames_end();
+ const float progress_per_frame = 1.0f / std::max(size_t(1), abc_archive->total_frame_count());
+ ABCArchive::Frames::const_iterator frame_it = abc_archive->frames_begin();
+ const ABCArchive::Frames::const_iterator frames_end = abc_archive->frames_end();
for (; frame_it != frames_end; frame_it++) {
double frame = *frame_it;
@@ -123,7 +153,7 @@ static void export_startjob(void *customdata, short *stop, short *do_update, flo
BKE_scene_graph_update_for_newframe(data->depsgraph, data->bmain);
CLOG_INFO(&LOG, 2, "Exporting frame %.2f", frame);
- ExportSubset export_subset = abc_archive.export_subset_for_frame(frame);
+ ExportSubset export_subset = abc_archive->export_subset_for_frame(frame);
iter.set_export_subset(export_subset);
iter.iterate_and_write();
diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
index 90004c0e85b..5b1b1b60b48 100644
--- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
+++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.cc
@@ -89,7 +89,7 @@ bool ABCHierarchyIterator::mark_as_weak_export(const Object *object) const
return false;
}
-void ABCHierarchyIterator::delete_object_writer(AbstractHierarchyWriter *writer)
+void ABCHierarchyIterator::release_writer(AbstractHierarchyWriter *writer)
{
delete writer;
}
@@ -107,20 +107,23 @@ AbstractHierarchyIterator::ExportGraph::key_type ABCHierarchyIterator::
determine_graph_index_object(const HierarchyContext *context)
{
if (params_.flatten_hierarchy) {
- return std::make_pair(nullptr, nullptr);
+ return ObjectIdentifier::for_graph_root();
}
return AbstractHierarchyIterator::determine_graph_index_object(context);
}
AbstractHierarchyIterator::ExportGraph::key_type ABCHierarchyIterator::determine_graph_index_dupli(
- const HierarchyContext *context, const std::set<Object *> &dupli_set)
+ const HierarchyContext *context,
+ const DupliObject *dupli_object,
+ const DupliParentFinder &dupli_parent_finder)
{
if (params_.flatten_hierarchy) {
- return std::make_pair(nullptr, nullptr);
+ return ObjectIdentifier::for_graph_root();
}
- return AbstractHierarchyIterator::determine_graph_index_dupli(context, dupli_set);
+ return AbstractHierarchyIterator::determine_graph_index_dupli(
+ context, dupli_object, dupli_parent_finder);
}
Alembic::Abc::OObject ABCHierarchyIterator::get_alembic_parent(
diff --git a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
index edcb31806ba..bd7e3f27c67 100644
--- a/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
+++ b/source/blender/io/alembic/exporter/abc_hierarchy_iterator.h
@@ -67,7 +67,9 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator {
virtual ExportGraph::key_type determine_graph_index_object(
const HierarchyContext *context) override;
virtual AbstractHierarchyIterator::ExportGraph::key_type determine_graph_index_dupli(
- const HierarchyContext *context, const std::set<Object *> &dupli_set) override;
+ const HierarchyContext *context,
+ const DupliObject *dupli_object,
+ const DupliParentFinder &dupli_parent_finder) override;
virtual AbstractHierarchyWriter *create_transform_writer(
const HierarchyContext *context) override;
@@ -76,7 +78,7 @@ class ABCHierarchyIterator : public AbstractHierarchyIterator {
virtual AbstractHierarchyWriter *create_particle_writer(
const HierarchyContext *context) override;
- virtual void delete_object_writer(AbstractHierarchyWriter *writer) override;
+ virtual void release_writer(AbstractHierarchyWriter *writer) override;
private:
Alembic::Abc::OObject get_alembic_parent(const HierarchyContext *context) const;
diff --git a/source/blender/io/alembic/exporter/abc_writer_curves.cc b/source/blender/io/alembic/exporter/abc_writer_curves.cc
index f2a46c5e4fe..6f185020b58 100644
--- a/source/blender/io/alembic/exporter/abc_writer_curves.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_curves.cc
@@ -80,9 +80,9 @@ void ABCCurveWriter::do_write(HierarchyContext &context)
std::vector<uint8_t> orders;
Imath::V3f temp_vert;
- Alembic::AbcGeom::BasisType curve_basis;
- Alembic::AbcGeom::CurveType curve_type;
- Alembic::AbcGeom::CurvePeriodicity periodicity;
+ Alembic::AbcGeom::BasisType curve_basis = Alembic::AbcGeom::kNoBasis;
+ Alembic::AbcGeom::CurveType curve_type = Alembic::AbcGeom::kVariableOrder;
+ Alembic::AbcGeom::CurvePeriodicity periodicity = Alembic::AbcGeom::kNonPeriodic;
Nurb *nurbs = static_cast<Nurb *>(curve->nurb.first);
for (; nurbs; nurbs = nurbs->next) {
diff --git a/source/blender/io/alembic/exporter/abc_writer_nurbs.cc b/source/blender/io/alembic/exporter/abc_writer_nurbs.cc
index 1fd382214a6..14cb7773e67 100644
--- a/source/blender/io/alembic/exporter/abc_writer_nurbs.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_nurbs.cc
@@ -64,7 +64,7 @@ void ABCNurbsWriter::create_alembic_objects(const HierarchyContext *context)
std::string patch_name = patch_name_stream.str();
CLOG_INFO(&LOG, 2, "exporting %s/%s", abc_parent_path, patch_name.c_str());
- ONuPatch nurbs(abc_parent, patch_name.c_str(), timesample_index_);
+ ONuPatch nurbs(abc_parent, patch_name, timesample_index_);
abc_nurbs_.push_back(nurbs);
abc_nurbs_schemas_.push_back(nurbs.getSchema());
}
diff --git a/source/blender/io/alembic/exporter/abc_writer_transform.cc b/source/blender/io/alembic/exporter/abc_writer_transform.cc
index 65d6b7c5b41..39af99c142c 100644
--- a/source/blender/io/alembic/exporter/abc_writer_transform.cc
+++ b/source/blender/io/alembic/exporter/abc_writer_transform.cc
@@ -107,6 +107,9 @@ bool ABCTransformWriter::check_is_animated(const HierarchyContext &context) cons
* depsgraph whether this object instance has a time source. */
return true;
}
+ if (check_has_physics(context)) {
+ return true;
+ }
return BKE_object_moves_in_time(context.object, context.animation_check_include_parent);
}
diff --git a/source/blender/io/alembic/intern/abc_axis_conversion.cc b/source/blender/io/alembic/intern/abc_axis_conversion.cc
index cebab1f2e41..396c8fdb28b 100644
--- a/source/blender/io/alembic/intern/abc_axis_conversion.cc
+++ b/source/blender/io/alembic/intern/abc_axis_conversion.cc
@@ -170,4 +170,4 @@ void create_transform_matrix(Object *obj,
} // namespace alembic
} // namespace io
-} // namespace blender \ No newline at end of file
+} // namespace blender
diff --git a/source/blender/io/alembic/intern/abc_axis_conversion.h b/source/blender/io/alembic/intern/abc_axis_conversion.h
index 9a19e9116be..645d9fc783b 100644
--- a/source/blender/io/alembic/intern/abc_axis_conversion.h
+++ b/source/blender/io/alembic/intern/abc_axis_conversion.h
@@ -100,4 +100,4 @@ void create_transform_matrix(Object *obj,
} // namespace alembic
} // namespace io
-} // namespace blender \ No newline at end of file
+} // namespace blender
diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc
index 756dde3783c..98130eb28cd 100644
--- a/source/blender/io/alembic/intern/abc_reader_mesh.cc
+++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc
@@ -104,7 +104,7 @@ static void assign_materials(Main *bmain,
for (; it != mat_index_map.end(); ++it) {
std::string mat_name = it->first;
- mat_iter = mat_map.find(mat_name.c_str());
+ mat_iter = mat_map.find(mat_name);
Material *assigned_mat;
diff --git a/source/blender/io/alembic/intern/abc_reader_object.cc b/source/blender/io/alembic/intern/abc_reader_object.cc
index 39b9cd4c161..06b0c07f4c5 100644
--- a/source/blender/io/alembic/intern/abc_reader_object.cc
+++ b/source/blender/io/alembic/intern/abc_reader_object.cc
@@ -236,7 +236,7 @@ Alembic::AbcGeom::IXform AbcObjectReader::xform()
* parent Alembic object should contain the transform. */
IObject abc_parent = m_iobject.getParent();
- /* The archive's top object can be recognised by not having a parent. */
+ /* The archive's top object can be recognized by not having a parent. */
if (abc_parent.getParent() && IXform::matches(abc_parent.getMetaData())) {
try {
return IXform(abc_parent, Alembic::AbcGeom::kWrapExisting);
diff --git a/source/blender/io/alembic/intern/alembic_capi.cc b/source/blender/io/alembic/intern/alembic_capi.cc
index 7cde2d4fe73..eba7f64db02 100644
--- a/source/blender/io/alembic/intern/alembic_capi.cc
+++ b/source/blender/io/alembic/intern/alembic_capi.cc
@@ -22,6 +22,7 @@
#include <Alembic/AbcMaterial/IMaterial.h>
+#include "abc_axis_conversion.h"
#include "abc_reader_archive.h"
#include "abc_reader_camera.h"
#include "abc_reader_curves.h"
@@ -47,18 +48,13 @@
#include "BKE_lib_id.h"
#include "BKE_object.h"
#include "BKE_scene.h"
+#include "BKE_screen.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "ED_undo.h"
-/* SpaceType struct has a member called 'new' which obviously conflicts with C++
- * so temporarily redefining the new keyword to make it compile. */
-#define new extern_new
-#include "BKE_screen.h"
-#undef new
-
#include "BLI_compiler_compat.h"
#include "BLI_fileops.h"
#include "BLI_ghash.h"
@@ -70,7 +66,10 @@
#include "WM_api.h"
#include "WM_types.h"
+using Alembic::Abc::IV3fArrayProperty;
using Alembic::Abc::ObjectHeader;
+using Alembic::Abc::PropertyHeader;
+using Alembic::Abc::V3fArraySamplePtr;
using Alembic::AbcGeom::ICamera;
using Alembic::AbcGeom::ICurves;
using Alembic::AbcGeom::IFaceSet;
@@ -79,9 +78,11 @@ using Alembic::AbcGeom::INuPatch;
using Alembic::AbcGeom::IObject;
using Alembic::AbcGeom::IPoints;
using Alembic::AbcGeom::IPolyMesh;
+using Alembic::AbcGeom::IPolyMeshSchema;
using Alembic::AbcGeom::ISampleSelector;
using Alembic::AbcGeom::ISubD;
using Alembic::AbcGeom::IXform;
+using Alembic::AbcGeom::kWrapExisting;
using Alembic::AbcGeom::MetaData;
using Alembic::AbcMaterial::IMaterial;
@@ -859,3 +860,136 @@ CacheReader *CacheReader_open_alembic_object(AbcArchiveHandle *handle,
return reinterpret_cast<CacheReader *>(abc_reader);
}
+
+/* ************************************************************************** */
+
+static const PropertyHeader *get_property_header(const IPolyMeshSchema &schema, const char *name)
+{
+ const PropertyHeader *prop_header = schema.getPropertyHeader(name);
+
+ if (prop_header) {
+ return prop_header;
+ }
+
+ ICompoundProperty prop = schema.getArbGeomParams();
+
+ if (!has_property(prop, name)) {
+ return nullptr;
+ }
+
+ return prop.getPropertyHeader(name);
+}
+
+bool ABC_has_vec3_array_property_named(struct CacheReader *reader, const char *name)
+{
+ AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
+
+ if (!abc_reader) {
+ return false;
+ }
+
+ IObject iobject = abc_reader->iobject();
+
+ if (!iobject.valid()) {
+ return false;
+ }
+
+ const ObjectHeader &header = iobject.getHeader();
+
+ if (!IPolyMesh::matches(header)) {
+ return false;
+ }
+
+ IPolyMesh mesh(iobject, kWrapExisting);
+ IPolyMeshSchema schema = mesh.getSchema();
+
+ const PropertyHeader *prop_header = get_property_header(schema, name);
+
+ if (!prop_header) {
+ return false;
+ }
+
+ return IV3fArrayProperty::matches(prop_header->getMetaData());
+}
+
+static V3fArraySamplePtr get_velocity_prop(const IPolyMeshSchema &schema,
+ const ISampleSelector &iss,
+ const std::string &name)
+{
+ const PropertyHeader *prop_header = schema.getPropertyHeader(name);
+
+ if (prop_header) {
+ const IV3fArrayProperty &velocity_prop = IV3fArrayProperty(schema, name, 0);
+ return velocity_prop.getValue(iss);
+ }
+
+ ICompoundProperty prop = schema.getArbGeomParams();
+
+ if (!has_property(prop, name)) {
+ return V3fArraySamplePtr();
+ }
+
+ const IV3fArrayProperty &velocity_prop = IV3fArrayProperty(prop, name, 0);
+
+ if (velocity_prop) {
+ return velocity_prop.getValue(iss);
+ }
+
+ return V3fArraySamplePtr();
+}
+
+int ABC_read_velocity_cache(CacheReader *reader,
+ const char *velocity_name,
+ const float time,
+ float velocity_scale,
+ int num_vertices,
+ float *r_vertex_velocities)
+{
+ AbcObjectReader *abc_reader = reinterpret_cast<AbcObjectReader *>(reader);
+
+ if (!abc_reader) {
+ return -1;
+ }
+
+ IObject iobject = abc_reader->iobject();
+
+ if (!iobject.valid()) {
+ return -1;
+ }
+
+ const ObjectHeader &header = iobject.getHeader();
+
+ if (!IPolyMesh::matches(header)) {
+ return -1;
+ }
+
+ IPolyMesh mesh(iobject, kWrapExisting);
+ IPolyMeshSchema schema = mesh.getSchema();
+ ISampleSelector sample_sel(time);
+ const IPolyMeshSchema::Sample sample = schema.getValue(sample_sel);
+
+ V3fArraySamplePtr velocities = get_velocity_prop(schema, sample_sel, velocity_name);
+
+ if (!velocities) {
+ return -1;
+ }
+
+ float vel[3];
+
+ int num_velocity_vectors = static_cast<int>(velocities->size());
+
+ if (num_velocity_vectors != num_vertices) {
+ return -1;
+ }
+
+ for (size_t i = 0; i < velocities->size(); ++i) {
+ const Imath::V3f &vel_in = (*velocities)[i];
+ copy_zup_from_yup(vel, vel_in.getValue());
+
+ mul_v3_fl(vel, velocity_scale);
+
+ copy_v3_v3(r_vertex_velocities + i * 3, vel);
+ }
+
+ return num_vertices;
+}