From c0faeea938e9132cb548c9783004e85cf2c44a87 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 15 Dec 2016 22:39:21 +0100 Subject: [PATCH] RigGeometry check if mesh has normals (Fixes #3667) --- components/sceneutil/riggeometry.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/components/sceneutil/riggeometry.cpp b/components/sceneutil/riggeometry.cpp index 3af5176f4..297dc6923 100644 --- a/components/sceneutil/riggeometry.cpp +++ b/components/sceneutil/riggeometry.cpp @@ -120,13 +120,17 @@ void RigGeometry::setSourceGeometry(osg::ref_ptr sourceGeometry) setVertexArray(vertexArray); } - osg::ref_ptr normalArray = osg::clone(from.getNormalArray(), osg::CopyOp::DEEP_COPY_ALL); - if (normalArray) + if (osg::Array* normals = from.getNormalArray()) { - normalArray->setVertexBufferObject(vbo); - setNormalArray(normalArray, osg::Array::BIND_PER_VERTEX); + osg::ref_ptr normalArray = osg::clone(normals, osg::CopyOp::DEEP_COPY_ALL); + if (normalArray) + { + normalArray->setVertexBufferObject(vbo); + setNormalArray(normalArray, osg::Array::BIND_PER_VERTEX); + } } + if (osg::Vec4Array* tangents = dynamic_cast(from.getTexCoordArray(7))) { mSourceTangents = tangents; @@ -273,7 +277,8 @@ void RigGeometry::update(osg::NodeVisitor* nv) { unsigned short vertex = *vertexIt; (*positionDst)[vertex] = resultMat.preMult((*positionSrc)[vertex]); - (*normalDst)[vertex] = osg::Matrix::transform3x3((*normalSrc)[vertex], resultMat); + if (normalDst) + (*normalDst)[vertex] = osg::Matrix::transform3x3((*normalSrc)[vertex], resultMat); if (tangentDst) { osg::Vec4f srcTangent = (*tangentSrc)[vertex]; @@ -284,7 +289,8 @@ void RigGeometry::update(osg::NodeVisitor* nv) } positionDst->dirty(); - normalDst->dirty(); + if (normalDst) + normalDst->dirty(); if (tangentDst) tangentDst->dirty(); }