Blender V5.3
abc_reader_object.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
9
10#include "BLI_vector.hh"
11
12#include <Alembic/Abc/IObject.h>
13#include <Alembic/Abc/ISampleSelector.h>
14#include <Alembic/AbcCoreAbstract/Foundation.h>
15#include <Alembic/AbcCoreAbstract/ObjectHeader.h>
16#include <Alembic/AbcGeom/IXform.h>
17
18#include <string>
19#include <vector>
20
21namespace blender {
22
23struct CacheFile;
24struct Main;
25struct Mesh;
26struct Object;
27
28namespace bke {
29struct GeometrySet;
30}
31
32using Alembic::AbcCoreAbstract::chrono_t;
33
34namespace io::alembic {
35
37
38struct TimeInfo;
39
42
43 bool do_convert_mat = false;
44 float conversion_mat[4][4];
45
46 int from_up = 0;
47 int from_forward = 0;
48 float scale = 1.0f;
49 bool is_sequence = false;
50 bool set_frame_range = false;
51
52 /* Min and max frame detected from file sequences. */
55
56 /* From MeshSeqCacheModifierData.read_flag */
57 int read_flag = 0;
58
59 /* From CacheFile and MeshSeqCacheModifierData */
60 std::string velocity_name;
61 float velocity_scale = 1.0f;
62
63 bool validate_meshes = false;
65
67
68 ImportSettings() = default;
69};
70
71template<typename Schema> static bool has_animations(Schema &schema, ImportSettings *settings)
72{
73 return settings->is_sequence || !schema.isConstant();
74}
75
77 std::string velocity_name;
78 int read_flag = 0;
79 float velocity_scale = 1.0f;
80};
81
83 const Alembic::Abc::IObject &object;
85};
86
87AbcReaderConstructorArgs create_reader_constructor_args(const Alembic::Abc::IObject &object,
88 ImportSettings &settings);
89
91 protected:
92 std::string m_name;
93 std::string m_object_name;
94 std::string m_data_name;
96 Alembic::Abc::IObject m_iobject;
97
98 /* XXX - This used to reference stack memory for MeshSequenceCache scenarios. That has been
99 * addressed but ownership of these settings should be made more apparent to prevent similar
100 * issues in the future. */
102 /* This is initialized from the ImportSettings above on construction. It will need to be removed
103 * once we fix the stack memory reference situation. */
105
106 /* Use reference counting since the same reader may be used by multiple
107 * modifiers and/or constraints. */
109
111
113
114 public:
116
117 public:
118 explicit AbcObjectReader(const AbcReaderConstructorArgs &args);
119
120 virtual ~AbcObjectReader() = default;
121
122 const Alembic::Abc::IObject &iobject() const;
123
124 using ptr_vector = std::vector<AbcObjectReader *>;
125
130 virtual Alembic::AbcGeom::IXform xform();
131
132 Object *object() const;
133 void object(Object *ob);
134
135 const std::string &name() const
136 {
137 return m_name;
138 }
139 const std::string &object_name() const
140 {
141 return m_object_name;
142 }
143 const std::string &data_name() const
144 {
145 return m_data_name;
146 }
147 bool inherits_xform() const
148 {
149 return m_inherits_xform;
150 }
152 {
154 }
155
156 virtual bool valid() const = 0;
157 virtual bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
158 const Object *const ob,
159 const char **r_err_str) const = 0;
160
161 virtual void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) = 0;
162
163 virtual void read_geometry(bke::GeometrySet &geometry_set,
164 const Alembic::Abc::ISampleSelector &sample_sel,
165 const AbcReadGeometryParams &read_params,
166 const char **r_err_str);
167
168 virtual bool topology_changed(const Mesh *existing_mesh,
169 const Alembic::Abc::ISampleSelector &sample_sel);
170
171 void getKeyFramingHelpers(Vector<std::unique_ptr<FCurveCreationHelper>> &keyframing_helpers);
172
173 virtual std::unique_ptr<FCurveCreationHelper> getKeyFramingHelper();
174
176 void setupObjectTransform(chrono_t time);
177
178 void addCacheModifier();
179 void readVisibility();
180
181 int refcount() const;
182 void incref();
183 void decref();
184
185 void read_matrix(float r_mat[4][4], chrono_t time, float scale, bool &is_constant);
186
187 protected:
190};
191
192Imath::M44d get_matrix(const Alembic::AbcGeom::IXformSchema &schema, chrono_t time);
193
194} // namespace io::alembic
195} // namespace blender
const std::string & object_name() const
virtual void read_geometry(bke::GeometrySet &geometry_set, const Alembic::Abc::ISampleSelector &sample_sel, const AbcReadGeometryParams &read_params, const char **r_err_str)
void getKeyFramingHelpers(Vector< std::unique_ptr< FCurveCreationHelper > > &keyframing_helpers)
void read_matrix(float r_mat[4][4], chrono_t time, float scale, bool &is_constant)
const Alembic::Abc::IObject & iobject() const
AbcObjectReader(const AbcReaderConstructorArgs &args)
virtual bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, const Object *const ob, const char **r_err_str) const =0
virtual bool topology_changed(const Mesh *existing_mesh, const Alembic::Abc::ISampleSelector &sample_sel)
virtual Alembic::AbcGeom::IXform xform()
const std::string & data_name() const
virtual void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)=0
std::vector< AbcObjectReader * > ptr_vector
virtual std::unique_ptr< FCurveCreationHelper > getKeyFramingHelper()
float3x3 scale(float3x3 mat, float2 scale)
Imath::M44d get_matrix(const IXformSchema &schema, const chrono_t time)
bool has_animations(Alembic::AbcGeom::ICurvesSchema &schema, ImportSettings *settings)
AbcReaderConstructorArgs create_reader_constructor_args(const IObject &object, ImportSettings &settings)
BMesh Iterators.