42 using Alembic::Abc::FloatArraySamplePtr;
43 using Alembic::Abc::Int32ArraySamplePtr;
44 using Alembic::Abc::P3fArraySamplePtr;
45 using Alembic::Abc::PropertyHeader;
46 using Alembic::Abc::UcharArraySamplePtr;
48 using Alembic::AbcGeom::CurvePeriodicity;
49 using Alembic::AbcGeom::ICompoundProperty;
50 using Alembic::AbcGeom::ICurves;
51 using Alembic::AbcGeom::ICurvesSchema;
52 using Alembic::AbcGeom::IFloatGeomParam;
53 using Alembic::AbcGeom::IInt16Property;
54 using Alembic::AbcGeom::ISampleSelector;
55 using Alembic::AbcGeom::kWrapExisting;
62 ICurves abc_curves(
object, kWrapExisting);
63 m_curves_schema = abc_curves.getSchema();
70 return m_curves_schema.valid();
74 const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
76 const char **err_str)
const
78 if (!Alembic::AbcGeom::ICurves::matches(alembic_header)) {
80 "Object type mismatch, Alembic object path pointed to Curves when importing, but not any "
86 *err_str =
"Object type mismatch, Alembic object path points to Curves.";
101 ICompoundProperty user_props = m_curves_schema.getUserProperties();
104 if (header !=
nullptr && header->isScalar() && IInt16Property::matches(*header)) {
105 IInt16Property resolu(user_props, header->getName());
106 cu->
resolu = resolu.getValue(sample_sel);
121 const ICurvesSchema &schema,
122 const ISampleSelector &sample_sel)
124 ICurvesSchema::Sample smp;
126 smp = schema.getValue(sample_sel);
128 catch (Alembic::Util::Exception &ex) {
129 printf(
"Alembic: error reading curve sample for '%s/%s' at time %f: %s\n",
131 schema.getName().c_str(),
132 sample_sel.getRequestedTime(),
137 const Int32ArraySamplePtr num_vertices = smp.getCurvesNumVertices();
138 const P3fArraySamplePtr positions = smp.getPositions();
139 const FloatArraySamplePtr weights = smp.getPositionWeights();
140 const FloatArraySamplePtr knots = smp.getKnots();
141 const CurvePeriodicity periodicity = smp.getWrap();
142 const UcharArraySamplePtr orders = smp.getOrders();
144 const IFloatGeomParam widths_param = schema.getWidthsParam();
145 FloatArraySamplePtr radiuses;
147 if (widths_param.valid()) {
148 IFloatGeomParam::Sample wsample = widths_param.getExpandedValue(sample_sel);
149 radiuses = wsample.getVals();
155 for (
size_t i = 0; i < num_vertices->size(); i++) {
156 const int num_verts = (*num_vertices)[i];
161 nu->
pntsu = num_verts;
165 switch (smp.getType()) {
166 case Alembic::AbcGeom::kCubic:
169 case Alembic::AbcGeom::kVariableOrder:
170 if (orders && orders->size() > i) {
171 nu->
orderu =
static_cast<short>((*orders)[i]);
175 case Alembic::AbcGeom::kLinear:
180 if (periodicity == Alembic::AbcGeom::kNonPeriodic) {
183 else if (periodicity == Alembic::AbcGeom::kPeriodic) {
192 const int start = idx;
193 const int end = idx + num_verts;
196 for (
int j = start, k = end - nu->
orderu; j < nu->orderu; j++, k++) {
197 const Imath::V3f &p1 = (*positions)[j];
198 const Imath::V3f &p2 = (*positions)[k];
208 if (overlap == 0 && num_verts > 2 && (*positions)[start] == (*positions)[end - 1]) {
218 nu->
pntsu -= overlap;
221 const bool do_weights = (weights !=
nullptr) && (weights->size() > 1);
224 const bool do_radius = (radiuses !=
nullptr) && (radiuses->size() > 1);
225 float radius = (radiuses && radiuses->size() == 1) ? (*radiuses)[0] : 1.0f;
232 for (
int j = 0; j < nu->
pntsu; j++, bp++, idx++) {
233 const Imath::V3f &
pos = (*positions)[idx];
236 radius = (*radiuses)[idx];
240 weight = (*weights)[idx];
250 if (knots && knots->size() != 0) {
251 nu->
knotsu =
static_cast<float *
>(
255 if (periodicity == Alembic::AbcGeom::kPeriodic && (
KNOTSU(nu) == knots->size() - 2)) {
257 for (
size_t i = 1; i < knots->size() - 1; i++) {
258 nu->
knotsu[i - 1] = (*knots)[knot_offset + i];
267 knot_offset += knots->size();
284 const ISampleSelector &sample_sel,
286 const char **err_str)
288 ICurvesSchema::Sample
sample;
291 sample = m_curves_schema.getValue(sample_sel);
293 catch (Alembic::Util::Exception &ex) {
294 *err_str =
"Error reading curve sample; more detail on the console";
295 printf(
"Alembic: error reading curve sample for '%s/%s' at time %f: %s\n",
297 m_curves_schema.getName().c_str(),
298 sample_sel.getRequestedTime(),
300 return existing_mesh;
303 const P3fArraySamplePtr &positions =
sample.getPositions();
304 const Int32ArraySamplePtr num_vertices =
sample.getCurvesNumVertices();
311 bool same_topology = curve_count == num_vertices->size();
315 for (curve_idx = 0; nurbs; nurbs = nurbs->
next, curve_idx++) {
316 const int num_in_alembic = (*num_vertices)[curve_idx];
317 const int num_in_blender = nurbs->
pntsu;
319 if (num_in_alembic != num_in_blender) {
320 same_topology =
false;
326 if (!same_topology) {
332 for (curve_idx = 0; nurbs; nurbs = nurbs->
next, curve_idx++) {
333 const int totpoint = (*num_vertices)[curve_idx];
338 for (
int i = 0; i < totpoint; i++, point++, vertex_idx++) {
339 const Imath::V3f &
pos = (*positions)[vertex_idx];
343 else if (nurbs->
bezt) {
346 for (
int i = 0; i < totpoint; i++, bezier++, vertex_idx++) {
347 const Imath::V3f &
pos = (*positions)[vertex_idx];
struct Curve * BKE_curve_add(struct Main *bmain, const char *name, int type)
void BKE_nurb_knot_calc_u(struct Nurb *nu)
void BKE_nurbList_free(struct ListBase *lb)
ListBase * BKE_curve_nurbs_get(struct Curve *cu)
struct Mesh * BKE_mesh_new_nomain_from_curve(struct Object *ob)
General operations, lookup, etc. for blender objects.
struct Object * BKE_object_add_only_object(struct Main *bmain, int type, const char *name) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel)
void read_curve_sample(Curve *cu, const Alembic::AbcGeom::ICurvesSchema &schema, const Alembic::Abc::ISampleSelector &sample_selector)
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, const Object *const ob, const char **err_str) const
struct Mesh * read_mesh(struct Mesh *existing_mesh, const Alembic::Abc::ISampleSelector &sample_sel, int read_flag, const char **err_str)
AbcCurveReader(const Alembic::Abc::IObject &object, ImportSettings &settings)
std::string m_object_name
Alembic::Abc::IObject m_iobject
ImportSettings * m_settings
void *(* MEM_callocN)(size_t len, const char *str)
static void sample(SocketReader *reader, int x, int y, float color[4])
void get_min_max_time(const Alembic::AbcGeom::IObject &object, const Schema &schema, chrono_t &min, chrono_t &max)
BLI_INLINE void copy_zup_from_yup(float zup[3], const float yup[3])
const std::string ABC_CURVE_RESOLUTION_U_PROPNAME
bool has_animations(Alembic::AbcGeom::IPolyMeshSchema &schema, ImportSettings *settings)