Skip to content

Commit

Permalink
Support Plane primitives in the usd procedural (#2059)
Browse files Browse the repository at this point in the history
* Add support for plane primitives #2058

* Add changelog

* Fix compilation with older versions of USD
  • Loading branch information
sebastienblor authored Aug 9, 2024
1 parent 48b01f5 commit f7c1e5d
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
- [usd#1965](https://github.com/Autodesk/arnold-usd/issues/1965) - Write color manager attributes in the RenderSettings primitive
- [usd#1974](https://github.com/Autodesk/arnold-usd/issues/1974) - Delegate should only create default shaders when needed
- [usd#1959](https://github.com/Autodesk/arnold-usd/issues/1959) - Improve translation of normals and primvars in hydra
- [usd#1972](https://github.com/Autodesk/arnold-usd/issues/1972) - Delegate should only create default shaders when needed
- [usd#1946](https://github.com/Autodesk/arnold-usd/issues/1946) - Support color space in materialx for hydra
- [usd#1972](https://github.com/Autodesk/arnold-usd/issues/1972) - Ensure subdivision is disabled when subdiv iterations is equal to 0 in Hydra
- [usd#1982](https://github.com/Autodesk/arnold-usd/issues/1982) - Fix subdivision when primvars are set in parent primitives
Expand All @@ -34,6 +33,7 @@
- [usd#2057](https://github.com/Autodesk/arnold-usd/issues/2057) - Add Ginstance support in hydra and fix a data race issue.
- [usd#2055](https://github.com/Autodesk/arnold-usd/issues/2055) - Support animated curves orientations in hydra
- [usd#2053](https://github.com/Autodesk/arnold-usd/issues/2053) - Visibility and sidedness attributes not supported in Arnold native hydra prims
- [usd#2058](https://github.com/Autodesk/arnold-usd/issues/2058) - Support UsdPlane primitives
- [usd#2061](https://github.com/Autodesk/arnold-usd/issues/2061) - Support arnold light groups in Hydra

### Bug fixes
Expand Down
69 changes: 69 additions & 0 deletions libs/translator/reader/read_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <pxr/usd/usdGeom/capsule.h>
#include <pxr/usd/usdGeom/cone.h>
#include <pxr/usd/usdGeom/cube.h>
#if PXR_VERSION >= 2208
#include <pxr/usd/usdGeom/plane.h>
#endif
#include <pxr/usd/usdGeom/curves.h>
#include <pxr/usd/usdGeom/cylinder.h>
#include <pxr/usd/usdGeom/mesh.h>
Expand Down Expand Up @@ -723,6 +726,72 @@ AtNode* UsdArnoldReadCube::Read(const UsdPrim &prim, UsdArnoldReaderContext &con
return node;
}

AtNode* UsdArnoldReadPlane::Read(const UsdPrim &prim, UsdArnoldReaderContext &context)
{
// Plane primitives were added in USD 22.08
#if PXR_VERSION >= 2208
const TimeSettings &time = context.GetTimeSettings();
float frame = time.frame;
AtNode *node = context.CreateArnoldNode("polymesh", prim.GetPath().GetText());
ReadMatrix(prim, node, time, context);
UsdGeomPlane plane(prim);

static const VtIntArray numVerts{4};
static const VtIntArray verts{0,1,2,3};

VtVec3fArray points(4);
VtValue widthValue;
if (!plane.GetWidthAttr().Get(&widthValue, frame))
AiMsgWarning("Could not evaluate width attribute on prim %s",
prim.GetPath().GetText());
float width = VtValueGetFloat(widthValue);
VtValue lengthValue;
if (!plane.GetLengthAttr().Get(&lengthValue, frame))
AiMsgWarning("Could not evaluate length attribute on prim %s",
prim.GetPath().GetText());
float length = VtValueGetFloat(lengthValue);

VtValue axisValue;
if (!plane.GetAxisAttr().Get(&axisValue, frame))
AiMsgWarning("Could not evaluate axis attribute on prim %s",
prim.GetPath().GetText());
TfToken axis = UsdGeomTokens->z;
if (axisValue.IsHolding<TfToken>())
axis = axisValue.UncheckedGet<TfToken>();

if (axis == UsdGeomTokens->x) {
points = { GfVec3f( 0.0f, 0.5f * length, 0.5f * width ),
GfVec3f( 0.0f, -0.5f * length, 0.5f * width ),
GfVec3f( 0.0f, -0.5f * length,-0.5f * width ),
GfVec3f( 0.0f, 0.5f * length,-0.5f * width ) };
} else if (axis == UsdGeomTokens->y) {
points = { GfVec3f(-0.5f * width, 0.0f, 0.5f * length ),
GfVec3f( 0.5f * width, 0.0f, 0.5f * length ),
GfVec3f( 0.5f * width, 0.0f,-0.5f * length ),
GfVec3f(-0.5f * width, 0.0f,-0.5f * length ) };
} else {
points = { GfVec3f( 0.5f * width, 0.5f * length, 0.0f ),
GfVec3f(-0.5f * width, 0.5f * length, 0.0f ),
GfVec3f(-0.5f * width,-0.5f * length, 0.0f ),
GfVec3f( 0.5f * width,-0.5f * length, 0.0f ) };
}

_ReadSidedness(plane, node, frame);
_ReadPointsAndVertices(node, numVerts, verts, points);
ReadPrimvars(prim, node, time, context);
ReadMaterialBinding(prim, node, context);
ReadMeshLight(prim, context, node, time);
ReadArnoldParameters(prim, context, node, time, "primvars:arnold");

// Check the primitive visibility, set the AtNode visibility to 0 if it's hidden
if (!context.GetPrimVisibility(prim, frame))
AiNodeSetByte(node, str::visibility, 0);
return node;
#else
return nullptr;
#endif
}

AtNode* UsdArnoldReadSphere::Read(const UsdPrim &prim, UsdArnoldReaderContext &context)
{
const TimeSettings &time = context.GetTimeSettings();
Expand Down
1 change: 1 addition & 0 deletions libs/translator/reader/read_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ PXR_NAMESPACE_USING_DIRECTIVE
REGISTER_PRIM_READER(UsdArnoldReadMesh, AI_NODE_SHAPE);
REGISTER_PRIM_READER(UsdArnoldReadCurves, AI_NODE_SHAPE);
REGISTER_PRIM_READER(UsdArnoldReadPoints, AI_NODE_SHAPE);
REGISTER_PRIM_READER(UsdArnoldReadPlane, AI_NODE_SHAPE);
REGISTER_PRIM_READER(UsdArnoldReadCube, AI_NODE_SHAPE);
REGISTER_PRIM_READER(UsdArnoldReadSphere, AI_NODE_SHAPE);
REGISTER_PRIM_READER(UsdArnoldReadCylinder, AI_NODE_SHAPE);
Expand Down
1 change: 1 addition & 0 deletions libs/translator/reader/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void UsdArnoldReaderRegistry::RegisterPrimitiveReaders()
RegisterReader("BasisCurves", new UsdArnoldReadCurves());
RegisterReader("NurbsCurves", new UsdArnoldReadCurves());
RegisterReader("Points", new UsdArnoldReadPoints());
RegisterReader("Plane", new UsdArnoldReadPlane());
RegisterReader("Cube", new UsdArnoldReadCube());
RegisterReader("Sphere", new UsdArnoldReadSphere());
RegisterReader("Cylinder", new UsdArnoldReadCylinder());
Expand Down
7 changes: 7 additions & 0 deletions testsuite/test_2058/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Render Plane primitives

Fixes #2058

author: sebastien.ortega

PARAMS: {'scene': 'test.usda'}
164 changes: 164 additions & 0 deletions testsuite/test_2058/data/test.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#usda 1.0
(
endTimeCode = 1
framesPerSecond = 24
metersPerUnit = 1
startTimeCode = 1
timeCodesPerSecond = 24
upAxis = "Y"
)

def Plane "primitive1" (
prepend apiSchemas = ["MaterialBindingAPI"]
)
{
rel material:binding = </materials/arnold_materialbuilder1>
matrix4d xformOp:transform:edit1 = ( (1, 0, 0, 0), (0, -0.08113957196474075, -0.9967027306556702, 0), (0, 0.9967027306556702, -0.08113957196474075, 0), (0, 0.40128639340400696, -0.032667919993400574, 1) )
uniform token[] xformOpOrder = ["xformOp:transform:edit1"]
}

def Xform "lights"
{
def DomeLight "domelight1" (
prepend apiSchemas = ["HoudiniViewportGuideAPI"]
)
{
custom rel filters = None
float houdini:guidescale = 1
bool houdini:inviewermenu = 0
color3f inputs:color = (1, 1, 1)
float inputs:diffuse = 1
bool inputs:enableColorTemperature = 0
float inputs:exposure = 0
float inputs:intensity = 0.64
bool inputs:normalize = 0
float inputs:specular = 1
asset inputs:texture:file = @@
token inputs:texture:format = "automatic"
rel light:filters = None
rel portals = None
matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
uniform token[] xformOpOrder = ["xformOp:transform"]
}
}

def Scope "materials"
{
def Material "arnold_materialbuilder1"
{
token outputs:arnold:surface.connect = </materials/arnold_materialbuilder1/standard_surface1.outputs:shader>

def Shader "standard_surface1"
{
uniform token info:id = "arnold:standard_surface"
string inputs:aov_id1 = ""
string inputs:aov_id2 = ""
string inputs:aov_id3 = ""
string inputs:aov_id4 = ""
string inputs:aov_id5 = ""
string inputs:aov_id6 = ""
string inputs:aov_id7 = ""
string inputs:aov_id8 = ""
float inputs:base = 1
color3f inputs:base_color = (0, 0.25, 0.5)
bool inputs:caustics = 0
float inputs:coat = 0
float inputs:coat_affect_color = 0
float inputs:coat_affect_roughness = 0
float inputs:coat_anisotropy = 0
color3f inputs:coat_color = (1, 1, 1)
float inputs:coat_IOR = 1.5
vector3f inputs:coat_normal = (0, 0, 0)
float inputs:coat_rotation = 0
float inputs:coat_roughness = 0.1
int inputs:dielectric_priority = 0
float inputs:diffuse_roughness = 0
float inputs:emission = 0
color3f inputs:emission_color = (1, 1, 1)
bool inputs:exit_to_background = 0
color3f inputs:id1 = (0, 0, 0)
color3f inputs:id2 = (0, 0, 0)
color3f inputs:id3 = (0, 0, 0)
color3f inputs:id4 = (0, 0, 0)
color3f inputs:id5 = (0, 0, 0)
color3f inputs:id6 = (0, 0, 0)
color3f inputs:id7 = (0, 0, 0)
color3f inputs:id8 = (0, 0, 0)
float inputs:indirect_diffuse = 1
float inputs:indirect_specular = 1
bool inputs:internal_reflections = 1
float inputs:metalness = 0
vector3f inputs:normal = (0, 0, 0)
color3f inputs:opacity = (1, 1, 1)
float inputs:sheen = 0
color3f inputs:sheen_color = (1, 1, 1)
float inputs:sheen_roughness = 0.3
float inputs:specular = 1
float inputs:specular_anisotropy = 0
color3f inputs:specular_color = (1, 1, 1)
float inputs:specular_IOR = 1.5
float inputs:specular_rotation = 0
float inputs:specular_roughness = 1
float inputs:subsurface = 0
float inputs:subsurface_anisotropy = 0
color3f inputs:subsurface_color = (1, 1, 1)
color3f inputs:subsurface_radius = (1, 1, 1)
float inputs:subsurface_scale = 1
token inputs:subsurface_type = "randomwalk"
vector3f inputs:tangent = (0, 0, 0)
float inputs:thin_film_IOR = 1.5
float inputs:thin_film_thickness = 0
bool inputs:thin_walled = 0
float inputs:transmission = 0
color3f inputs:transmission_color = (1, 1, 1)
float inputs:transmission_depth = 0
float inputs:transmission_dispersion = 0
float inputs:transmission_extra_roughness = 0
color3f inputs:transmission_scatter = (0, 0, 0)
float inputs:transmission_scatter_anisotropy = 0
bool inputs:transmit_aovs = 0
token outputs:shader
}
}
}

def Camera "persp" (
prepend apiSchemas = ["ArnoldPerspCameraAPI"]
kind = "assembly"
)
{
float2 clippingRange = (0.1, 10000)
float focalLength = 35
float focusDistance = 1
float horizontalAperture = 35.999928
float[] primvars:arnold:aperture_size = [0]
float[] primvars:arnold:fov = [54.432224]
float2[] primvars:arnold:lens_shift = [(0, 0)]
float2[] primvars:arnold:lens_tilt_angle = [(0, 0)]
vector3f[] primvars:arnold:look_at = [(0, 0, -1)]
float primvars:arnold:motion_end = 0
vector3f[] primvars:arnold:position = [(0, 0, 0)]
float2[] primvars:arnold:screen_window_max = [(1, 1)]
float2[] primvars:arnold:screen_window_min = [(-1, -1)]
vector3f[] primvars:arnold:up = [(0, 1, 0)]
color4f primvars:arnold:uv_remap = (0, 0, 0, 1)
string primvars:dcc_name = "cameraShape1" (
elementSize = 1
interpolation = "constant"
)
token projection = "perspective"
double shutter:close = 0
double shutter:open = 0
float verticalAperture = 23.999952
float3 xformOp:rotateXYZ = (-45, 46.8, 4.6462175e-15)
double3 xformOp:translate = (2.2549120264852296, 3.118549285632537, 2.17926632759013)
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ"]
}
def Scope "Render"
{
def RenderSettings "settings"
{
prepend rel camera = </persp>
uniform int2 resolution = (160, 120)
}
}
39 changes: 39 additions & 0 deletions testsuite/test_2058/ref/reference.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
00:00:00 92MB | log started Wed Aug 7 16:58:04 2024
00:00:00 92MB | Arnold 7.3.3.0 [321d3b3a] windows x86_64 clang-15.0.7 oiio-2.4.1 osl-1.13.0 vdb-11.0.0 adlsdk-8.0.7.50 clmhub-3.1.1.43 rlm-14.2.5 optix-8.0.0 2024/07/08 17:34:38
00:00:00 92MB | running on REMS4QL1726, pid=13168
00:00:00 92MB | 2 x Intel(R) Xeon(R) Gold 5218 CPU @ 2.30GHz (32 cores, 64 logical) with 65154MB
00:00:00 106MB | NVIDIA driver version 551.23
00:00:00 106MB | GPU 0: Quadro RTX 4000 @ 1545MHz (compute 7.5) with 8191MB (4767MB available) (NVLink:0)
00:00:00 106MB | Windows 10 (version 10.0, build 19045)
00:00:00 106MB | soft limit for open files is set at 2048
00:00:00 106MB |
00:00:00 106MB | Installing system handler with mask 255
00:00:00 118MB | loading plugins from C:\arnold\arnold-usd\build\windows_x86_64\msvc_opt\usd-0.23.11_arnold-7.3.3.0\plugins\procedural ...
00:00:00 125MB | usd_proc.dll: usd uses Arnold 7.3.3.0
00:00:00 125MB | loaded 1 plugins from 1 lib(s) in 0:00.09
00:00:00 125MB | loading plugins from C:\arnold\sdk\latest\bin\..\plugins ...
00:00:00 126MB | alembic_proc.dll: alembic uses Arnold 7.3.3.0
00:00:00 126MB | cryptomatte.dll: cryptomatte uses Arnold 7.3.3.0
00:00:00 126MB | cryptomatte.dll: cryptomatte_filter uses Arnold 7.3.3.0
00:00:00 126MB | cryptomatte.dll: cryptomatte_manifest_driver uses Arnold 7.3.3.0
00:00:00 126MB | skipping already loaded plugin: C:\arnold\sdk\latest\bin\..\plugins\usd_proc.dll ...
00:00:00 126MB | loaded 4 plugins from 2 lib(s) in 0:00.00
00:00:00 131MB | [kick] command: C:\arnold\sdk\latest\bin\kick test.usda -dw -r 160 120 -sm lambert -bs 16 -sl -o testrender.tif -set driver_tiff.dither false -nocrashpopup -dp -v 6
00:00:00 131MB | loading plugins from . ...
00:00:00 131MB | no plugins loaded
00:00:00 131MB | ARNOLD_ADP_DISABLE envar passed in -- ADP is disabled for this session
Warning: in _AdapterLookup at line 280 of S:\gocd\pipelines\kook\kook\usd\build\usd-23.11_windows-x86_64_static_vc-14.2_cxx14\pxr\usdImaging\usdImaging\delegate.cpp -- Selected hydra renderer doesn't support prim type 'RenderSettings'
00:00:00 192MB WARNING | /primitive1.subdiv_iterations: use type BYTE, not INT (converted automatically)
00:00:00 192MB | [kick] applying 2 attr value overrides
WARNING | rendering with watermarks because the skip_license_check option was enabled
00:00:00 329MB |
00:00:00 329MB | releasing resources
00:00:00 226MB |
00:00:00 226MB | releasing resources
00:00:00 213MB | unloading 3 plugins
00:00:00 213MB | closing usd_proc.dll ...
00:00:00 213MB | closing alembic_proc.dll ...
00:00:00 213MB | closing cryptomatte.dll ...
00:00:00 212MB | unloading plugins done
00:00:00 212MB | Arnold shutdown
00:00:00 198MB | Installing system handler with mask 0
Binary file added testsuite/test_2058/ref/reference.tif
Binary file not shown.

0 comments on commit f7c1e5d

Please sign in to comment.