HRESULT SkinnedMesh::SetupBoneMatrixPointers( LPD3DXFRAME pFrame ) { // 메시의 본 포인터 설정 // 해당 프레임에 있는 메시 컨테이너와 자식 형제 모두 다?? HRESULT hr; if ( pFrame->pMeshContainer != NULL ) { hr = SetupBoneMatrixPointersOnMesh( pFrame->pMeshContainer ); if ( FAILED( hr ) ) return hr; } if ( pFrame->pFrameSibling != NULL ) { hr = SetupBoneMatrixPointers( pFrame->pFrameSibling ); if ( FAILED( hr ) ) return hr; } if ( pFrame->pFrameFirstChild != NULL ) { hr = SetupBoneMatrixPointers( pFrame->pFrameFirstChild ); if ( FAILED( hr ) ) return hr; } return S_OK; }
HRESULT CDexModelXAni::SetupBoneMatrixPointers(LPD3DXFRAME pFrame) { HRESULT hr; if (pFrame->pMeshContainer != NULL) { hr = SetupBoneMatrixPointersOnMesh(pFrame->pMeshContainer); if (FAILED(hr)) return hr; } if (pFrame->pFrameSibling != NULL) { hr = SetupBoneMatrixPointers(pFrame->pFrameSibling); if (FAILED(hr)) return hr; } if (pFrame->pFrameFirstChild != NULL) { hr = SetupBoneMatrixPointers(pFrame->pFrameFirstChild); if (FAILED(hr)) return hr; } return S_OK; }
HRESULT CAnimationModel::SetupBoneMatrixPointers( LPD3DXFRAME pFrame ) { HRESULT hr = S_OK; LPD3DXMESHCONTAINER pMeshContainer = NULL; pMeshContainer = pFrame->pMeshContainer; while( NULL != pMeshContainer ) { hr = SetupBoneMatrixPointersOnMesh( pMeshContainer ); CHECK_FAILED( hr ); pMeshContainer = pMeshContainer->pNextMeshContainer; } if( NULL != pFrame->pFrameSibling ) { SetupBoneMatrixPointers( pFrame->pFrameSibling ); CHECK_FAILED( hr ); } if( NULL != pFrame->pFrameFirstChild ) { SetupBoneMatrixPointers( pFrame->pFrameFirstChild ); CHECK_FAILED( hr ); } return hr; }
//-------------------------------------------------------------------------------------- // This function loads the mesh and LDPRT data. It also centers and optimizes the // mesh for the graphics card's vertex cache. //-------------------------------------------------------------------------------------- HRESULT LoadLDPRTData( IDirect3DDevice9* pd3dDevice, WCHAR* strFilePrefixIn ) { WCHAR str[MAX_PATH]; WCHAR strFileName[MAX_PATH]; WCHAR strFilePrefix[MAX_PATH]; HRESULT hr; // Load the mesh with D3DX and get back a ID3DXMesh*. For this // sample we'll ignore the X file's embedded materials since we know // exactly the model we're loading. See the mesh samples such as // "OptimizedMesh" for a more generic mesh loading example. swprintf_s( strFilePrefix, MAX_PATH, TEXT( "%s" ), strFilePrefixIn ); strFilePrefix[MAX_PATH - 1] = 0; swprintf_s( strFileName, MAX_PATH, TEXT( "%s.x" ), strFilePrefix ); strFileName[MAX_PATH - 1] = 0; V_RETURN( DXUTFindDXSDKMediaFileCch( str, MAX_PATH, strFileName ) ); CAllocateHierarchy Alloc; // Delete existing resources if( g_pFrameRoot ) { D3DXFrameDestroy( g_pFrameRoot, &Alloc ); g_pFrameRoot = NULL; } // Create hierarchy V_RETURN( D3DXLoadMeshHierarchyFromX( str, D3DXMESH_MANAGED, pd3dDevice, &Alloc, NULL, &g_pFrameRoot, &g_pAnimController ) ); SetupBoneMatrixPointers( g_pFrameRoot, g_pFrameRoot ); return S_OK; }
bool CDexModelXAni::LoadModelFile(const char* filename) { HRESULT hr; int64 mseconds = getTime()->GetTotalMillSeconds(); //从.X文件加载层次框架和动画数据 hr = D3DXLoadMeshHierarchyFromX(filename, D3DXMESH_MANAGED, DexGameEngine::getEngine()->GetDevice(), m_pAlloc, NULL, &m_pFrameRoot, &m_pAnimController); //最后一个参数:动画控制器 if (FAILED(hr)) return false; //建立各级框架的组合变换矩阵 SetupBoneMatrixPointers(m_pFrameRoot); int index = 4; if(m_pAnimController != NULL) { m_pAnimController->GetAnimationSet(index, &m_pAnimationSet1); m_pAnimController->SetTrackAnimationSet(0, m_pAnimationSet1); m_pAnimController->ResetTime(); } getLog()->BeginLog(); getLog()->Log(log_ok, "加载animation模型%s成功!用时:%d ms\n",filename, getTime()->GetTotalMillSeconds() - mseconds); getLog()->EndLog(); return true; }
void SkinnedMesh::SetupBoneMatrixPointers(Bone *bone) { if (bone->pMeshContainer != NULL) { BoneMesh *boneMesh = (BoneMesh*)bone->pMeshContainer; if (boneMesh->pSkinInfo != NULL) { int NumBones = boneMesh->pSkinInfo->GetNumBones(); boneMesh->boneMatrixPtrs = new D3DXMATRIX*[NumBones]; for (int i=0; i < NumBones; i++) { Bone *b = (Bone*)D3DXFrameFind(m_pRootBone, boneMesh->pSkinInfo->GetBoneName(i)); if (b != NULL)boneMesh->boneMatrixPtrs[i] = &b->CombinedTransformationMatrix; else boneMesh->boneMatrixPtrs[i] = NULL; } } } if (bone->pFrameSibling != NULL)SetupBoneMatrixPointers((Bone*)bone->pFrameSibling); if (bone->pFrameFirstChild != NULL)SetupBoneMatrixPointers((Bone*)bone->pFrameFirstChild); }
void SKINNEDMESH::Load(char fileName[], IDirect3DDevice9 *Dev) { m_pDevice = Dev; BONE_HIERARCHY boneHierarchy; D3DXLoadMeshHierarchyFromX(fileName, D3DXMESH_MANAGED, m_pDevice, &boneHierarchy, NULL, &m_pRootBone, &m_pAnimControl); SetupBoneMatrixPointers((BONE*)m_pRootBone); }
void SkinnedMesh::Load(char fileName[]) { BoneHierarchyLoader boneHierarchy; D3DXLoadMeshHierarchyFromX(fileName, D3DXMESH_MANAGED, g_pDevice, &boneHierarchy, NULL, &m_pRootBone, NULL); SetupBoneMatrixPointers((Bone*)m_pRootBone); //Update all the bones D3DXMATRIX i; D3DXMatrixIdentity(&i); UpdateMatrices((Bone*)m_pRootBone, &i); //Create Sphere D3DXCreateSphere(g_pDevice, 0.02f, 10, 10, &m_pSphereMesh, NULL); }
HRESULT CAnimationModel::InitDeviceObjects(LPDIRECT3DDEVICE9 pd3dDevice) { HRESULT hr = S_OK; if( NULL == pd3dDevice ) return E_INVALIDARG; m_pd3dDevice = pd3dDevice; m_pd3dDevice->AddRef(); // 커스텀 애니메신컨트롤러 를 생성 m_pAniController = new CAnimationController; // X파이을 읽어들여 애니메이션 가능한 모델을 만든다. if( NULL == m_pXFileName ) return E_FAIL; CAllocateHierarchy alloc; alloc.SetCreationFlag( TRUE ); alloc.SetDwFrame( 0 ); alloc.SetDwMeshContainer( 0 ); alloc.SetFrameVector( &vFrame ); alloc.SetMeshContainerVector( &vMeshContainer ); hr = D3DXLoadMeshHierarchyFromX( m_pXFileName , D3DXMESH_MANAGED , m_pd3dDevice , &alloc , NULL , &m_pFrameRoot , &m_pAniController->m_pAniController ); CHECK_FAILED( hr ); hr = SetupBoneMatrixPointers( m_pFrameRoot ); CHECK_FAILED( hr ); m_pAniController->InitDeviceObjects( m_pd3dDevice ); return hr; }
HRESULT MoonSkinmesh::InitDeviceObjects() { HRESULT hr; AllocateHierarchy Alloc(this); string strMeshPath = MODEL_DIR(""); strMeshPath += _strMeshname; strMeshPath += "\\"; strMeshPath += _strMeshname; strMeshPath += ".x"; hr = D3DXLoadMeshHierarchyFromX(strMeshPath.c_str(), D3DXMESH_MANAGED, _pDevice, &Alloc, NULL, &_pFrameRoot, &_pAnimController); if(FAILED(hr)) return hr; hr = SetupBoneMatrixPointers(_pFrameRoot); if(FAILED(hr)) return hr; return S_OK; }
bool SkinnedMesh::Init( std::wstring path ) { AllocateHierarchy Alloc; DWORD dwShaderFlags = D3DXFX_NOT_CLONEABLE; #if defined( DEBUG ) || defined( _DEBUG ) dwShaderFlags |= D3DXSHADER_DEBUG; #endif #ifdef DEBUG_VS dwShaderFlags |= D3DXSHADER_FORCE_VS_SOFTWARE_NOOPT; #endif #ifdef DEBUG_PS dwShaderFlags |= D3DXSHADER_FORCE_PS_SOFTWARE_NOOPT; #endif LPDIRECT3DDEVICE9 pD3DDevice = DDRenderer::GetInstance()->GetDevice(); WCHAR str[MAX_PATH] = L".\\Resources\\3DModel\\SkinnedMesh.fx"; // shader 파일 읽어서 등록 if ( FAILED( D3DXCreateEffectFromFile( pD3DDevice, str, NULL, NULL, dwShaderFlags, NULL, &m_pEffect, NULL ) ) ) { assert( false ); return false; } // shader 파일 이름 생성 std::wstring xfilePath = L".\\Resources\\3DModel\\"; xfilePath.append( path ); // 메시 불러오기 // 애니메이션 계층 구조 만들기 if ( FAILED( D3DXLoadMeshHierarchyFromX( xfilePath.c_str(), D3DXMESH_MANAGED, pD3DDevice, &Alloc, NULL, &m_pFrameRoot, &m_pAnimController ) ) ) { assert( false ); return false; } // 조심해! // 예제에서는 m_pBoneMatrices를 전역 변수로 사용하므로 // AllocateHierarchy에서 할당했으나 이제는 여기서 해준다. // 그런데 사이즈는 어떻게 가져오지... 아무튼 지금 애니메이션 안 나오는 문제는 여기 아님 delete[] m_pBoneMatrices; m_pBoneMatrices = new D3DXMATRIXA16[64]; if ( m_pBoneMatrices == nullptr ) { assert( false ); return false; } // 본 매트릭스 생성 if ( FAILED( SetupBoneMatrixPointers( m_pFrameRoot ) ) ) { assert( false ); return false; } if ( FAILED( D3DXFrameCalculateBoundingSphere( m_pFrameRoot, &m_vObjectCenter, &m_fObjectRadius ) ) ) { assert( false ); return false; } // Obtain the behavior flags D3DDEVICE_CREATION_PARAMETERS cp; pD3DDevice->GetCreationParameters( &cp ); m_dwBehaviorFlags = cp.BehaviorFlags; return true; }