Refactor codes.

This commit is contained in:
Syoyo Fujita
2022-08-06 23:10:53 +09:00
parent e1310c99be
commit 5f27971086
16 changed files with 1059 additions and 507 deletions

View File

@@ -181,6 +181,8 @@ set(TINYUSDZ_SOURCES
${PROJECT_SOURCE_DIR}/src/value-types.cc
${PROJECT_SOURCE_DIR}/src/io-util.cc
${PROJECT_SOURCE_DIR}/src/image-loader.cc
${PROJECT_SOURCE_DIR}/src/usdGeom.cc
${PROJECT_SOURCE_DIR}/src/usdLux.cc
# usdMtlX has less dependency(tinyxml2), so add it to core component
${PROJECT_SOURCE_DIR}/src/usdMtlx.cc
${PROJECT_SOURCE_DIR}/src/usdObj.cc

View File

@@ -3,6 +3,7 @@
#include "value-types.hh"
#include "prim-types.hh"
#include "usdGeom.hh"
using namespace tinyusdz;

View File

@@ -475,24 +475,14 @@ struct StdHashWrapper {
namespace value {
// Same macro in value-type.hh
#define DEFINE_TYPE_TRAIT(__dty, __name, __tyid, __nc) \
template <> \
struct TypeTrait<__dty> { \
using value_type = __dty; \
using value_underlying_type = __dty; \
static constexpr uint32_t ndim = 0; /* array dim */ \
static constexpr uint32_t ncomp = \
__nc; /* the number of components(e.g. float3 => 3) */ \
static constexpr uint32_t type_id = __tyid; \
static constexpr uint32_t underlying_type_id = __tyid; \
static std::string type_name() { return __name; } \
static std::string underlying_type_name() { return __name; } \
}
#include "define-type-trait.inc"
// synonym to `value::dict`
DEFINE_TYPE_TRAIT(crate::CrateValue::Dictionary, "dict", TYPE_ID_DICT, 1);
#undef DEFINE_TYPE_TRAIT
#undef DEFINE_ROLE_TYPE_TRAIT
} // namespace value
} // namespace tinyusdz

29
src/define-type-trait.inc Normal file
View File

@@ -0,0 +1,29 @@
#define DEFINE_TYPE_TRAIT(__dty, __name, __tyid, __nc) \
template <> \
struct TypeTrait<__dty> { \
using value_type = __dty; \
using value_underlying_type = __dty; \
static constexpr uint32_t ndim = 0; /* array dim */ \
static constexpr uint32_t ncomp = \
__nc; /* the number of components(e.g. float3 => 3) */ \
static constexpr uint32_t type_id = __tyid; \
static constexpr uint32_t underlying_type_id = __tyid; \
static std::string type_name() { return __name; } \
static std::string underlying_type_name() { return __name; } \
}
// `role` type. Requies underlying type.
#define DEFINE_ROLE_TYPE_TRAIT(__dty, __name, __tyid, __uty) \
template <> \
struct TypeTrait<__dty> { \
using value_type = __dty; \
using value_underlying_type = TypeTrait<__uty>::value_type; \
static constexpr uint32_t ndim = 0; /* array dim */ \
static constexpr uint32_t ncomp = TypeTrait<__uty>::ncomp; \
static constexpr uint32_t type_id = __tyid; \
static constexpr uint32_t underlying_type_id = TypeTrait<__uty>::type_id; \
static std::string type_name() { return __name; } \
static std::string underlying_type_name() { \
return TypeTrait<__uty>::type_name(); \
} \
}

View File

@@ -11,6 +11,8 @@
#include <sstream>
#include "prim-types.hh"
#include "usdGeom.hh"
#include "usdLux.hh"
namespace tinyusdz {

View File

@@ -1055,6 +1055,7 @@ struct MaterialBindingAPI {
// Predefined node classes
//
#if 0
struct Xform {
std::string name;
int64_t parent_id{-1}; // Index to xform node
@@ -1092,6 +1093,7 @@ struct Xform {
mutable bool _dirty{true};
mutable value::matrix4d _matrix; // Resulting matrix of evaluated XformOps.
};
#endif
struct UVCoords {
using UVCoordType =
@@ -1107,392 +1109,7 @@ struct UVCoords {
std::vector<uint32_t> indices; // UV indices. Usually varying
};
struct GeomCamera {
std::string name;
int64_t parent_id{-1}; // Index to parent node
enum class Projection {
perspective, // "perspective"
orthographic, // "orthographic"
};
enum class StereoRole {
mono, // "mono"
left, // "left"
right, // "right"
};
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// TODO: Animatable?
std::vector<value::float4> clippingPlanes;
value::float2 clippingRange{{0.1f, 1000000.0f}};
float exposure{0.0f}; // in EV
float focalLength{50.0f};
float focusDistance{0.0f};
float horizontalAperture{20.965f};
float horizontalApertureOffset{0.0f};
float verticalAperture{15.2908f};
float verticalApertureOffset{0.0f};
float fStop{0.0f}; // 0.0 = no focusing
Projection projection;
float shutterClose = 0.0f; // shutter:close
float shutterOpen = 0.0f; // shutter:open
std::vector<value::token> xformOpOrder;
// xformOpOrder
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomBoundable {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomCone {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableDouble height{2.0};
AnimatableDouble radius{1.0};
Axis axis{Axis::Z};
AnimatableExtent extent{
Extent({-1.0, -1.0, -1.0},
{1.0, 1.0, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomCapsule {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableDouble height{2.0};
AnimatableDouble radius{0.5};
Axis axis{Axis::Z};
AnimatableExtent extent{
Extent({-0.5, -0.5, -1.0},
{0.5, 0.5, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomCylinder {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableDouble height{2.0};
AnimatableDouble radius{1.0};
Axis axis{Axis::Z};
AnimatableExtent extent{
Extent({-1.0, -1.0, -1.0},
{1.0, 1.0, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomCube {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableDouble size{2.0};
AnimatableExtent extent{
Extent({-1.0, -1.0, -1.0},
{1.0, 1.0, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomSphere {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Predefined attribs.
//
AnimatableDouble radius{1.0};
//
// Properties
//
AnimatableExtent extent{
Extent({-1.0, -1.0, -1.0},
{1.0, 1.0, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
//
// Basis Curves(for hair/fur)
//
struct GeomBasisCurves {
std::string name;
int64_t parent_id{-1}; // Index to parent node
// Interpolation attribute
std::string type = "cubic"; // "linear", "cubic"
std::string basis =
"bspline"; // "bezier", "catmullRom", "bspline" ("hermite" and "power" is
// not supported in TinyUSDZ)
std::string wrap = "nonperiodic"; // "nonperiodic", "periodic", "pinned"
//
// Predefined attribs.
//
std::vector<value::float3> points;
std::vector<value::float3> normals; // normal3f
std::vector<int> curveVertexCounts;
std::vector<float> widths;
std::vector<value::float3> velocities; // vector3f
std::vector<value::float3> accelerations; // vector3f
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
//
// Points primitive.
//
struct GeomPoints {
std::string name;
int64_t parent_id{-1}; // Index to xform node
//
// Predefined attribs.
//
std::vector<value::float3> points; // float3
std::vector<value::float3> normals; // normal3f
std::vector<float> widths;
std::vector<int64_t> ids; // per-point ids
std::vector<value::float3> velocities; // vector3f
std::vector<value::float3> accelerations; // vector3f
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` may exist(in that ase, please ignore `widths`
// parameter)
std::map<std::string, PrimAttrib> attribs;
};
struct LuxSphereLight {
std::string name;
int64_t parent_id{-1}; // Index to xform node
//
// Predefined attribs.
//
// Light API
value::color3f color{1.0f, 1.0f, 1.0f}; // inputs.color Light energy in linear color space.
float colorTemperature{6500.0f}; // inputs:colorTemperature
float diffuse{1.0f}; // inputs:diffuse diffuse multiplier
bool enableColorTemperature{false}; // inputs:enableColorTemperature
float exposure{0.0f}; // inputs:exposure EV
float intensity{1.0f}; // inputs:intensity
bool normalize{false}; // inputs:normalize normalize power by the surface area of the light.
float specular{1.0f}; // inputs:specular specular multiplier
// rel light:filters
float radius{0.5f}; // inputs:radius
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` may exist(in that ase, please ignore `widths`
// parameter)
std::map<std::string, PrimAttrib> attribs;
};
struct LuxDomeLight {
std::string name;
int64_t parent_id{-1}; // Index to xform node
enum class TextureFormat {
Automatic, // "automatic"
Latlong, // "latlong"
MirroredBall, // "mirroredBall"
Angular // "angular"
};
//
// Predefined attribs.
//
// TODO: Support texture
// Light API
value::color3f color{1.0f, 1.0f, 1.0f}; // inputs.color Light energy in linear color space.
float colorTemperature{6500.0f}; // inputs:colorTemperature
float diffuse{1.0f}; // inputs:diffuse diffuse multiplier
bool enableColorTemperature{false}; // inputs:enableColorTemperature
float exposure{0.0f}; // inputs:exposure EV
float intensity{1.0f}; // inputs:intensity
bool normalize{false}; // inputs:normalize normalize power by the surface area of the light.
float specular{1.0f}; // inputs:specular specular multiplier
// rel light:filters
// DomeLight specific
float guideRadius{1.0e5f};
// asset inputs:texture:file
TextureFormat textureFormat{TextureFormat::Automatic}; // token inputs:texture:format
// rel portals
// rel proxyPrim
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
std::vector<value::token> xformOpOrder;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` may exist(in that ase, please ignore `widths`
// parameter)
std::map<std::string, PrimAttrib> attribs;
};
// BlendShapes
// TODO(syoyo): Blendshape
@@ -1501,7 +1118,7 @@ struct BlendShape {
std::vector<float> offsets; // uniform vector3f[]. required property
std::vector<float> normalOffsets; // uniform vector3f[]. required property
std::vector<int>
pointIndices; // uniform int[]. optional. vertex indices to the original mesh for each
// values in `offsets` and `normalOffsets`.
@@ -1518,9 +1135,9 @@ struct Skeleton {
std::vector<std::string> jointNames; // uniform token[]
std::vector<std::string> joints; // uniform token[]
// rel proxyPrim
std::vector<value::matrix4d> restTransforms; // uniform matrix4d[] rest-pose transforms of each
// joint in local coordinate.
@@ -1578,6 +1195,7 @@ struct SkelBindingAPI {
int64_t skeleton{-1}; // index to Scene.skeletons. // ref skel:skeleton
};
#if 0
// Generic Prim
struct GPrim {
std::string name;
@@ -1738,6 +1356,7 @@ struct GeomMesh : GPrim {
// List of Primitive attributes(primvars)
// std::map<std::string, PrimAttrib> attribs;
};
#endif
//
// Similar to Maya's ShadingGroup
@@ -2039,20 +1658,7 @@ Orientation OrientationFromString(const std::string &v);
namespace value {
// Same macro in value-type.hh
#define DEFINE_TYPE_TRAIT(__dty, __name, __tyid, __nc) \
template <> \
struct TypeTrait<__dty> { \
using value_type = __dty; \
using value_underlying_type = __dty; \
static constexpr uint32_t ndim = 0; /* array dim */ \
static constexpr uint32_t ncomp = \
__nc; /* the number of components(e.g. float3 => 3) */ \
static constexpr uint32_t type_id = __tyid; \
static constexpr uint32_t underlying_type_id = __tyid; \
static std::string type_name() { return __name; } \
static std::string underlying_type_name() { return __name; } \
}
#include "define-type-trait.inc"
DEFINE_TYPE_TRAIT(Reference, "ref", TYPE_ID_REFERENCE, 1);
DEFINE_TYPE_TRAIT(Specifier, "specifier", TYPE_ID_SPECIFIER, 1);
@@ -2082,15 +1688,6 @@ DEFINE_TYPE_TRAIT(std::vector<value::token>, "TokenVector",
DEFINE_TYPE_TRAIT(value::TimeSamples, "TimeSamples", TYPE_ID_TIMESAMPLES, 1);
DEFINE_TYPE_TRAIT(GPrim, "GPRIM",
TYPE_ID_GPRIM, 1);
// Geom
DEFINE_TYPE_TRAIT(Xform, "Xform",
TYPE_ID_GEOM_XFORM, 1);
DEFINE_TYPE_TRAIT(GeomMesh, "Mesh",
TYPE_ID_GEOM_MESH, 1);
// Shader
DEFINE_TYPE_TRAIT(PreviewSurface, "PreviewSurface",
TYPE_ID_IMAGING_PREVIEWSURFACE, 1);
@@ -2107,6 +1704,7 @@ DEFINE_TYPE_TRAIT(PrimvarReader_int, "PrimvarReader_int",
TYPE_ID_IMAGING_PRIMVAR_READER_INT, 1);
#undef DEFINE_TYPE_TRAIT
#undef DEFINE_ROLE_TYPE_TRAIT
} // namespace value

View File

@@ -721,12 +721,15 @@ bool LoadUSDAFromFile(const std::string &_filename, HighLevelScene *scene,
options);
}
#if 0
size_t GeomMesh::GetNumPoints() const {
size_t n = points.size() / 3;
return n;
}
#endif
#if 0
bool GeomMesh::GetFacevaryingNormals(std::vector<float> *v) const {
(void)v;
@@ -744,7 +747,9 @@ bool GeomMesh::GetFacevaryingNormals(std::vector<float> *v) const {
return false;
}
#endif
#if 0
bool GeomMesh::GetFacevaryingTexcoords(std::vector<float> *v) const {
(void)v;
if (st.variability != Variability::Varying) {
@@ -771,7 +776,9 @@ bool GeomMesh::GetFacevaryingTexcoords(std::vector<float> *v) const {
return false;
}
#endif
#if 0
value::matrix4d GetTransform(XformOp xform)
{
value::matrix4d m;
@@ -886,7 +893,9 @@ bool Xform::EvaluateXformOps(value::matrix4d *out_matrix) const {
return true;
}
#endif
#if 0
void GeomMesh::Initialize(const GPrim &gprim)
{
name = gprim.name;
@@ -1000,6 +1009,7 @@ nonstd::expected<bool, std::string> GeomMesh::ValidateGeomSubset() {
//return true;
}
#endif
//static_assert(sizeof(crate::Index) == 4, "");
//static_assert(sizeof(crate::Field) == 16, "");

View File

@@ -56,6 +56,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "prim-types.hh"
#include "image-types.hh"
#include "texture-types.hh"
#include "usdGeom.hh"
namespace tinyusdz {
@@ -389,7 +390,7 @@ struct StringAndIdMap {
//
// For high-level scene graph.
// Easy to use API, but may not be performant.
//
//
class PrimNode {
public:
std::string name;
@@ -409,7 +410,7 @@ class PrimNode {
//
// For low-level scene graph representation, something like Vulkan.
// Less abstraction, and scene graph is representated by indices.
//
//
struct Node {
std::string name;
@@ -458,6 +459,7 @@ struct NodeIndex {
// -1 = invlid(or not set)
};
#if 0
struct LowLevelScene {
std::string name; // Scene name
int64_t default_root_node{-1}; // index to default root node
@@ -510,6 +512,7 @@ struct LowLevelScene {
std::vector<NodeIndex> node_indices;
};
#endif
#if 0
// Similar to UsdStage. Mostly equals to `Scene`

View File

@@ -1,80 +1,55 @@
#include "render-data.hh"
#include "prim-types.hh"
#include "pprinter.hh"
#include "prim-types.hh"
namespace tinyusdz {
namespace tydra {
namespace {
template<typename T>
#if 0
template <typename T>
inline T Get(const nonstd::optional<T> &nv, const T &default_value) {
if (nv) {
return nv.value();
}
return default_value;
}
#endif
} // namespace
} // namespace
nonstd::expected<RenderMesh, std::string> Convert(const GeomMesh &mesh) {
RenderMesh dst;
{
dst.points.resize(mesh.points.size());
memcpy(dst.points.data(), mesh.points.data(), sizeof(value::float3) * mesh.points.size());
memcpy(dst.points.data(), mesh.points.data(),
sizeof(value::float3) * mesh.points.size());
}
// normals
// Both `primvar::normals` and `normals` are defined, `primvar::normals` is used.
// Do not compute smooth normals when neither `primvar::normals` nor `normals` defined(Only faceted normals are computed).
auto GetNormals = [](const GeomMesh &m) -> nonstd::optional<PrimAttrib> {
constexpr auto kPrimvarNormals = "primvar::normals";
if (m.props.count(kPrimvarNormals)) {
const auto prop = m.props.at(kPrimvarNormals);
if (prop.IsRel()) {
// TODO:
return nonstd::nullopt;
}
return prop.attrib;
}
if (m.normals) {
return m.normals.value();
}
return nonstd::nullopt;
};
if (auto nv = GetNormals(mesh)) {
auto normalsAttr = nv.value();
// normal3f
const std::vector<value::normal3f> *normals = normalsAttr.var.as<std::vector<value::normal3f>>();
if (normals == nullptr) {
return nonstd::make_unexpected("`normal3f[]` type expected for `normals` attribute, but got `" + normalsAttr.var.type_name() + "`.\n");
}
auto interp = Get(normalsAttr.meta.interpolation, Interpolation::Vertex); // default 'vertex'
{
std::vector<value::normal3f> normals = mesh.GetNormals();
Interpolation interp = mesh.GetNormalsInterpolation();
if (interp == Interpolation::Vertex) {
return nonstd::make_unexpected("TODO: `vertex` interpolation for `normals` attribute.\n");
return nonstd::make_unexpected(
"TODO: `vertex` interpolation for `normals` attribute.\n");
} else if (interp == Interpolation::FaceVarying) {
dst.facevaryingNormals.resize(normals->size());
memcpy(dst.facevaryingNormals.data(), normals, sizeof(value::normal3f) * normals->size());
dst.facevaryingNormals.resize(normals.size());
memcpy(dst.facevaryingNormals.data(), normals.data(),
sizeof(value::normal3f) * normals.size());
} else {
return nonstd::make_unexpected("Unsupported/unimplemented interpolation for `normals` attribute: " + to_string(interp) + ".\n");
return nonstd::make_unexpected(
"Unsupported/unimplemented interpolation for `normals` attribute: " +
to_string(interp) + ".\n");
}
}
return dst;
}
} // namespace tydra
} // namespace tinyusdz
} // namespace tydra
} // namespace tinyusdz

307
src/usdGeom.cc Normal file
View File

@@ -0,0 +1,307 @@
// SPDX-License-Identifier: MIT
// Copyright 2022 - Present, Syoyo Fujita.
//
// UsdGeom API implementations
#include <sstream>
#include "usdGeom.hh"
#include "prim-types.hh"
#if !defined(TINYUSDZ_PRODUCTION_BUILD)
#define TINYUSDZ_LOCAL_DEBUG_PRINT
#endif
#if defined(TINYUSDZ_LOCAL_DEBUG_PRINT)
#define DCOUT(x) do { std::cout << __FILE__ << ":" << __func__ << ":" << std::to_string(__LINE__) << " " << x << "\n"; } while (false)
#else
#define DCOUT(x)
#endif
namespace tinyusdz {
namespace {
constexpr auto kPrimvarNormals = "primvar::normals";
} // namespace
std::vector<value::normal3f> GeomMesh::GetNormals() const {
std::vector<value::normal3f> dst;
if (props.count(kPrimvarNormals)) {
const auto prop = props.at(kPrimvarNormals);
if (prop.IsRel()) {
// TODO:
return dst;
}
if (prop.attrib.var.type_name() == "normal3f[]") {
if (auto pv = prop.attrib.var.get_value<std::vector<value::normal3f>>()) {
dst = pv.value();
}
}
} else if (normals) {
if (normals.value().var.type_name() == "normal3f[]") {
if (auto pv = normals.value().var.get_value<std::vector<value::normal3f>>()) {
dst = pv.value();
}
}
}
return dst;
}
Interpolation GeomMesh::GetNormalsInterpolation() const {
if (props.count(kPrimvarNormals)) {
// TODO: Check if `primvar::normals` type is `normal3f[]`
const auto &prop = props.at(kPrimvarNormals);
if (prop.attrib.meta.interpolation) {
return prop.attrib.meta.interpolation.value();
}
} else if (normals) {
return normals.value().meta.interpolation.value();
}
return Interpolation::Vertex; // default 'vertex'
}
void GeomMesh::Initialize(const GPrim &gprim)
{
name = gprim.name;
parent_id = gprim.parent_id;
props = gprim.props;
#if 0
for (auto &prop_item : gprim.props) {
std::string attr_name = std::get<0>(prop_item);
const Property &prop = std::get<1>(prop_item);
if (prop.is_rel) {
//LOG_INFO("TODO: Rel property:" + attr_name);
continue;
}
const PrimAttrib &attr = prop.attrib;
if (attr_name == "points") {
//if (auto p = primvar::as_vector<value::float3>(&attr.var)) {
// points = *p;
//}
} else if (attr_name == "faceVertexIndices") {
//if (auto p = primvar::as_vector<int>(&attr.var)) {
// faceVertexIndices = *p;
//}
} else if (attr_name == "faceVertexCounts") {
//if (auto p = primvar::as_vector<int>(&attr.var)) {
// faceVertexCounts = *p;
//}
} else if (attr_name == "normals") {
//if (auto p = primvar::as_vector<value::float3>(&attr.var)) {
// normals.var = *p;
// normals.interpolation = attr.interpolation;
//}
} else if (attr_name == "velocitiess") {
//if (auto p = primvar::as_vector<value::float3>(&attr.var)) {
// velocitiess.var = (*p);
// velocitiess.interpolation = attr.interpolation;
//}
} else if (attr_name == "primvars:uv") {
//if (auto pv2f = primvar::as_vector<Vec2f>(&attr.var)) {
// st.buffer = (*pv2f);
// st.interpolation = attr.interpolation;
//} else if (auto pv3f = primvar::as_vector<value::float3>(&attr.var)) {
// st.buffer = (*pv3f);
// st.interpolation = attr.interpolation;
//}
} else {
// Generic PrimAtrr
props[attr_name] = attr;
}
}
#endif
doubleSided = gprim.doubleSided;
orientation = gprim.orientation;
visibility = gprim.visibility;
extent = gprim.extent;
purpose = gprim.purpose;
displayColor = gprim.displayColor;
displayOpacity = gprim.displayOpacity;
#if 0 // TODO
// PrimVar(TODO: Remove)
UVCoords st;
//
// Properties
//
#endif
};
nonstd::expected<bool, std::string> GeomMesh::ValidateGeomSubset() {
std::stringstream ss;
if (geom_subset_children.empty()) {
return true;
}
auto CheckFaceIds = [](const size_t nfaces, const std::vector<uint32_t> ids) {
if (std::any_of(ids.begin(), ids.end(), [&nfaces](uint32_t id) { return id >= nfaces; })) {
return false;
}
return true;
};
size_t n = faceVertexIndices.size();
// Currently we only check if face ids are valid.
for (size_t i = 0; i < geom_subset_children.size(); i++) {
const GeomSubset & subset = geom_subset_children[i];
if (!CheckFaceIds(n, subset.indices)) {
ss << "Face index out-of-range.\n";
return nonstd::make_unexpected(ss.str());
}
}
return nonstd::make_unexpected("TODO: Implent GeomMesh::ValidateGeomSubset\n");
//return true;
}
namespace {
#if 0
value::matrix4d GetTransform(XformOp xform)
{
value::matrix4d m;
Identity(&m);
if (xform.op == XformOp::OpType::TRANSFORM) {
if (auto v = xform.value.get<value::matrix4d>()) {
m = v.value();
}
} else if (xform.op == XformOp::OpType::TRANSLATE) {
if (auto sf = xform.value.get<value::float3>()) {
m.m[3][0] = double(sf.value()[0]);
m.m[3][1] = double(sf.value()[1]);
m.m[3][2] = double(sf.value()[2]);
} else if (auto sd = xform.value.get<value::double3>()) {
m.m[3][0] = sd.value()[0];
m.m[3][1] = sd.value()[1];
m.m[3][2] = sd.value()[2];
}
} else if (xform.op == XformOp::OpType::SCALE) {
if (auto sf = xform.value.get<value::float3>()) {
m.m[0][0] = double(sf.value()[0]);
m.m[1][1] = double(sf.value()[1]);
m.m[2][2] = double(sf.value()[2]);
} else if (auto sd = xform.value.get<value::double3>()) {
m.m[0][0] = sd.value()[0];
m.m[1][1] = sd.value()[1];
m.m[2][2] = sd.value()[2];
}
} else {
DCOUT("TODO: xform.op = " << XformOp::GetOpTypeName(xform.op));
}
return m;
}
#endif
} // namespace
bool Xform::EvaluateXformOps(value::matrix4d *out_matrix) const {
Identity(out_matrix);
value::matrix4d cm;
// Concat matrices
for (const auto &x : xformOps) {
value::matrix4d m;
Identity(&m);
(void)x;
if (x.op == XformOp::TRANSLATE) {
if (auto txf = x.value.get<value::float3>()) {
m.m[3][0] = double(txf.value()[0]);
m.m[3][1] = double(txf.value()[1]);
m.m[3][2] = double(txf.value()[2]);
} else if (auto txd = x.value.get<value::double3>()) {
m.m[3][0] = txd.value()[0];
m.m[3][1] = txd.value()[1];
m.m[3][2] = txd.value()[2];
} else {
return false;
}
// FIXME: Validate ROTATE_X, _Y, _Z implementation
} else if (x.op == XformOp::ROTATE_X) {
double theta;
if (auto rf = x.value.get<float>()) {
theta = double(rf.value());
} else if (auto rd = x.value.get<double>()) {
theta = rd.value();
} else {
return false;
}
m.m[1][1] = std::cos(theta);
m.m[1][2] = std::sin(theta);
m.m[2][1] = -std::sin(theta);
m.m[2][2] = std::cos(theta);
} else if (x.op == XformOp::ROTATE_Y) {
double theta;
if (auto f = x.value.get<float>()) {
theta = double(f.value());
} else if (auto d = x.value.get<double>()) {
theta = d.value();
} else {
return false;
}
m.m[0][0] = std::cos(theta);
m.m[0][2] = -std::sin(theta);
m.m[2][0] = std::sin(theta);
m.m[2][2] = std::cos(theta);
} else if (x.op == XformOp::ROTATE_Z) {
double theta;
if (auto f = x.value.get<float>()) {
theta = double(f.value());
} else if (auto d = x.value.get<double>()) {
theta = d.value();
} else {
return false;
}
m.m[0][0] = std::cos(theta);
m.m[0][1] = std::sin(theta);
m.m[1][0] = -std::sin(theta);
m.m[1][1] = std::cos(theta);
} else {
// TODO
DCOUT("TODO");
return false;
}
cm = Mult<value::matrix4d, double, 4>(cm, m);
}
(*out_matrix) = cm;
return true;
}
} // namespace tinyusdz

546
src/usdGeom.hh Normal file
View File

@@ -0,0 +1,546 @@
// SPDX-License-Identifier: MIT
// Copyright 2022 - Present, Syoyo Fujita.
//
// UsdGeom
#pragma once
#include "prim-types.hh"
namespace tinyusdz {
// Generic Prim
struct GPrim {
std::string name;
int64_t parent_id{-1}; // Index to parent node
std::string prim_type; // Primitive type(if specified by `def`)
// Gprim
AnimatableExtent extent; // bounding extent(in local coord?).
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
std::map<std::string, Property> props;
std::map<std::string, value::Value> args;
bool _valid{true}; // default behavior is valid(allow empty GPrim)
bool active{true};
// child nodes
std::vector<GPrim> children;
};
struct Xform {
std::string name;
int64_t parent_id{-1}; // Index to xform node
std::vector<XformOp> xformOps;
Orientation orientation{Orientation::RightHanded};
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
Xform() {}
///
/// Evaluate XformOps
///
bool EvaluateXformOps(value::matrix4d *out_matrix) const;
///
/// Get concatenated matrix.
///
nonstd::optional<value::matrix4d> GetMatrix() const {
if (_dirty) {
value::matrix4d m;
if (EvaluateXformOps(&m)) {
_matrix = m;
_dirty = false;
} else {
// TODO: Report an error.
return nonstd::nullopt;
}
}
return _matrix;
}
mutable bool _dirty{true};
mutable value::matrix4d _matrix; // Resulting matrix of evaluated XformOps.
};
// GeomSubset
struct GeomSubset {
enum class ElementType { Face };
enum class FamilyType {
Partition, // 'partition'
NonOverlapping, // 'nonOverlapping'
Unrestricted, // 'unrestricted' (fallback)
};
std::string name;
int64_t parent_id{-1}; // Index to parent node
ElementType elementType{ElementType::Face}; // must be face
FamilyType familyType{FamilyType::Unrestricted};
nonstd::expected<bool, std::string> SetElementType(const std::string &str) {
if (str == "face") {
elementType = ElementType::Face;
return true;
}
return nonstd::make_unexpected(
"Only `face` is supported for `elementType`, but `" + str +
"` specified");
}
nonstd::expected<bool, std::string> SetFamilyType(const std::string &str) {
if (str == "partition") {
familyType = FamilyType::Partition;
return true;
} else if (str == "nonOverlapping") {
familyType = FamilyType::NonOverlapping;
return true;
} else if (str == "unrestricted") {
familyType = FamilyType::Unrestricted;
return true;
}
return nonstd::make_unexpected("Invalid `familyType` specified: `" + str +
"`.");
}
std::vector<uint32_t> indices;
std::map<std::string, PrimAttrib> attribs; // custom Attrs
};
// Polygon mesh geometry
struct GeomMesh : GPrim {
//
// Predefined attribs.
//
std::vector<value::point3f> points; // point3f
nonstd::optional<PrimAttrib> normals; // normal3f[]
//
// Utility functions
//
// Initialize GeomMesh by GPrim(prepend references)
void Initialize(const GPrim &pprim);
// Update GeomMesh by GPrim(append references)
void UpdateBy(const GPrim &pprim);
///
/// @brief Returns normals vector. Precedence order: `primvar::normals` then
/// `normals`.
///
/// @return normals vector(copied). Returns empty normals vector when neither
/// `primvar::normals` nor `normals` attribute defined, attribute is a
/// relation or normals attribute have invalid type(other than `normal3f`).
///
std::vector<value::normal3f> GetNormals() const;
///
/// @brief Get interpolation of normals.
/// @return Interpolation of normals. `vertex` by defaut.
///
Interpolation GetNormalsInterpolation() const;
#if 0
// Get `normals` as float3 array + facevarying
// Return false if `normals` is neither float3[] type nor `varying`
bool GetFacevaryingNormals(std::vector<float> *v) const;
#endif
// Get `texcoords` as float2 array + facevarying
// Return false if `texcoords` is neither float2[] type nor `varying`
bool GetFacevaryingTexcoords(std::vector<float> *v) const;
// Primary UV coords(TODO: Remove. Read uv coords through PrimVarReader)
UVCoords st;
PrimAttrib velocitiess; // Usually float3[], varying
std::vector<int32_t> faceVertexCounts;
std::vector<int32_t> faceVertexIndices;
//
// Properties
//
// AnimatableExtent extent; // bounding extent(in local coord?).
std::string facevaryingLinearInterpolation = "cornerPlus1";
// AnimatableVisibility visibility{Visibility::Inherited};
// Purpose purpose{Purpose::Default};
// Gprim
// bool doubleSided{false};
// Orientation orientation{Orientation::RightHanded};
// AnimatableVec3fArray displayColor; // primvars:displayColor
// AnimatableFloatArray displayOpacity; // primvars:displaOpacity
// MaterialBindingAPI materialBinding;
//
// SubD attribs.
//
std::vector<int32_t> cornerIndices;
std::vector<float> cornerSharpnesses;
std::vector<int32_t> creaseIndices;
std::vector<int32_t> creaseLengths;
std::vector<float> creaseSharpnesses;
std::vector<int32_t> holeIndices;
std::string interpolateBoundary =
"edgeAndCorner"; // "none", "edgeAndCorner" or "edgeOnly"
SubdivisionScheme subdivisionScheme{SubdivisionScheme::CatmullClark};
//
// GeomSubset
//
// uniform token `subsetFamily:materialBind:familyType`
GeomSubset::FamilyType materialBindFamilyType{
GeomSubset::FamilyType::Partition};
std::vector<GeomSubset> geom_subset_children;
///
/// Validate GeomSubset data attached to this GeomMesh.
///
nonstd::expected<bool, std::string> ValidateGeomSubset();
// List of Primitive attributes(primvars)
// std::map<std::string, PrimAttrib> attribs;
};
struct GeomCamera {
std::string name;
int64_t parent_id{-1}; // Index to parent node
enum class Projection {
perspective, // "perspective"
orthographic, // "orthographic"
};
enum class StereoRole {
mono, // "mono"
left, // "left"
right, // "right"
};
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// TODO: Animatable?
std::vector<value::float4> clippingPlanes;
value::float2 clippingRange{{0.1f, 1000000.0f}};
float exposure{0.0f}; // in EV
float focalLength{50.0f};
float focusDistance{0.0f};
float horizontalAperture{20.965f};
float horizontalApertureOffset{0.0f};
float verticalAperture{15.2908f};
float verticalApertureOffset{0.0f};
float fStop{0.0f}; // 0.0 = no focusing
Projection projection;
float shutterClose = 0.0f; // shutter:close
float shutterOpen = 0.0f; // shutter:open
std::vector<value::token> xformOpOrder;
// xformOpOrder
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomBoundable {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomCone {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableDouble height{2.0};
AnimatableDouble radius{1.0};
Axis axis{Axis::Z};
AnimatableExtent extent{
Extent({-1.0, -1.0, -1.0},
{1.0, 1.0, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomCapsule {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableDouble height{2.0};
AnimatableDouble radius{0.5};
Axis axis{Axis::Z};
AnimatableExtent extent{
Extent({-0.5, -0.5, -1.0},
{0.5, 0.5, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomCylinder {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableDouble height{2.0};
AnimatableDouble radius{1.0};
Axis axis{Axis::Z};
AnimatableExtent extent{
Extent({-1.0, -1.0, -1.0},
{1.0, 1.0, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomCube {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Properties
//
AnimatableDouble size{2.0};
AnimatableExtent extent{
Extent({-1.0, -1.0, -1.0},
{1.0, 1.0, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
struct GeomSphere {
std::string name;
int64_t parent_id{-1}; // Index to parent node
//
// Predefined attribs.
//
AnimatableDouble radius{1.0};
//
// Properties
//
AnimatableExtent extent{
Extent({-1.0, -1.0, -1.0},
{1.0, 1.0, 1.0})}; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
//
// Basis Curves(for hair/fur)
//
struct GeomBasisCurves {
std::string name;
int64_t parent_id{-1}; // Index to parent node
// Interpolation attribute
std::string type = "cubic"; // "linear", "cubic"
std::string basis =
"bspline"; // "bezier", "catmullRom", "bspline" ("hermite" and "power" is
// not supported in TinyUSDZ)
std::string wrap = "nonperiodic"; // "nonperiodic", "periodic", "pinned"
//
// Predefined attribs.
//
std::vector<value::float3> points;
std::vector<value::float3> normals; // normal3f
std::vector<int> curveVertexCounts;
std::vector<float> widths;
std::vector<value::float3> velocities; // vector3f
std::vector<value::float3> accelerations; // vector3f
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
MaterialBindingAPI materialBinding;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` are not stored here(stored in `widths`)
std::map<std::string, PrimAttrib> attribs;
};
//
// Points primitive.
//
struct GeomPoints {
std::string name;
int64_t parent_id{-1}; // Index to xform node
//
// Predefined attribs.
//
std::vector<value::float3> points; // float3
std::vector<value::float3> normals; // normal3f
std::vector<float> widths;
std::vector<int64_t> ids; // per-point ids
std::vector<value::float3> velocities; // vector3f
std::vector<value::float3> accelerations; // vector3f
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// Gprim
bool doubleSided{false};
Orientation orientation{Orientation::RightHanded};
AnimatableVec3fArray displayColor; // primvars:displayColor
AnimatableFloatArray displayOpacity; // primvars:displaOpacity
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` may exist(in that ase, please ignore `widths`
// parameter)
std::map<std::string, PrimAttrib> attribs;
};
// import DEFINE_TYPE_TRAIT and DEFINE_ROLE_TYPE_TRAIT
#include "define-type-trait.inc"
namespace value {
// Geom
DEFINE_TYPE_TRAIT(GPrim, "GPRIM", TYPE_ID_GPRIM, 1);
DEFINE_TYPE_TRAIT(Xform, "Xform", TYPE_ID_GEOM_XFORM, 1);
DEFINE_TYPE_TRAIT(GeomMesh, "Mesh", TYPE_ID_GEOM_MESH, 1);
#undef DEFINE_TYPE_TRAIT
#undef DEFINE_ROLE_TYPE_TRAIT
} // namespace value
} // namespace tinyusdz

12
src/usdLux.cc Normal file
View File

@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
// Copyright 2022 - Present, Syoyo Fujita.
//
// UsdLux implementations
#include "usdLux.hh"
namespace tinyusdz {
} // namespace tinyusdz

107
src/usdLux.hh Normal file
View File

@@ -0,0 +1,107 @@
// SPDX-License-Identifier: MIT
// Copyright 2022 - Present, Syoyo Fujita.
//
// UsdLux LightSource
#pragma once
#include "prim-types.hh"
namespace tinyusdz {
struct LuxSphereLight {
std::string name;
int64_t parent_id{-1}; // Index to xform node
//
// Predefined attribs.
//
// Light API
value::color3f color{1.0f, 1.0f, 1.0f}; // inputs.color Light energy in linear color space.
float colorTemperature{6500.0f}; // inputs:colorTemperature
float diffuse{1.0f}; // inputs:diffuse diffuse multiplier
bool enableColorTemperature{false}; // inputs:enableColorTemperature
float exposure{0.0f}; // inputs:exposure EV
float intensity{1.0f}; // inputs:intensity
bool normalize{false}; // inputs:normalize normalize power by the surface area of the light.
float specular{1.0f}; // inputs:specular specular multiplier
// rel light:filters
float radius{0.5f}; // inputs:radius
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` may exist(in that ase, please ignore `widths`
// parameter)
std::map<std::string, PrimAttrib> attribs;
};
struct LuxDomeLight {
std::string name;
int64_t parent_id{-1}; // Index to xform node
enum class TextureFormat {
Automatic, // "automatic"
Latlong, // "latlong"
MirroredBall, // "mirroredBall"
Angular // "angular"
};
//
// Predefined attribs.
//
// TODO: Support texture
// Light API
value::color3f color{1.0f, 1.0f, 1.0f}; // inputs.color Light energy in linear color space.
float colorTemperature{6500.0f}; // inputs:colorTemperature
float diffuse{1.0f}; // inputs:diffuse diffuse multiplier
bool enableColorTemperature{false}; // inputs:enableColorTemperature
float exposure{0.0f}; // inputs:exposure EV
float intensity{1.0f}; // inputs:intensity
bool normalize{false}; // inputs:normalize normalize power by the surface area of the light.
float specular{1.0f}; // inputs:specular specular multiplier
// rel light:filters
// DomeLight specific
float guideRadius{1.0e5f};
// asset inputs:texture:file
TextureFormat textureFormat{TextureFormat::Automatic}; // token inputs:texture:format
// rel portals
// rel proxyPrim
//
// Properties
//
AnimatableExtent extent; // bounding extent(in local coord?).
AnimatableVisibility visibility{Visibility::Inherited};
Purpose purpose{Purpose::Default};
std::vector<value::token> xformOpOrder;
// List of Primitive attributes(primvars)
// NOTE: `primvar:widths` may exist(in that ase, please ignore `widths`
// parameter)
std::map<std::string, PrimAttrib> attribs;
};
// import DEFINE_TYPE_TRAIT and DEFINE_ROLE_TYPE_TRAIT
#include "define-type-trait.inc"
namespace value {
#undef DEFINE_TYPE_TRAIT
#undef DEFINE_ROLE_TYPE_TRAIT
} // namespace value
} // namespace tinyusdz

View File

@@ -39,9 +39,6 @@
// external
//#include "ryu/ryu.h"
//#include "ryu/ryu_parse.h"
#include "fast_float/fast_float.h"
#include "nonstd/expected.hpp"
#include "nonstd/optional.hpp"

View File

@@ -23,7 +23,7 @@ class USDCReader {
bool ReconstructHighLevelScene(HighLevelScene *scene);
bool ReconstructLowLevelScene(LowLevelScene *scene);
//bool ReconstructLowLevelScene(LowLevelScene *scene);
// Approximated memory usage in [mb]
size_t GetMemoryUsage() const;

View File

@@ -645,35 +645,8 @@ using dict = std::map<std::string, linb::any>;
template <class dtype>
struct TypeTrait;
#define DEFINE_TYPE_TRAIT(__dty, __name, __tyid, __nc) \
template <> \
struct TypeTrait<__dty> { \
using value_type = __dty; \
using value_underlying_type = __dty; \
static constexpr uint32_t ndim = 0; /* array dim */ \
static constexpr uint32_t ncomp = \
__nc; /* the number of components(e.g. float3 => 3) */ \
static constexpr uint32_t type_id = __tyid; \
static constexpr uint32_t underlying_type_id = __tyid; \
static std::string type_name() { return __name; } \
static std::string underlying_type_name() { return __name; } \
}
// `role` type. Requies underlying type.
#define DEFINE_ROLE_TYPE_TRAIT(__dty, __name, __tyid, __uty) \
template <> \
struct TypeTrait<__dty> { \
using value_type = __dty; \
using value_underlying_type = TypeTrait<__uty>::value_type; \
static constexpr uint32_t ndim = 0; /* array dim */ \
static constexpr uint32_t ncomp = TypeTrait<__uty>::ncomp; \
static constexpr uint32_t type_id = __tyid; \
static constexpr uint32_t underlying_type_id = TypeTrait<__uty>::type_id; \
static std::string type_name() { return __name; } \
static std::string underlying_type_name() { \
return TypeTrait<__uty>::type_name(); \
} \
}
// import DEFINE_TYPE_TRAIT and DEFINE_ROLE_TYPE_TRAIT
#include "define-type-trait.inc"
DEFINE_TYPE_TRAIT(std::nullptr_t, "null", TYPE_ID_NULL, 1);
DEFINE_TYPE_TRAIT(void, "void", TYPE_ID_VOID, 1);
@@ -761,8 +734,8 @@ DEFINE_TYPE_TRAIT(dict, kDictionary, TYPE_ID_DICT, 1);
DEFINE_TYPE_TRAIT(asset_path, kAssetPath, TYPE_ID_ASSET_PATH, 1);
//
// Other types(e.g. TYPE_ID_REFERENCE) are defined in `prim-types.hh` and
// `crate-format.hh`(Data types used in Crate data)
// Other types(e.g. TYPE_ID_REFERENCE) are defined in corresponding header files(e.g. `prim-types.hh`,
// `crate-format.hh`(Data types used in Crate data))
//
#undef DEFINE_TYPE_TRAIT