It was difficult to notice, but we weren't making use of the `USDPrimReader::valid()` API calls during import. In many(all?) cases this was fine as we would check the validity during `read_object_data` or similar anyhow. Rather than just removing the API entirely, this patch attempts to use it and has the following design: - Where ever and whenever a reader is created, in addition to checking null, we should now also check for `valid()` This happens in `usd_capi_import` and `usd_reader_stage`. - The `valid()` call is intended to check just the USD object status. Blender object checks are handled elsewhere (same as they are currently) since these objects are often not available at the time of the call to `valid()` This has the benefit that we at least know that USD is valid before our heavy reading code ever starts executing. Some duplicate checks are now removed. Pull Request: https://projects.blender.org/blender/blender/pulls/129181
45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
/* SPDX-FileCopyrightText: 2023 NVIDIA Corporation. All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "usd_reader_instance.hh"
|
|
|
|
#include "BKE_lib_id.hh"
|
|
#include "BKE_object.hh"
|
|
|
|
#include "DNA_collection_types.h"
|
|
#include "DNA_object_types.h"
|
|
|
|
namespace blender::io::usd {
|
|
|
|
void USDInstanceReader::create_object(Main *bmain, const double /*motionSampleTime*/)
|
|
{
|
|
this->object_ = BKE_object_add_only_object(bmain, OB_EMPTY, name_.c_str());
|
|
this->object_->data = nullptr;
|
|
this->object_->instance_collection = nullptr;
|
|
this->object_->transflag |= OB_DUPLICOLLECTION;
|
|
}
|
|
|
|
void USDInstanceReader::set_instance_collection(Collection *coll)
|
|
{
|
|
if (this->object_ && this->object_->instance_collection != coll) {
|
|
if (this->object_->instance_collection) {
|
|
id_us_min(&this->object_->instance_collection->id);
|
|
this->object_->instance_collection = nullptr;
|
|
}
|
|
id_us_plus(&coll->id);
|
|
this->object_->instance_collection = coll;
|
|
}
|
|
}
|
|
|
|
pxr::SdfPath USDInstanceReader::proto_path() const
|
|
{
|
|
if (pxr::UsdPrim proto = prim_.GetPrototype()) {
|
|
return proto.GetPath();
|
|
}
|
|
|
|
return pxr::SdfPath();
|
|
}
|
|
|
|
} // namespace blender::io::usd
|