Blender V4.3
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
22 const pxr::UsdTimeCode motionSampleTime)
23{
24 if (!prim_ || !object_) {
25 return;
26 }
27
28 eUSDAttrImportMode attr_import_mode = this->import_params_.attr_import_mode;
29
30 if (attr_import_mode == USD_ATTR_IMPORT_NONE) {
31 return;
32 }
33
35 /* This object represents a parent Xform merged with its child prim.
36 * Set the parent prim's custom properties on the Object ID. */
37 if (const pxr::UsdPrim parent_prim = prim_.GetParent()) {
38 set_id_props_from_prim(&object_->id, parent_prim, attr_import_mode, motionSampleTime);
39 }
40 }
41 if (!object_->data) {
42 /* If the object has no data, set the prim's custom properties on the object.
43 * This applies to Xforms that have been converted to Empty objects. */
44 set_id_props_from_prim(&object_->id, prim_, attr_import_mode, motionSampleTime);
45 }
46
47 if (object_->data) {
48 /* If the object has data, the data represents the USD prim, so set the prim's custom
49 * properties on the data directly. */
51 static_cast<ID *>(object_->data), prim_, attr_import_mode, motionSampleTime);
52 }
53}
54
55USDPrimReader::USDPrimReader(const pxr::UsdPrim &prim,
56 const USDImportParams &import_params,
57 const ImportSettings &settings)
58 : name_(prim.GetName().GetString()),
59 prim_path_(prim.GetPrimPath().GetString()),
60 object_(nullptr),
61 prim_(prim),
62 import_params_(import_params),
63 parent_reader_(nullptr),
64 settings_(&settings),
65 refcount_(0),
66 is_in_instancer_proto_(false)
67{
68}
69
71
72const pxr::UsdPrim &USDPrimReader::prim() const
73{
74 return prim_;
75}
76
78{
79 return object_;
80}
81
83{
84 object_ = ob;
85}
86
88{
89 return prim_.IsValid();
90}
91
93{
94 return refcount_;
95}
96
98{
99 refcount_++;
100}
101
103{
104 refcount_--;
105 BLI_assert(refcount_ >= 0);
106}
107
109{
110 return prim_ && (prim_.IsInPrototype() || is_in_instancer_proto_);
111}
112
113} // namespace blender::io::usd
#define BLI_assert(a)
Definition BLI_assert.h:50
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
void set_props(bool merge_with_parent=false, pxr::UsdTimeCode motionSampleTime=pxr::UsdTimeCode::Default())
const USDImportParams & import_params_
void set_id_props_from_prim(ID *id, const pxr::UsdPrim &prim, const eUSDAttrImportMode attr_import_mode, const pxr::UsdTimeCode time_code)
@ USD_ATTR_IMPORT_NONE
Definition usd.hh:55
static bool merge_with_parent(USDPrimReader *reader)
Definition DNA_ID.h:413
eUSDAttrImportMode attr_import_mode
Definition usd.hh:222