small refactor.

add attribute connection from string to token type example.
This commit is contained in:
Syoyo Fujita
2024-04-16 23:36:27 +09:00
parent dca093bb4e
commit 5e70dd1186
4 changed files with 171 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
#usda 1.0
(
defaultPrim = "root"
doc = "Blender v3.5.0 Alpha"
metersPerUnit = 0.01
upAxis = "Z"
)
def Xform "root"
{
float3 xformOp:scale = (100, 100, 100)
uniform token[] xformOpOrder = ["xformOp:scale"]
def Scope "lights"
{
def DomeLight "environment"
{
custom color3f color = (0.05087609, 0.05087609, 0.05087609)
color3f inputs:color = (0.05087609, 0.05087609, 0.05087609)
float inputs:intensity = 683.0135
custom float intensity = 683.0135
}
}
def Scope "materials"
{
def Material "Material_001"
{
token outputs:surface.connect = </root/materials/Material_001/preview/Principled_BSDF.outputs:surface>
custom string userProperties:blenderName:data = "Material.001"
token inputs:stname = "st"
def Scope "preview"
{
def Shader "Principled_BSDF"
{
uniform token info:id = "UsdPreviewSurface"
float inputs:clearcoat = 0
float inputs:clearcoatRoughness = 0.03
color3f inputs:diffuseColor.connect = </root/materials/Material_001/preview/Image_Texture.outputs:rgb>
color3f inputs:emissiveColor = (0, 0, 0)
float inputs:ior = 1.45
float inputs:metallic = 0
float inputs:opacity = 1
float inputs:roughness = 0.5
float inputs:specular = 0.5
token outputs:surface
}
def Shader "Image_Texture"
{
uniform token info:id = "UsdUVTexture"
asset inputs:file = @./textures/texture-cat.jpg@
token inputs:sourceColorSpace = "sRGB"
float2 inputs:st.connect = </root/materials/Material_001/preview/uvmap.outputs:result>
token inputs:wrapS = "repeat"
token inputs:wrapT = "repeat"
color3f outputs:rgb
}
def Shader "uvmap"
{
uniform token info:id = "UsdPrimvarReader_float2"
# connect to `token` type attribute
string inputs:varname.connect = </root/materials/Material_001.inputs:stname>
float2 outputs:result
}
}
}
}
def Xform "Grid"
{
custom string userProperties:blenderName:object = "Grid"
float3 xformOp:rotateXYZ = (90, -0.000032328113, -0.19013378)
float3 xformOp:scale = (1, 1, 1)
double3 xformOp:translate = (0, 0, 0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
def Mesh "Grid" (
active = true
)
{
uniform bool doubleSided = 1
int[] faceVertexCounts = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
int[] faceVertexIndices = [1, 4, 0, 2, 5, 1, 3, 6, 2, 5, 8, 4, 6, 9, 5, 7, 10, 6, 9, 12, 8, 10, 13, 9, 11, 14, 10, 1, 5, 4, 2, 6, 5, 3, 7, 6, 5, 9, 8, 6, 10, 9, 7, 11, 10, 9, 13, 12, 10, 14, 13, 11, 15, 14]
rel material:binding = </root/materials/Material_001>
normal3f[] normals = [(0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 0.99999994), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1)] (
interpolation = "faceVarying"
)
point3f[] points = [(-1, -1, 0), (-0.3333333, -1, 0), (0.33333337, -1, 0), (1, -1, 0), (-1, -0.3333333, 0), (-0.3333333, -0.3333333, 0), (0.33333337, -0.3333333, 0), (1, -0.3333333, 0), (-1, 0.33333337, 0), (-0.3333333, 0.33333337, 0), (0.33333337, 0.33333337, 0), (1, 0.33333337, 0), (-1, 1, 0), (-0.3333333, 1, 0), (0.33333337, 1, 0), (1, 1, 0)]
texCoord2f[] primvars:st = [(0.33333334, 0), (0, 0.33333334), (0, 0), (0.6666667, 0), (0.33333334, 0.33333334), (0.33333334, 0), (1, 0), (0.6666666, 0.33333334), (0.6666667, 0), (0.33333334, 0.33333334), (0, 0.6666667), (0, 0.33333334), (0.6666667, 0.33333334), (0.33333334, 0.6666667), (0.33333334, 0.33333334), (1, 0.33333334), (0.6666666, 0.6666667), (0.6666667, 0.33333334), (0.33333334, 0.6666666), (0, 1), (0, 0.6666666), (0.6666667, 0.6666666), (0.33333334, 1), (0.33333334, 0.6666666), (1, 0.6666666), (0.6666666, 1), (0.6666667, 0.6666666), (0.33333334, 0), (0.33333334, 0.33333334), (0, 0.33333334), (0.6666667, 0), (0.6666667, 0.33333334), (0.33333334, 0.33333334), (1, 0), (1, 0.33333334), (0.6666666, 0.33333334), (0.33333334, 0.33333334), (0.33333334, 0.6666667), (0, 0.6666667), (0.6666667, 0.33333334), (0.6666667, 0.6666667), (0.33333334, 0.6666667), (1, 0.33333334), (1, 0.6666667), (0.6666666, 0.6666667), (0.33333334, 0.6666666), (0.33333334, 1), (0, 1), (0.6666667, 0.6666666), (0.6666667, 1), (0.33333334, 1), (1, 0.6666666), (1, 1), (0.6666666, 1)] (
interpolation = "faceVarying"
)
int[] primvars:st:indices = None
uniform token subdivisionScheme = "none"
custom string userProperties:blenderName:data = "Mesh"
custom string userProperties:blenderName:data:st = "UVMap"
}
}
def Xform "Camera"
{
custom string userProperties:blenderName:object = "Camera"
float3 xformOp:rotateXYZ = (89.99999, -0, 0)
float3 xformOp:scale = (1, 1, 1)
double3 xformOp:translate = (0, -10, 0)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
def Camera "Camera"
{
float2 clippingRange = (10, 10000)
float focalLength = 50
float horizontalAperture = 36
float horizontalApertureOffset = 0
token projection = "perspective"
double shutter:close = 0.25
double shutter:open = -0.25
custom string userProperties:blenderName:data = "Camera"
float verticalAperture = 24
float verticalApertureOffset = 0
}
}
}

View File

@@ -191,6 +191,7 @@ nonstd::optional<Animatable<Extent>> ConvertToAnimatable(const primvar::PrimVar
return nonstd::nullopt;
}
#if 0 // TODO: remove. moved to prim-types.cc
static bool ConvertTokenAttributeToStringAttribute(
const TypedAttribute<Animatable<value::token>> &inp,
TypedAttribute<Animatable<std::string>> &out) {
@@ -227,6 +228,7 @@ static bool ConvertTokenAttributeToStringAttribute(
return true;
}
#endif
static bool ConvertStringDataAttributeToStringAttribute(
const TypedAttribute<Animatable<value::StringData>> &inp,

View File

@@ -76,6 +76,45 @@ bool operator==(const Path &lhs, const Path &rhs) {
return (lhs.full_path_name() == rhs.full_path_name());
}
bool ConvertTokenAttributeToStringAttribute(
const TypedAttribute<Animatable<value::token>> &inp,
TypedAttribute<Animatable<std::string>> &out) {
out.metas() = inp.metas();
if (inp.is_blocked()) {
out.set_blocked(true);
} else if (inp.is_value_empty()) {
out.set_value_empty();
} else if (inp.is_connection()) {
out.set_connections(inp.get_connections());
} else {
Animatable<value::token> toks;
Animatable<std::string> strs;
if (inp.get_value(&toks)) {
if (toks.is_scalar()) {
value::token tok;
toks.get_scalar(&tok);
strs.set(tok.str());
} else if (toks.is_timesamples()) {
auto tok_ts = toks.get_timesamples();
for (auto &item : tok_ts.get_samples()) {
strs.add_sample(item.t, item.value.str());
}
} else if (toks.is_blocked()) {
// TODO
return false;
}
}
out.set_value(strs);
}
return true;
}
//
// -- Path
//

View File

@@ -1743,6 +1743,11 @@ class TypedAttributeWithFallback {
template <typename T>
using TypedAnimatableAttributeWithFallback =
TypedAttributeWithFallback<Animatable<T>>;
bool ConvertTokenAttributeToStringAttribute(
const TypedAttribute<Animatable<value::token>> &inp,
TypedAttribute<Animatable<std::string>> &out);
///
/// Similar to pxrUSD's PrimIndex