Blender V5.0
usd_reader_prim.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Tangent Animation. All rights reserved.
2 * SPDX-FileCopyrightText: 2023 Blender Authors
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 *
6 * Adapted from the Blender Alembic importer implementation. */
7
8#include "usd_reader_prim.hh"
9#include "usd_reader_utils.hh"
10
11#include "usd.hh"
12
13#include "DNA_object_types.h"
14
15#include <pxr/usd/usd/prim.h>
16
17#include "BLI_assert.h"
18
19namespace blender::io::usd {
20
21void USDPrimReader::set_props(const bool merge_with_parent, const pxr::UsdTimeCode time)
22{
23 if (!prim_ || !object_) {
24 return;
25 }
26
27 eUSDPropertyImportMode property_import_mode = this->import_params_.property_import_mode;
28
29 if (property_import_mode == USD_ATTR_IMPORT_NONE) {
30 return;
31 }
32
33 if (merge_with_parent) {
34 /* This object represents a parent Xform merged with its child prim.
35 * Set the parent prim's custom properties on the Object ID. */
36 if (const pxr::UsdPrim parent_prim = prim_.GetParent()) {
37 set_id_props_from_prim(&object_->id, parent_prim, property_import_mode, time);
38 }
39 }
40 if (!object_->data) {
41 /* If the object has no data, set the prim's custom properties on the object.
42 * This applies to Xforms that have been converted to Empty objects. */
43 set_id_props_from_prim(&object_->id, prim_, property_import_mode, time);
44 }
45
46 if (object_->data) {
47 /* If the object has data, the data represents the USD prim, so set the prim's custom
48 * properties on the data directly. */
49 set_id_props_from_prim(static_cast<ID *>(object_->data), prim_, property_import_mode, time);
50 }
51}
52
54 const USDImportParams &import_params,
55 const ImportSettings &settings)
56 : name_(prim.GetName().GetString()),
58 prim_(prim),
60 import_params_(import_params),
61 settings_(&settings),
62 refcount_(0),
64{
65}
66
68
69const pxr::UsdPrim &USDPrimReader::prim() const
70{
71 return prim_;
72}
73
75{
76 return object_;
77}
78
80{
81 object_ = ob;
82}
83
85{
86 return prim_.IsValid();
87}
88
90{
91 return refcount_;
92}
93
95{
96 refcount_++;
97}
98
100{
101 refcount_--;
102 BLI_assert(refcount_ >= 0);
103}
104
106{
107 return prim_ && (prim_.IsInPrototype() || is_in_instancer_proto_);
108}
109
110} // namespace blender::io::usd
#define BLI_assert(a)
Definition BLI_assert.h:46
Object is a sort of wrapper for general info.
USDPrimReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
const pxr::UsdPrim & prim() const
const ImportSettings * settings_
void set_props(bool merge_with_parent=false, pxr::UsdTimeCode time=pxr::UsdTimeCode::Default())
const USDImportParams & import_params_
eUSDPropertyImportMode
Definition usd.hh:54
@ USD_ATTR_IMPORT_NONE
Definition usd.hh:55
void set_id_props_from_prim(ID *id, const pxr::UsdPrim &prim, const eUSDPropertyImportMode property_import_mode, const pxr::UsdTimeCode time_code)
Definition DNA_ID.h:414