13#include <Alembic/Abc/ICompoundProperty.h>
14#include <Alembic/Abc/ISampleSelector.h>
15#include <Alembic/Abc/OCompoundProperty.h>
16#include <Alembic/Abc/TypedArraySample.h>
17#include <Alembic/AbcCoreAbstract/PropertyHeader.h>
18#include <Alembic/AbcGeom/GeometryScope.h>
19#include <Alembic/AbcGeom/IGeomParam.h>
20#include <Alembic/AbcGeom/OGeomParam.h>
41using Alembic::AbcGeom::kFacevaryingScope;
42using Alembic::AbcGeom::kVaryingScope;
43using Alembic::AbcGeom::kVertexScope;
45using Alembic::Abc::C4fArraySample;
46using Alembic::Abc::UInt32ArraySample;
47using Alembic::Abc::V2fArraySample;
49using Alembic::AbcGeom::OC4fGeomParam;
50using Alembic::AbcGeom::OV2fGeomParam;
51using Alembic::AbcGeom::OV3fGeomParam;
59 std::vector<Imath::V2f> &uvs,
60 std::vector<uint32_t> &uvidx,
63 const float2 *uv_map_array =
static_cast<const float2 *
>(cd_data);
78 for (
const int i :
faces.index_range()) {
82 for (
int j = 0; j < face.
size(); j++,
count++) {
86 uvs[
count][0] = (*loopuv)[0];
87 uvs[
count][1] = (*loopuv)[1];
93 std::vector<std::vector<uint32_t>> idx_map(config.
totvert);
96 for (
const int i :
faces.index_range()) {
98 int *face_verts = corner_verts + face.
start() + face.
size();
101 for (
int j = 0; j < face.
size(); j++) {
105 Imath::V2f uv((*loopuv)[0], (*loopuv)[1]);
106 bool found_same =
false;
109 for (uint32_t uv_idx : idx_map[*face_verts]) {
110 if (uvs[uv_idx] == uv) {
112 uvidx.push_back(uv_idx);
119 uint32_t uv_idx = idx_count++;
120 idx_map[*face_verts].push_back(uv_idx);
121 uvidx.push_back(uv_idx);
133 if (active_uvlayer < 0) {
152 const std::string &uv_map_name)
155 std::vector<Imath::V2f> uvs;
159 if (
indices.empty() || uvs.empty()) {
163 OV2fGeomParam param = config.
abc_uv_maps[uv_map_name];
165 if (!param.valid()) {
166 param = OV2fGeomParam(prop, uv_map_name,
true, kFacevaryingScope, 1);
168 OV2fGeomParam::Sample
sample(V2fArraySample(&uvs.front(), uvs.size()),
178 std::vector<Imath::C4f> &buffer,
179 std::vector<uint32_t> &uvidx,
182 const float cscale = 1.0f / 255.0f;
184 const MCol *cfaces =
static_cast<const MCol *
>(cd_data);
186 buffer.reserve(config.
totvert);
191 for (
const int i :
faces.index_range()) {
195 for (
int j = 0; j < face.
size(); j++) {
198 col[0] = cface->
a * cscale;
199 col[1] = cface->
r * cscale;
200 col[2] = cface->
g * cscale;
201 col[3] = cface->
b * cscale;
203 buffer.push_back(
col);
204 uvidx.push_back(buffer.size() - 1);
216 const std::string &vcol_name)
219 std::vector<Imath::C4f> buffer;
223 if (
indices.empty() || buffer.empty()) {
229 if (!param.valid()) {
230 param = OC4fGeomParam(prop, vcol_name,
true, kFacevaryingScope, 1);
233 OC4fGeomParam::Sample
sample(C4fArraySample(&buffer.front(), buffer.size()),
247 if (customdata ==
nullptr) {
251 const float (*orcodata)[3] =
static_cast<const float (*)[3]
>(customdata);
254 std::vector<Imath::V3f> coords(config.
totvert);
256 for (
int vertex_idx = 0; vertex_idx < config.
totvert; vertex_idx++) {
258 coords[vertex_idx].setValue(orco_yup[0], orco_yup[1], orco_yup[2]);
264 mesh,
reinterpret_cast<float (*)[3]
>(coords.data()), mesh->
verts_num,
true);
271 OV3fGeomParam::Sample
sample(coords, kVertexScope);
289 for (
int i = 0;
i < tot_layers;
i++) {
295 if (
i == active_layer) {
309using Alembic::Abc::C3fArraySamplePtr;
310using Alembic::Abc::C4fArraySamplePtr;
311using Alembic::Abc::PropertyHeader;
312using Alembic::Abc::UInt32ArraySamplePtr;
314using Alembic::AbcGeom::IC3fGeomParam;
315using Alembic::AbcGeom::IC4fGeomParam;
316using Alembic::AbcGeom::IV2fGeomParam;
317using Alembic::AbcGeom::IV3fGeomParam;
322 const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
323 const UInt32ArraySamplePtr &
indices)
329 uint uv_index, loop_index, rev_loop_index;
334 for (
const int i :
faces.index_range()) {
338 for (
int f = 0; f < face.
size(); f++) {
339 rev_loop_index = rev_loop_offset - f;
340 loop_index = do_uvs_per_loop ? face.
start() + f : corner_verts[rev_loop_index];
341 uv_index = (*indices)[loop_index];
342 const Imath::V2f &uv = (*uvs)[uv_index];
344 float2 &loopuv = uv_map[rev_loop_index];
352 const size_t array_size,
353 const std::string &iobject_full_name,
354 const PropertyHeader &prop_header,
355 bool &r_is_out_of_bounds,
356 bool &r_bounds_warning_given)
358 if (color_index < array_size) {
362 if (!r_bounds_warning_given) {
363 std::cerr <<
"Alembic: color index out of bounds "
364 "reading face colors for object "
365 << iobject_full_name <<
", property " << prop_header.getName() << std::endl;
366 r_bounds_warning_given =
true;
368 r_is_out_of_bounds =
true;
373 const ICompoundProperty &arbGeomParams,
374 const PropertyHeader &prop_header,
376 const Alembic::Abc::ISampleSelector &iss)
378 C3fArraySamplePtr c3f_ptr = C3fArraySamplePtr();
379 C4fArraySamplePtr c4f_ptr = C4fArraySamplePtr();
380 Alembic::Abc::UInt32ArraySamplePtr
indices;
385 if (IC3fGeomParam::matches(prop_header)) {
386 IC3fGeomParam color_param(arbGeomParams, prop_header.getName());
387 IC3fGeomParam::Sample
sample;
390 color_param.getIndexed(
sample, iss);
391 is_facevarying =
sample.getScope() == kFacevaryingScope &&
394 c3f_ptr =
sample.getVals();
398 else if (IC4fGeomParam::matches(prop_header)) {
399 IC4fGeomParam color_param(arbGeomParams, prop_header.getName());
400 IC4fGeomParam::Sample
sample;
403 color_param.getIndexed(
sample, iss);
404 is_facevarying =
sample.getScope() == kFacevaryingScope &&
407 c4f_ptr =
sample.getVals();
420 MCol *cfaces =
static_cast<MCol *
>(cd_data);
424 size_t face_index = 0;
426 bool bounds_warning_given =
false;
432 bool use_dual_indexing = is_facevarying &&
indices->size() > 0;
434 for (
const int i :
faces.index_range()) {
437 const int *face_verts = &corner_verts[face.
start() + face.
size()];
439 for (
int j = 0; j < face.
size(); j++, face_index++) {
443 color_index = is_facevarying ? face_index : *face_verts;
444 if (use_dual_indexing) {
445 color_index = (*indices)[color_index];
448 bool is_mcols_out_of_bounds =
false;
453 is_mcols_out_of_bounds,
454 bounds_warning_given);
455 if (is_mcols_out_of_bounds) {
458 const Imath::C3f &
color = (*c3f_ptr)[color_index];
465 bool is_mcols_out_of_bounds =
false;
470 is_mcols_out_of_bounds,
471 bounds_warning_given);
472 if (is_mcols_out_of_bounds) {
475 const Imath::C4f &
color = (*c4f_ptr)[color_index];
486 const PropertyHeader &prop_header,
488 const Alembic::Abc::ISampleSelector &iss)
490 IV2fGeomParam uv_param(prop, prop_header.getName());
492 if (!uv_param.isIndexed()) {
496 IV2fGeomParam::Sample
sample;
497 uv_param.getIndexed(
sample, iss);
499 UInt32ArraySamplePtr uvs_indices =
sample.getIndices();
510 read_uvs(config, cd_data, uv_scope,
sample.getVals(), uvs_indices);
515 const float velocity_scale)
517 const int num_velocity_vectors = int(velocities->size());
529 for (
int i = 0;
i < num_velocity_vectors;
i++) {
530 const Imath::V3f &vel_in = (*velocities)[
i];
538 const Alembic::Abc::ISampleSelector &iss)
546 if (!param.valid() || param.isIndexed()) {
550 if (param.getScope() != kVertexScope) {
555 IV3fGeomParam::Sample
sample = param.getExpandedValue(iss);
556 Alembic::AbcGeom::V3fArraySamplePtr abc_orco =
sample.getVals();
557 const size_t totvert = abc_orco.get()->size();
574 float (*orcodata)[3] =
static_cast<float (*)[3]
>(cd_data);
575 for (
int vertex_idx = 0; vertex_idx < totvert; ++vertex_idx) {
576 const Imath::V3f &abc_coords = (*abc_orco)[vertex_idx];
586 const ICompoundProperty &prop,
588 const Alembic::Abc::ISampleSelector &iss)
596 const size_t num_props = prop.getNumProperties();
598 for (
size_t i = 0;
i < num_props;
i++) {
599 const Alembic::Abc::PropertyHeader &prop_header = prop.getPropertyHeader(
i);
602 if (IV2fGeomParam::matches(prop_header) && Alembic::AbcGeom::isUV(prop_header)) {
612 if (IC3fGeomParam::matches(prop_header) || IC4fGeomParam::matches(prop_header)) {
621 const Alembic::AbcGeom::UInt32ArraySamplePtr &
indices)
623 if (scope == kFacevaryingScope &&
indices->size() == config.
totloop) {
struct CustomDataLayer * BKE_attribute_new(AttributeOwner &owner, blender::StringRef name, eCustomDataType type, blender::bke::AttrDomain domain, struct ReportList *reports)
CustomData interface, see also DNA_customdata_types.h.
const void * CustomData_get_layer_n(const CustomData *data, eCustomDataType type, int n)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
const char * CustomData_get_layer_name(const CustomData *data, eCustomDataType type, int n)
int CustomData_get_active_layer(const CustomData *data, eCustomDataType type)
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
void BKE_mesh_orco_verts_transform(Mesh *mesh, blender::MutableSpan< blender::float3 > orco, bool invert)
MINLINE void mul_v3_fl(float r[3], float f)
BMesh const char void * data
static AttributeOwner from_id(ID *id)
constexpr int64_t size() const
constexpr int64_t start() const
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
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])
const char * get_uv_sample(UVSample &sample, const CDStreamConfig &config, CustomData *data)
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)
void write_custom_data(const OCompoundProperty &prop, CDStreamConfig &config, CustomData *data, int data_type)
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 void get_uvs(const CDStreamConfig &config, std::vector< Imath::V2f > &uvs, std::vector< uint32_t > &uvidx, const void *cd_data)
static const std::string propNameOriginalCoordinates("Pref")
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 size_t mcols_out_of_bounds_check(const size_t color_index, const size_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 write_generated_coordinates(const OCompoundProperty &prop, CDStreamConfig &config)
static void get_cols(const CDStreamConfig &config, std::vector< Imath::C4f > &buffer, std::vector< uint32_t > &uvidx, const void *cd_data)
static void read_uvs(const CDStreamConfig &config, void *data, const AbcUvScope uv_scope, const Alembic::AbcGeom::V2fArraySamplePtr &uvs, const UInt32ArraySamplePtr &indices)
static void write_mcol(const OCompoundProperty &prop, CDStreamConfig &config, const void *data, const std::string &vcol_name)
static void write_uv(const OCompoundProperty &prop, CDStreamConfig &config, const void *data, const std::string &uv_map_name)
VecBase< float, 2 > float2
std::map< std::string, Alembic::AbcGeom::OC4fGeomParam > abc_vertex_colors
void *(* add_customdata_cb)(Mesh *mesh, const char *name, int data_type)
Alembic::AbcGeom::OV3fGeomParam abc_orco
std::map< std::string, Alembic::AbcGeom::OV2fGeomParam > abc_uv_maps