mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Refactoring Shader class(W.I.P.)
This commit is contained in:
@@ -817,7 +817,7 @@ std::string to_string(const Material &material, const uint32_t indent, bool clos
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string to_string(const Shader &shader, const uint32_t indent, bool closing_brace) {
|
||||
std::string to_string(const UsdPrimvarReader_float &shader, const uint32_t indent, bool closing_brace) {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << Indent(indent) << "def Shader \"" << shader.name << "\"\n";
|
||||
@@ -827,13 +827,40 @@ std::string to_string(const Shader &shader, const uint32_t indent, bool closing_
|
||||
ss << Indent(indent) << "{\n";
|
||||
|
||||
// members
|
||||
ss << Indent(indent) << " uniform token info:id = \"" << shader.info_id << "\"\n";
|
||||
ss << Indent(indent) << " uniform token info:id = \"UsdPrimvarReader_float\"\n";
|
||||
|
||||
if (closing_brace) {
|
||||
ss << Indent(indent) << "}\n";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
|
||||
}
|
||||
|
||||
std::string to_string(const Shader &shader, const uint32_t indent, bool closing_brace) {
|
||||
|
||||
if (auto pv = shader.value.get_value<UsdPrimvarReader_float>()) {
|
||||
return to_string(pv.value());
|
||||
} else {
|
||||
// generic Shader class
|
||||
std::stringstream ss;
|
||||
|
||||
ss << Indent(indent) << "def Shader \"" << shader.name << "\"\n";
|
||||
ss << Indent(indent) << "(\n";
|
||||
//print_prim_metas(shader.metas, indent);
|
||||
ss << Indent(indent) << ")\n";
|
||||
ss << Indent(indent) << "{\n";
|
||||
|
||||
// members
|
||||
ss << Indent(indent) << " uniform token info:id = \"" << shader.info_id << "\"\n";
|
||||
|
||||
if (closing_brace) {
|
||||
ss << Indent(indent) << "}\n";
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string to_string(const Skeleton &skel, const uint32_t indent, bool closing_brace) {
|
||||
@@ -855,6 +882,7 @@ std::string to_string(const Skeleton &skel, const uint32_t indent, bool closing_
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
std::string to_string(const LuxSphereLight &light, const uint32_t indent, bool closing_brace) {
|
||||
std::stringstream ss;
|
||||
|
||||
|
||||
@@ -99,6 +99,14 @@ std::string to_string(const LuxDomeLight &light, const uint32_t indent = 0, bool
|
||||
std::string to_string(const Material &material, const uint32_t indent = 0, bool closing_brace = true);
|
||||
std::string to_string(const Shader &shader, const uint32_t indent = 0, bool closing_brace = true);
|
||||
|
||||
std::string to_string(const UsdPreviewSurface &shader, const uint32_t indent = 0, bool closing_brace = true);
|
||||
std::string to_string(const UsdUVTexture &shader, const uint32_t indent = 0, bool closing_brace = true);
|
||||
std::string to_string(const UsdPrimvarReader_float &shader, const uint32_t indent = 0, bool closing_brace = true);
|
||||
std::string to_string(const UsdPrimvarReader_float2 &shader, const uint32_t indent = 0, bool closing_brace = true);
|
||||
std::string to_string(const UsdPrimvarReader_float3 &shader, const uint32_t indent = 0, bool closing_brace = true);
|
||||
std::string to_string(const UsdPrimvarReader_float4 &shader, const uint32_t indent = 0, bool closing_brace = true);
|
||||
std::string to_string(const UsdPrimvarReader_int &shader, const uint32_t indent = 0, bool closing_brace = true);
|
||||
|
||||
std::string to_string(const GeomCamera::Projection &proj, const uint32_t indent = 0, bool closing_brace = true);
|
||||
|
||||
std::string to_string(const tinyusdz::AnimatableVisibility &v, const uint32_t indent = 0, bool closing_brace = true);
|
||||
|
||||
@@ -338,7 +338,7 @@ class Path {
|
||||
public:
|
||||
Path() : valid(false) {}
|
||||
|
||||
// `p` is split into prim_part and prop_part
|
||||
// `p` is split into prim_part and prop_part
|
||||
Path(const std::string &p);
|
||||
Path(const std::string &prim, const std::string &prop);
|
||||
|
||||
@@ -658,6 +658,12 @@ struct ConnectionPath {
|
||||
// `Scene.shaders`)
|
||||
};
|
||||
|
||||
class Asset
|
||||
{
|
||||
public:
|
||||
std::string value;
|
||||
};
|
||||
|
||||
// struct Connection {
|
||||
// int64_t src_index{-1};
|
||||
// int64_t dest_index{-1};
|
||||
@@ -668,8 +674,17 @@ struct ConnectionPath {
|
||||
|
||||
// Relation and Connection
|
||||
struct Relation {
|
||||
// string, Path or PathVector
|
||||
tinyusdz::variant<std::string, Path, std::vector<Path>> targets;
|
||||
public:
|
||||
// monostate(empty(define only)), string, Path or PathVector
|
||||
tinyusdz::variant<tinyusdz::monostate, std::string, Path, std::vector<Path>> targets;
|
||||
|
||||
bool IsEmpty() {
|
||||
return targets.is<tinyusdz::monostate>();
|
||||
}
|
||||
|
||||
Relation() : targets(tinyusdz::monostate()) {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Variable class for Prim and Attribute Metadataum.
|
||||
@@ -883,6 +898,7 @@ struct Property {
|
||||
bool HasCustom() const { return has_custom; }
|
||||
};
|
||||
|
||||
#if 0 // Moved to usdShade.
|
||||
// Currently for UV texture coordinate
|
||||
template <typename T>
|
||||
struct PrimvarReader {
|
||||
@@ -903,6 +919,7 @@ using PrimvarReaderType =
|
||||
tinyusdz::variant<PrimvarReader_float, PrimvarReader_float2,
|
||||
PrimvarReader_float3, PrimvarReader_float4,
|
||||
PrimvarReader_int>;
|
||||
#endif
|
||||
|
||||
// Orient: axis/angle expressed as a quaternion.
|
||||
// NOTE: no `matrix4f`
|
||||
@@ -1248,7 +1265,7 @@ struct NodeGraph {
|
||||
};
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#if 0
|
||||
|
||||
// result = (texture_id == -1) ? use color : lookup texture
|
||||
struct Color3OrTexture {
|
||||
|
||||
@@ -46,6 +46,8 @@ For more information, please refer to <http://unlicense.org/>
|
||||
|
||||
namespace tinyusdz {
|
||||
|
||||
namespace {
|
||||
|
||||
// Equivalent to std::aligned_storage
|
||||
template <unsigned int Len, unsigned int Align>
|
||||
struct aligned_storage {
|
||||
@@ -189,6 +191,8 @@ struct is_one_of<T, S, Ts...> {
|
||||
std::is_same<T, S>::value || is_one_of<T, Ts...>::value;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
template <typename... Ts>
|
||||
struct variant {
|
||||
private:
|
||||
|
||||
@@ -35,7 +35,6 @@ struct BufferData {
|
||||
std::vector<uint8_t> data; // binary data
|
||||
|
||||
// TODO: Stride
|
||||
|
||||
};
|
||||
|
||||
// glTF-like Attribute
|
||||
@@ -54,11 +53,12 @@ enum class ColorSpace {
|
||||
Custom, // TODO: Custom colorspace
|
||||
};
|
||||
|
||||
// NOTE: Please distinguish with image::Image(src/image-types.hh). image::Image is much more generic image class.
|
||||
// This `ImageData` class has typed pixel format and has colorspace info, which is suited for renderer/viewer/DCC backends.
|
||||
// NOTE: Please distinguish with image::Image(src/image-types.hh). image::Image
|
||||
// is much more generic image class. This `ImageData` class has typed pixel
|
||||
// format and has colorspace info, which is suited for renderer/viewer/DCC
|
||||
// backends.
|
||||
template <typename T, ColorSpace cs>
|
||||
struct ImageData {
|
||||
|
||||
std::vector<T> image; // raw pixel data
|
||||
ColorSpace colorSpace{cs};
|
||||
int32_t width{-1};
|
||||
@@ -177,11 +177,89 @@ class RenderScene {
|
||||
buffers; // Various data storage(e.g. primvar texcoords)
|
||||
|
||||
// uint32_t rootNodeId{0}; // root node = nodes[rootNodeId]
|
||||
|
||||
};
|
||||
|
||||
nonstd::expected<RenderMesh, std::string> Convert(const Stage &stage, const GeomMesh &mesh);
|
||||
|
||||
#if 0 // TODO:
|
||||
// result = (texture_id == -1) ? use color : lookup texture
|
||||
struct Color3OrTexture {
|
||||
Color3OrTexture(float x, float y, float z) {
|
||||
color[0] = x;
|
||||
color[1] = y;
|
||||
color[2] = z;
|
||||
}
|
||||
|
||||
std::array<float, 3> color{{0.0f, 0.0f, 0.0f}};
|
||||
|
||||
std::string path; // path to .connect(We only support texture file connection
|
||||
// at the moment)
|
||||
int64_t texture_id{-1};
|
||||
|
||||
bool HasTexture() const { return texture_id > -1; }
|
||||
};
|
||||
|
||||
struct FloatOrTexture {
|
||||
FloatOrTexture(float x) { value = x; }
|
||||
|
||||
float value{0.0f};
|
||||
|
||||
std::string path; // path to .connect(We only support texture file connection
|
||||
// at the moment)
|
||||
int64_t texture_id{-1};
|
||||
|
||||
bool HasTexture() const { return texture_id > -1; }
|
||||
};
|
||||
|
||||
enum TextureWrap {
|
||||
TextureWrapUseMetadata, // look for wrapS and wrapT metadata in the texture
|
||||
// file itself
|
||||
TextureWrapBlack,
|
||||
TextureWrapClamp,
|
||||
TextureWrapRepeat,
|
||||
TextureWrapMirror
|
||||
};
|
||||
|
||||
// For texture transform
|
||||
// result = in * scale * rotate * translation
|
||||
struct UsdTranform2d {
|
||||
float rotation =
|
||||
0.0f; // counter-clockwise rotation in degrees around the origin.
|
||||
std::array<float, 2> scale{{1.0f, 1.0f}};
|
||||
std::array<float, 2> translation{{0.0f, 0.0f}};
|
||||
};
|
||||
|
||||
// UsdUvTexture
|
||||
struct UVTexture {
|
||||
std::string asset; // asset name(usually file path)
|
||||
int64_t image_id{
|
||||
-1}; // TODO(syoyo): Consider UDIM `@textures/occlusion.<UDIM>.tex@`
|
||||
|
||||
TextureWrap wrapS{};
|
||||
TextureWrap wrapT{};
|
||||
|
||||
std::array<float, 4> fallback{
|
||||
{0.0f, 0.0f, 0.0f,
|
||||
1.0f}}; // fallback color used when texture cannot be read.
|
||||
std::array<float, 4> scale{
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}; // scale to be applied to output texture value
|
||||
std::array<float, 4> bias{
|
||||
{0.0f, 0.0f, 0.0f, 0.0f}}; // bias to be applied to output texture value
|
||||
|
||||
UsdTranform2d texture_transfom; // texture coordinate orientation.
|
||||
|
||||
// key = connection name: e.g. "outputs:rgb"
|
||||
// item = pair<type, name> : example: <"float3", "outputs:rgb">
|
||||
std::map<std::string, std::pair<std::string, std::string>> outputs;
|
||||
|
||||
PrimvarReaderType st; // texture coordinate(`inputs:st`). We assume there is
|
||||
// a connection to this.
|
||||
|
||||
// TODO: orientation?
|
||||
// https://graphics.pixar.com/usd/docs/UsdPreviewSurface-Proposal.html#UsdPreviewSurfaceProposal-TextureCoordinateOrientationinUSD
|
||||
};
|
||||
#endif
|
||||
|
||||
nonstd::expected<RenderMesh, std::string> Convert(const Stage &stage,
|
||||
const GeomMesh &mesh);
|
||||
|
||||
} // namespace tydra
|
||||
} // namespace tinyusdz
|
||||
|
||||
174
src/usdShade.hh
174
src/usdShade.hh
@@ -16,15 +16,9 @@ struct Material {
|
||||
|
||||
int64_t parent_id{-1};
|
||||
|
||||
std::string outputs_surface; // Intermediate variable. Path of
|
||||
// `outputs:surface.connect`
|
||||
std::string outputs_volume; // Intermediate variable. Path of
|
||||
// `outputs:volume.connect`
|
||||
Relation surface; // outputs:surface.connect
|
||||
Relation volume; // outputs:volume.connect
|
||||
|
||||
// Id will be filled after resolving paths
|
||||
int64_t surface_shader_id{-1}; // Index to `Scene::shaders`
|
||||
int64_t volume_shader_id{-1}; // Index to `Scene::shaders`
|
||||
// int64_t displacement_shader_id{-1}; // Index to shader object. TODO(syoyo)
|
||||
};
|
||||
|
||||
// TODO
|
||||
@@ -34,79 +28,73 @@ struct NodeGraph {
|
||||
int64_t parent_id{-1};
|
||||
};
|
||||
|
||||
// TODO: Move to Tydra/
|
||||
// result = (texture_id == -1) ? use color : lookup texture
|
||||
struct Color3OrTexture {
|
||||
Color3OrTexture(float x, float y, float z) {
|
||||
color[0] = x;
|
||||
color[1] = y;
|
||||
color[2] = z;
|
||||
}
|
||||
template <typename T>
|
||||
struct UsdPrimvarReader {
|
||||
std::string name;
|
||||
|
||||
std::array<float, 3> color{{0.0f, 0.0f, 0.0f}};
|
||||
nonstd::optional<T> fallback; // "inputs:fallback"
|
||||
|
||||
std::string path; // path to .connect(We only support texture file connection
|
||||
// at the moment)
|
||||
int64_t texture_id{-1};
|
||||
nonstd::optional<std::string> varname; // Name of the primvar to be fetched from the geometry("primvar" namespace is omitted).
|
||||
|
||||
bool HasTexture() const { return texture_id > -1; }
|
||||
// "outputs:result"
|
||||
nonstd::optional<Relation> result; // "outputs:result"
|
||||
};
|
||||
|
||||
struct FloatOrTexture {
|
||||
FloatOrTexture(float x) { value = x; }
|
||||
using UsdPrimvarReader_float = UsdPrimvarReader<float>;
|
||||
using UsdPrimvarReader_float2 = UsdPrimvarReader<value::float2>;
|
||||
using UsdPrimvarReader_float3 = UsdPrimvarReader<value::float3>;
|
||||
using UsdPrimvarReader_float4 = UsdPrimvarReader<value::float4>;
|
||||
using UsdPrimvarReader_int = UsdPrimvarReader<int>;
|
||||
|
||||
float value{0.0f};
|
||||
using UsdPrimvarReaderType =
|
||||
tinyusdz::variant<UsdPrimvarReader_float, UsdPrimvarReader_float2,
|
||||
UsdPrimvarReader_float3, UsdPrimvarReader_float4,
|
||||
UsdPrimvarReader_int>;
|
||||
|
||||
std::string path; // path to .connect(We only support texture file connection
|
||||
// at the moment)
|
||||
int64_t texture_id{-1};
|
||||
#if 0
|
||||
#endif
|
||||
|
||||
bool HasTexture() const { return texture_id > -1; }
|
||||
};
|
||||
struct UsdUVTexture {
|
||||
|
||||
enum TextureWrap {
|
||||
TextureWrapUseMetadata, // look for wrapS and wrapT metadata in the texture
|
||||
// file itself
|
||||
TextureWrapBlack,
|
||||
TextureWrapClamp,
|
||||
TextureWrapRepeat,
|
||||
TextureWrapMirror
|
||||
};
|
||||
enum class Wrap {
|
||||
UseMetadata, // "useMetadata" (default)
|
||||
Black, // "black"
|
||||
Clamp, // "clamp"
|
||||
Repeat, // "repeat"
|
||||
Mirror, // "mirror"
|
||||
};
|
||||
|
||||
// For texture transform
|
||||
// result = in * scale * rotate * translation
|
||||
struct UsdTranform2d {
|
||||
float rotation =
|
||||
0.0f; // counter-clockwise rotation in degrees around the origin.
|
||||
std::array<float, 2> scale{{1.0f, 1.0f}};
|
||||
std::array<float, 2> translation{{0.0f, 0.0f}};
|
||||
};
|
||||
enum class SourceColorSpace {
|
||||
Auto, // "auto"(default)
|
||||
Raw, // "raw"
|
||||
SRgb, // "sRGB
|
||||
};
|
||||
|
||||
// UsdUvTexture
|
||||
struct UVTexture {
|
||||
std::string asset; // asset name(usually file path)
|
||||
int64_t image_id{
|
||||
-1}; // TODO(syoyo): Consider UDIM `@textures/occlusion.<UDIM>.tex@`
|
||||
std::string name;
|
||||
|
||||
TextureWrap wrapS{};
|
||||
TextureWrap wrapT{};
|
||||
Asset file; // "asset inputs:file" interfaceOnly
|
||||
|
||||
std::array<float, 4> fallback{
|
||||
{0.0f, 0.0f, 0.0f,
|
||||
1.0f}}; // fallback color used when texture cannot be read.
|
||||
std::array<float, 4> scale{
|
||||
{1.0f, 1.0f, 1.0f, 1.0f}}; // scale to be applied to output texture value
|
||||
std::array<float, 4> bias{
|
||||
{0.0f, 0.0f, 0.0f, 0.0f}}; // bias to be applied to output texture value
|
||||
AttribWithFallback<value::texcoord2f> st{{0.0f, 0.0f}}; // "inputs:st"
|
||||
|
||||
UsdTranform2d texture_transfom; // texture coordinate orientation.
|
||||
nonstd::optional<Wrap> wrapS; // "inputs:wrapS" interfaceOnly
|
||||
nonstd::optional<Wrap> wrapT; // "inputs:wrapT" interfaceOnly
|
||||
|
||||
// key = connection name: e.g. "outputs:rgb"
|
||||
// item = pair<type, name> : example: <"float3", "outputs:rgb">
|
||||
std::map<std::string, std::pair<std::string, std::string>> outputs;
|
||||
AttribWithFallback<value::color4f> falllback{{0.0f, 0.0f, 0.0f, 1.0f}}; // "inputs:fallback" Fallback value when no texture is connected(TODO: Disallow Relation?(i.e, `fallback.connect = </Path/To/FallbackColor>`)
|
||||
|
||||
nonstd::optional<SourceColorSpace> sourceColorSpace; // "inputs:sourceColorSpace" interfaceOnly
|
||||
|
||||
AttribWithFallback<value::float4> scale{{1.0f, 1.0f, 1.0f, 1.0f}}; // "inputs:scale" interfaceOnly
|
||||
AttribWithFallback<value::float4> bias{{0.0f, 0.0f, 0.0f, 0.0f}}; // "inputs:bias" interfaceOnly
|
||||
|
||||
///
|
||||
/// Outputs
|
||||
///
|
||||
nonstd::optional<Relation> outputsR; // "outputs:r"
|
||||
nonstd::optional<Relation> outputsG; // "outputs:g"
|
||||
nonstd::optional<Relation> outputsB; // "outputs:b"
|
||||
nonstd::optional<Relation> outputsA; // "outputs:a"
|
||||
nonstd::optional<Relation> outputsRGB; // "outputs:rgb"
|
||||
|
||||
PrimvarReaderType st; // texture coordinate(`inputs:st`). We assume there is
|
||||
// a connection to this.
|
||||
|
||||
// TODO: orientation?
|
||||
// https://graphics.pixar.com/usd/docs/UsdPreviewSurface-Proposal.html#UsdPreviewSurfaceProposal-TextureCoordinateOrientationinUSD
|
||||
@@ -116,6 +104,42 @@ struct UVTexture {
|
||||
// USD's default? PBR shader
|
||||
// https://graphics.pixar.com/usd/docs/UsdPreviewSurface-Proposal.html
|
||||
// $USD/pxr/usdImaging/plugin/usdShaders/shaders/shaderDefs.usda
|
||||
|
||||
struct UsdPreviewSurface {
|
||||
|
||||
std::string name;
|
||||
|
||||
AttribWithFallback<value::color3f> diffuseColor{{0.18f, 0.18f, 0.18f}}; // "inputs:diffuseColor"
|
||||
AttribWithFallback<value::color3f> emissiveColor{{0.0f, 0.0f, 0.0f}}; // "inputs:emissiveColor"
|
||||
|
||||
AttribWithFallback<int> useSpecularWorkflow{0}; // "inputs:useSpecularWorkflow"
|
||||
|
||||
// specular workflow
|
||||
AttribWithFallback<value::color3f> specularColor{{0.0f, 0.0f, 0.0f}};
|
||||
|
||||
// metalness workflow
|
||||
AttribWithFallback<float> metallic{0.0f}; // "inputs:clearcoat"
|
||||
|
||||
//
|
||||
AttribWithFallback<float> clearcoat{0.0f}; // "inputs:clearcoat"
|
||||
AttribWithFallback<float> clearcoatRoughness{0.01f}; // "inputs:clearcoatRouighness"
|
||||
AttribWithFallback<float> roughness{0.5f}; // "inputs:roughness"
|
||||
AttribWithFallback<float> opacity{1.0f}; // "inputs:opacity"
|
||||
AttribWithFallback<float> opacityThreshold{0.0f}; // "inputs:opacityThreshold"
|
||||
AttribWithFallback<float> ior{1.5f}; // "inputs:ior"
|
||||
|
||||
AttribWithFallback<value::normal3f> normal{{0.0f, 0.0f, 1.0f}}; // "inputs:normal"
|
||||
AttribWithFallback<float> displacement{0.0f}; // "inputs:displacement"
|
||||
AttribWithFallback<float> occlusion{0.0f}; // "inputs:occlusion"
|
||||
|
||||
//
|
||||
// Outputs
|
||||
//
|
||||
nonstd::optional<Relation> outputsSurface; // "outputs:surface", "outputs:surface.connect"
|
||||
nonstd::optional<Relation> outputsDisplacement; // "outputs:displacement", "outputs:displacement.connect"
|
||||
};
|
||||
|
||||
#if 0 // TODO: Move to Tydra
|
||||
struct PreviewSurface {
|
||||
std::string doc;
|
||||
|
||||
@@ -158,17 +182,22 @@ struct PreviewSurface {
|
||||
int64_t surface_id{-1}; // index to `Scene::shaders`
|
||||
int64_t displacement_id{-1}; // index to `Scene::shaders`
|
||||
};
|
||||
#endif
|
||||
|
||||
struct Shader {
|
||||
std::string name;
|
||||
|
||||
std::string info_id; // Shader type.
|
||||
|
||||
// UsdPreviewSurface, UsdUVTexture, UsdPrimvarReader_float2, ...
|
||||
value::Value value;
|
||||
#if 0
|
||||
// Currently we only support PreviewSurface, UVTexture and
|
||||
// PrimvarReader_float2
|
||||
tinyusdz::variant<tinyusdz::monostate, PreviewSurface, UVTexture,
|
||||
PrimvarReader_float2>
|
||||
value;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -185,18 +214,19 @@ DEFINE_TYPE_TRAIT(Material, "Material",
|
||||
DEFINE_TYPE_TRAIT(Shader, "Shader",
|
||||
TYPE_ID_SHADER, 1);
|
||||
|
||||
DEFINE_TYPE_TRAIT(PreviewSurface, "PreviewSurface",
|
||||
DEFINE_TYPE_TRAIT(UsdPreviewSurface, "UsdPreviewSurface",
|
||||
TYPE_ID_IMAGING_PREVIEWSURFACE, 1);
|
||||
DEFINE_TYPE_TRAIT(UVTexture, "UVTexture", TYPE_ID_IMAGING_UVTEXTURE, 1);
|
||||
DEFINE_TYPE_TRAIT(PrimvarReader_float, "PrimvarReader_float",
|
||||
DEFINE_TYPE_TRAIT(UsdUVTexture, "UsdUVTexture", TYPE_ID_IMAGING_UVTEXTURE, 1);
|
||||
|
||||
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float, "UsdPrimvarReader_float",
|
||||
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT, 1);
|
||||
DEFINE_TYPE_TRAIT(PrimvarReader_float2, "PrimvarReader_float2",
|
||||
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float2, "UsdPrimvarReader_float2",
|
||||
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT2, 1);
|
||||
DEFINE_TYPE_TRAIT(PrimvarReader_float3, "PrimvarReader_float3",
|
||||
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float3, "UsdPrimvarReader_float3",
|
||||
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT3, 1);
|
||||
DEFINE_TYPE_TRAIT(PrimvarReader_float4, "PrimvarReader_float4",
|
||||
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float4, "UsdPrimvarReader_float4",
|
||||
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT4, 1);
|
||||
DEFINE_TYPE_TRAIT(PrimvarReader_int, "PrimvarReader_int",
|
||||
DEFINE_TYPE_TRAIT(UsdPrimvarReader_int, "UsdPrimvarReader_int",
|
||||
TYPE_ID_IMAGING_PRIMVAR_READER_INT, 1);
|
||||
|
||||
#undef DEFINE_TYPE_TRAIT
|
||||
|
||||
@@ -394,6 +394,16 @@ class USDAReader::Impl {
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
T *out);
|
||||
|
||||
///
|
||||
/// TinyUSDZ reconstruct some frequently used shaders(e.g. UsdPreviewSurface) here,
|
||||
/// not in Tydra
|
||||
///
|
||||
template <typename T>
|
||||
bool ReconstructShader(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
T *out);
|
||||
|
||||
// T = Prim class(e.g. Xform)
|
||||
template <typename T>
|
||||
bool RegisterReconstructCallback() {
|
||||
@@ -460,6 +470,7 @@ class USDAReader::Impl {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool ReconstructPreviewSurface(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
@@ -476,6 +487,7 @@ class USDAReader::Impl {
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
T *reader);
|
||||
#endif
|
||||
|
||||
void ImportScene(tinyusdz::Stage &scene) { _imported_scene = scene; }
|
||||
|
||||
@@ -693,7 +705,7 @@ void ReconstructNodeRec(const size_t idx, const std::vector<PrimNode> &prim_node
|
||||
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
bool USDAReader::Impl::ReconstructStage() {
|
||||
_stage.root_nodes.clear();
|
||||
@@ -2191,40 +2203,161 @@ bool USDAReader::Impl::ReconstructPrim<Skeleton>(
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool USDAReader::Impl::ReconstructShader<UsdPreviewSurface>(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
UsdPreviewSurface *surface) {
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool USDAReader::Impl::ReconstructShader<UsdUVTexture>(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
UsdUVTexture *texture) {
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool USDAReader::Impl::ReconstructShader<UsdPrimvarReader_int>(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
UsdPrimvarReader_int *preader) {
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool USDAReader::Impl::ReconstructShader<UsdPrimvarReader_float>(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
UsdPrimvarReader_float *preader) {
|
||||
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool USDAReader::Impl::ReconstructShader<UsdPrimvarReader_float2>(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
UsdPrimvarReader_float2 *preader) {
|
||||
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool USDAReader::Impl::ReconstructShader<UsdPrimvarReader_float3>(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
UsdPrimvarReader_float3 *preader) {
|
||||
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool USDAReader::Impl::ReconstructShader<UsdPrimvarReader_float4>(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
UsdPrimvarReader_float4 *preader) {
|
||||
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool USDAReader::Impl::ReconstructPrim<Shader>(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
Shader *shader) {
|
||||
|
||||
constexpr auto kUsdPreviewSurface = "UsdPreviewSurface";
|
||||
constexpr auto kUsdUVTexture = "UsdUVTexture";
|
||||
constexpr auto kUsdPrimvarReader_int = "UsdPrimvarReader_int";
|
||||
constexpr auto kUsdPrimvarReader_float = "UsdPrimvarReader_float";
|
||||
constexpr auto kUsdPrimvarReader_float2 = "UsdPrimvarReader_float2";
|
||||
constexpr auto kUsdPrimvarReader_float3 = "UsdPrimvarReader_float3";
|
||||
constexpr auto kUsdPrimvarReader_float4 = "UsdPrimvarReader_float4";
|
||||
|
||||
for (const auto &prop : properties) {
|
||||
|
||||
if (prop.first == "info:id") {
|
||||
const PrimAttrib &attr = prop.second.attrib;
|
||||
|
||||
auto p = attr.var.get_value<std::string>();
|
||||
if (p) {
|
||||
if (p->compare("UsdPreviewSurface") == 0) {
|
||||
PreviewSurface surface;
|
||||
if (!ReconstructPreviewSurface(properties, references, &surface)) {
|
||||
PUSH_WARN("TODO: reconstruct PreviewSurface.");
|
||||
}
|
||||
shader->value = surface;
|
||||
} else if (p->compare("UsdUVTexture") == 0) {
|
||||
UVTexture texture;
|
||||
if (!ReconstructUVTexture(properties, references, &texture)) {
|
||||
PUSH_WARN("TODO: reconstruct UVTexture.");
|
||||
}
|
||||
shader->value = texture;
|
||||
} else if (p->compare("UsdPrimvarReader_float2") == 0) {
|
||||
PrimvarReader_float2 preader;
|
||||
if (!ReconstructPrimvarReader<PrimvarReader_float2>(
|
||||
properties, references, &preader)) {
|
||||
PUSH_WARN("TODO: reconstruct PrimvarReader_float2.");
|
||||
}
|
||||
shader->value = preader;
|
||||
} else {
|
||||
PUSH_ERROR_AND_RETURN("Invalid or Unsupported Shader id: " + (*p));
|
||||
}
|
||||
auto pv = attr.var.get_value<value::token>();
|
||||
if (!pv) {
|
||||
PUSH_ERROR_AND_RETURN("`info:id` must be type `token`, but got type `" << attr.var.type_name() << "`.");
|
||||
}
|
||||
|
||||
std::string shader_type = pv.value().str();
|
||||
|
||||
DCOUT("info:id = " << shader_type);
|
||||
|
||||
if (shader_type.compare(kUsdPreviewSurface) == 0) {
|
||||
UsdPreviewSurface surface;
|
||||
if (!ReconstructShader<UsdPreviewSurface>(properties, references, &surface)) {
|
||||
PUSH_ERROR_AND_RETURN("Failed to Reconstruct " << kUsdPreviewSurface);
|
||||
}
|
||||
shader->info_id = kUsdPreviewSurface;
|
||||
shader->value = surface;
|
||||
DCOUT("info_id = " << shader->info_id);
|
||||
} else if (shader_type.compare(kUsdUVTexture) == 0) {
|
||||
UsdUVTexture texture;
|
||||
if (!ReconstructShader<UsdUVTexture>(properties, references, &texture)) {
|
||||
PUSH_ERROR_AND_RETURN("Failed to Reconstruct " << kUsdUVTexture);
|
||||
}
|
||||
shader->info_id = kUsdUVTexture;
|
||||
shader->value = texture;
|
||||
} else if (shader_type.compare(kUsdPrimvarReader_int) == 0) {
|
||||
UsdPrimvarReader_int preader;
|
||||
if (!ReconstructShader<UsdPrimvarReader_int>(
|
||||
properties, references, &preader)) {
|
||||
PUSH_ERROR_AND_RETURN("Failed to Reconstruct " << kUsdPrimvarReader_int);
|
||||
}
|
||||
shader->info_id = kUsdPrimvarReader_int;
|
||||
shader->value = preader;
|
||||
} else if (shader_type.compare(kUsdPrimvarReader_float) == 0) {
|
||||
UsdPrimvarReader_float preader;
|
||||
if (!ReconstructShader<UsdPrimvarReader_float>(
|
||||
properties, references, &preader)) {
|
||||
PUSH_ERROR_AND_RETURN("Failed to Reconstruct " << kUsdPrimvarReader_float);
|
||||
}
|
||||
shader->info_id = kUsdPrimvarReader_float;
|
||||
shader->value = preader;
|
||||
} else if (shader_type.compare(kUsdPrimvarReader_float2) == 0) {
|
||||
UsdPrimvarReader_float2 preader;
|
||||
if (!ReconstructShader<UsdPrimvarReader_float2>(
|
||||
properties, references, &preader)) {
|
||||
PUSH_ERROR_AND_RETURN("Failed to Reconstruct " << kUsdPrimvarReader_float2);
|
||||
}
|
||||
shader->info_id = kUsdPrimvarReader_float2;
|
||||
shader->value = preader;
|
||||
} else if (shader_type.compare(kUsdPrimvarReader_float3) == 0) {
|
||||
UsdPrimvarReader_float3 preader;
|
||||
if (!ReconstructShader<UsdPrimvarReader_float3>(
|
||||
properties, references, &preader)) {
|
||||
PUSH_ERROR_AND_RETURN("Failed to Reconstruct " << kUsdPrimvarReader_float3);
|
||||
}
|
||||
shader->info_id = kUsdPrimvarReader_float3;
|
||||
shader->value = preader;
|
||||
} else if (shader_type.compare(kUsdPrimvarReader_float4) == 0) {
|
||||
UsdPrimvarReader_float4 preader;
|
||||
if (!ReconstructShader<UsdPrimvarReader_float4>(
|
||||
properties, references, &preader)) {
|
||||
PUSH_ERROR_AND_RETURN("Failed to Reconstruct " << kUsdPrimvarReader_float4);
|
||||
}
|
||||
shader->info_id = kUsdPrimvarReader_float4;
|
||||
shader->value = preader;
|
||||
} else {
|
||||
// TODO: string, point, vector, matrix
|
||||
PUSH_ERROR_AND_RETURN("Invalid or Unsupported Shader type. info:id = \"" + shader_type + "\n");
|
||||
}
|
||||
|
||||
} else {
|
||||
// std::cout << "TODO: " << prop.first << "\n";
|
||||
}
|
||||
@@ -2261,51 +2394,6 @@ bool USDAReader::Impl::ReconstructPrim<Material>(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool USDAReader::Impl::ReconstructPreviewSurface(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
PreviewSurface *surface) {
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool USDAReader::Impl::ReconstructUVTexture(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
UVTexture *texture) {
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool USDAReader::Impl::ReconstructPrimvarReader(
|
||||
const std::map<std::string, Property> &properties,
|
||||
const std::vector<std::pair<ListEditQual, Reference>> &references,
|
||||
T *preader) {
|
||||
// TODO: string, point, vector, matrix
|
||||
static_assert(std::is_same<T, PrimvarReader_int>::value ||
|
||||
std::is_same<T, PrimvarReader_float>::value ||
|
||||
std::is_same<T, PrimvarReader_float2>::value ||
|
||||
std::is_same<T, PrimvarReader_float3>::value ||
|
||||
std::is_same<T, PrimvarReader_float4>::value,
|
||||
"Invalid type for PrimvarReader");
|
||||
|
||||
// Common
|
||||
// uniform token info:implementationSource
|
||||
// uniform asset info:glslfx:sourceAsset
|
||||
// string inputs:varname (`primvar` namespace should be omitted)
|
||||
// ( sdrMetadata = {
|
||||
// bool primvarProperty = 1 # or string primvarProperty = "1"
|
||||
// }
|
||||
// )
|
||||
|
||||
// Per shader
|
||||
// T inputs:fallback
|
||||
// T outputs:result
|
||||
|
||||
// TODO:
|
||||
return false;
|
||||
}
|
||||
|
||||
///
|
||||
/// -- Impl callback specializations
|
||||
|
||||
Reference in New Issue
Block a user