32using namespace Alembic::AbcGeom;
41 if (settings->
is_sequence || !schema.isConstant()) {
45 IFloatGeomParam widths_param = schema.getWidthsParam();
46 if (widths_param.valid() && !widths_param.isConstant()) {
50 IV3fArrayProperty velocities_prop = schema.getVelocitiesProperty();
51 if (velocities_prop.valid() && !velocities_prop.isConstant()) {
60 IPoints ipoints(
m_iobject, kWrapExisting);
61 m_schema = ipoints.getSchema();
66 return m_schema.valid();
70 const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header,
72 const char **r_err_str)
const
74 if (!Alembic::AbcGeom::IPoints::matches(alembic_header)) {
76 "Object type mismatch, Alembic object path pointed to Points when importing, but not any "
82 *r_err_str =
RPT_(
"Object type mismatch, Alembic object path points to Points.");
96 read_geometry(geometry_set, sample_sel, read_params,
nullptr);
101 if (read_pointcloud != pointcloud) {
115 for (
size_t i = 0; i < positions->size(); i++) {
121 const ISampleSelector &selector,
124 Alembic::AbcGeom::IPointsSchema::Sample
sample = schema.getValue(selector);
126 const P3fArraySamplePtr &positions =
sample.getPositions();
132 static_assert(std::is_same_v<TIn, TOut>,
133 "convert_abc_value needs to be explicitly specialized for each pair of types");
151 return in.getValue();
154template<
typename TArrayProperty,
typename TWriteValue>
156 const ISampleSelector &selector,
157 const std::string &name,
160 const TArrayProperty &array_prop = TArrayProperty(parent, name);
162 using SamplePtr =
typename TArrayProperty::sample_ptr_type;
163 using ValueType =
typename TArrayProperty::value_type;
165 const SamplePtr sample_ptr = array_prop.getValue(selector);
170 ValueType value = (*sample_ptr)[i];
178 const ISampleSelector &selector,
181 const ICompoundProperty prop = schema.getArbGeomParams();
186 for (
size_t i = 0; i < prop.getNumProperties(); i++) {
187 const PropertyHeader header = prop.getPropertyHeader(i);
188 const PropertyType property_type = header.getPropertyType();
189 if (property_type != kArrayProperty) {
194 const DataType data_type = header.getDataType();
195 const MetaData
metadata = header.getMetaData();
196 const std::string interpretation =
metadata.get(
"interpretation");
197 const std::string name = header.getName();
199 if (data_type ==
DataType(kFloat32POD, 3)) {
200 if (interpretation == C3fTPTraits::interpretation()) {
202 prop, selector, name, attribute_accessor);
204 else if (interpretation == N3fTPTraits::interpretation()) {
206 prop, selector, name, attribute_accessor);
210 prop, selector, name, attribute_accessor);
213 else if (data_type ==
DataType(kFloat32POD, 2)) {
215 prop, selector, name, attribute_accessor);
217 else if (data_type ==
DataType(kFloat32POD, 1)) {
219 prop, selector, name, attribute_accessor);
225 const Alembic::Abc::ISampleSelector &sample_sel,
227 const char **r_err_str)
231 IPointsSchema::Sample
sample;
233 sample = m_schema.getValue(sample_sel);
235 catch (Alembic::Util::Exception &ex) {
236 *r_err_str =
RPT_(
"Error reading points sample; more detail on the console");
238 "Error reading points sample for '%s/%s' at time %f: %s",
240 m_schema.getName().c_str(),
241 sample_sel.getRequestedTime(),
249 const P3fArraySamplePtr &positions =
sample.getPositions();
251 const IFloatGeomParam widths_param = m_schema.getWidthsParam();
252 FloatArraySamplePtr widths;
254 if (widths_param.valid()) {
255 IFloatGeomParam::Sample wsample = widths_param.getExpandedValue(sample_sel);
256 widths = wsample.getVals();
261 "Point cloud too large to import for '%s/%s' at time %f, exceeds max int size",
263 m_schema.getName().c_str(),
264 sample_sel.getRequestedTime());
268 if (pointcloud->
totpoint != positions->size()) {
277 bool widths_handled =
false;
279 switch (widths_param.getScope()) {
280 case Alembic::AbcGeom::kConstantScope: {
281 if (widths->size() >= 1) {
282 const float radius = (*widths)[0] / 2.0f;
283 attribute_accessor.
remove(
"radius");
284 attribute_accessor.
add<
float>(
286 widths_handled =
true;
290 case Alembic::AbcGeom::kUniformScope:
291 case Alembic::AbcGeom::kVaryingScope:
292 case Alembic::AbcGeom::kVertexScope:
293 case Alembic::AbcGeom::kFacevaryingScope: {
296 point_radii[i] = (*widths)[i] / 2.0f;
298 widths_handled =
true;
301 case Alembic::AbcGeom::kUnknownScope:
306 if (!widths_handled) {
307 attribute_accessor.
remove(
"radius");
308 attribute_accessor.
add<
float>(
317 if (velocities && pointcloud->
totpoint ==
int(velocities->size())) {
325 const Imath::V3f &vel_in = (*velocities)[i];
General operations, lookup, etc. for blender objects.
General operations for point clouds.
#define CLOG_WARN(clg_ref,...)
Object is a sort of wrapper for general info.
constexpr IndexRange()=default
constexpr int64_t size() const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
bool remove(const StringRef name)
std::string m_object_name
Alembic::Abc::IObject m_iobject
AbcObjectReader(const AbcReaderConstructorArgs &args)
ImportSettings * m_settings
void read_geometry(bke::GeometrySet &geometry_set, const Alembic::Abc::ISampleSelector &sample_sel, const AbcReadGeometryParams &read_params, const char **r_err_str) override
bool accepts_object_type(const Alembic::AbcCoreAbstract::ObjectHeader &alembic_header, const Object *const ob, const char **r_err_str) const override
AbcPointsReader(const AbcReaderConstructorArgs &args)
bool valid() const override
void readObjectData(Main *bmain, const Alembic::Abc::ISampleSelector &sample_sel) override
static void read_typed_property_sample(const ICompoundProperty &parent, const ISampleSelector &selector, const std::string &name, bke::MutableAttributeAccessor &attribute_accessor)
static void read_points(const P3fArraySamplePtr positions, MutableSpan< float3 > r_points)
BLI_INLINE void copy_zup_from_yup(float zup[3], const float yup[3])
V3fArraySamplePtr get_velocity_prop(const Alembic::Abc::ICompoundProperty &schema, const Alembic::AbcGeom::ISampleSelector &selector, const std::string &name)
static void read_point_arb_geom_params(const IPointsSchema &schema, const ISampleSelector &selector, bke::MutableAttributeAccessor &attribute_accessor)
bool has_animations(Alembic::AbcGeom::ICurvesSchema &schema, ImportSettings *settings)
static void read_points_sample(const IPointsSchema &schema, const ISampleSelector &selector, MutableSpan< float3 > r_points)
static TOut convert_abc_value(const TIn &in)
bool size_fits_in_int(const int64_t size)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, PointCloud *pointcloud_dst)
VecBase< float, 2 > float2
PointCloud * BKE_pointcloud_add(Main *bmain, const char *name)
PointCloud * BKE_pointcloud_new_nomain(PointCloudType type, int totpoint)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
PointCloud * get_pointcloud_for_write()
bool has_pointcloud() const
void replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static GeometrySet from_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
MutableVArraySpan< T > span
std::string velocity_name
bool always_add_cache_reader