Blender V5.0
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 <Alembic/Abc/IObject.h>
11#include <Alembic/Abc/ISampleSelector.h>
12#include <Alembic/AbcCoreAbstract/Foundation.h>
13#include <Alembic/AbcCoreAbstract/ObjectHeader.h>
14#include <Alembic/AbcGeom/IXform.h>
15
16#include <string>
17#include <vector>
18
19struct CacheFile;
20struct Main;
21struct Mesh;
22struct Object;
23
24namespace blender::bke {
25struct GeometrySet;
26}
27
28using Alembic::AbcCoreAbstract::chrono_t;
29
30namespace blender::io::alembic {
31
34
35 bool do_convert_mat = false;
36 float conversion_mat[4][4];
37
38 int from_up = 0;
39 int from_forward = 0;
40 float scale = 1.0f;
41 bool is_sequence = false;
42 bool set_frame_range = false;
43
44 /* Min and max frame detected from file sequences. */
47
48 /* From MeshSeqCacheModifierData.read_flag */
49 int read_flag = 0;
50
51 /* From CacheFile and MeshSeqCacheModifierData */
52 std::string velocity_name;
53 float velocity_scale = 1.0f;
54
55 bool validate_meshes = false;
57
59
60 ImportSettings() = default;
61};
62
63template<typename Schema> static bool has_animations(Schema &schema, ImportSettings *settings)
64{
65 return settings->is_sequence || !schema.isConstant();
66}
67
69 protected:
70 std::string m_name;
71 std::string m_object_name;
72 std::string m_data_name;
74 Alembic::Abc::IObject m_iobject;
75
76 /* XXX - This used to reference stack memory for MeshSequenceCache scenarios. That has been
77 * addressed but ownership of these settings should be made more apparent to prevent similar
78 * issues in the future. */
80 /* This is initialized from the ImportSettings above on construction. It will need to be removed
81 * once we fix the stack memory reference situation. */
83
84 chrono_t m_min_time;
85 chrono_t m_max_time;
86
87 /* Use reference counting since the same reader may be used by multiple
88 * modifiers and/or constraints. */
90
92
93 public:
95
96 explicit AbcObjectReader(const Alembic::Abc::IObject &object, ImportSettings &settings);
97
98 virtual ~AbcObjectReader() = default;
99
100 const Alembic::Abc::IObject &iobject() const;
101
102 using ptr_vector = std::vector<AbcObjectReader *>;
103
108 virtual Alembic::AbcGeom::IXform xform();
109
110 Object *object() const;
111 void object(Object *ob);
112
113 const std::string &name() const
114 {
115 return m_name;
116 }
117 const std::string &object_name() const
118 {
119 return m_object_name;
120 }
121 const std::string &data_name() const
122 {
123 return m_data_name;
124 }
125 bool inherits_xform() const
126 {
127 return m_inherits_xform;
128 }
129
130 virtual bool valid() const = 0;
131 virtual bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
132 const Object *const ob,
133 const char **r_err_str) const = 0;
134
135 virtual void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) = 0;
136
137 virtual void read_geometry(bke::GeometrySet &geometry_set,
138 const Alembic::Abc::ISampleSelector &sample_sel,
139 int read_flag,
140 const char *velocity_name,
141 float velocity_scale,
142 const char **r_err_str);
143
144 virtual bool topology_changed(const Mesh *existing_mesh,
145 const Alembic::Abc::ISampleSelector &sample_sel);
146
148 void setupObjectTransform(chrono_t time);
149
150 void addCacheModifier();
151
152 chrono_t minTime() const;
153 chrono_t maxTime() const;
154
155 int refcount() const;
156 void incref();
157 void decref();
158
159 void read_matrix(float r_mat[4][4], chrono_t time, float scale, bool &is_constant);
160
161 protected:
164};
165
166Imath::M44d get_matrix(const Alembic::AbcGeom::IXformSchema &schema, chrono_t time);
167
168} // namespace blender::io::alembic
const std::string & object_name() const
AbcObjectReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
void read_matrix(float r_mat[4][4], chrono_t time, float scale, bool &is_constant)
const Alembic::Abc::IObject & iobject() const
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 read_geometry(bke::GeometrySet &geometry_set, const Alembic::Abc::ISampleSelector &sample_sel, int read_flag, const char *velocity_name, float velocity_scale, const char **r_err_str)
virtual void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)=0
std::vector< AbcObjectReader * > ptr_vector
Imath::M44d get_matrix(const IXformSchema &schema, const chrono_t time)
bool has_animations(Alembic::AbcGeom::IPolyMeshSchema &schema, ImportSettings *settings)