This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/io/alembic/ABC_alembic.h
Sybren A. Stüvel ee97add4c4 Alembic export: write custom properties
Write custom properties (aka ID properties) to Alembic, to the
`.userProperties` compound property.

Manifest Task: https://developer.blender.org/T50725

Scalar properties (so single-value/non-array properties) are written as
single-element array properties to Alembic. This is also what's done by
Houdini and Maya exporters, so it seems to be the standard way of doing
things. It also simplifies the implementation.

Two-dimensional arrays are flattened by concatenating all the numbers
into a single array. This is because ID properties have a limited type
system. This means that a 3x3 "matrix" could just as well be a list of
three 3D vectors.

Alembic has two container properties to store custom data:
- `.userProperties`, which is meant for properties that aren't
  necessarily understood by other software packages, and
- `.arbGeomParams`, which can contain the same kind of data as
  `.userProperties`, but can also specify that these vary per face of a
  mesh. This property is mostly intended for renderers.

Most industry packages write their custom data to `.arbGeomParams`.
However, given their goals I feel that `.userProperties` is the more
appropriate one for Blender's ID Properties.

The code is a bit more involved than I would have liked. An
`ABCAbstractWriter` has a `uniqueptr` to its `CustomPropertiesExporter`,
but the `CustomPropertiesExporter` also has a pointer back to its owning
`ABCAbstractWriter`. It's the latter pointer that I'm not too happy
with, but it has a reason. Getting the aforementioned `.userProperties`
from the Alembic library will automatically create it if it doesn't
exist already. If it's not used to actually add custom properties to, it
will crash the Alembic CLI tools (and maybe others too). This is what
the pointer back to the `ABCAbstractWriter` is used for: to get the
`.userProperties` at the last moment, when it's 100% sure at least one
custom property will be written.

Differential Revision: https://developer.blender.org/D8869

Reviewed by: sergey, dbystedt
2020-09-14 12:49:27 +02:00

146 lines
4.5 KiB
C++

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#pragma once
/** \file
* \ingroup balembic
*/
#ifdef __cplusplus
extern "C" {
#endif
struct CacheReader;
struct ListBase;
struct Main;
struct Mesh;
struct Object;
struct Scene;
struct bContext;
typedef struct AbcArchiveHandle AbcArchiveHandle;
int ABC_get_version(void);
struct AlembicExportParams {
double frame_start;
double frame_end;
unsigned int frame_samples_xform;
unsigned int frame_samples_shape;
double shutter_open;
double shutter_close;
bool selected_only;
bool uvs;
bool normals;
bool vcolors;
bool apply_subdiv;
bool curves_as_mesh;
bool flatten_hierarchy;
bool visible_objects_only;
bool renderable_only;
bool face_sets;
bool use_subdiv_schema;
bool packuv;
bool triangulate;
bool export_hair;
bool export_particles;
bool export_custom_properties;
bool use_instancing;
/* See MOD_TRIANGULATE_NGON_xxx and MOD_TRIANGULATE_QUAD_xxx
* in DNA_modifier_types.h */
int quad_method;
int ngon_method;
float global_scale;
};
/* The ABC_export and ABC_import functions both take a as_background_job
* parameter, and return a boolean.
*
* When as_background_job=true, returns false immediately after scheduling
* a background job.
*
* When as_background_job=false, performs the export synchronously, and returns
* true when the export was ok, and false if there were any errors.
*/
bool ABC_export(struct Scene *scene,
struct bContext *C,
const char *filepath,
const struct AlembicExportParams *params,
bool as_background_job);
bool ABC_import(struct bContext *C,
const char *filepath,
float scale,
bool is_sequence,
bool set_frame_range,
int sequence_len,
int offset,
bool validate_meshes,
bool as_background_job);
AbcArchiveHandle *ABC_create_handle(struct Main *bmain,
const char *filename,
struct ListBase *object_paths);
void ABC_free_handle(AbcArchiveHandle *handle);
void ABC_get_transform(struct CacheReader *reader,
float r_mat_world[4][4],
float time,
float scale);
/* Either modifies existing_mesh in-place or constructs a new mesh. */
struct Mesh *ABC_read_mesh(struct CacheReader *reader,
struct Object *ob,
struct Mesh *existing_mesh,
const float time,
const char **err_str,
int read_flags);
bool ABC_mesh_topology_changed(struct CacheReader *reader,
struct Object *ob,
struct Mesh *existing_mesh,
const float time,
const char **err_str);
void CacheReader_incref(struct CacheReader *reader);
void CacheReader_free(struct CacheReader *reader);
struct CacheReader *CacheReader_open_alembic_object(struct AbcArchiveHandle *handle,
struct CacheReader *reader,
struct Object *object,
const char *object_path);
bool ABC_has_vec3_array_property_named(struct CacheReader *reader, const char *name);
/* r_vertex_velocities should point to a preallocated array of num_vertices floats */
int ABC_read_velocity_cache(struct CacheReader *reader,
const char *velocity_name,
float time,
float velocity_scale,
int num_vertices,
float *r_vertex_velocities);
#ifdef __cplusplus
}
#endif