optimize timesamples and Property reconstruction.

This commit is contained in:
Syoyo Fujita
2025-10-07 12:50:02 +09:00
parent 68c80b5b3b
commit c47cab45c6
11 changed files with 916 additions and 222 deletions

View File

@@ -289,7 +289,7 @@ class AsciiParser {
const Path &full_path, const Specifier spec,
const std::string &primTypeName, const Path &prim_name,
const int64_t primIdx, const int64_t parentPrimIdx,
const std::map<std::string, Property> &properties,
std::map<std::string, Property> &properties,
const PrimMetaMap &in_meta, const VariantSetList &in_variantSetList)>;
///

View File

@@ -45,7 +45,7 @@ namespace prim {
// implimentations will be located in prim-reconstruct.cc
#define RECONSTRUCT_PRIM_DECL(__ty) \
template <> \
bool ReconstructPrim<__ty>(const PrimSpec &, __ty *, std::string *, \
bool ReconstructPrim<__ty>(PrimSpec &, __ty *, std::string *, \
std::string *, const PrimReconstructOptions &)
RECONSTRUCT_PRIM_DECL(Xform);
@@ -1302,7 +1302,7 @@ bool CompositeInherits(const Layer &in_layer, Layer *composited_layer,
namespace detail {
static nonstd::optional<Prim> ReconstructPrimFromPrimSpec(
const PrimSpec &primspec, std::string *warn, std::string *err) {
PrimSpec &primspec, std::string *warn, std::string *err) {
(void)warn;
// TODO:
@@ -1387,7 +1387,7 @@ static nonstd::optional<Prim> ReconstructPrimFromPrimSpec(
}
static nonstd::optional<Prim> ReconstructPrimFromPrimSpecRec(
const PrimSpec &primspec, std::string *warn, std::string *err) {
PrimSpec &primspec, std::string *warn, std::string *err) {
auto pprim = ReconstructPrimFromPrimSpec(primspec, warn, err);
@@ -1509,7 +1509,7 @@ static bool InheritPrimSpecImpl(PrimSpec &dst, const PrimSpec &src,
} // namespace detail
bool LayerToStage(const Layer &layer, Stage *stage_out, std::string *warn,
bool LayerToStage(Layer &&layer, Stage *stage_out, std::string *warn,
std::string *err) {
if (!stage_out) {
if (err) {
@@ -1523,7 +1523,7 @@ bool LayerToStage(const Layer &layer, Stage *stage_out, std::string *warn,
stage.metas() = layer.metas();
// TODO: primChildren metadatum
for (const auto &primspec : layer.primspecs()) {
for (auto &primspec : layer.primspecs()) {
if (auto pv =
detail::ReconstructPrimFromPrimSpecRec(primspec.second, warn, err)) {
stage.add_root_prim(std::move(pv.value()));

View File

@@ -290,11 +290,13 @@ bool OverridePrimSpec(PrimSpec &dst, const PrimSpec &src, std::string *warn,
bool InheritPrimSpec(PrimSpec &dst, const PrimSpec &src, std::string *warn,
std::string *err);
#if 0
///
/// Build USD Stage from Layer
///
bool LayerToStage(const Layer &layer, Stage *stage, std::string *warn,
bool LayerToStage(Layer &layer, Stage *stage, std::string *warn,
std::string *err);
#endif
///
/// Build USD Stage from Layer

View File

@@ -391,7 +391,9 @@ class CrateValue {
//std::string GetTypeName() const;
//uint32_t GetTypeId() const;
#define SET_TYPE_SCALAR(__ty) void Set(const __ty& v) { value_ = v; }
#define SET_TYPE_SCALAR(__ty) void Set(const __ty& v) { TUSDZ_LOG_I("copy set"); value_ = v; } void Set(__ty&& v) { TUSDZ_LOG_I("move set"); value::Value src(std::move(v)); value_ = std::move(src); }
//#define MOVE_SET_TYPE_SCALAR(__ty) void MoveSet(__ty&& v) { TUSDZ_LOG_I("move set"); value::Value src(std::move(v)); value_ = std::move(src); }
#define SET_TYPE_1D(__ty) void Set(const std::vector<__ty> &v) { value_ = v; }
// TODO: Use TypedArray
@@ -463,10 +465,10 @@ class CrateValue {
SET_TYPE_SCALAR(CustomDataType) // for (type-restricted) dist
SET_TYPE_LIST(SET_TYPE_SCALAR)
//SET_TYPE_LIST(MOVE_SET_TYPE_SCALAR)
SET_TYPE_LIST(SET_TYPE_1D)
// FIXME
//SET_TYPE_LIST(MOVE_SET_TYPE_1D)
// TypedArray Set methods for efficient array handling with mmap support
@@ -497,7 +499,9 @@ class CrateValue {
// Type-safe way to get concrete value.
template <class T>
nonstd::optional<T> get_value() const {
return value_.get_value<T>();
// HACK
//return value_.get_value<T>();
return std::move(value_.get_value<T>());
}
// Return null when type-mismatch

File diff suppressed because it is too large Load Diff

View File

@@ -365,8 +365,12 @@ class CrateReader {
bool UnpackTimeSampleValue_UINT32(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_INT64(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_UINT64(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_HALF(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_FLOAT(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_DOUBLE(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_HALF2(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_HALF3(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_HALF4(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_FLOAT2(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_FLOAT3(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_FLOAT4(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
@@ -381,6 +385,9 @@ class CrateReader {
bool UnpackTimeSampleValue_MATRIX3D(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
bool UnpackTimeSampleValue_MATRIX4D(double t, const crate::ValueRep &rep, value::TimeSamples &dst);
// times(double[])
bool UnpackTimeSampleTimes(const crate::ValueRep &rep, std::vector<double> &dst);
//
// Construct node hierarchy.
//

View File

@@ -66,7 +66,7 @@ constexpr auto kInputsVarname = "inputs:varname";
template <typename T>
bool ReconstructShader(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
T *out,
std::string *warn,
@@ -1926,7 +1926,7 @@ bool ParseTimeSampledEnumProperty(
/* Check if the property name is a predefined property */ \
if (!__table.count(__prop.first)) { \
DCOUT("custom property added: name = " << __prop.first); \
__dst[__prop.first] = __prop.second; \
__dst[__prop.first] = std::move(__prop.second); \
__table.insert(__prop.first); \
} \
}
@@ -1949,7 +1949,7 @@ bool ParseTimeSampledEnumProperty(
static bool ReconstructXformOpFromToken(
const std::string &token, int i,
const std::map<std::string, Property> &properties,
std::map<std::string, Property> &properties,
std::set<std::string> &table, /* inout */
std::vector<XformOp> *xformOps, std::string *err) {
if (!xformOps) {
@@ -2517,7 +2517,7 @@ static bool ReconstructXformOpFromToken(
bool ReconstructXformOpsFromProperties(
const Specifier &spec,
std::set<std::string> &table, /* inout */
const std::map<std::string, Property> &properties,
std::map<std::string, Property> &properties,
std::vector<XformOp> *xformOps,
std::string *err)
{
@@ -3145,7 +3145,7 @@ namespace {
bool ReconstructMaterialBindingProperties(
std::set<std::string> &table, /* inout */
const std::map<std::string, Property> &properties,
std::map<std::string, Property> &properties,
MaterialBinding *mb, /* inout */
std::string *err)
{
@@ -3245,7 +3245,7 @@ bool ReconstructMaterialBindingProperties(
bool ReconstructCollectionProperties(
std::set<std::string> &table, /* inout */
const std::map<std::string, Property> &properties,
std::map<std::string, Property> &properties,
Collection *coll, /* inout */
std::string *warn,
std::string *err,
@@ -3338,7 +3338,7 @@ bool ReconstructCollectionProperties(
bool ReconstructGPrimProperties(
const Specifier &spec,
std::set<std::string> &table, /* inout */
const std::map<std::string, Property> &properties,
std::map<std::string, Property> &properties,
GPrim *gprim, /* inout */
std::string *warn,
std::string *err,
@@ -3380,7 +3380,7 @@ bool ReconstructGPrimProperties(
template <>
bool ReconstructPrim<Xform>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
Xform *xform,
std::string *warn,
@@ -3406,7 +3406,7 @@ bool ReconstructPrim<Xform>(
template <>
bool ReconstructPrim<Model>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
Model *model,
std::string *warn,
@@ -3431,7 +3431,7 @@ bool ReconstructPrim<Model>(
template <>
bool ReconstructPrim<Scope>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
Scope *scope,
std::string *warn,
@@ -3460,7 +3460,7 @@ bool ReconstructPrim<Scope>(
template <>
bool ReconstructPrim<SkelRoot>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
SkelRoot *root,
std::string *warn,
@@ -3496,7 +3496,7 @@ bool ReconstructPrim<SkelRoot>(
template <>
bool ReconstructPrim<Skeleton>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
Skeleton *skel,
std::string *warn,
@@ -3589,7 +3589,7 @@ bool ReconstructPrim<Skeleton>(
template <>
bool ReconstructPrim<SkelAnimation>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
SkelAnimation *skelanim,
std::string *warn,
@@ -3618,7 +3618,7 @@ bool ReconstructPrim<SkelAnimation>(
template <>
bool ReconstructPrim<BlendShape>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
BlendShape *bs,
std::string *warn,
@@ -3660,7 +3660,7 @@ bool ReconstructPrim<BlendShape>(
template <>
bool ReconstructPrim(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GPrim *gprim,
std::string *warn,
@@ -3683,7 +3683,7 @@ bool ReconstructPrim(
template <>
bool ReconstructPrim(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomBasisCurves *curves,
std::string *warn,
@@ -3763,7 +3763,7 @@ bool ReconstructPrim(
template <>
bool ReconstructPrim(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomNurbsCurves *curves,
std::string *warn,
@@ -3806,7 +3806,7 @@ bool ReconstructPrim(
template <>
bool ReconstructPrim<SphereLight>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
SphereLight *light,
std::string *warn,
@@ -3853,7 +3853,7 @@ bool ReconstructPrim<SphereLight>(
template <>
bool ReconstructPrim<RectLight>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
RectLight *light,
std::string *warn,
@@ -3902,7 +3902,7 @@ bool ReconstructPrim<RectLight>(
template <>
bool ReconstructPrim<DiskLight>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
DiskLight *light,
std::string *warn,
@@ -3950,7 +3950,7 @@ bool ReconstructPrim<DiskLight>(
template <>
bool ReconstructPrim<CylinderLight>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
CylinderLight *light,
std::string *warn,
@@ -3994,7 +3994,7 @@ bool ReconstructPrim<CylinderLight>(
template <>
bool ReconstructPrim<DistantLight>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
DistantLight *light,
std::string *warn,
@@ -4038,7 +4038,7 @@ bool ReconstructPrim<DistantLight>(
template <>
bool ReconstructPrim<DomeLight>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
DomeLight *light,
std::string *warn,
@@ -4088,7 +4088,7 @@ bool ReconstructPrim<DomeLight>(
template <>
bool ReconstructPrim<GeomSphere>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomSphere *sphere,
std::string *warn,
@@ -4118,7 +4118,7 @@ bool ReconstructPrim<GeomSphere>(
template <>
bool ReconstructPrim<GeomPoints>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomPoints *points,
std::string *warn,
@@ -4154,7 +4154,7 @@ bool ReconstructPrim<GeomPoints>(
template <>
bool ReconstructPrim<GeomCone>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomCone *cone,
std::string *warn,
@@ -4185,7 +4185,7 @@ bool ReconstructPrim<GeomCone>(
template <>
bool ReconstructPrim<GeomCylinder>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomCylinder *cylinder,
std::string *warn,
@@ -4218,7 +4218,7 @@ bool ReconstructPrim<GeomCylinder>(
template <>
bool ReconstructPrim<GeomCapsule>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomCapsule *capsule,
std::string *warn,
@@ -4248,7 +4248,7 @@ bool ReconstructPrim<GeomCapsule>(
template <>
bool ReconstructPrim<GeomCube>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomCube *cube,
std::string *warn,
@@ -4280,7 +4280,7 @@ bool ReconstructPrim<GeomCube>(
template <>
bool ReconstructPrim<GeomMesh>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomMesh *mesh,
std::string *warn,
@@ -4357,7 +4357,7 @@ bool ReconstructPrim<GeomMesh>(
return false;
}
for (const auto &prop : properties) {
for (auto &prop : properties) {
DCOUT("GeomMesh prop: " << prop.first);
PARSE_SINGLE_TARGET_PATH_RELATION(table, prop, kSkelSkeleton, mesh->skeleton)
PARSE_TARGET_PATHS_RELATION(table, prop, kSkelBlendShapeTargets, mesh->blendShapeTargets)
@@ -4416,6 +4416,7 @@ bool ReconstructPrim<GeomMesh>(
}
}
TUSDZ_LOG_I("add prop: " << prop.first);
// generic
ADD_PROPERTY(table, prop, GeomMesh, mesh->props)
PARSE_PROPERTY_END_MAKE_WARN(table, prop)
@@ -4429,7 +4430,7 @@ bool ReconstructPrim<GeomMesh>(
template <>
bool ReconstructPrim<GeomCamera>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomCamera *camera,
std::string *warn,
@@ -4530,7 +4531,7 @@ bool ReconstructPrim<GeomCamera>(
template <>
bool ReconstructPrim<GeomSubset>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomSubset *subset,
std::string *warn,
@@ -4579,7 +4580,7 @@ bool ReconstructPrim<GeomSubset>(
template <>
bool ReconstructPrim<GeomPointInstancer>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
GeomPointInstancer *instancer,
std::string *warn,
@@ -4620,7 +4621,7 @@ bool ReconstructPrim<GeomPointInstancer>(
template <>
bool ReconstructShader<ShaderNode>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
ShaderNode *node,
std::string *warn,
@@ -4653,7 +4654,7 @@ bool ReconstructShader<ShaderNode>(
template <>
bool ReconstructShader<UsdPreviewSurface>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPreviewSurface *surface,
std::string *warn,
@@ -4725,7 +4726,7 @@ bool ReconstructShader<UsdPreviewSurface>(
template <>
bool ReconstructShader<UsdUVTexture>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdUVTexture *texture,
std::string *warn,
@@ -4802,7 +4803,7 @@ bool ReconstructShader<UsdUVTexture>(
template <>
bool ReconstructShader<UsdPrimvarReader_int>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_int *preader,
std::string *warn,
@@ -4847,7 +4848,7 @@ bool ReconstructShader<UsdPrimvarReader_int>(
template <>
bool ReconstructShader<UsdPrimvarReader_float>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_float *preader,
std::string *warn,
@@ -4902,7 +4903,7 @@ bool ReconstructShader<UsdPrimvarReader_float>(
template <>
bool ReconstructShader<UsdPrimvarReader_float2>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_float2 *preader,
std::string *warn,
@@ -4959,7 +4960,7 @@ bool ReconstructShader<UsdPrimvarReader_float2>(
template <>
bool ReconstructShader<UsdPrimvarReader_float3>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_float3 *preader,
std::string *warn,
@@ -5015,7 +5016,7 @@ bool ReconstructShader<UsdPrimvarReader_float3>(
template <>
bool ReconstructShader<UsdPrimvarReader_float4>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_float4 *preader,
std::string *warn,
@@ -5071,7 +5072,7 @@ bool ReconstructShader<UsdPrimvarReader_float4>(
template <>
bool ReconstructShader<UsdPrimvarReader_string>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_string *preader,
std::string *warn,
@@ -5127,7 +5128,7 @@ bool ReconstructShader<UsdPrimvarReader_string>(
template <>
bool ReconstructShader<UsdPrimvarReader_vector>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_vector *preader,
std::string *warn,
@@ -5183,7 +5184,7 @@ bool ReconstructShader<UsdPrimvarReader_vector>(
template <>
bool ReconstructShader<UsdPrimvarReader_normal>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_normal *preader,
std::string *warn,
@@ -5239,7 +5240,7 @@ bool ReconstructShader<UsdPrimvarReader_normal>(
template <>
bool ReconstructShader<UsdPrimvarReader_point>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_point *preader,
std::string *warn,
@@ -5295,7 +5296,7 @@ bool ReconstructShader<UsdPrimvarReader_point>(
template <>
bool ReconstructShader<UsdPrimvarReader_matrix>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdPrimvarReader_matrix *preader,
std::string *warn,
@@ -5351,7 +5352,7 @@ bool ReconstructShader<UsdPrimvarReader_matrix>(
template <>
bool ReconstructShader<UsdTransform2d>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
UsdTransform2d *transform,
std::string *warn,
@@ -5385,7 +5386,7 @@ bool ReconstructShader<UsdTransform2d>(
template <>
bool ReconstructPrim<Shader>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
Shader *shader,
std::string *warn,
@@ -5559,7 +5560,7 @@ bool ReconstructPrim<Shader>(
template <>
bool ReconstructPrim<Material>(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties,
const ReferenceList &references,
Material *material,
std::string *warn,
@@ -5596,7 +5597,7 @@ bool ReconstructPrim<Material>(
#define RECONSTRUCT_PRIM_PRIMSPEC_IMPL(__prim_ty) \
template <> \
bool ReconstructPrim<__prim_ty>( \
const PrimSpec &primspec, \
PrimSpec &primspec, \
__prim_ty *prim, \
std::string *warn, \
std::string *err, \

View File

@@ -29,7 +29,7 @@ struct PrimReconstructOptions
bool ReconstructXformOpsFromProperties(
const Specifier &spec,
std::set<std::string> &table, /* inout */
const PropertyMap &properties,
PropertyMap &properties,
std::vector<XformOp> *xformOps,
std::string *err);
@@ -39,7 +39,7 @@ bool ReconstructXformOpsFromProperties(
template <typename T>
bool ReconstructPrim(
const Specifier &spec,
const PropertyMap &properties,
PropertyMap &properties, // modified
const ReferenceList &references,
T *out,
std::string *warn,
@@ -51,7 +51,7 @@ bool ReconstructPrim(
///
template <typename T>
bool ReconstructPrim(
const PrimSpec &primspec,
PrimSpec &primspec,
T *out,
std::string *warn,
std::string *err,

View File

@@ -25,6 +25,7 @@
#include "nonstd/optional.hpp"
#include "typed-array.hh"
#include "value-types.hh"
#include "logger.hh"
// Enable SoA (Structure of Arrays) layout for TypedTimeSamples
@@ -55,9 +56,11 @@ struct TimeSamples;
inline bool is_pod_type_id(uint32_t type_id) {
// POD types: bool, numeric types (char, int, uint, float, double, half),
// and their vector variants (float2, float3, etc.)
// Excludes: string, token, path, array types, complex types
return (type_id >= 8 && type_id <= 75) || // Basic numeric types and vectors
(type_id == 5); // bool
// turn off 1D array flag
uint32_t tid = type_id & (~TYPE_ID_1D_ARRAY_BIT);
return (tid >= uint32_t(TYPE_ID_BOOL) && tid <= uint32_t(TYPE_ID_TIMECODE));
}
} // namespace value
@@ -115,6 +118,68 @@ struct PODTimeSamples {
_dirty_end = 0;
}
/// Move constructor
PODTimeSamples(PODTimeSamples&& other) noexcept
: _type_id(other._type_id),
_is_array(other._is_array),
_element_size(other._element_size),
_array_size(other._array_size),
_dirty(other._dirty),
_dirty_start(other._dirty_start),
_dirty_end(other._dirty_end),
_times(std::move(other._times)),
_blocked(std::move(other._blocked)),
_values(std::move(other._values)),
_offsets(std::move(other._offsets)),
_blocked_count(other._blocked_count) {
// Reset moved-from object to valid empty state
other._type_id = 0;
other._is_array = false;
other._element_size = 0;
other._array_size = 0;
other._dirty = false;
other._dirty_start = SIZE_MAX;
other._dirty_end = 0;
other._blocked_count = 0;
}
/// Move assignment operator
PODTimeSamples& operator=(PODTimeSamples&& other) noexcept {
if (this != &other) {
// Move data from other
_type_id = other._type_id;
_is_array = other._is_array;
_element_size = other._element_size;
_array_size = other._array_size;
_dirty = other._dirty;
_dirty_start = other._dirty_start;
_dirty_end = other._dirty_end;
_times = std::move(other._times);
_blocked = std::move(other._blocked);
_values = std::move(other._values);
_offsets = std::move(other._offsets);
_blocked_count = other._blocked_count;
// Reset moved-from object to valid empty state
other._type_id = 0;
other._is_array = false;
other._element_size = 0;
other._array_size = 0;
other._dirty = false;
other._dirty_start = SIZE_MAX;
other._dirty_end = 0;
other._blocked_count = 0;
}
return *this;
}
// Default copy operations
PODTimeSamples(const PODTimeSamples&) = default;
PODTimeSamples& operator=(const PODTimeSamples&) = default;
// Default constructor
PODTimeSamples() = default;
/// Pre-allocate capacity for known number of samples
void reserve(size_t n) {
_times.reserve(n);
@@ -335,6 +400,56 @@ public:
return true;
}
/// Add an matrix array sample with POD element type checking
template<typename T>
bool add_matrix_array_sample(double t, const T* values, size_t count, std::string *err = nullptr) {
static_assert((value::TypeTraits<T>::type_id() == value::TYPE_ID_MATRIX2D) ||
(value::TypeTraits<T>::type_id() == value::TYPE_ID_MATRIX3D) ||
(value::TypeTraits<T>::type_id() == value::TYPE_ID_MATRIX4D),
"requires matrix type");
// Set type_id and array info on first sample - use underlying_type_id
if (_times.empty()) {
_type_id = value::TypeTraits<T>::underlying_type_id();
_is_array = true;
_array_size = count;
_element_size = sizeof(T); // Cache element size
} else {
// Verify type consistency - check underlying type
if (_type_id != value::TypeTraits<T>::underlying_type_id()) {
if (err) {
(*err) += "Type mismatch in PODTimeSamples array: expected underlying_type_id " +
std::to_string(_type_id) + " but got " +
std::to_string(value::TypeTraits<T>::underlying_type_id()) + ".\n";
}
return false;
}
// Verify array size consistency
if (_array_size != count) {
if (err) {
(*err) += "Array size mismatch in PODTimeSamples: expected " +
std::to_string(_array_size) + " but got " +
std::to_string(count) + ".\n";
}
return false;
}
}
size_t new_idx = _times.size();
_times.push_back(t);
_blocked.push_back(0); // false = 0
// Store offset and append array data
_offsets.push_back(_values.size());
size_t byte_size = sizeof(T) * count;
_values.resize(_values.size() + byte_size);
std::memcpy(_values.data() + _offsets.back(), values, byte_size);
_dirty = true;
mark_dirty_range(new_idx);
return true;
}
/// Get samples as vector of TimeSamples::Sample for backward compatibility
/// This converts the POD storage back to value::Value representation
/// Implementation is in timesamples.cc to avoid circular dependency
@@ -614,10 +729,49 @@ struct TimeSamples {
_dirty = true;
}
/// Move constructor
TimeSamples(TimeSamples&& other) noexcept
: _samples(std::move(other._samples)),
_pod_samples(std::move(other._pod_samples)),
_type_id(other._type_id),
_use_pod(other._use_pod),
_dirty(other._dirty) {
// Reset moved-from object to valid empty state
other._type_id = 0;
other._use_pod = false;
other._dirty = false;
}
/// Move assignment operator
TimeSamples& operator=(TimeSamples&& other) noexcept {
if (this != &other) {
// Move data from other
_samples = std::move(other._samples);
_pod_samples = std::move(other._pod_samples);
_type_id = other._type_id;
_use_pod = other._use_pod;
_dirty = other._dirty;
// Reset moved-from object to valid empty state
other._type_id = 0;
other._use_pod = false;
other._dirty = false;
}
return *this;
}
// Default copy operations
TimeSamples(const TimeSamples&) = default;
TimeSamples& operator=(const TimeSamples&) = default;
// Default constructor
TimeSamples() = default;
/// type_id = TypeId
/// Initialize TimeSamples with a specific type_id
/// This determines whether to use POD optimization or regular storage
bool init(uint32_t type_id) {
TUSDZ_LOG_D("init" << type_id);
TUSDZ_LOG_I("init" << type_id);
DCOUT("init" << type_id);
// Allow initialization if empty OR if it contains only uninitialized blocked samples
@@ -627,6 +781,7 @@ struct TimeSamples {
_type_id = type_id;
_use_pod = value::is_pod_type_id(type_id);
if (_use_pod) {
TUSDZ_LOG_I(" use_pod: " << type_id);
_pod_samples._type_id = type_id;
}
return true;
@@ -843,6 +998,48 @@ struct TimeSamples {
return false; // Not using POD storage
}
template<typename T>
bool add_array_sample_pod(double t, const std::vector<T>& value, std::string *err = nullptr) {
static_assert(std::is_trivial<T>::value && std::is_standard_layout<T>::value,
"add_sample_pod requires POD types");
// Auto-initialize on first sample
if (empty()) {
init(value::TypeTraits<T>::type_id());
}
if (_use_pod) {
bool result = _pod_samples.add_array_sample<T>(t, value.data(), value.size(), err);
_dirty = true;
return result;
}
if (err) {
(*err) += "Not using POD storage for type " + std::string(value::TypeTraits<T>::type_name()) + "[].\n";
}
return false; // Not using POD storage
}
template<typename T>
bool add_matrix_array_sample_pod(double t, const std::vector<T>& value, std::string *err = nullptr) {
// Auto-initialize on first sample
if (empty()) {
init(value::TypeTraits<T>::type_id());
}
if (_use_pod) {
bool result = _pod_samples.add_matrix_array_sample<T>(t, value.data(), value.size(), err);
_dirty = true;
return result;
}
if (err) {
(*err) += "Not using POD storage for type " + std::string(value::TypeTraits<T>::type_name()) + "[].\n";
}
return false; // Not using POD storage
}
/// Typed add blocked sample for POD types (optimization path)
template<typename T>
bool add_blocked_sample_pod(double t, std::string *err = nullptr) {
@@ -1574,7 +1771,7 @@ struct TypedTimeSamples {
return _values;
}
const std::vector<bool> &get_blocked() const {
const std::vector<uint8_t> &get_blocked() const {
if (_dirty) {
update();
}

View File

@@ -83,7 +83,7 @@ namespace prim {
// template specialization forward decls.
// implimentations will be located in prim-reconstruct.cc
#define RECONSTRUCT_PRIM_DECL(__ty) template<> bool ReconstructPrim<__ty>(const Specifier &spec, const PropertyMap &, const ReferenceList &, __ty *, std::string *, std::string *, const PrimReconstructOptions &)
#define RECONSTRUCT_PRIM_DECL(__ty) template<> bool ReconstructPrim<__ty>(const Specifier &spec, PropertyMap &, const ReferenceList &, __ty *, std::string *, std::string *, const PrimReconstructOptions &)
RECONSTRUCT_PRIM_DECL(Xform);
RECONSTRUCT_PRIM_DECL(Model);
@@ -357,7 +357,7 @@ class USDAReader::Impl {
template <typename T>
bool ReconstructPrim(
const Specifier &spec,
const prim::PropertyMap &properties,
prim::PropertyMap &properties,
const prim::ReferenceList &references,
T *out);
@@ -368,7 +368,7 @@ class USDAReader::Impl {
PrimTypeTraits<T>::prim_type_name,
[&](const Path &full_path, const Specifier spec, const std::string &_primTypeName, const Path &prim_name, const int64_t primIdx,
const int64_t parentPrimIdx,
const prim::PropertyMap &properties,
prim::PropertyMap &properties,
const ascii::AsciiParser::PrimMetaMap &in_meta,
const ascii::AsciiParser::VariantSetList &in_variants)
-> nonstd::expected<bool, std::string> {
@@ -1560,7 +1560,7 @@ bool USDAReader::Impl::ReconstructStage() {
template <>
bool USDAReader::Impl::ReconstructPrim(
const Specifier &spec,
const prim::PropertyMap &properties,
prim::PropertyMap &properties,
const prim::ReferenceList &references,
Xform *xform) {
@@ -1613,7 +1613,7 @@ bool USDAReader::Impl::ReconstructPrim<NodeGraph>(
template <typename T>
bool USDAReader::Impl::ReconstructPrim(
const Specifier &spec,
const prim::PropertyMap &properties,
prim::PropertyMap &properties,
const prim::ReferenceList &references,
T *prim) {

View File

@@ -74,7 +74,7 @@ namespace prim {
// implimentations will be located in prim-reconstruct.cc
#define RECONSTRUCT_PRIM_DECL(__ty) \
template <> \
bool ReconstructPrim<__ty>(const Specifier &spec, const PropertyMap &, const ReferenceList &, \
bool ReconstructPrim<__ty>(const Specifier &spec, PropertyMap &, const ReferenceList &, \
__ty *, std::string *, std::string *, const PrimReconstructOptions &)
RECONSTRUCT_PRIM_DECL(Xform);
@@ -895,7 +895,7 @@ bool USDCReader::Impl::BuildPropertyMap(const std::vector<size_t> &pathIndices,
prop_name));
}
(*props)[prop_name] = prop;
(*props)[prop_name] = std::move(prop);
DCOUT("Add property : " << prop_name);
}
}
@@ -1043,7 +1043,7 @@ bool USDCReader::Impl::ParseProperty(const SpecType spec_type,
hasTimeSamples = true;
if (auto pv = fv.second.get_value<value::TimeSamples>()) {
value::TimeSamples ts = pv.value();
value::TimeSamples &ts = pv.value();
// If TimeSamples is uninitialized (all samples were VALUE_BLOCK),
// initialize it with the type from the attribute's typeName
@@ -1392,7 +1392,8 @@ bool USDCReader::Impl::ParseProperty(const SpecType spec_type,
}
}
attr.set_var(var);
// HACK
attr.set_var(std::move(var));
if (isValueBlock) {
// attr's type is replaced with ValueBlock type by `set_var`, so overwrite type with typeName