Skip to content

Commit

Permalink
MAYA-127453: combine util.cpp/h and utils.cpp/h; add mayahydra namesp…
Browse files Browse the repository at this point in the history
…ace instead of free functions (#345)

* MAYA-127453: combine util.cpp/h and utils.cpp/h; add mayahydra namespace instead of free functions

* MAYA-127453: remove using ns
  • Loading branch information
perrauo-adsk authored and GitHub Enterprise committed Feb 1, 2023
1 parent 3d82cf9 commit 4bb3332
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 286 deletions.
4 changes: 2 additions & 2 deletions lib/mayaUsd/render/mayaToHydra/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ MStatus MtohRenderOverride::Render(const MHWRender::MDrawContext& drawContext, c
}

_taskController->SetFreeCameraMatrices(
GetGfMatrixFromMaya(drawContext.getMatrix(MHWRender::MFrameContext::kViewMtx)),
GetGfMatrixFromMaya(drawContext.getMatrix(MHWRender::MFrameContext::kProjectionMtx)));
MAYAHYDRA_NS::GetGfMatrixFromMaya(drawContext.getMatrix(MHWRender::MFrameContext::kViewMtx)),
MAYAHYDRA_NS::GetGfMatrixFromMaya(drawContext.getMatrix(MHWRender::MFrameContext::kProjectionMtx)));

if (delegateParams.motionSamplesEnabled()) {
MStatus status;
Expand Down
16 changes: 4 additions & 12 deletions lib/usd/mayaHydraLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@ set(HEADERS
debugCodes.h
)

if(NOT BUILD_MAYAUSD_LIBRARY)
# Copied from maya-usd and reduced to minimal interface.
target_sources(${TARGET_NAME}
PRIVATE
usd/util.cpp
)

list(APPEND HEADERS
usd/util.h
)
endif()

# -----------------------------------------------------------------------------
# compiler configuration
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -140,6 +128,10 @@ endif()
# -----------------------------------------------------------------------------
# promoted headers
# -----------------------------------------------------------------------------
set(SRCFILE ${CMAKE_CURRENT_SOURCE_DIR}/mayaHydra.h.src)
set(DSTFILE ${CMAKE_BINARY_DIR}/include/mayaHydraLib/mayaHydra.h)
configure_file(${SRCFILE} ${DSTFILE})

mayaUsd_promoteHeaderList(
HEADERS
${HEADERS}
Expand Down
6 changes: 3 additions & 3 deletions lib/usd/mayaHydraLib/adapters/dagAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ GfMatrix4d MayaHydraDagAdapter::GetTransform()
if (IsInstanced()) {
_transform.SetIdentity();
} else {
_transform = GetGfMatrixFromMaya(_dagPath.inclusiveMatrix());
_transform = MAYAHYDRA_NS::GetGfMatrixFromMaya(_dagPath.inclusiveMatrix());
}
_invalidTransform = false;
}
Expand All @@ -155,7 +155,7 @@ GfMatrix4d MayaHydraDagAdapter::GetTransform()
size_t MayaHydraDagAdapter::SampleTransform(size_t maxSampleCount, float* times, GfMatrix4d* samples)
{
return GetDelegate()->SampleValues(maxSampleCount, times, samples, [&]() -> GfMatrix4d {
return GetGfMatrixFromMaya(_dagPath.inclusiveMatrix());
return MAYAHYDRA_NS::GetGfMatrixFromMaya(_dagPath.inclusiveMatrix());
});
}

Expand Down Expand Up @@ -317,7 +317,7 @@ VtValue MayaHydraDagAdapter::GetInstancePrimvar(const TfToken& key)
ret.reserve(numDags);
for (auto i = decltype(numDags) { 0 }; i < numDags; ++i) {
if (dags[i].isValid() && dags[i].isVisible()) {
ret.push_back(GetGfMatrixFromMaya(dags[i].inclusiveMatrix()));
ret.push_back(MAYAHYDRA_NS::GetGfMatrixFromMaya(dags[i].inclusiveMatrix()));
}
}
return VtValue(ret);
Expand Down
2 changes: 1 addition & 1 deletion lib/usd/mayaHydraLib/adapters/lightAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ VtValue MayaHydraLightAdapter::Get(const TfToken& key)
} else if (decayRate == 2) {
light.SetAttenuation(GfVec3f(0.0f, 0.0f, 1.0f));
}
light.SetTransform(GetGfMatrixFromMaya(GetDagPath().inclusiveMatrixInverse()));
light.SetTransform(MAYAHYDRA_NS::GetGfMatrixFromMaya(GetDagPath().inclusiveMatrixInverse()));
_CalculateLightParams(light);
return VtValue(light);
} else if (key == HdTokens->transform) {
Expand Down
9 changes: 2 additions & 7 deletions lib/usd/mayaHydraLib/adapters/materialNetworkConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
#include <mayaHydraLib/adapters/mayaAttrs.h>
#include <mayaHydraLib/adapters/tokens.h>
#include <mayaHydraLib/utils.h>
#if defined(MAYAUSD_VERSION)
#include <mayaUsd/utils/util.h>
#else
#include <mayaHydraLib/usd/util.h>
#endif

#include <pxr/usd/sdr/registry.h>
#include <pxr/usd/sdr/shaderProperty.h>
Expand Down Expand Up @@ -540,7 +535,7 @@ class MayaHydraFilenameMaterialAttrConverter : public MayaHydraComputedMaterialA
const VtValue* fallback = nullptr,
MPlugArray* outPlug = nullptr) override
{
auto path = GetFileTexturePath(node);
auto path = MAYAHYDRA_NS::GetFileTexturePath(node);
return VtValue(SdfAssetPath(path.GetText(), path.GetText()));
}
};
Expand Down Expand Up @@ -757,7 +752,7 @@ HdMaterialNode* MayaHydraMaterialNetworkConverter::GetMaterial(const MObject& ma
}
TF_DEBUG(MAYAHYDRALIB_ADAPTER_MATERIALS)
.Msg("MayaHydraMaterialNetworkConverter::GetMaterial(node=%s)\n", chr);
std::string usdNameStr = UsdMayaUtil::SanitizeName(chr);
std::string usdNameStr = MAYAHYDRA_NS::SanitizeName(chr);
const auto materialPath = _prefix.AppendChild(TfToken(usdNameStr));

auto findResult = std::find_if(
Expand Down
5 changes: 2 additions & 3 deletions lib/usd/mayaHydraLib/adapters/renderItemAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
*/


PXR_NAMESPACE_OPEN_SCOPE


Expand Down Expand Up @@ -94,11 +93,11 @@ void MayaHydraRenderItemAdapter::UpdateTransform(MRenderItem& ri)
MMatrix matrix;
if (ri.getMatrix(matrix) == MStatus::kSuccess)
{
_transform[0] = GetGfMatrixFromMaya(matrix);
_transform[0] = MAYAHYDRA_NS::GetGfMatrixFromMaya(matrix);
if (GetDelegate()->GetParams().motionSamplesEnabled())
{
MDGContextGuard guard(MAnimControl::currentTime() + 1.0);
_transform[1] = GetGfMatrixFromMaya(matrix);
_transform[1] = MAYAHYDRA_NS::GetGfMatrixFromMaya(matrix);
}
else
{
Expand Down
10 changes: 3 additions & 7 deletions lib/usd/mayaHydraLib/delegates/delegateCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
//
#include "delegateCtx.h"

#if defined(MAYAUSD_VERSION)
#include "mayaUsd/utils/util.h"
#else
#include <mayaHydraLib/usd/util.h>
#endif
#include <mayaHydraLib/utils.h>

#include <pxr/base/gf/frustum.h>
#include <pxr/base/gf/plane.h>
Expand All @@ -43,7 +39,7 @@ SdfPath _GetRenderItemMayaPrimPath(const MRenderItem& ri)
{
if (ri.InternalObjectId() == 0) return {};

SdfPath mayaPath = UsdMayaUtil::RenderItemToUsdPath(ri, false, false);
SdfPath mayaPath = MAYAHYDRA_NS::RenderItemToSdfPath(ri, false, false);
if (mayaPath.IsEmpty()) return {};

const std::string theString = std::string(mayaPath.GetText());
Expand All @@ -66,7 +62,7 @@ SdfPath _GetRenderItemMayaPrimPath(const MRenderItem& ri)

SdfPath _GetPrimPath(const SdfPath& base, const MDagPath& dg)
{
SdfPath mayaPath = UsdMayaUtil::MDagPathToUsdPath(dg, false, false);
SdfPath mayaPath = MAYAHYDRA_NS::DagPathToSdfPath(dg, false, false);
if (mayaPath.IsEmpty()) {
return {};
}
Expand Down
4 changes: 2 additions & 2 deletions lib/usd/mayaHydraLib/delegates/sceneDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ void MayaHydraSceneDelegate::PreFrame(const MHWRender::MDrawContext& context)
GetPrimPath(lightPath, true),
[&matrixVal](MayaHydraLightAdapter* a) {
// TODO: Mark Dirty?
a->SetShadowProjectionMatrix(GetGfMatrixFromMaya(matrixVal));
a->SetShadowProjectionMatrix(MAYAHYDRA_NS::GetGfMatrixFromMaya(matrixVal));
},
_lightAdapters);
}
Expand Down Expand Up @@ -1096,7 +1096,7 @@ void MayaHydraSceneDelegate::PopulateSelectedPaths(
// be a huge number of different types of instances, so tracking this
// won't be too bad...
std::unordered_set<SdfPath, SdfPath::Hash> selectedMasters;
MapSelectionDescendents(
MAYAHYDRA_NS::MapSelectionDescendents(
mayaSelection,
[this, &selectedSdfPaths, &selectedMasters, &selection](const MDagPath& dagPath) {
SdfPath primId;
Expand Down
46 changes: 46 additions & 0 deletions lib/usd/mayaHydraLib/mayaHydra.h.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright 2023 Autodesk
//
// 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.
//

#pragma once

#define MAYAHYDRA_MAJOR_VERSION ${MAYAHYDRA_MAJOR_VERSION}
#define MAYAHYDRA_MINOR_VERSION ${MAYAHYDRA_MINOR_VERSION}
#define MAYAHYDRA_PATCH_LEVEL ${MAYAHYDRA_PATCH_LEVEL}

// MayaHydra public namespace string will never change.
#define MAYAHYDRA_NS MayaHydra
// C preprocessor trickery to expand arguments.
#define MAYAHYDRA_CONCAT(A, B) MAYAHYDRA_CONCAT_IMPL(A, B)
#define MAYAHYDRA_CONCAT_IMPL(A, B) A##B
// Versioned namespace includes the major version number.
#define MAYAHYDRA_VERSIONED_NS MAYAHYDRA_CONCAT(MAYAHYDRA_NS, _v${MAYAHYDRA_MAJOR_VERSION})

namespace MAYAHYDRA_VERSIONED_NS {}

// With a using namespace declaration, pull in the versioned namespace into the
// MayaHydra public namespace, to allow client code to use the plain MayaHydra
// namespace, e.g. MayaHydra::Class.
namespace MAYAHYDRA_NS {
using namespace MAYAHYDRA_VERSIONED_NS;
}

// Macro to place the MayaHydra symbols in the versioned namespace, which is how
// they will appear in the shared library, e.g. MayaHydra_v1::Class.
#ifdef DOXYGEN
#define MAYAHYDRA_NS_DEF MAYAHYDRA_NS
#else
#define MAYAHYDRA_NS_DEF MAYAHYDRA_VERSIONED_NS
#endif
149 changes: 0 additions & 149 deletions lib/usd/mayaHydraLib/usd/util.cpp

This file was deleted.

Loading

0 comments on commit 4bb3332

Please sign in to comment.