Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move rig and morph update in update thread #2445

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
move rig update in update thread
  • Loading branch information
juval committed Jul 9, 2019
commit bf0b560ec240183ea35d0ac0f7ce2f3df779a25b
43 changes: 34 additions & 9 deletions components/sceneutil/riggeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,29 +171,31 @@ bool RigGeometry::initFromParentSkeleton(osg::NodeVisitor* nv)
return true;
}

void RigGeometry::cull(osg::NodeVisitor* nv)
{
void RigGeometry::update(osg::NodeVisitor* nv){

if (!mSkeleton)
{
Log(Debug::Error) << "Error: RigGeometry rendering with no skeleton, should have been initialized by UpdateVisitor";
// try to recover anyway, though rendering is likely to be incorrect.
if (!initFromParentSkeleton(nv))
if (!initFromParentSkeleton(nv))
return;
}

//update next frame geom in order not to interfere with draw thread
mLastFrameMutex.lock();
unsigned int traversalNumber = nv->getTraversalNumber();

if (mLastFrameNumber == traversalNumber || (mLastFrameNumber != 0 && !mSkeleton->getActive()))
{
osg::Geometry& geom = *getGeometry(mLastFrameNumber);
osg::Geometry& geom = *getGeometry(mLastFrameNumber+1);
mLastFrameMutex.unlock();
nv->pushOntoNodePath(&geom);
nv->apply(geom);
nv->popFromNodePath();
return;
}
mLastFrameNumber = traversalNumber;
osg::Geometry& geom = *getGeometry(mLastFrameNumber);
osg::Geometry& geom = *getGeometry(mLastFrameNumber+1);

mSkeleton->updateBoneMatrices(traversalNumber);
mLastFrameMutex.unlock();
mSkeleton->updateBoneMatrices(mLastFrameNumber+1);

// skinning
const osg::Vec3Array* positionSrc = static_cast<osg::Vec3Array*>(mSourceGeometry->getVertexArray());
Expand Down Expand Up @@ -255,6 +257,26 @@ void RigGeometry::cull(osg::NodeVisitor* nv)
nv->popFromNodePath();
}

void RigGeometry::cull(osg::NodeVisitor* nv)
{
if (!mSkeleton)
{
Log(Debug::Error) << "Error: RigGeometry rendering with no skeleton, should have been initialized by UpdateVisitor";
// try to recover anyway, though rendering is likely to be incorrect.
if (!initFromParentSkeleton(nv))
return;
}

mLastFrameMutex.lock();
osg::Geometry& geom = *getGeometry(mLastFrameNumber);
mLastFrameMutex.unlock();

nv->pushOntoNodePath(&geom);
nv->apply(geom);
nv->popFromNodePath();

}

void RigGeometry::updateBounds(osg::NodeVisitor *nv)
{
if (!mSkeleton)
Expand Down Expand Up @@ -376,7 +398,10 @@ void RigGeometry::accept(osg::NodeVisitor &nv)
if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
cull(&nv);
else if (nv.getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
{
update(&nv);
updateBounds(&nv);
}
else
nv.apply(*this);

Expand Down
2 changes: 2 additions & 0 deletions components/sceneutil/riggeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace SceneUtil

private:
void cull(osg::NodeVisitor* nv);
void update(osg::NodeVisitor* nv);
void updateBounds(osg::NodeVisitor* nv);

osg::ref_ptr<osg::Geometry> mGeometry[2];
Expand Down Expand Up @@ -101,6 +102,7 @@ namespace SceneUtil
std::vector<Bone*> mBoneNodesVector;

unsigned int mLastFrameNumber;
OpenThreads::Mutex mLastFrameMutex;
bool mBoundsFirstFrame;

bool initFromParentSkeleton(osg::NodeVisitor* nv);
Expand Down