RigGeometry check if mesh has normals (Fixes #3667)

This commit is contained in:
scrawl 2016-12-15 22:39:21 +01:00
parent 81b9b07820
commit c0faeea938

View file

@ -120,12 +120,16 @@ void RigGeometry::setSourceGeometry(osg::ref_ptr<osg::Geometry> sourceGeometry)
setVertexArray(vertexArray); setVertexArray(vertexArray);
} }
osg::ref_ptr<osg::Array> normalArray = osg::clone(from.getNormalArray(), osg::CopyOp::DEEP_COPY_ALL); if (osg::Array* normals = from.getNormalArray())
{
osg::ref_ptr<osg::Array> normalArray = osg::clone(normals, osg::CopyOp::DEEP_COPY_ALL);
if (normalArray) if (normalArray)
{ {
normalArray->setVertexBufferObject(vbo); normalArray->setVertexBufferObject(vbo);
setNormalArray(normalArray, osg::Array::BIND_PER_VERTEX); setNormalArray(normalArray, osg::Array::BIND_PER_VERTEX);
} }
}
if (osg::Vec4Array* tangents = dynamic_cast<osg::Vec4Array*>(from.getTexCoordArray(7))) if (osg::Vec4Array* tangents = dynamic_cast<osg::Vec4Array*>(from.getTexCoordArray(7)))
{ {
@ -273,6 +277,7 @@ void RigGeometry::update(osg::NodeVisitor* nv)
{ {
unsigned short vertex = *vertexIt; unsigned short vertex = *vertexIt;
(*positionDst)[vertex] = resultMat.preMult((*positionSrc)[vertex]); (*positionDst)[vertex] = resultMat.preMult((*positionSrc)[vertex]);
if (normalDst)
(*normalDst)[vertex] = osg::Matrix::transform3x3((*normalSrc)[vertex], resultMat); (*normalDst)[vertex] = osg::Matrix::transform3x3((*normalSrc)[vertex], resultMat);
if (tangentDst) if (tangentDst)
{ {
@ -284,6 +289,7 @@ void RigGeometry::update(osg::NodeVisitor* nv)
} }
positionDst->dirty(); positionDst->dirty();
if (normalDst)
normalDst->dirty(); normalDst->dirty();
if (tangentDst) if (tangentDst)
tangentDst->dirty(); tangentDst->dirty();