Skip to content

Commit b8fdefb

Browse files
committed
ToMayaMeshConverter : No longer set normals
Currently, when converting from a Cortex object to a Maya Mesh, we set the normals anytime the normals are stored in the scc. Setting the normals explicitly implies these are static values and so Maya locks them rather than computing them on the fly. Locked normales are undesirable in many parts of the Pipeline, especially for deforming geometry as not recomputing them leads to unexpected results, e.g. wrong tangents or incorrect shader computations. This change removes the normal transfer from the scc to the Maya geometry and instead we rely on Maya to compute them.
1 parent e6d4406 commit b8fdefb

File tree

1 file changed

+4
-73
lines changed

1 file changed

+4
-73
lines changed

src/IECoreMaya/ToMayaMeshConverter.cpp

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ void ToMayaMeshConverter::addUVSet( MFnMesh &fnMesh, const MIntArray &polygonCou
183183

184184
bool ToMayaMeshConverter::doConversion( IECore::ConstObjectPtr from, MObject &to, IECore::ConstCompoundObjectPtr operands ) const
185185
{
186+
// Note: Normals are not set on the Mesh from the scc as by setting them
187+
// explicitly we are implying they should be locked which is not
188+
// supported, instead we rely on Maya computing the normals everytime
189+
186190
MStatus s;
187191

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

266-
it = mesh->variables.find("N");
267-
if ( it != mesh->variables.end() )
268-
{
269-
if (it->second.interpolation == IECoreScene::PrimitiveVariable::FaceVarying )
270-
{
271-
/// \todo Employ some M*Array converters to simplify this
272-
MVectorArray vertexNormalsArray;
273-
IECore::ConstV3fVectorDataPtr n = IECore::runTimeCast<const IECore::V3fVectorData>(it->second.data);
274-
if (n)
275-
{
276-
IECoreScene::PrimitiveVariable::IndexedView<Imath::V3f> normalView = IECoreScene::PrimitiveVariable::IndexedView<Imath::V3f>( it->second );
277-
vertexNormalsArray.setLength( normalView.size() );
278-
279-
size_t i = 0;
280-
for(const auto& normal : normalView)
281-
{
282-
vertexNormalsArray[i++] = IECore::convert<MVector, Imath::V3f>( normal );
283-
}
284-
}
285-
else
286-
{
287-
IECore::ConstV3dVectorDataPtr n = IECore::runTimeCast<const IECore::V3dVectorData>(it->second.data);
288-
if (n)
289-
{
290-
IECoreScene::PrimitiveVariable::IndexedView<Imath::V3d> normalView = IECoreScene::PrimitiveVariable::IndexedView<Imath::V3d>( it->second );
291-
vertexNormalsArray.setLength( normalView.size() );
292-
293-
size_t i = 0;
294-
for(const auto& normal : normalView)
295-
{
296-
vertexNormalsArray[i++] = IECore::convert<MVector, Imath::V3d>( normal );
297-
}
298-
}
299-
else
300-
{
301-
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", boost::format( "PrimitiveVariable \"N\" has unsupported type \"%s\"." ) % it->second.data->typeName() );
302-
}
303-
}
304-
305-
if ( vertexNormalsArray.length() )
306-
{
307-
MStatus status;
308-
MItMeshPolygon itPolygon( mObj, &status );
309-
if( status != MS::kSuccess )
310-
{
311-
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", "Failed to create mesh iterator" );
312-
}
313-
314-
unsigned v = 0;
315-
MIntArray vertexIds;
316-
MIntArray faceIds;
317-
318-
for ( ; !itPolygon.isDone(); itPolygon.next() )
319-
{
320-
for ( v=0; v < itPolygon.polygonVertexCount(); ++v )
321-
{
322-
faceIds.append( itPolygon.index() );
323-
vertexIds.append( itPolygon.vertexIndex( v ) );
324-
}
325-
}
326-
327-
if( !fnMesh.setFaceVertexNormals( vertexNormalsArray, faceIds, vertexIds ) )
328-
{
329-
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", "Setting normals failed" );
330-
}
331-
}
332-
}
333-
else
334-
{
335-
IECore::msg( IECore::Msg::Warning, "ToMayaMeshConverter::doConversion", "PrimitiveVariable \"N\" has unsupported interpolation (expected FaceVarying)." );
336-
}
337-
}
338-
339270
/// Add UV sets
340271
for ( it = mesh->variables.begin(); it != mesh->variables.end(); ++it )
341272
{

0 commit comments

Comments
 (0)