mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Support UsdTransform2d shader.
Fix pprinting varying attribute. Fix GeomMesh hierarchy check.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
//
|
||||
#include "pprinter.hh"
|
||||
#include "prim-types.hh"
|
||||
#include "usdShade.hh"
|
||||
#include "value-pprint.hh"
|
||||
#include "str-util.hh"
|
||||
|
||||
@@ -1879,6 +1880,20 @@ static std::string print_shader_params(const UsdPrimvarReader_float4 &shader, co
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static std::string print_shader_params(const UsdTransform2d &shader, const uint32_t indent) {
|
||||
std::stringstream ss;
|
||||
|
||||
ss << print_typed_attr(shader.in, "inputs:in", indent);
|
||||
ss << print_typed_attr(shader.rotation, "inputs:rotation", indent);
|
||||
ss << print_typed_attr(shader.scale, "inputs:scale", indent);
|
||||
ss << print_typed_attr(shader.translation, "inputs:translation", indent);
|
||||
ss << print_typed_terminal_attr(shader.result, "outputs:result", indent);
|
||||
|
||||
ss << print_props(shader.props, indent);
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static std::string print_shader_params(const UsdPreviewSurface &shader, const uint32_t indent) {
|
||||
std::stringstream ss;
|
||||
|
||||
@@ -1969,6 +1984,8 @@ std::string to_string(const Shader &shader, const uint32_t indent, bool closing_
|
||||
ss << print_shader_params(pvr4.value(), indent+1);
|
||||
} else if (auto pvtex = shader.value.get_value<UsdUVTexture>()) {
|
||||
ss << print_shader_params(pvtex.value(), indent+1);
|
||||
} else if (auto pvtx2d = shader.value.get_value<UsdTransform2d>()) {
|
||||
ss << print_shader_params(pvtx2d.value(), indent+1);
|
||||
} else if (auto pvs = shader.value.get_value<UsdPreviewSurface>()) {
|
||||
ss << print_shader_params(pvs.value(), indent+1);
|
||||
} else {
|
||||
|
||||
@@ -276,6 +276,18 @@ static ParseResult ParseTypedAttribute(std::set<std::string> &table, /* inout */
|
||||
ret.err = "Converting Attribute data failed. Maybe TimeSamples have values with different types?";
|
||||
return ret;
|
||||
}
|
||||
} else if (attr.get_var().is_scalar()) {
|
||||
if (auto pv = attr.get_value<T>()) {
|
||||
target.SetValue(pv.value());
|
||||
} else {
|
||||
ret.code = ParseResult::ResultCode::InternalError;
|
||||
ret.err = "Invalid attribute value.";
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
ret.code = ParseResult::ResultCode::InternalError;
|
||||
ret.err = "Invalid attribute value.";
|
||||
return ret;
|
||||
}
|
||||
|
||||
target.meta = attr.meta;
|
||||
@@ -387,7 +399,7 @@ static ParseResult ParseTypedAttribute(std::set<std::string> &table, /* inout */
|
||||
if (auto pv = attr.get_value<T>()) {
|
||||
target.SetValue(pv.value());
|
||||
} else {
|
||||
ret.code = ParseResult::ResultCode::VariabilityMismatch;
|
||||
ret.code = ParseResult::ResultCode::InternalError;
|
||||
ret.err = "Internal data corrupsed.";
|
||||
return ret;
|
||||
}
|
||||
@@ -3303,6 +3315,36 @@ bool ReconstructShader<UsdPrimvarReader_float4>(
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool ReconstructShader<UsdTransform2d>(
|
||||
const PropertyMap &properties,
|
||||
const ReferenceList &references,
|
||||
UsdTransform2d *transform,
|
||||
std::string *warn,
|
||||
std::string *err)
|
||||
{
|
||||
(void)references;
|
||||
std::set<std::string> table;
|
||||
table.insert("info:id"); // `info:id` is already parsed in ReconstructPrim<Shader>
|
||||
for (auto &prop : properties) {
|
||||
DCOUT("prop = " << prop.first);
|
||||
PARSE_TYPED_ATTRIBUTE(table, prop, "inputs:in", UsdTransform2d,
|
||||
transform->in)
|
||||
PARSE_TYPED_ATTRIBUTE(table, prop, "inputs:rotation", UsdTransform2d,
|
||||
transform->rotation)
|
||||
PARSE_TYPED_ATTRIBUTE(table, prop, "inputs:scale", UsdTransform2d,
|
||||
transform->scale)
|
||||
PARSE_TYPED_ATTRIBUTE(table, prop, "inputs:translation", UsdTransform2d,
|
||||
transform->translation)
|
||||
PARSE_SHADER_TERMINAL_ATTRIBUTE(table, prop, "outputs:result",
|
||||
UsdTransform2d, transform->result)
|
||||
ADD_PROPERTY(table, prop, UsdPrimvarReader_float2, transform->props)
|
||||
PARSE_PROPERTY_END_MAKE_WARN(table, prop)
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool ReconstructPrim<Shader>(
|
||||
const PropertyMap &properties,
|
||||
@@ -3320,6 +3362,7 @@ bool ReconstructPrim<Shader>(
|
||||
constexpr auto kUsdPrimvarReader_float2 = "UsdPrimvarReader_float2";
|
||||
constexpr auto kUsdPrimvarReader_float3 = "UsdPrimvarReader_float3";
|
||||
constexpr auto kUsdPrimvarReader_float4 = "UsdPrimvarReader_float4";
|
||||
constexpr auto kUsdTransform2d = "UsdTransform2d";
|
||||
|
||||
auto info_id_prop = properties.find("info:id");
|
||||
if (info_id_prop == properties.end()) {
|
||||
@@ -3413,6 +3456,15 @@ bool ReconstructPrim<Shader>(
|
||||
}
|
||||
shader->info_id = kUsdPrimvarReader_float4;
|
||||
shader->value = preader;
|
||||
} else if (shader_type.compare(kUsdTransform2d) == 0) {
|
||||
UsdTransform2d transform;
|
||||
if (!ReconstructShader<UsdTransform2d>(properties, references,
|
||||
&transform, warn, err)) {
|
||||
PUSH_ERROR_AND_RETURN("Failed to Reconstruct "
|
||||
<< kUsdTransform2d);
|
||||
}
|
||||
shader->info_id = kUsdTransform2d;
|
||||
shader->value = transform;
|
||||
} else {
|
||||
// TODO: string, point, vector, matrix
|
||||
PUSH_ERROR_AND_RETURN(
|
||||
|
||||
@@ -1019,6 +1019,9 @@ class TypedAttributeWithFallback {
|
||||
if (_paths.size()) {
|
||||
return true;
|
||||
}
|
||||
if (_blocked) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -221,6 +221,28 @@ struct PreviewSurface {
|
||||
};
|
||||
#endif
|
||||
|
||||
struct UsdTransform2d {
|
||||
|
||||
std::string name;
|
||||
|
||||
TypedAttributeWithFallback<Animatable<value::float2>> in{value::float2{0.0f, 0.0f}}; // "inputs:in" Usually connected to UsdPrimvarReader_float2
|
||||
|
||||
TypedAttributeWithFallback<Animatable<float>> rotation{0.0f}; // "inputs:rotation" CCW, in degree.
|
||||
TypedAttributeWithFallback<Animatable<value::float2>> scale{value::float2{1.0f, 1.0f}}; // "inputs:scale"
|
||||
TypedAttributeWithFallback<Animatable<value::float2>> translation{value::float2{0.0f, 0.0f}}; // "inputs:translation"
|
||||
|
||||
|
||||
///
|
||||
/// Outputs
|
||||
///
|
||||
TypedTerminalAttribute<value::float2> result; // "float2 outputs:result"
|
||||
|
||||
// Custom properties
|
||||
std::map<std::string, Property> props;
|
||||
|
||||
PrimMeta meta;
|
||||
};
|
||||
|
||||
struct Shader {
|
||||
std::string name;
|
||||
|
||||
@@ -267,6 +289,8 @@ DEFINE_TYPE_TRAIT(UsdPrimvarReader_float4, "UsdPrimvarReader_float4",
|
||||
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT4, 1);
|
||||
DEFINE_TYPE_TRAIT(UsdPrimvarReader_int, "UsdPrimvarReader_int",
|
||||
TYPE_ID_IMAGING_PRIMVAR_READER_INT, 1);
|
||||
DEFINE_TYPE_TRAIT(UsdTransform2d, "UsdTransform2d",
|
||||
TYPE_ID_IMAGING_TRANSFORM_2D, 1);
|
||||
|
||||
#undef DEFINE_TYPE_TRAIT
|
||||
#undef DEFINE_ROLE_TYPE_TRAIT
|
||||
|
||||
@@ -1029,10 +1029,12 @@ bool USDAReader::Impl::RegisterReconstructCallback<GeomSubset>() {
|
||||
return nonstd::make_unexpected("Invalid Prim path.");
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (parent.IsRootPrim()) {
|
||||
return nonstd::make_unexpected(
|
||||
"GeomSubset must be defined as a child of GeomMesh prim.");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (parentPrimIdx < 0) {
|
||||
return nonstd::make_unexpected(
|
||||
|
||||
61
tests/usda/shader-transform2d-000.usda
Normal file
61
tests/usda/shader-transform2d-000.usda
Normal file
@@ -0,0 +1,61 @@
|
||||
#usda 1.0
|
||||
(
|
||||
customLayerData = {
|
||||
string copyright = "Copyright (c) 2019 Apple Inc. All rights reserved."
|
||||
string creator = "USD 19.05 Maya Plugin (Apple Internal a3)"
|
||||
}
|
||||
defaultPrim = "teapot"
|
||||
metersPerUnit = 0.01
|
||||
timeCodesPerSecond = 24
|
||||
upAxis = "Y"
|
||||
)
|
||||
|
||||
def Xform "teapot" (
|
||||
kind = "component"
|
||||
)
|
||||
{
|
||||
def Scope "Looks"
|
||||
{
|
||||
def Material "pxrUsdPreviewSurface1SG"
|
||||
{
|
||||
token outputs:surface.connect = </teapot/Looks/pxrUsdPreviewSurface1SG/TeapotMaterial.outputs:surface>
|
||||
|
||||
def Shader "TeapotMaterial"
|
||||
{
|
||||
uniform token info:id = "UsdPreviewSurface"
|
||||
color3f inputs:diffuseColor.connect = </teapot/Looks/pxrUsdPreviewSurface1SG/teapot_high_lambert1_BaseColor_1.outputs:rgb>
|
||||
float inputs:metallic.connect = </teapot/Looks/pxrUsdPreviewSurface1SG/teapot_high_lambert1_Metallic_1.outputs:r>
|
||||
normal3f inputs:normal.connect = </teapot/Looks/pxrUsdPreviewSurface1SG/teapot_high_lambert1_Normal_1.outputs:rgb>
|
||||
float inputs:occlusion.connect = </teapot/Looks/pxrUsdPreviewSurface1SG/file4.outputs:r>
|
||||
float inputs:roughness.connect = </teapot/Looks/pxrUsdPreviewSurface1SG/teapot_high_lambert1_Roughness_1.outputs:r>
|
||||
token outputs:displacement
|
||||
token outputs:surface
|
||||
}
|
||||
|
||||
def Shader "teapot_high_lambert1_Normal_1"
|
||||
{
|
||||
uniform token info:id = "UsdUVTexture"
|
||||
float4 inputs:fallback = (0.5, 0.5, 0.5, 1)
|
||||
asset inputs:file = @0/teapot_n.png@
|
||||
float2 inputs:st.connect = </teapot/Looks/pxrUsdPreviewSurface1SG/teapot_high_lambert1_Normal_1/TexCoordReader.outputs:result>
|
||||
token inputs:wrapS = "repeat"
|
||||
token inputs:wrapT = "repeat"
|
||||
float3 outputs:rgb
|
||||
|
||||
def Shader "TexCoordReader"
|
||||
{
|
||||
uniform token info:id = "UsdPrimvarReader_float2"
|
||||
token inputs:varname = "st"
|
||||
float2 outputs:result
|
||||
}
|
||||
|
||||
def Shader "transform"
|
||||
{
|
||||
uniform token info:id = "UsdTransform2d"
|
||||
float2 inputs:in.connect = </Materials/stone_trims_01_Metalness/PrimvarReader_map1.outputs:result> float inputs:rotation = 0 float2 inputs:scale = (1, 1) float2 inputs:translation = (0, 0) float2 outputs:result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user