Blender
V4.5
source
blender
io
usd
intern
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
19
namespace
blender::io::usd
{
20
21
void
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. */
50
set_id_props_from_prim
(
51
static_cast<
ID
*
>
(
object_
->data),
prim_
, attr_import_mode, motionSampleTime);
52
}
53
}
54
55
USDPrimReader::USDPrimReader
(
const
pxr::UsdPrim &
prim
,
56
const
USDImportParams
&import_params,
57
const
ImportSettings
&settings)
58
:
name_
(
prim
.GetName().GetString()),
59
object_
(
nullptr
),
60
prim_
(
prim
),
61
parent_reader_
(
nullptr
),
62
import_params_
(import_params),
63
settings_
(&settings),
64
refcount_
(0),
65
is_in_instancer_proto_
(
false
)
66
{
67
}
68
69
USDPrimReader::~USDPrimReader
() =
default
;
70
71
const
pxr::UsdPrim &
USDPrimReader::prim
()
const
72
{
73
return
prim_
;
74
}
75
76
Object
*
USDPrimReader::object
()
const
77
{
78
return
object_
;
79
}
80
81
void
USDPrimReader::object
(
Object
*ob)
82
{
83
object_
= ob;
84
}
85
86
bool
USDPrimReader::valid
()
const
87
{
88
return
prim_
.IsValid();
89
}
90
91
int
USDPrimReader::refcount
()
const
92
{
93
return
refcount_
;
94
}
95
96
void
USDPrimReader::incref
()
97
{
98
refcount_
++;
99
}
100
101
void
USDPrimReader::decref
()
102
{
103
refcount_
--;
104
BLI_assert
(
refcount_
>= 0);
105
}
106
107
bool
USDPrimReader::is_in_proto
()
const
108
{
109
return
prim_
&& (
prim_
.IsInPrototype() ||
is_in_instancer_proto_
);
110
}
111
112
}
// namespace blender::io::usd
BLI_assert.h
BLI_assert
#define BLI_assert(a)
Definition
BLI_assert.h:46
DNA_object_types.h
Object is a sort of wrapper for general info.
nullptr
return nullptr
Definition
bmesh_operator_api_inline.hh:210
false
return false
Definition
bmesh_operator_api_inline.hh:198
blender::io::usd::USDPrimReader::object
Object * object() const
Definition
usd_reader_prim.cc:76
blender::io::usd::USDPrimReader::is_in_instancer_proto_
bool is_in_instancer_proto_
Definition
usd_reader_prim.hh:84
blender::io::usd::USDPrimReader::USDPrimReader
USDPrimReader(const pxr::UsdPrim &prim, const USDImportParams &import_params, const ImportSettings &settings)
Definition
usd_reader_prim.cc:55
blender::io::usd::USDPrimReader::refcount_
int refcount_
Definition
usd_reader_prim.hh:83
blender::io::usd::USDPrimReader::~USDPrimReader
virtual ~USDPrimReader()
blender::io::usd::USDPrimReader::refcount
int refcount() const
Definition
usd_reader_prim.cc:91
blender::io::usd::USDPrimReader::object_
Object * object_
Definition
usd_reader_prim.hh:78
blender::io::usd::USDPrimReader::prim_
pxr::UsdPrim prim_
Definition
usd_reader_prim.hh:79
blender::io::usd::USDPrimReader::prim
const pxr::UsdPrim & prim() const
Definition
usd_reader_prim.cc:71
blender::io::usd::USDPrimReader::incref
void incref()
Definition
usd_reader_prim.cc:96
blender::io::usd::USDPrimReader::is_in_proto
bool is_in_proto() const
Definition
usd_reader_prim.cc:107
blender::io::usd::USDPrimReader::decref
void decref()
Definition
usd_reader_prim.cc:101
blender::io::usd::USDPrimReader::settings_
const ImportSettings * settings_
Definition
usd_reader_prim.hh:82
blender::io::usd::USDPrimReader::set_props
void set_props(bool merge_with_parent=false, pxr::UsdTimeCode motionSampleTime=pxr::UsdTimeCode::Default())
Definition
usd_reader_prim.cc:21
blender::io::usd::USDPrimReader::valid
virtual bool valid() const
Definition
usd_reader_prim.cc:86
blender::io::usd::USDPrimReader::import_params_
const USDImportParams & import_params_
Definition
usd_reader_prim.hh:81
blender::io::usd::USDPrimReader::name_
StringRefNull name_
Definition
usd_reader_prim.hh:77
blender::io::usd::USDPrimReader::parent_reader_
USDPrimReader * parent_reader_
Definition
usd_reader_prim.hh:80
blender::io::usd
Definition
usd_armature_utils.cc:24
blender::io::usd::set_id_props_from_prim
void set_id_props_from_prim(ID *id, const pxr::UsdPrim &prim, const eUSDAttrImportMode attr_import_mode, const pxr::UsdTimeCode time_code)
Definition
usd_reader_utils.cc:158
blender::io::usd::eUSDAttrImportMode
eUSDAttrImportMode
Definition
usd.hh:54
blender::io::usd::USD_ATTR_IMPORT_NONE
@ USD_ATTR_IMPORT_NONE
Definition
usd.hh:55
ID
Definition
DNA_ID.h:404
Object
Definition
DNA_object_types.h:192
blender::io::usd::ImportSettings
Definition
usd_reader_prim.hh:31
blender::io::usd::USDImportParams
Definition
usd.hh:191
usd.hh
usd_reader_prim.hh
usd_reader_utils.hh
Generated on
for Blender by
doxygen
1.15.0