-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HYDRA-1291 : Fix default maya material is not picked up correctly #201
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
#include <maya/MSelectionList.h> | ||
#include <maya/MObjectArray.h> | ||
#include <maya/MFnAttribute.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All that has been removed is not used any more |
||
#include <maya/MItDependencyNodes.h> | ||
|
||
namespace | ||
{ | ||
|
@@ -193,6 +194,37 @@ bool IsDagPathAnArnoldSkyDomeLight(const MDagPath& dagPath) | |
shapeDagPath.extendToShape(); | ||
return _aiSkyDomeLight == MFnDependencyNode(shapeDagPath.node()).typeName(); | ||
} | ||
|
||
|
||
|
||
MObject getDefaultMaterialShadingGroupNode() | ||
{ | ||
MStatus status; | ||
|
||
// Iterate over all shading engines | ||
MItDependencyNodes itDep(MFn::kShadingEngine, &status); | ||
if (status != MStatus::kSuccess) { | ||
MGlobal::displayError("Failed to create dependency node iterator."); | ||
return MObject::kNullObj; | ||
} | ||
|
||
while (!itDep.isDone()) { | ||
MObject shadingEngine = itDep.item(); | ||
MFnDependencyNode shadingEngineFn(shadingEngine, &status); | ||
if (status != MStatus::kSuccess) { | ||
MGlobal::displayError("Failed to create dependency node function set."); | ||
return MObject::kNullObj; | ||
} | ||
|
||
// Is this shading engine the default material ? | ||
if (shadingEngineFn.name() == "initialShadingGroup") { | ||
return shadingEngine; | ||
} | ||
|
||
itDep.next(); | ||
} | ||
|
||
MGlobal::displayError("Failed to find the default material shader."); | ||
return MObject::kNullObj; | ||
} | ||
|
||
} // namespace MAYAHYDRA_NS_DEF |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,15 +24,11 @@ | |
#include <maya/MDagPath.h> | ||
#include <maya/MDagPathArray.h> | ||
#include <maya/MFnComponent.h> | ||
#include <maya/MFnMesh.h> | ||
#include <maya/MItDag.h> | ||
#include <maya/MMatrixArray.h> | ||
#include <maya/MObjectHandle.h> | ||
#include <maya/MPlug.h> | ||
#include <maya/MPlugArray.h> | ||
#include <maya/MProfiler.h> | ||
#include <maya/MObjectArray.h> | ||
#include <maya/MSelectionList.h> | ||
#include <maya/MShaderManager.h> | ||
#include <maya/MString.h> | ||
#include <maya/MGlobal.h> | ||
#include <maya/MItSelectionList.h> | ||
|
@@ -163,7 +159,7 @@ TF_DEFINE_PRIVATE_TOKENS( | |
|
||
SdfPath MayaHydraSceneIndex::_fallbackMaterial; | ||
SdfPath MayaHydraSceneIndex::_mayaDefaultMaterialPath; // Common to all scene indexes | ||
VtValue MayaHydraSceneIndex::_mayaDefaultMaterialFallback;//Used only if we cannot find the default material named standardSurface1 | ||
VtValue MayaHydraSceneIndex::_mayaDefaultMaterialFallback;//Used only if we cannot find the maya default material | ||
SdfPath MayaHydraSceneIndex::_mayaDefaultLightPath; // Common to all scene indexes | ||
SdfPath MayaHydraSceneIndex::_mayaFacesSelectionMaterialPath; // Common to all scene indexes | ||
|
||
|
@@ -773,26 +769,20 @@ VtValue MayaHydraSceneIndex::GetMaterialResource(const SdfPath& id) | |
return ret.IsEmpty() ? MayaHydraMaterialAdapter::GetPreviewMaterialResource(id) : ret; | ||
} | ||
|
||
//Create the default material from the "standardSurface1" maya material or create a fallback material if it cannot be found | ||
//Create the default maya material or create a fallback material if it cannot be found | ||
void MayaHydraSceneIndex::CreateMayaDefaultMaterialData() | ||
{ | ||
// Try to get the standardSurface1 material | ||
MObject defaultShaderObj; | ||
GetDependNodeFromNodeName("standardSurface1", defaultShaderObj); // From mayautils.cpp | ||
bool defaultMaterialSuccessfullyCreated = false; | ||
if (MObjectHandle(defaultShaderObj).isValid()) { | ||
//Get its shading group as it is what we use to create a material adapter | ||
MObject defaultMaterialShadingGroupObj | ||
= GetShadingGroupFromShader(defaultShaderObj); // From mayautils.cpp | ||
if (MObjectHandle(defaultMaterialShadingGroupObj).isValid()) { | ||
defaultMaterialSuccessfullyCreated = _CreateMaterial(MayaHydraSceneIndex::_mayaDefaultMaterialPath, defaultMaterialShadingGroupObj); | ||
} | ||
} | ||
|
||
if (! defaultMaterialSuccessfullyCreated){ | ||
TF_CODING_WARNING("standardSurface1 material and its shading group could not be retrieved, using a fallback material"); | ||
// In case we could not create the default material from the standardSurface1 material, we | ||
// create a fallback material | ||
bool defaultMaterialCreatedSuccessfully = false; | ||
|
||
MObject defaultMaterialShadingGroupObj = getDefaultMaterialShadingGroupNode(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recall there's already an Maya API (MMaterial::defaultMaterial()) to get the default Material, no need to query again. Just use MObject defaultMaterialShadingGroupObj = MMaterial::defaultMaterial().shadingEngine(); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here's the API doc: static MMaterial defaultMaterial() Get the default material. |
||
if (defaultMaterialShadingGroupObj != MObject::kNullObj) { | ||
defaultMaterialCreatedSuccessfully = _CreateMaterial( | ||
MayaHydraSceneIndex::_mayaDefaultMaterialPath, defaultMaterialShadingGroupObj); | ||
} | ||
|
||
if (! defaultMaterialCreatedSuccessfully){ | ||
TF_CODING_WARNING("maya default material and its shading group could not be retrieved, using a fallback material"); | ||
|
||
_mayaDefaultMaterialFallback = MayaHydraSceneIndex::_CreateDefaultMaterialFallback(); | ||
|
||
auto mayaHydraDefaultMaterialDataSource = MayaHydraMaterialDataSource::New( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a bit of headers cleaning in this PR.