14#include <Alembic/Abc/ICompoundProperty.h>
15#include <Alembic/Abc/ISampleSelector.h>
16#include <Alembic/Abc/OCompoundProperty.h>
17#include <Alembic/Abc/TypedArraySample.h>
18#include <Alembic/AbcCoreAbstract/PropertyHeader.h>
19#include <Alembic/AbcGeom/GeometryScope.h>
20#include <Alembic/AbcGeom/IGeomParam.h>
21#include <Alembic/AbcGeom/OGeomParam.h>
47using Alembic::AbcGeom::kFacevaryingScope;
48using Alembic::AbcGeom::kVaryingScope;
49using Alembic::AbcGeom::kVertexScope;
51using Alembic::Abc::C4fArraySample;
52using Alembic::Abc::UInt32ArraySample;
53using Alembic::Abc::V2fArraySample;
55using Alembic::AbcGeom::OC4fGeomParam;
56using Alembic::AbcGeom::OV2fGeomParam;
57using Alembic::AbcGeom::OV3fGeomParam;
61 std::vector<Imath::V2f> &uvs,
62 std::vector<uint32_t> &uvidx,
78 for (
int j = 0; j < face.
size(); j++, count++) {
82 uvs[count][0] = (*loopuv)[0];
83 uvs[count][1] = (*loopuv)[1];
89 std::vector<std::vector<uint32_t>> idx_map(config.
totvert);
94 int *face_verts = corner_verts + face.
start() + face.
size();
97 for (
int j = 0; j < face.
size(); j++) {
101 Imath::V2f uv((*loopuv)[0], (*loopuv)[1]);
102 bool found_same =
false;
105 for (
uint32_t uv_idx : idx_map[*face_verts]) {
106 if (uvs[uv_idx] == uv) {
108 uvidx.push_back(uv_idx);
116 idx_map[*face_verts].push_back(uv_idx);
117 uvidx.push_back(uv_idx);
149 const std::string &uv_map_name)
151 std::vector<uint32_t> indices;
152 std::vector<Imath::V2f> uvs;
156 if (indices.empty() || uvs.empty()) {
160 OV2fGeomParam param = config.
abc_uv_maps[uv_map_name];
162 if (!param.valid()) {
163 param = OV2fGeomParam(prop, uv_map_name,
true, kFacevaryingScope, 1);
165 OV2fGeomParam::Sample
sample(V2fArraySample(&uvs.front(), uvs.size()),
166 UInt32ArraySample(&indices.front(), indices.size()),
178 if (customdata ==
nullptr) {
182 const float (*orcodata)[3] =
static_cast<const float (*)[3]
>(customdata);
185 std::vector<Imath::V3f> coords(config.
totvert);
187 for (
int vertex_idx = 0; vertex_idx < config.
totvert; vertex_idx++) {
189 coords[vertex_idx].setValue(orco_yup[0], orco_yup[1], orco_yup[2]);
195 mesh,
reinterpret_cast<float (*)[3]
>(coords.data()),
mesh->verts_num,
true);
199 config.
abc_orco = OV3fGeomParam(prop, propNameOriginalCoordinates,
false, kVertexScope, 1);
202 OV3fGeomParam::Sample
sample(coords, kVertexScope);
211 if (name == active_uv_name) {
222using Alembic::Abc::C3fArraySamplePtr;
223using Alembic::Abc::C4fArraySamplePtr;
224using Alembic::Abc::PropertyHeader;
225using Alembic::Abc::UInt32ArraySamplePtr;
227using Alembic::AbcGeom::IC3fGeomParam;
228using Alembic::AbcGeom::IC4fGeomParam;
229using Alembic::AbcGeom::IV2fGeomParam;
230using Alembic::AbcGeom::IV3fGeomParam;
235 const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
236 const UInt32ArraySamplePtr &indices)
251 const int64_t rev_loop_index = rev_loop_offset - f;
252 const int64_t loop_index = do_uvs_per_loop ? face.
start() + f : corner_verts[rev_loop_index];
256 const int64_t uv_index = (*indices)[loop_index];
260 const Imath::V2f &uv = (*uvs)[uv_index];
262 float2 &loopuv = uv_map[rev_loop_index];
271 const std::string &iobject_full_name,
272 const PropertyHeader &prop_header,
273 bool &r_is_out_of_bounds,
274 bool &r_bounds_warning_given)
280 if (!r_bounds_warning_given) {
281 std::cerr <<
"Alembic: color index out of bounds "
282 "reading face colors for object "
283 << iobject_full_name <<
", property " << prop_header.getName() << std::endl;
284 r_bounds_warning_given =
true;
286 r_is_out_of_bounds =
true;
291 const ICompoundProperty &arbGeomParams,
292 const PropertyHeader &prop_header,
294 const Alembic::Abc::ISampleSelector &iss)
296 C3fArraySamplePtr c3f_ptr = C3fArraySamplePtr();
297 C4fArraySamplePtr c4f_ptr = C4fArraySamplePtr();
298 Alembic::Abc::UInt32ArraySamplePtr indices;
303 if (IC3fGeomParam::matches(prop_header)) {
304 IC3fGeomParam color_param(arbGeomParams, prop_header.getName());
305 IC3fGeomParam::Sample
sample;
308 color_param.getIndexed(
sample, iss);
309 is_facevarying =
sample.getScope() == kFacevaryingScope &&
312 c3f_ptr =
sample.getVals();
313 indices =
sample.getIndices();
316 else if (IC4fGeomParam::matches(prop_header)) {
317 IC4fGeomParam color_param(arbGeomParams, prop_header.getName());
318 IC4fGeomParam::Sample
sample;
321 color_param.getIndexed(
sample, iss);
322 is_facevarying =
sample.getScope() == kFacevaryingScope &&
325 c4f_ptr =
sample.getVals();
326 indices =
sample.getIndices();
344 bool bounds_warning_given =
false;
350 bool use_dual_indexing = is_facevarying && indices->size() > 0;
356 for (
int64_t j = 0; j < face.
size(); j++, face_index++) {
359 color_index = is_facevarying ? face_index : corner_verts[corner];
360 if (use_dual_indexing) {
361 color_index = (*indices)[color_index];
364 bool is_mcols_out_of_bounds =
false;
369 is_mcols_out_of_bounds,
370 bounds_warning_given);
371 if (is_mcols_out_of_bounds) {
374 const Imath::C3f &
color = (*c3f_ptr)[color_index];
378 attr.
span[corner].a = 255;
381 bool is_mcols_out_of_bounds =
false;
386 is_mcols_out_of_bounds,
387 bounds_warning_given);
388 if (is_mcols_out_of_bounds) {
391 const Imath::C4f &
color = (*c4f_ptr)[color_index];
404 const PropertyHeader &prop_header,
406 const Alembic::Abc::ISampleSelector &iss)
408 IV2fGeomParam uv_param(prop, prop_header.getName());
410 if (!uv_param.isIndexed()) {
414 IV2fGeomParam::Sample
sample;
415 uv_param.getIndexed(
sample, iss);
417 UInt32ArraySamplePtr uvs_indices =
sample.getIndices();
436 const float velocity_scale)
449 for (
int64_t i = 0; i < num_velocity_vectors; i++) {
450 const Imath::V3f &vel_in = (*velocities)[i];
459 const Alembic::Abc::ISampleSelector &iss)
461 if (!prop.valid() || prop.getPropertyHeader(propNameOriginalCoordinates) ==
nullptr) {
466 IV3fGeomParam param(prop, propNameOriginalCoordinates);
467 if (!param.valid() || param.isIndexed()) {
471 if (param.getScope() != kVertexScope) {
476 IV3fGeomParam::Sample
sample = param.getExpandedValue(iss);
477 Alembic::AbcGeom::V3fArraySamplePtr abc_orco =
sample.getVals();
478 const size_t totvert = abc_orco.get()->size();
481 if (totvert !=
mesh->verts_num) {
495 float (*orcodata)[3] =
static_cast<float (*)[3]
>(cd_data);
496 for (
int vertex_idx = 0; vertex_idx < totvert; ++vertex_idx) {
497 const Imath::V3f &abc_coords = (*abc_orco)[vertex_idx];
507 const ICompoundProperty &prop,
509 const Alembic::Abc::ISampleSelector &iss)
517 const size_t num_props = prop.getNumProperties();
519 for (
size_t i = 0; i < num_props; i++) {
520 const Alembic::Abc::PropertyHeader &prop_header = prop.getPropertyHeader(i);
523 if (IV2fGeomParam::matches(prop_header) && Alembic::AbcGeom::isUV(prop_header)) {
533 if (IC3fGeomParam::matches(prop_header) || IC4fGeomParam::matches(prop_header)) {
542 const Alembic::AbcGeom::UInt32ArraySamplePtr &indices)
544 if (scope == kFacevaryingScope && indices->size() == config.
totloop) {
551 if (
ELEM(scope, kVaryingScope, kVertexScope) && indices->size() == config.
totvert) {
560 const Alembic::AbcGeom::ISampleSelector &sample_sel)
565 const PropertyHeader *header = prop.getPropertyHeader(name);
566 if (header && header->isScalar() && Alembic::AbcGeom::IStringProperty::matches(*header)) {
567 Alembic::AbcGeom::IStringProperty active_color_attribute(prop, header->getName());
568 return active_color_attribute.getValue(sample_sel);
574 const ICompoundProperty &user_props,
575 const Alembic::AbcGeom::ISampleSelector &sample_sel)
578 user_props, ABC_ACTIVE_COLOR_ATTRIBUTE_PROPNAME, sample_sel);
580 user_props, ABC_DEFAULT_COLOR_ATTRIBUTE_PROPNAME, sample_sel);
596 if (first_color_attribute.
is_empty()) {
597 first_color_attribute = iter.
name;
600 if (iter.
name == active_color_attribute) {
601 final_active_color_attribute = active_color_attribute;
603 if (iter.
name == default_color_attribute) {
604 final_default_color_attribute = default_color_attribute;
608 if (final_active_color_attribute.
is_empty()) {
609 final_active_color_attribute = first_color_attribute;
611 if (final_default_color_attribute.
is_empty()) {
612 final_default_color_attribute = first_color_attribute;
615 if (!final_default_color_attribute.
is_empty()) {
618 if (!final_active_color_attribute.
is_empty()) {
Generic geometry attributes built on CustomData.
CustomData interface, see also DNA_customdata_types.h.
constexpr int64_t size() const
constexpr int64_t start() const
constexpr const T * data() const
constexpr const char * c_str() const
GAttributeReader lookup(const StringRef name) const
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
constexpr bool is_empty() const
constexpr bool is_empty() const
IndexRange index_range() const
void write_uv_maps(const OCompoundProperty &prop, CDStreamConfig &config, const Mesh &mesh)
AbcUvScope get_uv_scope(const Alembic::AbcGeom::GeometryScope scope, const CDStreamConfig &config, const Alembic::AbcGeom::UInt32ArraySamplePtr &indices)
BLI_INLINE void copy_yup_from_zup(float yup[3], const float zup[3])
void read_velocity(const V3fArraySamplePtr &velocities, const CDStreamConfig &config, const float velocity_scale)
std::string get_valid_abc_name(const char *name)
static void read_custom_data_mcols(const std::string &iobject_full_name, const ICompoundProperty &arbGeomParams, const PropertyHeader &prop_header, const CDStreamConfig &config, const Alembic::Abc::ISampleSelector &iss)
static void read_uvs(const CDStreamConfig &config, MutableSpan< float2 > uv_map, const AbcUvScope uv_scope, const Alembic::AbcGeom::V2fArraySamplePtr &uvs, const UInt32ArraySamplePtr &indices)
BLI_INLINE void copy_zup_from_yup(float zup[3], const float yup[3])
void read_custom_data(const std::string &iobject_full_name, const ICompoundProperty &prop, const CDStreamConfig &config, const Alembic::Abc::ISampleSelector &iss)
static std::string get_string_property(const ICompoundProperty &prop, const StringRefNull name, const Alembic::AbcGeom::ISampleSelector &sample_sel)
static void read_custom_data_uvs(const ICompoundProperty &prop, const PropertyHeader &prop_header, const CDStreamConfig &config, const Alembic::Abc::ISampleSelector &iss)
void read_generated_coordinates(const ICompoundProperty &prop, const CDStreamConfig &config, const Alembic::Abc::ISampleSelector &iss)
static void get_uvs(const CDStreamConfig &config, std::vector< Imath::V2f > &uvs, std::vector< uint32_t > &uvidx, const Span< float2 > uv_map_array)
void write_generated_coordinates(const OCompoundProperty &prop, CDStreamConfig &config)
const char * get_uv_sample(UVSample &sample, const CDStreamConfig &config, const Mesh &mesh)
static void write_uv(const OCompoundProperty &prop, CDStreamConfig &config, const Span< float2 > data, const std::string &uv_map_name)
static int64_t mcols_out_of_bounds_check(const int64_t color_index, const int64_t array_size, const std::string &iobject_full_name, const PropertyHeader &prop_header, bool &r_is_out_of_bounds, bool &r_bounds_warning_given)
void read_active_and_default_color_attributes(Mesh &mesh, const ICompoundProperty &user_props, const Alembic::AbcGeom::ISampleSelector &sample_sel)
bool index_in_range(const int64_t index, const int64_t size)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
void BKE_id_attributes_default_color_set(struct ID *id, std::optional< StringRef > name)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
MINLINE void mul_v3_fl(float r[3], float f)
VecBase< float, 2 > float2
BMesh const char void * data
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void BKE_mesh_orco_verts_transform(Mesh *mesh, MutableSpan< float3 > orco, bool invert)
void BKE_id_attributes_active_color_set(struct ID *id, std::optional< StringRef > name)
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
VecBase< float, 3 > float3
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
MutableVArraySpan< T > span
Alembic::AbcGeom::OV3fGeomParam abc_orco
std::map< std::string, Alembic::AbcGeom::OV2fGeomParam > abc_uv_maps