📄 nvworldtree.cpp
字号:
while (SUCCEEDED(pxofobjCur->GetNextObject(&pxofChild)))
{
// Query the child for it's FileData
hr = pxofChild->QueryInterface(IID_IDirectXFileData,
(LPVOID *)&pxofobjChild);
if (SUCCEEDED(hr))
{
hr = LoadXFileFrames(pD3DDevice, pxofobjChild, options, pframeCur);
if (FAILED(hr))
goto e_Exit;
SAFE_RELEASE(pxofobjChild);
}
SAFE_RELEASE(pxofChild);
}
}
e_Exit:
SAFE_RELEASE(pxofobjChild);
SAFE_RELEASE(pxofChild);
return hr;
}
HRESULT NVWorldTree::LoadXFileAnimation(LPDIRECT3DDEVICE8 pD3DDevice, LPDIRECTXFILEDATA pxofobjCur, DWORD options, NVWorldFrame* pframeParent)
{
HRESULT hr = S_OK;
NVXFileRotateKey *pFileRotateKey;
NVXFileScaleKey *pFileScaleKey;
NVXFilePositionKey *pFilePosKey;
NVXFileMatrixKey *pFileMatrixKey;
NVWorldFrame *pframeCur;
LPDIRECTXFILEDATA pxofobjChild = NULL;
LPDIRECTXFILEOBJECT pxofChild = NULL;
LPDIRECTXFILEDATAREFERENCE pxofobjChildRef = NULL;
const GUID *type;
DWORD dwSize;
PBYTE pData;
DWORD dwKeyType;
DWORD cKeys;
DWORD iKey;
DWORD cchName;
std::string strAnimationName;
hr = pxofobjCur->GetName(NULL, &cchName);
if (FAILED(hr))
{
NVASSERT(0,"Couldn't find animation name");
goto e_Exit;
}
strAnimationName.resize(cchName);
hr = pxofobjCur->GetName(&strAnimationName[0], &cchName);
if (FAILED(hr))
{
NVASSERT(0,"Couldn't find animation name");
goto e_Exit;
}
pframeCur = new NVWorldFrame(this, strAnimationName.c_str());
if (pframeCur == NULL)
{
hr = E_OUTOFMEMORY;
goto e_Exit;
}
pframeCur->m_bAnimationFrame = true;
pframeParent->AddChildFrame(pframeCur);
m_AnimationFrames.push_back(pframeCur);
// Enumerate child objects.
// Child object can be data, data reference or binary.
// Use QueryInterface() to find what type of object a child is.
while (SUCCEEDED(pxofobjCur->GetNextObject(&pxofChild)))
{
// Query the child for it's FileDataReference
hr = pxofChild->QueryInterface(IID_IDirectXFileDataReference,
(LPVOID *)&pxofobjChildRef);
if (SUCCEEDED(hr))
{
hr = pxofobjChildRef->Resolve(&pxofobjChild);
if (SUCCEEDED(hr))
{
hr = pxofobjChild->GetType(&type);
if (FAILED(hr))
goto e_Exit;
if( TID_D3DRMFrame == *type )
{
if (pframeCur->m_pframeToAnimate != NULL)
{
hr = E_INVALIDARG;
goto e_Exit;
}
hr = pxofobjChild->GetName(NULL, &cchName);
if (FAILED(hr))
{
NVASSERT(0,"Couldn't find frame name");
goto e_Exit;
}
std::string strFrameName;
strFrameName.resize(cchName);
hr = pxofobjChild->GetName(&strFrameName[0], &cchName);
if (FAILED(hr))
{
NVASSERT(0,"Couldn't find frame name");
goto e_Exit;
}
pframeCur->m_pframeToAnimate = FindFrame(strFrameName.c_str());
if (pframeCur->m_pframeToAnimate == NULL)
{
hr = E_INVALIDARG;
goto e_Exit;
}
}
SAFE_RELEASE(pxofobjChild);
}
SAFE_RELEASE(pxofobjChildRef);
}
else
{
// Query the child for it's FileData
hr = pxofChild->QueryInterface(IID_IDirectXFileData,
(LPVOID *)&pxofobjChild);
if (SUCCEEDED(hr))
{
hr = pxofobjChild->GetType(&type);
if (FAILED(hr))
goto e_Exit;
if ( TID_D3DRMFrame == *type )
{
hr = LoadXFileFrames(pD3DDevice, pxofobjChild, options, pframeCur);
if (FAILED(hr))
goto e_Exit;
}
else if ( TID_D3DRMAnimationOptions == *type )
{
//ParseAnimOptions(pChildData,pParentFrame);
//i=2;
}
else if ( TID_D3DRMAnimationKey == *type )
{
hr = pxofobjChild->GetData( NULL, &dwSize, (PVOID*)&pData );
if (FAILED(hr))
goto e_Exit;
dwKeyType = ((DWORD*)pData)[0];
cKeys = ((DWORD*)pData)[1];
if (dwKeyType == 0)
{
if (!pframeCur->m_RotateKeys.empty())
{
hr = E_INVALIDARG;
goto e_Exit;
}
//NOTE x files are w x y z and QUATERNIONS are x y z w
pFileRotateKey = (NVXFileRotateKey*)(pData + (sizeof(DWORD) * 2));
for (iKey = 0;iKey < cKeys; iKey++)
{
NVRotateKey RotateKey;
RotateKey.dwTime = pFileRotateKey->dwTime;
RotateKey.quatRotate.x = pFileRotateKey->x;
RotateKey.quatRotate.y = pFileRotateKey->y;
RotateKey.quatRotate.z = pFileRotateKey->z;
RotateKey.quatRotate.w = pFileRotateKey->w;
pframeCur->m_RotateKeys.push_back(RotateKey);
pFileRotateKey++;
}
}
else if (dwKeyType == 1)
{
if (!pframeCur->m_ScaleKeys.empty())
{
hr = E_INVALIDARG;
goto e_Exit;
}
pFileScaleKey = (NVXFileScaleKey*)(pData + (sizeof(DWORD) * 2));
for (iKey = 0;iKey < cKeys; iKey++)
{
NVScaleKey ScaleKey;
ScaleKey.dwTime = pFileScaleKey->dwTime;
ScaleKey.vScale = pFileScaleKey->vScale;
pframeCur->m_ScaleKeys.push_back(ScaleKey);
pFileScaleKey++;
}
}
else if (dwKeyType == 2)
{
if (!pframeCur->m_PositionKeys.empty())
{
hr = E_INVALIDARG;
goto e_Exit;
}
pFilePosKey = (NVXFilePositionKey*)(pData + (sizeof(DWORD) * 2));
for (iKey = 0;iKey < cKeys; iKey++)
{
NVPositionKey PositionKey;
PositionKey.dwTime = pFilePosKey->dwTime;
PositionKey.vPos = pFilePosKey->vPos;
pframeCur->m_PositionKeys.push_back(PositionKey);
pFilePosKey++;
}
}
else if (dwKeyType == 4)
{
if (!pframeCur->m_MatrixKeys.empty())
{
hr = E_INVALIDARG;
goto e_Exit;
}
pFileMatrixKey = (NVXFileMatrixKey*)(pData + (sizeof(DWORD) * 2));
for (iKey = 0;iKey < cKeys; iKey++)
{
NVMatrixKey MatrixKey;
MatrixKey.dwTime = pFileMatrixKey->dwTime;
MatrixKey.mat = pFileMatrixKey->mat;
pframeCur->m_MatrixKeys.push_back(MatrixKey);
pFileMatrixKey ++;
}
}
else
{
hr = E_INVALIDARG;
goto e_Exit;
}
}
SAFE_RELEASE(pxofobjChild);
}
}
SAFE_RELEASE(pxofChild);
}
e_Exit:
SAFE_RELEASE(pxofobjChild);
SAFE_RELEASE(pxofChild);
SAFE_RELEASE(pxofobjChildRef);
return hr;
}
HRESULT NVWorldTree::LoadXFileAnimationSet(LPDIRECT3DDEVICE8 pD3DDevice, LPDIRECTXFILEDATA pxofobjCur, DWORD options, NVWorldFrame* pframeParent)
{
NVWorldFrame *pframeCur;
const GUID *type;
HRESULT hr = S_OK;
LPDIRECTXFILEDATA pxofobjChild = NULL;
LPDIRECTXFILEOBJECT pxofChild = NULL;
DWORD cchName;
std::string strAnimationName;
hr = pxofobjCur->GetName(NULL, &cchName);
if (FAILED(hr))
{
NVASSERT(0,"Couldn't find animation name");
goto e_Exit;
}
strAnimationName.resize(cchName);
hr = pxofobjCur->GetName(&strAnimationName[0], &cchName);
if (FAILED(hr))
{
NVASSERT(0,"Couldn't find animation name");
goto e_Exit;
}
pframeCur = new NVWorldFrame(this, strAnimationName.c_str());
if (pframeCur == NULL)
{
hr = E_OUTOFMEMORY;
goto e_Exit;
}
pframeCur->m_bAnimationFrame = true;
pframeParent->AddChildFrame(pframeCur);
// Enumerate child objects.
// Child object can be data, data reference or binary.
// Use QueryInterface() to find what type of object a child is.
while (SUCCEEDED(pxofobjCur->GetNextObject(&pxofChild)))
{
// Query the child for it's FileData
hr = pxofChild->QueryInterface(IID_IDirectXFileData,
(LPVOID *)&pxofobjChild);
if (SUCCEEDED(hr))
{
hr = pxofobjChild->GetType(&type);
if (FAILED(hr))
goto e_Exit;
if( TID_D3DRMAnimation == *type )
{
hr = LoadXFileAnimation(pD3DDevice, pxofobjChild, options, pframeCur);
if (FAILED(hr))
goto e_Exit;
}
SAFE_RELEASE(pxofobjChild);
}
SAFE_RELEASE(pxofChild);
}
e_Exit:
SAFE_RELEASE(pxofobjChild);
SAFE_RELEASE(pxofChild);
return hr;
}
}; // namespace nv_objects
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -