Blender V5.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.hh"
18
19#include "WM_types.hh"
20
21namespace blender::io::usd {
22
27
28void USDPrimReader::set_props(const bool merge_with_parent, const pxr::UsdTimeCode time)
29{
30 if (!prim_ || !object_) {
31 return;
32 }
33
34 PropertyImportMode property_import_mode = this->import_params_.property_import_mode;
35
36 if (property_import_mode == PropertyImportMode::None) {
37 return;
38 }
39
40 if (merge_with_parent) {
41 /* This object represents a parent Xform merged with its child prim.
42 * Set the parent prim's custom properties on the Object ID. */
43 if (const pxr::UsdPrim parent_prim = prim_.GetParent()) {
44 set_id_props_from_prim(&object_->id, parent_prim, property_import_mode, time);
45 }
46 }
47 if (!object_->data) {
48 /* If the object has no data, set the prim's custom properties on the object.
49 * This applies to Xforms that have been converted to Empty objects. */
50 set_id_props_from_prim(&object_->id, prim_, property_import_mode, time);
51 }
52
53 if (object_->data) {
54 /* If the object has data, the data represents the USD prim, so set the prim's custom
55 * properties on the data directly. */
56 set_id_props_from_prim(object_->data, prim_, property_import_mode, time);
57 }
58}
59
61 const USDImportParams &import_params,
62 const ImportSettings &settings)
63 : name_(prim.GetName().GetString()),
65 prim_(prim),
67 import_params_(import_params),
68 settings_(&settings),
69 refcount_(0),
71{
72}
73
75
76const pxr::UsdPrim &USDPrimReader::prim() const
77{
78 return prim_;
79}
80
82{
83 return object_;
84}
85
87{
88 object_ = ob;
89}
90
92{
93 return prim_.IsValid();
94}
95
97{
98 return refcount_;
99}
100
102{
103 refcount_++;
104}
105
107{
108 refcount_--;
109 BLI_assert(refcount_ >= 0);
110}
111
113{
114 return prim_ && (prim_.IsInPrototype() || is_in_instancer_proto_);
115}
116
117} // namespace blender::io::usd
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_
void set_id_props_from_prim(ID *id, const pxr::UsdPrim &prim, const PropertyImportMode property_import_mode, const pxr::UsdTimeCode time_code)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
PropertyImportMode property_import_mode
Definition usd.hh:236
wmJobWorkerStatus * worker_status
Definition usd.hh:242