Alembic

repository·master·Indexed 22 days ago

https://github.com/alembic/alembic

A reference implementation for reading Alembic data into Houdini and a suite of CLI tools for managing .abc archives. Includes AbcConvert for HDF5/Ogawa format conversion, AbcDiff for comparing files, AbcEcho and AbcLs for inspecting hierarchy and metadata, AbcBoundsEcho for bounding box extraction, and AbcStitcher for merging files. Also provides the AlembicArnoldProcedural for loading Alembic archives into Arnold with support for motion blur, instancing, and subdivision.

Tokens
12.1K
Snippets
45
Records
65
Agent score
73%

What's inside alembic-alembic

  1. Core AbcMaterial classes and patterns

    master

    AbcMaterial is a module designed to provide schemas and object types for representing materials and material bindings. It sits above the core Abc module and is independent of AbcGeom.

    Major Classes

    • (I|O)MaterialSchema: Provides an interface for writing data and metadata to a compound property that represents a material definition.
    • (I|O)Material: Interfaces a MaterialSchema onto an IObject using an "is a" pattern. Use this to create objects that function as material definitions themselves.
    • MaterialFlatten: A utility class used for flattening material inheritance. This is the primary interface for applications that only care about the final resulting material of an object, regardless of whether that material was defined via assignment, local definition, or inheritance.
  2. Use the Alembic reference implementation in Houdini

    master

    The Alembic reference implementation for Houdini provides three primary nodes to read and represent Alembic data:

    1. Alembic_In (SOP): Reads an entire Alembic archive or a specific subtree. It can bake in transformations, recreate transformation hierarchies as Houdini objects, and load arbitrary geometry parameters (AbcGeom::GeomParams) as attributes. It includes options to remap attribute names and optimizes performance by detecting constant data or topology.
    2. Alembic Archive (Python Object Node): Constructs and maintains the hierarchy of object, SOP, and camera nodes representing the Alembic scene. Use the 'Build or Update Hierarchy' button to read the archive (or a subtree) and automatically create expressions for matching parameters.
    3. Alembic Xform (Python Object Node): Queries local transformations for a specific path within an archive. It caches non-animated transformations to optimize frame changes.
  3. Understand AbcMaterial terminology

    master

    When working with AbcMaterial, the following terms define how material data is structured and applied:

    • target: A string representing a specific application or renderer (e.g., "prman", "arnold", "maya"). A reserved value "abc" can be used for general interchange.
    • shader type: A string classifying the shader (e.g., "surface", "displacement", "light"). It can also include coshader instances using the prefix "coshader_" (e.g., "coshader_taco").
    • shader name: A string identifying a specific shader object within a target and type (e.g., "paintedplastic").
    • assignment: The process of binding a material object to another object via an Alembic object path.
    • inheritance/flattening: The process of combining contributions from multiple material definitions. This includes combining a hierarchy of material objects or merging a locally defined material with an assigned one.
  4. Handle instanced objects in Alembic

    master

    Alembic supports instancing where one hierarchy can point to another to save space. When reading instanced data, use these methods to identify the relationship:

    • isInstanceRoot(): Returns true if this object is the source/root of an instance.
    • isInstanceDescendant(): Returns true if this object is an instance of another hierarchy.
    • instanceSourcePath(): If the object is an instance root, returns the path to the source hierarchy. Otherwise, returns an empty string.
    • getInstancePtr(): Returns the original AbcA::ObjectReaderPtr if the object is an instance.
  5. Understand the purpose of ScalarSample

    master

    In Alembic, ScalarSample is a helper class used primarily by Scalar Readers and Writers. It is not intended to be the primary object of exchange for scalar data in your application, as it carries an extra DataType overhead (approximately 2 bytes) that can be wasteful when passing data frequently.

    Its main roles are:

    1. Comparison: Allowing readers and writers to compare new samples against previously written/read samples.
    2. Copying: Facilitating the copying of sample values.
    3. Encapsulation: Providing a unified interface for handling different scalar types at the abstract level.
  6. Handle missing samples with the -hold flag in AbcStitcher

    master

    When stitching files that may have non-contiguous time samples, you can control how the output archive handles gaps using the -hold flag.

    • Without -hold (Default): Missing samples are filled with an empty sample (oSchema.set(emptySample)).
    • With -hold: Missing samples are filled using the value from the previous sample (oSchema.setFromPrevious()).
  7. How material inheritance and flattening work

    master

    AbcMaterial supports a hierarchical model where material definitions can inherit and override data from parent materials.

    Inheritance Model

    Material objects can be organized in a hierarchy. A child material inherits the data defined in its parent. For example, if a parent defines a "prman" "surface" shader with a roughness parameter, a child material can define a "prman" "displacement" shader and override the roughness value of the parent's surface shader.

    Note: IMaterial and IMaterialSchema only return data defined locally. To resolve the full state of a material (including inherited values), you must use the MaterialFlatten class.

    Flattening Scenarios

    1. Simple Assignment: An object is assigned a material that has no parents. The resulting material is identical to the local definition.
    2. Hierarchical Assignment: An object is assigned a material that is a child in a material hierarchy. The resulting material is the combination of the local data in the material hierarchy.
    3. Local Definition + Assignment: An object has a material assignment AND a local material definition. The resulting material combines the flattened results of the assignment with the local definition (where local values typically override assigned ones).
  8. Use the AbcExport command to write Alembic files in Maya

    master

    The AbcExport plugin provides a single command to write Alembic files from Maya. Unlike standard file translators, AbcExport can write multiple files with different settings in a single pass through the frame range.

    To use the command, pass a JSON-formatted string to the -j flag containing the specific Alembic export options.

    // Write out the entire scene from frame 1 to 100
    AbcExport -j "-fr 1 100 -file scene.abc";
    
    // Write out only selected shapes and their ancestor nodes
    AbcExport -j "-sl -file scene.abc";
  9. Register the Alembic Maya Plugin

    master

    The Alembic Maya plugin provides integration for importing Alembic files into Autodesk Maya. It registers three primary components: a command, a node, and a file translator.

    Upon initialization, the plugin displays its version and the version of the underlying Alembic::AbcCoreAbstract library in the Maya information console.

  10. Install and build AbcMaterial

    master

    To include AbcMaterial in your Alembic build:

    1. Place the AbcMaterial directory within the lib/Alembic directory of your Alembic checkout.
    2. Add ADD_SUBDIRECTORY( AbcMaterial ) to the CMakeLists.txt file located within the lib/Alembic directory.
    3. Compile the project using CMake.
    # Add this to lib/Alembic/CMakeLists.txt
    ADD_SUBDIRECTORY( AbcMaterial )
  11. Load an Alembic file using AbcImport

    master

    To load an Alembic file into Maya, use the AbcImport command. This is the simplest method for importing an Alembic scene.

    Note that AbcImport manages an AlembicNode. While an AlembicNode exists in the scene, you should use the AbcImport command to create and manage it rather than interacting with the node directly, especially if the scene contains animated data.

    AbcImport "scene.abc";
  12. Import the Alembic Python module

    master

    The Alembic Python bindings are organized into several submodules that correspond to the core C++ library components. To use Alembic in Python, you must import the base alembic module and then import the specific submodules required for your task (e.g., Abc, AbcGeom, AbcCoreAbstract).

    Note: The bindings depend on the imath module, which must be available in your Python environment.

    import alembic
    import alembic.Abc
    import alembic.AbcGeom
    import alembic.AbcCoreAbstract
    import alembic.Util