Skip to content

Commit

Permalink
Merge pull request #1386 from chrisc-lee/mayaMeshLockedNormals
Browse files Browse the repository at this point in the history
ToMayaMeshConverter : No longer set normals
  • Loading branch information
ivanimanishi authored Aug 17, 2023
2 parents e6d4406 + fd1087f commit 6103e34
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 74 deletions.
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
10.5.x.x (relative to 10.5.1.0)
========

Breaking Changes
----------------
- IECoreMaya : Maya meshes converted from Cortex data no longer have normals set explicitly and instead relies on Maya to calculate them.

Fixes
---
- ToMayaMeshConverter : No longer locks normals set on the Mesh from the scc.

10.5.1.0 (relative to 10.5.0.0)
========
Expand Down
77 changes: 4 additions & 73 deletions src/IECoreMaya/ToMayaMeshConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ void ToMayaMeshConverter::addUVSet( MFnMesh &fnMesh, const MIntArray &polygonCou

bool ToMayaMeshConverter::doConversion( IECore::ConstObjectPtr from, MObject &to, IECore::ConstCompoundObjectPtr operands ) const
{
// Note: Normals are not set on the Mesh from the scc as by setting them
// explicitly we are implying they should be locked which is not
// supported, instead we rely on Maya computing the normals everytime

MStatus s;

IECoreScene::ConstMeshPrimitivePtr mesh = IECore::runTimeCast<const IECoreScene::MeshPrimitive>( from );
Expand Down Expand Up @@ -263,79 +267,6 @@ bool ToMayaMeshConverter::doConversion( IECore::ConstObjectPtr from, MObject &to
return false;
}

it = mesh->variables.find("N");
if ( it != mesh->variables.end() )
{
if (it->second.interpolation == IECoreScene::PrimitiveVariable::FaceVarying )
{
/// \todo Employ some M*Array converters to simplify this
MVectorArray vertexNormalsArray;
IECore::ConstV3fVectorDataPtr n = IECore::runTimeCast<const IECore::V3fVectorData>(it->second.data);
if (n)
{
IECoreScene::PrimitiveVariable::IndexedView<Imath::V3f> normalView = IECoreScene::PrimitiveVariable::IndexedView<Imath::V3f>( it->second );
vertexNormalsArray.setLength( normalView.size() );

size_t i = 0;
for(const auto& normal : normalView)
{
vertexNormalsArray[i++] = IECore::convert<MVector, Imath::V3f>( normal );
}
}
else
{
IECore::ConstV3dVectorDataPtr n = IECore::runTimeCast<const IECore::V3dVectorData>(it->second.data);
if (n)
{
IECoreScene::PrimitiveVariable::IndexedView<Imath::V3d> normalView = IECoreScene::PrimitiveVariable::IndexedView<Imath::V3d>( it->second );
vertexNormalsArray.setLength( normalView.size() );

size_t i = 0;
for(const auto& normal : normalView)
{
vertexNormalsArray[i++] = IECore::convert<MVector, Imath::V3d>( normal );
}
}
else
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"N\" has unsupported type \"%s\"." ) % it->second.data->typeName() );
}
}

if ( vertexNormalsArray.length() )
{
MStatus status;
MItMeshPolygon itPolygon( mObj, &status );
if( status != MS::kSuccess )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", "Failed to create mesh iterator" );
}

unsigned v = 0;
MIntArray vertexIds;
MIntArray faceIds;

for ( ; !itPolygon.isDone(); itPolygon.next() )
{
for ( v=0; v < itPolygon.polygonVertexCount(); ++v )
{
faceIds.append( itPolygon.index() );
vertexIds.append( itPolygon.vertexIndex( v ) );
}
}

if( !fnMesh.setFaceVertexNormals( vertexNormalsArray, faceIds, vertexIds ) )
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", "Setting normals failed" );
}
}
}
else
{
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", "PrimitiveVariable \"N\" has unsupported interpolation (expected FaceVarying)." );
}
}

/// Add UV sets
for ( it = mesh->variables.begin(); it != mesh->variables.end(); ++it )
{
Expand Down
7 changes: 6 additions & 1 deletion test/IECoreMaya/ParameterisedHolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ def testMeshParameterIOProblem( self ) :
op = fnOP.getOp()

mesh = IECoreScene.MeshPrimitive.createBox( imath.Box3f( imath.V3f( -2, -2, -2 ), imath.V3f( 2, 3, 4 ) ) )
mesh[ "N" ] = IECoreScene.PrimitiveVariable( mesh[ "N" ].interpolation, mesh[ "N" ].expandedData() )
op.parameters()[ "input" ].setValue( mesh )
fnOP.setNodeValues()

Expand All @@ -301,7 +300,13 @@ def testMeshParameterIOProblem( self ) :
op = fnOP.getOp()

mesh2 = op.parameters()["input"].getValue()

self.assertTrue( mesh2.arePrimitiveVariablesValid() )
# The ToMayaMeshConverter relies on Maya to calculate the normals
# whereas createBox uses indexed normals so we cannot include them
# in the comparison otherwise they will never be the same
del mesh[ "N" ]
del mesh2[ "N" ]
self.assertEqual( mesh2, mesh )

def testOpHolder( self ) :
Expand Down
3 changes: 3 additions & 0 deletions test/IECoreMaya/ToMayaMeshConverterTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ def testNormals( self ) :
self.assertAlmostEqual( origNormal[j], normal3f[j], 6 )
self.assertAlmostEqual( origNormal[j], normal3d[j], 6 )

# normals should always be unlocked when reading from scc
self.assertFalse( any( maya.cmds.polyNormalPerVertex( newSphere+".vtx[*]", query=True, allLocked=True ) ) )

def testSetMeshInterpolation( self ) :

sphere = maya.cmds.polySphere( subdivisionsX=10, subdivisionsY=5, constructionHistory=False )
Expand Down

0 comments on commit 6103e34

Please sign in to comment.