示例#1
0
bool CXModel::LoadXFile(char *file)
{
   if(!m_device) return false;

   CD3DAllocate alh;

   // Load X mesh from a file.
   if(FAILED(D3DXLoadMeshHierarchyFromX(file, D3DXMESH_MANAGED,
      m_device, &alh, NULL, &m_root, &m_animControl))) return false;

   // Record max number of animation sets in the X model.
   if(m_animControl)
      m_numAnimations = m_animControl->GetMaxNumAnimationSets();

   // Setup Bones.
   if(m_root)
      {
         SetupMatrices((stD3DFrameEx*)m_root, NULL);

         m_boneMatrices = new D3DXMATRIX[m_maxBones];
         ZeroMemory(m_boneMatrices, sizeof(D3DXMATRIX)*m_maxBones);

         D3DXFrameCalculateBoundingSphere(m_root, &m_center,
                                          &m_radius);
      }

   // Set initialize animation.
   SetAnimation(0);

   return true;
}
示例#2
0
bool CXFileEntity::Load(const std::string &filename)
{
	// Create our mesh hierarchy class to control the allocation of memory - only used temporarily
	CMeshHierarchy *memoryAllocator=new CMeshHierarchy;

	// To make it easier to find the textures change the current directory to the one containing the .x file
	// First though remember the current one to put it back afterwards
	std::string currentDirectory=CUtility::GetTheCurrentDirectory();

	std::string xfilePath;
	CUtility::SplitPath(filename,&xfilePath,&m_filename);

	SetCurrentDirectory(xfilePath.c_str());

	// This is the function that does all the .x file loading. We provide a pointer to an instance of our 
	// memory allocator class to handle memory allocationm during the frame and mesh loading
	HRESULT hr = D3DXLoadMeshHierarchyFromX(filename.c_str(), D3DXMESH_MANAGED, m_d3dDevice, 
		memoryAllocator, NULL, &m_frameRoot, &m_animController);

	delete memoryAllocator;
	memoryAllocator=0;

	SetCurrentDirectory(currentDirectory.c_str());
	
	if (FAILED(hr))
		return false; 

	// if the x file contains any animation remember how many sets there are
	if(m_animController)
		m_numAnimationSets = m_animController->GetMaxNumAnimationSets();

	// Bones for skining
	if(m_frameRoot)
	{
		// Set the bones up
		SetupBoneMatrices((D3DXFRAME_EXTENDED*)m_frameRoot, NULL);

		// Create the bone matrices array for use during FrameMove to hold the final transform
		m_boneMatrices  = new D3DXMATRIX[m_maxBones];
		ZeroMemory(m_boneMatrices, sizeof(D3DXMATRIX)*m_maxBones);

		// Calculate the Bounding Sphere for this model (used in CalculateInitialViewMatrix to position camera correctly)
		D3DXFrameCalculateBoundingSphere(m_frameRoot, &m_sphereCentre, &m_sphereRadius);
	}

	m_firstMesh->MeshData.pMesh->GetVertexBuffer(&vb.vb);
	m_firstMesh->MeshData.pMesh->GetIndexBuffer(&ib.ib);

	D3DVERTEXELEMENT9 pDecl[MAX_FVF_DECL_SIZE];
	m_firstMesh->MeshData.pMesh->GetDeclaration(pDecl);
	renderSystem->CreateVertexDeclaration(&pDecl[0],&vb.declaration);
	// Получение данных о количестве вершин, индексов и полигонов
	dwNumVerticies	= m_firstMesh->MeshData.pMesh->GetNumVertices();
	dwNumIndecies	= m_firstMesh->MeshData.pMesh->GetNumFaces()*3;
	dwNumFaces		= m_firstMesh->MeshData.pMesh->GetNumFaces();
	vb.vertexSize = (short)m_firstMesh->MeshData.pMesh->GetNumBytesPerVertex();
	return true;
}
示例#3
0
INT CLcXSkinSrc::Create(void* p1, void* p2, void*, void* )
{
	HRESULT				hr;
	CLcXSkinAlloc		Alloc(this);

	char* sFile			= NULL;
	
	m_pDevice	= (LPDIRECT3DDEVICE9)p1;
	sFile		= (char*)p2;

	::strcpy(m_sFile, sFile);
	

	WCHAR* wFile = new WCHAR[strlen(m_sFile)+1];
	DXUtil_ConvertAnsiStringToWideCch(wFile, m_sFile, strlen(m_sFile)+1);

	hr = D3DXLoadMeshHierarchyFromX(wFile
								, D3DXMESH_MANAGED
								, m_pDevice
								, &Alloc
								, NULL
								, (LPD3DXFRAME*)&m_pFrameRoot
								, &m_pAC);
	delete[] wFile;

	if (FAILED(hr))
		return hr;
	
	
	hr = FindBones(m_pFrameRoot);
	if (FAILED(hr))
		return hr;
	
	hr = D3DXFrameCalculateBoundingSphere((const D3DXFRAME*)m_pFrameRoot, &m_ObjectCenter, &m_ObjectRadius);
	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;
}