Advertisement
expired6978

BodyFork

May 11th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1.         if (!it.second.HasMorphs(refr))
  2.             continue;
  3.  
  4.         BSFixedString nodeName = it.first.data;
  5.         NiGeometry * triShape = rootNode->GetAsNiGeometry();
  6.         NiAVObject * bodyNode = triShape ? triShape : rootNode->GetObjectByName(&nodeName.data);
  7.         if (bodyNode)
  8.         {
  9.             NiGeometry * bodyGeometry = bodyNode->GetAsNiGeometry();
  10.             if (bodyGeometry)
  11.             {
  12.                 NiGeometryData * geometryData = niptr_cast<NiGeometryData>(bodyGeometry->m_spModelData);
  13.                 NiSkinInstance * skinInstance = niptr_cast<NiSkinInstance>(bodyGeometry->m_spSkinInstance);
  14.                 if (geometryData && skinInstance) {
  15.                     NiSkinPartition * skinPartition = niptr_cast<NiSkinPartition>(skinInstance->m_spSkinPartition);
  16.                     if (skinPartition) {
  17.                         NiGeometryData * targetShapeData = NULL;
  18.                         CALL_MEMBER_FN(geometryData, DeepCopy)((NiObject **)&targetShapeData);
  19.  
  20.                         NiSkinPartition * newPartition = NULL;
  21.                         CALL_MEMBER_FN(skinPartition, DeepCopy)((NiObject **)&newPartition);
  22.  
  23.                         NiSkinInstance * newSkinInstance = CALL_MEMBER_FN(skinInstance, Copy)();
  24.                         newSkinInstance->m_spSkinPartition = newPartition;
  25.                         newPartition->DecRef();
  26.  
  27.                         if (targetShapeData) {
  28.                             BSFaceGenBaseMorphExtraData * bodyData = (BSFaceGenBaseMorphExtraData *)bodyGeometry->GetExtraData("FOD");
  29.                             if (bodyData) {
  30.                                 bodyData->IncRef();
  31.                                 // Undo old morphs for this trishape
  32.                                 for (UInt16 i = 0; i < targetShapeData->m_usVertices; i++) {
  33.                                     if (!isAttaching)
  34.                                         targetShapeData->m_pkVertex[i] -= bodyData->vertexData[i];
  35.                                     bodyData->vertexData[i] = NiPoint3(0, 0, 0);
  36.                                 }
  37.                                 bodyData->DecRef();
  38.                             }
  39.  
  40.                             // No old morphs, add one
  41.                             if (!bodyData) {
  42.                                 bodyData = BSFaceGenBaseMorphExtraData::Create(geometryData, false);
  43.                                 bodyGeometry->AddExtraData(bodyData);
  44.                             }
  45.  
  46.                             bodyGeometry->SetModelData(targetShapeData);
  47.                             bodyGeometry->SetSkinInstance(newSkinInstance);
  48.                             targetShapeData->DecRef();
  49.  
  50.                             if (bodyData) {
  51.                                 bodyData->IncRef();
  52.                                 it.second.ApplyMorphs(refr, targetShapeData->m_usVertices, targetShapeData->m_pkVertex, bodyData->vertexData);
  53.                                 bodyData->DecRef();
  54.                             }
  55.  
  56.                             targetShapeData->m_usDirtyFlags = 0x0001;
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement