Blender  V3.3
abc_writer_abstract.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 #pragma once
4 
6 #include "abc_custom_props.h"
8 
9 #include <Alembic/Abc/OObject.h>
10 #include <vector>
11 
12 #include "DEG_depsgraph_query.h"
13 #include "DNA_material_types.h"
14 
15 struct IDProperty;
16 struct Object;
17 
18 namespace blender::io::alembic {
19 
21  protected:
23 
27  Imath::Box3d bounding_box_;
28 
29  /* Visibility of this writer's data in Alembic. */
30  Alembic::Abc::OCharProperty abc_visibility_;
31 
32  /* Optional writer for custom properties. */
33  std::unique_ptr<CustomPropertiesExporter> custom_props_;
34 
35  public:
36  explicit ABCAbstractWriter(const ABCWriterConstructorArgs &args);
37 
38  virtual void write(HierarchyContext &context) override;
39 
40  /* Returns true if the data to be written is actually supported. This would, for example, allow a
41  * hypothetical camera writer accept a perspective camera but reject an orthogonal one.
42  *
43  * Returning false from a transform writer will prevent the object and all its descendants from
44  * being exported. Returning false from a data writer (object data, hair, or particles) will
45  * only prevent that data from being written (and thus cause the object to be exported as an
46  * Empty). */
47  virtual bool is_supported(const HierarchyContext *context) const;
48 
49  uint32_t timesample_index() const;
50  const Imath::Box3d &bounding_box() const;
51 
52  /* Called by AlembicHierarchyCreator after checking that the data is supported via
53  * is_supported(). */
55 
56  virtual Alembic::Abc::OObject get_alembic_object() const = 0;
57 
58  /* Return the Alembic object's CompoundProperty that'll contain the custom properties.
59  *
60  * This function is called whenever there are custom properties to be written to Alembic. It
61  * should call abc_schema_prop_for_custom_props() with the writer's Alembic schema object.
62  *
63  * If custom properties are not supported by a specific subclass, it should return an empty
64  * OCompoundProperty() and override ensure_custom_properties_exporter() to do nothing.
65  */
66  virtual Alembic::Abc::OCompoundProperty abc_prop_for_custom_props() = 0;
67 
68  protected:
69  virtual void do_write(HierarchyContext &context) = 0;
70 
71  virtual void update_bounding_box(Object *object);
72 
73  /* Return ID properties of whatever ID datablock is written by this writer. Defaults to the
74  * properties of the object data. Can return nullptr if no custom properties are to be written.
75  */
76  virtual const IDProperty *get_id_properties(const HierarchyContext &context) const;
77 
79 
81 
82  /* Return the Alembic schema's compound property, which will be used for writing custom
83  * properties.
84  *
85  * This can return either abc_schema.getUserProperties() or abc_schema.getArbGeomParams(). The
86  * former only holds values similar to Blender's custom properties, whereas the latter can also
87  * specify that certain custom properties vary per mesh component (so per face, vertex, etc.). As
88  * such, .userProperties is more suitable for custom properties. However, Maya, Houdini use
89  * .arbGeomParams for custom data.
90  *
91  * Because of this, the code uses this templated function so that there is one place that
92  * determines where custom properties are exporter to.
93  */
94  template<typename T>
95  Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
96  {
97  return abc_schema.getUserProperties();
98  }
99 };
100 
101 } // namespace blender::io::alembic
virtual Alembic::Abc::OCompoundProperty abc_prop_for_custom_props()=0
void write_visibility(const HierarchyContext &context)
ABCAbstractWriter(const ABCWriterConstructorArgs &args)
virtual void do_write(HierarchyContext &context)=0
Alembic::Abc::OCompoundProperty abc_schema_prop_for_custom_props(T abc_schema)
virtual const IDProperty * get_id_properties(const HierarchyContext &context) const
virtual void create_alembic_objects(const HierarchyContext *context)=0
std::unique_ptr< CustomPropertiesExporter > custom_props_
virtual void ensure_custom_properties_exporter(const HierarchyContext &context)
virtual void write(HierarchyContext &context) override
const ABCWriterConstructorArgs args_
virtual bool is_supported(const HierarchyContext *context) const
virtual Alembic::Abc::OObject get_alembic_object() const =0
virtual void update_bounding_box(Object *object)
Alembic::Abc::OCharProperty abc_visibility_
const Imath::Box3d & bounding_box() const
#define T
unsigned int uint32_t
Definition: stdint.h:80