Skip to content

Commit

Permalink
Adding usd imaging adapters for the Arnold shape schemas. (#185) (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpalee authored Apr 1, 2021
1 parent c1e352e commit 69a15f3
Show file tree
Hide file tree
Showing 22 changed files with 571 additions and 36 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ endif ()
# Common directory includes.
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/common")
set(COMMON_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/common/common_utils.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/constant_strings.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/shape_utils.cpp")

set(COMMON_HDR
"${CMAKE_CURRENT_SOURCE_DIR}/common/common_bits.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/common_utils.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/constant_strings.h"
"${CMAKE_CURRENT_SOURCE_DIR}/common/shape_utils.h")

Expand Down
5 changes: 4 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,16 @@ else:
plugInfos = [
renderdelegate_plug_info,
ndrplugin_plug_info,
usdimagingplugin_plug_info,
]

for plugInfo in plugInfos:
env.Command(target=plugInfo, source=['%s.in' % plugInfo],
action=configure.configure_plug_info)

if BUILD_USD_IMAGING_PLUGIN:
env.Command(target=usdimagingplugin_plug_info,
source=['{}.in'.format(usdimagingplugin_plug_info)], action=configure.configure_usd_maging_plug_info)

if RENDERDELEGATE:
Depends(RENDERDELEGATE, renderdelegate_plug_info)

Expand Down
29 changes: 29 additions & 0 deletions common/common_bits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2021 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// @file common_bits.h
///
/// Common bits for Hydra and Usd Imaging Adapters.
#include "api.h"
#include <pxr/pxr.h>

#include <pxr/imaging/hd/changeTracker.h>

PXR_NAMESPACE_OPEN_SCOPE

// For now we reserve a single bit for all the parameter changes.
enum ArnoldUsdRprimBits : HdDirtyBits {
ArnoldUsdRprimBitsParams = HdChangeTracker::CustomBitsBegin,
};

PXR_NAMESPACE_CLOSE_SCOPE
39 changes: 39 additions & 0 deletions common/common_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2021 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "common_utils.h"

PXR_NAMESPACE_OPEN_SCOPE

std::string MakeCamelCase(const std::string &in)
{
std::string out;
out.reserve(in.length());
bool capitalize = false;
unsigned char c;
for (size_t i = 0; i < in.length(); ++i) {
c = in[i];
if (c == '_') {
capitalize = true;
} else {
if (capitalize) {
c = toupper(c);
capitalize = false;
}
out += c;
}
}
return out;
}

PXR_NAMESPACE_CLOSE_SCOPE
30 changes: 30 additions & 0 deletions common/common_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// @file common_utils.h
///
/// Common utils.
#include "api.h"

#include <string>

PXR_NAMESPACE_OPEN_SCOPE

// convert from "snake_case" to "camelCase"
// ignores the capitalization of input strings: letters are only capitalized
// if they follow an underscore
//
ARNOLDUSD_API
std::string MakeCamelCase(const std::string &in);

PXR_NAMESPACE_CLOSE_SCOPE
4 changes: 3 additions & 1 deletion common/constant_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ ASTR2(_min, "min");
ASTR2(arnold_camera, "arnold:camera");
ASTR2(arnold_filename, "arnold:filename");
ASTR2(arnold_node_entry, "arnold:node_entry");
ASTR2(arnold_prefix, "arnold:");
ASTR2(b_spline, "b-spline");
ASTR2(catmull_rom, "catmull-rom");
ASTR2(inputs_code, "inputs:code");
Expand Down Expand Up @@ -98,6 +99,7 @@ ASTR(UsdUVTexture);
ASTR(abort_on_error);
ASTR(abort_on_license_fail);
ASTR(accelerations);
ASTR(all_attributes);
ASTR(ambocc);
ASTR(angle);
ASTR(angular);
Expand All @@ -115,7 +117,6 @@ ASTR(arnold);
ASTR(attribute);
ASTR(auto_transparency_depth);
ASTR(autobump_visibility);
ASTR(all_attributes);
ASTR(barndoor);
ASTR(barndoor_bottom_edge);
ASTR(barndoor_bottom_left);
Expand Down Expand Up @@ -358,6 +359,7 @@ ASTR(uvlist);
ASTR(uvs);
ASTR(uvset);
ASTR(varname);
ASTR(velocities);
ASTR(vertices);
ASTR(vidxs);
ASTR(viewMtx);
Expand Down
15 changes: 9 additions & 6 deletions render_delegate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(SRC
light.cpp
material.cpp
mesh.cpp
native_rprim.cpp
openvdb_asset.cpp
points.cpp
render_buffer.cpp
Expand All @@ -35,6 +36,7 @@ set(HDR
light.h
material.h
mesh.h
native_rprim.h
openvdb_asset.h
points.h
render_buffer.h
Expand All @@ -44,7 +46,8 @@ set(HDR
renderer_plugin.h
shape.h
utils.h
volume.h)
volume.h
)

add_library(hdArnold SHARED ${COMMON_SRC} ${SRC})
if (BUILD_HEADERS_AS_SOURCES)
Expand Down Expand Up @@ -95,15 +98,15 @@ else ()
endif ()

configure_file(
plugInfo.json.in
${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json
plugInfo.json.in
${CMAKE_CURRENT_BINARY_DIR}/plugInfo.json
)

install(TARGETS hdArnold
DESTINATION "${PREFIX_PLUGINS}")
DESTINATION "${PREFIX_PLUGINS}")

install(FILES ${PLUGINFO}
DESTINATION "${PREFIX_PLUGINS}/hdArnold/resources")
DESTINATION "${PREFIX_PLUGINS}/hdArnold/resources")

install(FILES ${HDR}
DESTINATION "${PREFIX_HEADERS}/render_delegate")
DESTINATION "${PREFIX_HEADERS}/render_delegate")
1 change: 1 addition & 0 deletions render_delegate/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ source_files = [
'light.cpp',
'material.cpp',
'mesh.cpp',
'native_rprim.cpp',
'openvdb_asset.cpp',
'points.cpp',
'render_buffer.cpp',
Expand Down
14 changes: 13 additions & 1 deletion render_delegate/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,20 @@ void HdArnoldGenericLight::Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* r
SetupTexture(sceneDelegate->GetLightParamValue(id, HdLightTokens->textureFile));
#endif
}
// Primvars are not officially supported on lights, but pre-20.11 the query functions checked for primvars
// on all primitives uniformly. We have to pass the full name of the primvar post-20.11 to make this bit still
// work.
for (const auto& primvar : sceneDelegate->GetPrimvarDescriptors(id, HdInterpolation::HdInterpolationConstant)) {
ConvertPrimvarToBuiltinParameter(_light, primvar.name, sceneDelegate->Get(id, primvar.name));
ConvertPrimvarToBuiltinParameter(
_light, primvar.name,
sceneDelegate->Get(
id,
#if PXR_VERSION >= 2011
TfToken { TfStringPrintf("primvars:%s", primvar.name.GetText()) }
#else
primvar.name
#endif
));
}
const auto filtersValue = sceneDelegate->GetLightParamValue(id, _tokens->filters);
if (filtersValue.IsHolding<SdfPathVector>()) {
Expand Down
101 changes: 101 additions & 0 deletions render_delegate/native_rprim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2021 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "native_rprim.h"

#include "material.h"

#include <common_bits.h>
#include <constant_strings.h>

PXR_NAMESPACE_OPEN_SCOPE

#if PXR_VERSION >= 2102
HdArnoldNativeRprim::HdArnoldNativeRprim(
HdArnoldRenderDelegate* renderDelegate, const AtString& arnoldType, const SdfPath& id)
: HdArnoldRprim<HdRprim>(arnoldType, renderDelegate, id),
_paramList(renderDelegate->GetNativeRprimParamList(arnoldType))
{
}
#else
HdArnoldNativeRprim::HdArnoldNativeRprim(
HdArnoldRenderDelegate* renderDelegate, const AtString& arnoldType, const SdfPath& id, const SdfPath& instancerId)
: HdArnoldRprim<HdRprim>(arnoldType, renderDelegate, id, instancerId),
_paramList(renderDelegate->GetNativeRprimParamList(arnoldType))
{
}
#endif

void HdArnoldNativeRprim::Sync(
HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits, const TfToken& reprToken)
{
TF_UNUSED(reprToken);
HdArnoldRenderParamInterrupt param(renderParam);
const auto& id = GetId();

// Sync any built-in parameters.
if (*dirtyBits & ArnoldUsdRprimBitsParams && Ai_likely(_paramList != nullptr)) {
param.Interrupt();
for (const auto& paramIt : *_paramList) {
const auto val = sceneDelegate->Get(id, paramIt.first);
// Do we need to check for this?
if (!val.IsEmpty()) {
HdArnoldSetParameter(GetArnoldNode(), paramIt.second, val);
}
}
}

if (HdChangeTracker::IsVisibilityDirty(*dirtyBits, id)) {
param.Interrupt();
_UpdateVisibility(sceneDelegate, dirtyBits);
SetShapeVisibility(_sharedData.visible ? AI_RAY_ALL : uint8_t{0});
}

auto transformDirtied = false;
if (HdChangeTracker::IsTransformDirty(*dirtyBits, id)) {
param.Interrupt();
HdArnoldSetTransform(GetArnoldNode(), sceneDelegate, GetId());
transformDirtied = true;
}

if (*dirtyBits & HdChangeTracker::DirtyMaterialId) {
param.Interrupt();
const auto* material = reinterpret_cast<const HdArnoldMaterial*>(
sceneDelegate->GetRenderIndex().GetSprim(HdPrimTypeTokens->material, sceneDelegate->GetMaterialId(id)));
if (material != nullptr) {
AiNodeSetPtr(GetArnoldNode(), str::shader, material->GetSurfaceShader());
} else {
// AiNodeSetPtr(GetArnoldNode(), str::shader, GetRenderDelegate()->GetFallbackShader());
AiNodeResetParameter(GetArnoldNode(), str::shader);
}
}

SyncShape(*dirtyBits, sceneDelegate, param, transformDirtied);

*dirtyBits = HdChangeTracker::Clean;
}

HdDirtyBits HdArnoldNativeRprim::GetInitialDirtyBitsMask() const
{
return HdChangeTracker::Clean | HdChangeTracker::InitRepr | HdChangeTracker::DirtyTransform |
HdChangeTracker::DirtyMaterialId | HdChangeTracker::DirtyPrimvar | HdChangeTracker::DirtyVisibility |
HdArnoldShape::GetInitialDirtyBitsMask() | ArnoldUsdRprimBitsParams;
}

const TfTokenVector& HdArnoldNativeRprim::GetBuiltinPrimvarNames() const
{
const static TfTokenVector r{};
return r;
}

PXR_NAMESPACE_CLOSE_SCOPE
Loading

0 comments on commit 69a15f3

Please sign in to comment.