|
|
|
@ -101,7 +101,6 @@ namespace MWRender{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Animation::handleShapes(std::vector<Nif::NiTriShapeCopy>* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel){
|
|
|
|
|
bool useHandles = skel == creaturemodel->getSkeleton();
|
|
|
|
|
shapeNumber = 0;
|
|
|
|
|
|
|
|
|
|
std::vector<Nif::NiTriShapeCopy>::iterator allshapesiter;
|
|
|
|
@ -112,6 +111,9 @@ namespace MWRender{
|
|
|
|
|
|
|
|
|
|
Nif::NiTriShapeCopy& copy = *allshapesiter;
|
|
|
|
|
std::vector<Ogre::Vector3>* allvertices = ©.vertices;
|
|
|
|
|
std::vector<Ogre::Vector3>* allnormals = ©.normals;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//std::set<unsigned int> vertices;
|
|
|
|
|
//std::set<unsigned int> normals;
|
|
|
|
@ -121,8 +123,7 @@ namespace MWRender{
|
|
|
|
|
//std::cout << "Name " << copy.sname << "\n";
|
|
|
|
|
Ogre::HardwareVertexBufferSharedPtr vbuf = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(0);
|
|
|
|
|
Ogre::Real* pReal = static_cast<Ogre::Real*>(vbuf->lock(Ogre::HardwareBuffer::HBL_NORMAL));
|
|
|
|
|
//Ogre::HardwareVertexBufferSharedPtr vbufNormal = creaturemodel->getMesh()->getSubMesh(copy.sname)->vertexData->vertexBufferBinding->getBuffer(1);
|
|
|
|
|
// Ogre::Real* pRealNormal = static_cast<Ogre::Real*>(vbufNormal->lock(Ogre::HardwareBuffer::HBL_NORMAL));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Ogre::Vector3> initialVertices = copy.morph.getInitialVertices();
|
|
|
|
|
//Each shape has multiple indices
|
|
|
|
@ -181,146 +182,76 @@ namespace MWRender{
|
|
|
|
|
std::vector<Nif::NiSkinData::IndividualWeight> inds = iter->second;
|
|
|
|
|
int verIndex = iter->first;
|
|
|
|
|
Ogre::Vector3 currentVertex = (*allvertices)[verIndex];
|
|
|
|
|
Ogre::Vector3 currentNormal = (*allnormals)[verIndex];
|
|
|
|
|
Nif::NiSkinData::BoneInfoCopy* boneinfocopy = &(allshapesiter->boneinfo[inds[0].boneinfocopyindex]);
|
|
|
|
|
Ogre::Bone *bonePtr = 0;
|
|
|
|
|
if(useHandles)
|
|
|
|
|
{
|
|
|
|
|
bonePtr = skel->getBone(boneinfocopy->bonehandle);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
bonePtr = skel->getBone(boneinfocopy->bonename);
|
|
|
|
|
|
|
|
|
|
Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans;
|
|
|
|
|
Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){
|
|
|
|
|
Ogre::Vector3 vecPos;
|
|
|
|
|
Ogre::Quaternion vecRot;
|
|
|
|
|
std::map<Nif::NiSkinData::BoneInfoCopy*, PosAndRot>::iterator result = vecRotPos.find(boneinfocopy);
|
|
|
|
|
|
|
|
|
|
if(result == vecRotPos.end()){
|
|
|
|
|
bonePtr = skel->getBone(boneinfocopy->bonename);
|
|
|
|
|
|
|
|
|
|
vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans;
|
|
|
|
|
vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation;
|
|
|
|
|
|
|
|
|
|
if(useHandles){
|
|
|
|
|
|
|
|
|
|
PosAndRot both;
|
|
|
|
|
both.vecPos = vecPos;
|
|
|
|
|
both.vecRot = vecRot;
|
|
|
|
|
vecPosRot[boneinfocopy->bonehandle] = both;
|
|
|
|
|
}
|
|
|
|
|
vecRotPos[boneinfocopy] = both;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
PosAndRot both = vecPosRot[boneinfocopy->bonehandle];
|
|
|
|
|
PosAndRot both = result->second;
|
|
|
|
|
vecPos = both.vecPos;
|
|
|
|
|
vecRot = both.vecRot;
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ogre::Vector3 absVertPos = (vecPos + vecRot * currentVertex) * inds[0].weight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(std::size_t i = 1; i < inds.size(); i++){
|
|
|
|
|
boneinfocopy = &(allshapesiter->boneinfo[inds[i].boneinfocopyindex]);
|
|
|
|
|
if(useHandles)
|
|
|
|
|
bonePtr = skel->getBone(boneinfocopy->bonehandle);
|
|
|
|
|
else
|
|
|
|
|
bonePtr = skel->getBone(boneinfocopy->bonename);
|
|
|
|
|
vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans;
|
|
|
|
|
vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation;
|
|
|
|
|
result = vecRotPos.find(boneinfocopy);
|
|
|
|
|
|
|
|
|
|
/*if(vecPosRot.find(boneinfocopy->bonehandle) == vecPosRot.end()){
|
|
|
|
|
|
|
|
|
|
if(result == vecRotPos.end()){
|
|
|
|
|
bonePtr = skel->getBone(boneinfocopy->bonename);
|
|
|
|
|
vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.trans;
|
|
|
|
|
vecRot = bonePtr->_getDerivedOrientation() * boneinfocopy->trafo.rotation;
|
|
|
|
|
|
|
|
|
|
if(useHandles){
|
|
|
|
|
PosAndRot both;
|
|
|
|
|
both.vecPos = vecPos;
|
|
|
|
|
both.vecRot = vecRot;
|
|
|
|
|
vecPosRot[boneinfocopy->bonehandle] = both;
|
|
|
|
|
}
|
|
|
|
|
vecRotPos[boneinfocopy] = both;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
PosAndRot both = vecPosRot[boneinfocopy->bonehandle];
|
|
|
|
|
PosAndRot both = result->second;
|
|
|
|
|
vecPos = both.vecPos;
|
|
|
|
|
vecRot = both.vecRot;
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
absVertPos += (vecPos + vecRot * currentVertex) * inds[i].weight;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Ogre::Real* addr = (pReal + 3 * verIndex);
|
|
|
|
|
*addr = absVertPos.x;
|
|
|
|
|
*(addr+1) = absVertPos.y;
|
|
|
|
|
*(addr+2) = absVertPos.z;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
for (unsigned int i = 0; i < boneinfovector.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
Nif::NiSkinData::BoneInfoCopy boneinfo = boneinfovector[i];
|
|
|
|
|
if(skel->hasBone(boneinfo.bonename)){
|
|
|
|
|
Ogre::Bone *bonePtr = skel->getBone(boneinfo.bonename);
|
|
|
|
|
Ogre::Vector3 vecPos = bonePtr->_getDerivedPosition() + bonePtr->_getDerivedOrientation() * boneinfo.trafo.trans;
|
|
|
|
|
Ogre::Quaternion vecRot = bonePtr->_getDerivedOrientation() * boneinfo.trafo.rotation;
|
|
|
|
|
|
|
|
|
|
for (unsigned int j=0; j < boneinfo.weights.size(); j++)
|
|
|
|
|
{
|
|
|
|
|
unsigned int verIndex = boneinfo.weights[j].vertex;
|
|
|
|
|
if(vertices.find(verIndex) == vertices.end())
|
|
|
|
|
{
|
|
|
|
|
Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex];
|
|
|
|
|
absVertPos = absVertPos * boneinfo.weights[j].weight;
|
|
|
|
|
vertices.insert(verIndex);
|
|
|
|
|
Ogre::Real* addr = (pReal + 3 * verIndex);
|
|
|
|
|
*addr = absVertPos.x;
|
|
|
|
|
*(addr+1) = absVertPos.y;
|
|
|
|
|
*(addr+2) = absVertPos.z;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Ogre::Vector3 absVertPos = vecPos + vecRot * allvertices[verIndex];
|
|
|
|
|
absVertPos = absVertPos * boneinfo.weights[j].weight;
|
|
|
|
|
Ogre::Vector3 old = Ogre::Vector3(pReal + 3 * verIndex);
|
|
|
|
|
absVertPos = absVertPos + old;
|
|
|
|
|
Ogre::Real* addr = (pReal + 3 * verIndex);
|
|
|
|
|
*addr = absVertPos.x;
|
|
|
|
|
*(addr+1) = absVertPos.y;
|
|
|
|
|
*(addr+2) = absVertPos.z;
|
|
|
|
|
|
|
|
|
|
//std::cout << "Vertex" << verIndex << "Weight: " << boneinfo.weights[i].weight << "was seen twice\n";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(normals.find(verIndex) == normals.end())
|
|
|
|
|
{
|
|
|
|
|
Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex];
|
|
|
|
|
absNormalsPos = absNormalsPos * boneinfo.weights[j].weight;
|
|
|
|
|
normals.insert(verIndex);
|
|
|
|
|
Ogre::Real* addr = (pRealNormal + 3 * verIndex);
|
|
|
|
|
*addr = absNormalsPos.x;
|
|
|
|
|
*(addr+1) = absNormalsPos.y;
|
|
|
|
|
*(addr+2) = absNormalsPos.z;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Ogre::Vector3 absNormalsPos = vecRot * allnormals[verIndex];
|
|
|
|
|
absNormalsPos = absNormalsPos * boneinfo.weights[j].weight;
|
|
|
|
|
Ogre::Vector3 old = Ogre::Vector3(pRealNormal + 3 * verIndex);
|
|
|
|
|
absNormalsPos = absNormalsPos + old;
|
|
|
|
|
|
|
|
|
|
Ogre::Real* addr = (pRealNormal + 3 * verIndex);
|
|
|
|
|
*addr = absNormalsPos.x;
|
|
|
|
|
*(addr+1) = absNormalsPos.y;
|
|
|
|
|
*(addr+2) = absNormalsPos.z;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
//}
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//} //Comment out
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -329,11 +260,13 @@ namespace MWRender{
|
|
|
|
|
Ogre::Vector3 shapetrans = copy.trafo.trans;
|
|
|
|
|
float shapescale = copy.trafo.scale;
|
|
|
|
|
std::vector<std::string> boneSequence = copy.boneSequence;
|
|
|
|
|
std::vector<std::string>::iterator boneSequenceIter = boneSequence.begin();
|
|
|
|
|
|
|
|
|
|
Ogre::Vector3 transmult;
|
|
|
|
|
Ogre::Quaternion rotmult;
|
|
|
|
|
float scale;
|
|
|
|
|
if(skel->hasBone(*boneSequenceIter)){
|
|
|
|
|
if(boneSequence.size() > 0){
|
|
|
|
|
std::vector<std::string>::iterator boneSequenceIter = boneSequence.begin();
|
|
|
|
|
if(skel->hasBone(*boneSequenceIter)){
|
|
|
|
|
Ogre::Bone *bonePtr = skel->getBone(*boneSequenceIter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -360,6 +293,7 @@ namespace MWRender{
|
|
|
|
|
|
|
|
|
|
//std::cout << "Position: " << transmult << "Rotation: " << rotmult << "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
transmult = shapetrans;
|
|
|
|
@ -392,7 +326,7 @@ namespace MWRender{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
vbuf->unlock();
|
|
|
|
|
//vbufNormal->unlock();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -465,22 +399,18 @@ namespace MWRender{
|
|
|
|
|
|
|
|
|
|
base->getAllAnimationStates()->_notifyDirty();
|
|
|
|
|
//base->_updateAnimation();
|
|
|
|
|
base->_notifyMoved();
|
|
|
|
|
//base->_notifyMoved();
|
|
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < entityparts.size(); i++){
|
|
|
|
|
Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton();
|
|
|
|
|
for(unsigned int i = 0; i < entityparts.size(); i++){
|
|
|
|
|
//Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton();
|
|
|
|
|
|
|
|
|
|
Ogre::Bone* b = skel->getRootBone();
|
|
|
|
|
b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick
|
|
|
|
|
|
|
|
|
|
skel->_updateTransforms();
|
|
|
|
|
// skel->_notifyManualBonesDirty();
|
|
|
|
|
|
|
|
|
|
entityparts[i]->getAllAnimationStates()->_notifyDirty();
|
|
|
|
|
//entityparts[i]->_updateAnimation();
|
|
|
|
|
entityparts[i]->_notifyMoved();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Nif::NiKeyframeData>::iterator iter;
|
|
|
|
|
int slot = 0;
|
|
|
|
|
if(transformations){
|
|
|
|
@ -488,9 +418,7 @@ namespace MWRender{
|
|
|
|
|
if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime())
|
|
|
|
|
{
|
|
|
|
|
slot++;
|
|
|
|
|
//iter++;
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float x;
|
|
|
|
@ -511,7 +439,6 @@ namespace MWRender{
|
|
|
|
|
|
|
|
|
|
timeIndex(time, ttime, tindexI[slot], tindexJ, x);
|
|
|
|
|
|
|
|
|
|
//std::cout << "X: " << x << " X2: " << x2 << "\n";
|
|
|
|
|
Ogre::Vector3 t;
|
|
|
|
|
Ogre::Quaternion r;
|
|
|
|
|
|
|
|
|
@ -526,7 +453,6 @@ namespace MWRender{
|
|
|
|
|
bool bQuats = quats.size() > 0;
|
|
|
|
|
if(bQuats){
|
|
|
|
|
r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true);
|
|
|
|
|
//bone->setOrientation(r);
|
|
|
|
|
}
|
|
|
|
|
skel = base->getSkeleton();
|
|
|
|
|
if(skel->hasBone(iter->getBonename())){
|
|
|
|
@ -539,27 +465,10 @@ namespace MWRender{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
skel->_updateTransforms();
|
|
|
|
|
//skel->_notifyManualBonesDirty();
|
|
|
|
|
base->getAllAnimationStates()->_notifyDirty();
|
|
|
|
|
//base->_updateAnimation();
|
|
|
|
|
base->_notifyMoved();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
for(std::size_t i = 0; i < entityparts.size(); i++){
|
|
|
|
|
skel = entityparts[i]->getSkeleton();
|
|
|
|
|
if(skel->hasBone(iter->getBonename())){
|
|
|
|
|
Ogre::Bone* bone = skel->getBone(iter->getBonename());
|
|
|
|
|
if(bTrans)
|
|
|
|
|
bone->setPosition(t);
|
|
|
|
|
if(bQuats)
|
|
|
|
|
bone->setOrientation(r);
|
|
|
|
|
|
|
|
|
|
skel->_updateTransforms();
|
|
|
|
|
//skel->_notifyManualBonesDirty();
|
|
|
|
|
entityparts[i]->getAllAnimationStates()->_notifyDirty();
|
|
|
|
|
// entityparts[i]->_updateAnimation();
|
|
|
|
|
entityparts[i]->_notifyMoved();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slot++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|