Blender V4.5
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,
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
34 if (merge_with_parent) {
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
56 const USDImportParams &import_params,
57 const ImportSettings &settings)
58 : name_(prim.GetName().GetString()),
60 prim_(prim),
62 import_params_(import_params),
63 settings_(&settings),
64 refcount_(0),
66{
67}
68
70
71const pxr::UsdPrim &USDPrimReader::prim() const
72{
73 return prim_;
74}
75
77{
78 return object_;
79}
80
82{
83 object_ = ob;
84}
85
87{
88 return prim_.IsValid();
89}
90
92{
93 return refcount_;
94}
95
97{
98 refcount_++;
99}
100
102{
103 refcount_--;
104 BLI_assert(refcount_ >= 0);
105}
106
108{
109 return prim_ && (prim_.IsInPrototype() || is_in_instancer_proto_);
110}
111
112} // 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 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
Definition DNA_ID.h:404