From 06ed20abf8e9b59384c3221dd2c390d205296ae8 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 3 Feb 2016 18:53:38 +0100 Subject: [PATCH] Use the initial pose of a MorphGeometry for object placement (Fixes #3136) --- components/nifosg/nifloader.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index f4dae52c3..280985f7e 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -999,7 +999,7 @@ namespace NifOsg continue; if(ctrl->recType == Nif::RC_NiGeomMorpherController) { - geometry = handleMorphGeometry(static_cast(ctrl.getPtr())); + geometry = handleMorphGeometry(static_cast(ctrl.getPtr()), triShape, parentNode, composite, boundTextures, animflags); osg::ref_ptr morphctrl = new GeomMorpherController( static_cast(ctrl.getPtr())->data.getPtr()); @@ -1010,9 +1010,10 @@ namespace NifOsg } if (!geometry.get()) + { geometry = new osg::Geometry; - - triShapeToGeometry(triShape, geometry, parentNode, composite, boundTextures, animflags); + triShapeToGeometry(triShape, geometry, parentNode, composite, boundTextures, animflags); + } #if OSG_VERSION_LESS_THAN(3,3,3) osg::ref_ptr geode (new osg::Geode); @@ -1046,7 +1047,7 @@ namespace NifOsg #endif } - osg::ref_ptr handleMorphGeometry(const Nif::NiGeomMorpherController* morpher) + osg::ref_ptr handleMorphGeometry(const Nif::NiGeomMorpherController* morpher, const Nif::NiTriShape *triShape, osg::Node* parentNode, SceneUtil::CompositeStateSetUpdater* composite, const std::vector& boundTextures, int animflags) { osg::ref_ptr morphGeom = new osgAnimation::MorphGeometry; morphGeom->setMethod(osgAnimation::MorphGeometry::RELATIVE); @@ -1056,6 +1057,8 @@ namespace NifOsg morphGeom->setUpdateCallback(NULL); morphGeom->setCullCallback(new UpdateMorphGeometry); + triShapeToGeometry(triShape, morphGeom, parentNode, composite, boundTextures, animflags); + const std::vector& morphs = morpher->data.getPtr()->mMorphs; if (!morphs.size()) return morphGeom; @@ -1096,6 +1099,10 @@ namespace NifOsg box.expandBy(vertBounds[i]); } + // For the initial bounding box (used for object placement) use the default pose, fire off a bounding compute to set this initial box + morphGeom->getBoundingBox(); + + // Now set up the callback so that we get properly enlarged bounds if/when the mesh starts animating morphGeom->setComputeBoundingBoxCallback(new StaticBoundingBoxCallback(box)); return morphGeom;