Adding support for converting between Blender custom properties and USD user-defined custom attributes. Custom attributes on Xforms, many data types, and materials are all supported for round-tripping. Please see the USD attributes documentation for more information on custom attributes. Properties are exported with a userProperties: namespace for simple filtering in external apps. This namespace is stripped on import, but other namespace are allowed to persist. An "Import Attributes" parameter has been added with options "None" (do not import attributes), "User" (import attributes in the 'userProperties' namespace only), "All custom" (import all USD custom attributes, the default). An "Export Custom Properties" export option has been added. The property conversion code handles float, double, string and bool types, as well as tuples of size 2, 3 and 4. Note that USD quaternions and arrays of arbitrary length are not yet supported. There is currently no attempt to set the Blender property subtype based on the USD type "role" (e.g., specifying Color or XYZ vector subtypes). This can be addressed in future work. In addition to exporting custom properties, the original Blender object and data names are now saved as USD custom string attributes "userProperties:blender:object_name" and "userProperties:blender:data_name", respectively, on the corresponding USD prims. This feature is enabled with the "Author Blender Name" export option. If a Blender custom string property is named "displayName", it's handled in a special way on export in that its value is used to set the USD prim's "displayName" metadata. Co-authored-by: kiki <charles@skeletalstudios.com> Co-authored-by: Michael Kowalski <makowalski@nvidia.com> Co-authored-by: Charles Wardlaw <kattkieru@users.noreply.github.com> Pull Request: https://projects.blender.org/blender/blender/pulls/118938
114 lines
2.7 KiB
C++
114 lines
2.7 KiB
C++
/* SPDX-FileCopyrightText: 2021 Tangent Animation. All rights reserved.
|
|
* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*
|
|
* Adapted from the Blender Alembic importer implementation. */
|
|
|
|
#include "usd_reader_prim.hh"
|
|
#include "usd_reader_utils.hh"
|
|
|
|
#include "usd.hh"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include <pxr/usd/usd/prim.h>
|
|
|
|
#include "BLI_assert.h"
|
|
|
|
namespace blender::io::usd {
|
|
|
|
void USDPrimReader::set_props(const bool merge_with_parent,
|
|
const pxr::UsdTimeCode motionSampleTime)
|
|
{
|
|
if (!prim_ || !object_) {
|
|
return;
|
|
}
|
|
|
|
eUSDAttrImportMode attr_import_mode = this->import_params_.attr_import_mode;
|
|
|
|
if (attr_import_mode == USD_ATTR_IMPORT_NONE) {
|
|
return;
|
|
}
|
|
|
|
if (merge_with_parent) {
|
|
/* This object represents a parent Xform merged with its child prim.
|
|
* Set the parent prim's custom properties on the Object ID. */
|
|
if (const pxr::UsdPrim parent_prim = prim_.GetParent()) {
|
|
set_id_props_from_prim(&object_->id, parent_prim, attr_import_mode, motionSampleTime);
|
|
}
|
|
}
|
|
if (!object_->data) {
|
|
/* If the object has no data, set the prim's custom properties on the object.
|
|
* This applies to Xforms that have been converted to Empty objects. */
|
|
set_id_props_from_prim(&object_->id, prim_, attr_import_mode, motionSampleTime);
|
|
}
|
|
|
|
if (object_->data) {
|
|
/* If the object has data, the data represents the USD prim, so set the prim's custom
|
|
* properties on the data directly. */
|
|
set_id_props_from_prim(
|
|
static_cast<ID *>(object_->data), prim_, attr_import_mode, motionSampleTime);
|
|
}
|
|
}
|
|
|
|
USDPrimReader::USDPrimReader(const pxr::UsdPrim &prim,
|
|
const USDImportParams &import_params,
|
|
const ImportSettings &settings)
|
|
: name_(prim.GetName().GetString()),
|
|
prim_path_(prim.GetPrimPath().GetString()),
|
|
object_(nullptr),
|
|
prim_(prim),
|
|
import_params_(import_params),
|
|
parent_reader_(nullptr),
|
|
settings_(&settings),
|
|
refcount_(0),
|
|
is_in_instancer_proto_(false)
|
|
{
|
|
}
|
|
|
|
USDPrimReader::~USDPrimReader() = default;
|
|
|
|
const pxr::UsdPrim &USDPrimReader::prim() const
|
|
{
|
|
return prim_;
|
|
}
|
|
|
|
Object *USDPrimReader::object() const
|
|
{
|
|
return object_;
|
|
}
|
|
|
|
void USDPrimReader::object(Object *ob)
|
|
{
|
|
object_ = ob;
|
|
}
|
|
|
|
bool USDPrimReader::valid() const
|
|
{
|
|
return prim_.IsValid();
|
|
}
|
|
|
|
int USDPrimReader::refcount() const
|
|
{
|
|
return refcount_;
|
|
}
|
|
|
|
void USDPrimReader::incref()
|
|
{
|
|
refcount_++;
|
|
}
|
|
|
|
void USDPrimReader::decref()
|
|
{
|
|
refcount_--;
|
|
BLI_assert(refcount_ >= 0);
|
|
}
|
|
|
|
bool USDPrimReader::is_in_proto() const
|
|
{
|
|
return prim_ && (prim_.IsInPrototype() || is_in_instancer_proto_);
|
|
}
|
|
|
|
} // namespace blender::io::usd
|