Blender V5.0
abc_util.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 "abc_reader_object.h"
11
12#include <Alembic/Abc/Foundation.h>
13#include <Alembic/Abc/ICompoundProperty.h>
14#include <Alembic/Abc/IObject.h>
15#include <Alembic/Abc/ISampleSelector.h>
16#include <Alembic/Abc/TypedArraySample.h>
17#include <Alembic/AbcCoreAbstract/Foundation.h>
18#include <Alembic/AbcCoreAbstract/TimeSampling.h>
19#include <Alembic/AbcGeom/IXform.h>
20
21#include <optional>
22#include <string>
23#include <vector>
24
25using Alembic::Abc::chrono_t;
26using Alembic::Abc::V3fArraySamplePtr;
27
28struct ID;
29struct Object;
30
31namespace blender::io::alembic {
32
33class AbcObjectReader;
34struct ImportSettings;
35
36std::string get_valid_abc_name(const char *name);
37
38/* Convert from float to Alembic matrix representations. Does NOT convert from Z-up to Y-up. */
39Imath::M44d convert_matrix_datatype(const float mat[4][4]);
40/* Convert from Alembic to float matrix representations. Does NOT convert from Y-up to Z-up. */
41void convert_matrix_datatype(const Imath::M44d &xform, float r_mat[4][4]);
42
43void split(const std::string &s, char delim, std::vector<std::string> &tokens);
44
45template<class TContainer> bool begins_with(const TContainer &input, const TContainer &match)
46{
47 return input.size() >= match.size() && std::equal(match.begin(), match.end(), input.begin());
48}
49
50template<typename Schema>
51void get_min_max_time_ex(const Schema &schema, chrono_t &min, chrono_t &max)
52{
53 const Alembic::Abc::TimeSamplingPtr &time_samp = schema.getTimeSampling();
54
55 if (!schema.isConstant()) {
56 const size_t num_samps = schema.getNumSamples();
57
58 if (num_samps > 0) {
59 const chrono_t min_time = time_samp->getSampleTime(0);
60 min = std::min(min, min_time);
61
62 const chrono_t max_time = time_samp->getSampleTime(num_samps - 1);
63 max = std::max(max, max_time);
64 }
65 }
66}
67
68template<typename Schema>
69void get_min_max_time(const Alembic::AbcGeom::IObject &object,
70 const Schema &schema,
71 chrono_t &min,
72 chrono_t &max)
73{
74 get_min_max_time_ex(schema, min, max);
75
76 const Alembic::AbcGeom::IObject &parent = object.getParent();
77 if (parent.valid() && Alembic::AbcGeom::IXform::matches(parent.getMetaData())) {
78 Alembic::AbcGeom::IXform xform(parent, Alembic::AbcGeom::kWrapExisting);
79 get_min_max_time_ex(xform.getSchema(), min, max);
80 }
81}
82
83bool has_property(const Alembic::Abc::ICompoundProperty &prop, const std::string &name);
84V3fArraySamplePtr get_velocity_prop(const Alembic::Abc::ICompoundProperty &schema,
85 const Alembic::AbcGeom::ISampleSelector &selector,
86 const std::string &name);
87
93 /* Index of the first ("floor") sample. */
94 Alembic::AbcGeom::index_t index;
95 /* Index of the second ("ceil") sample. */
96 Alembic::AbcGeom::index_t ceil_index;
97 /* Factor to interpolate between the `index` and `ceil_index`. */
98 double weight;
99};
100
107std::optional<SampleInterpolationSettings> get_sample_interpolation_settings(
108 const Alembic::AbcGeom::ISampleSelector &selector,
109 const Alembic::AbcCoreAbstract::TimeSamplingPtr &time_sampling,
110 size_t samples_number);
111
112AbcObjectReader *create_reader(const Alembic::AbcGeom::IObject &object, ImportSettings &settings);
113
114} // namespace blender::io::alembic
#define input
bool begins_with(const TContainer &input, const TContainer &match)
Definition abc_util.h:45
void get_min_max_time(const Alembic::AbcGeom::IObject &object, const Schema &schema, chrono_t &min, chrono_t &max)
Definition abc_util.h:69
std::string get_valid_abc_name(const char *name)
Definition abc_util.cc:29
V3fArraySamplePtr get_velocity_prop(const Alembic::Abc::ICompoundProperty &schema, const Alembic::AbcGeom::ISampleSelector &selector, const std::string &name)
Definition abc_util.cc:84
Imath::M44d convert_matrix_datatype(const float mat[4][4])
Definition abc_util.cc:39
bool has_property(const Alembic::Abc::ICompoundProperty &prop, const std::string &name)
Definition abc_util.cc:75
void get_min_max_time_ex(const Schema &schema, chrono_t &min, chrono_t &max)
Definition abc_util.h:51
AbcObjectReader * create_reader(const Alembic::AbcGeom::IObject &object, ImportSettings &settings)
Definition abc_util.cc:155
std::optional< SampleInterpolationSettings > get_sample_interpolation_settings(const Alembic::AbcGeom::ISampleSelector &selector, const Alembic::AbcCoreAbstract::TimeSamplingPtr &time_sampling, size_t samples_number)
Definition abc_util.cc:122
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:61
const char * name
#define min(a, b)
Definition sort.cc:36
Definition DNA_ID.h:414
max
Definition text_draw.cc:251