Exemple #1
0
// Creates a DirectX specific material from an imported material
bool CMesh::CreateMaterialDX
(
	const SMeshMaterial& material,
	SMeshMaterialDX*     materialDX
)
{
	// Load shaders for render method
	materialDX->renderMethod = material.renderMethod;
	if (!LoadMethod( materialDX->renderMethod ))
	{
		return false;
	}

	// Copy colours and shininess from material
	materialDX->diffuseColour = D3DXCOLOR( material.diffuseColour.r, material.diffuseColour.g, 
	                                       material.diffuseColour.b, material.diffuseColour.a );
	materialDX->specularColour = D3DXCOLOR( material.specularColour.r, material.specularColour.g, 
	                                        material.specularColour.b, material.specularColour.a );
	materialDX->specularPower = material.specularPower;

	// Load material textures
	materialDX->numTextures = material.numTextures;
	for (TUInt32 texture = 0; texture < material.numTextures; ++texture)
	{
		string fullFileName = MediaFolder + material.textureFileNames[texture];
		if (FAILED(D3DXCreateTextureFromFile( g_pd3dDevice, fullFileName.c_str(),
											  &materialDX->textures[texture] )))
		{
			string errorMsg = "Error loading texture " + fullFileName;
			SystemMessageBox( errorMsg.c_str(), "CMesh Error" );
			return false;
		}
	}
	return true;
}
Exemple #2
0
	bool VirtualAddress::Reserve(uint section){
		if(_Handle) ::VirtualFree(_Handle,0,MEM_FREE);
		_Size = section*0x10000;
		_Handle = ::VirtualAlloc(0,_Size,MEM_RESERVE,PAGE_READWRITE);
		if(_Handle==0){
			_Size = 0;
#ifdef _DEBUG
			SystemMessageBox(0,L"VirtualAddress::Reserve");
#endif
			return 0;
		}
		else return 1;
	}
// Initialises the given render method, returns true on success
bool PrepareMethod( ERenderMethod method )
{
	// Initialise the technique for this method if it hasn't been already
	if (!RenderMethods[method].technique)
	{
		RenderMethods[method].technique = Effect->GetTechniqueByName( RenderMethods[method].techniqueName.c_str() );
		if (!RenderMethods[method].technique->IsValid())
		{
			string errorMsg = "Error selecting technique " + RenderMethods[method].techniqueName;
			SystemMessageBox( errorMsg.c_str(), "Shader Error" );
			return false;
		}
	}

	return true;
}
// Display the exception details to the user
void CFatalException::Display() const
{
	// Append all information into a single text string
	string sMessage = m_sDescription + ksNewline + ksNewline;

	// Strip any path from filename
	sMessage += "File: " + LastDelimitedSubstr( m_sFileName, ksPathSeparator );

	// If line number -ve then unknown line number
	if (m_iLineNum >= 0)
	{
		sMessage += ",  Line: " + ToString( m_iLineNum );
	}
	sMessage += ksNewline + ksNewline + "Call stack: " + m_sCallStack;

	SystemMessageBox( sMessage, "Fatal Exception" );
}
Exemple #5
0
// Create the model from an X-File, returns true on success
bool CMesh::Load( const string& fileName )
{
	// Create a X-File import helper class
	CImportXFile importFile;

	// Add media folder path
	string fullFileName = MediaFolder + fileName;

	// Check that the given file is an X-file
	if (!importFile.IsXFile( fullFileName ))
	{
		return false;
	}

	// Import the file, return on failure
	EImportError error = importFile.ImportFile( fullFileName );
	if (error != kSuccess)
	{
		if (error == kFileError)
		{
			string errorMsg = "Error loading mesh " + fullFileName;
			SystemMessageBox( errorMsg.c_str(), "Mesh Error" );
		}
		return false;
	}

	// Release any existing geometry
	if (m_HasGeometry)
	{
		ReleaseResources();
	}

	// Get node data from import class
	m_NumNodes = importFile.GetNumNodes();
	m_Nodes = new SMeshNode[m_NumNodes];
	if (!m_Nodes)
	{
		return false;
	}
	for (TUInt32 node = 0; node < m_NumNodes; ++node)
	{
		importFile.GetNode( node, &m_Nodes[node] );
	}

	// Get submesh data from import class - convert to DirectX data for rendering
	// but retain original data for easy access to vertices / faces
	TUInt32 requiredSubMeshes = importFile.GetNumSubMeshes();
	m_SubMeshes = new SSubMesh[requiredSubMeshes];
	m_SubMeshesDX = new SSubMeshDX[requiredSubMeshes];
	if (!m_SubMeshes || !m_SubMeshesDX)
	{
		ReleaseResources();
		return false;
	}
	for (m_NumSubMeshes = 0; m_NumSubMeshes < requiredSubMeshes; ++m_NumSubMeshes)
	{
		// Determine if the render method for this mesh needs tangents
		ERenderMethod meshMethod = importFile.GetSubMeshRenderMethod( m_NumSubMeshes );
		bool needTangents = RenderMethodUsesTangents( meshMethod );

		importFile.GetSubMesh( m_NumSubMeshes, &m_SubMeshes[m_NumSubMeshes], needTangents );
		if (!CreateSubMeshDX( m_SubMeshes[m_NumSubMeshes], &m_SubMeshesDX[m_NumSubMeshes] ))
		{
			ReleaseResources();
			return false;
		}
	}

	// Get material data from import class, also load textures
	TUInt32 requiredMaterials = importFile.GetNumMaterials();
	m_Materials = new SMeshMaterialDX[requiredMaterials];
	if (!m_Materials)
	{
		ReleaseResources();
		return false;
	}
	for (m_NumMaterials = 0; m_NumMaterials < requiredMaterials; ++m_NumMaterials)
	{
		SMeshMaterial importMaterial; 
		importFile.GetMaterial( m_NumMaterials, &importMaterial );
		if (!CreateMaterialDX( importMaterial, &m_Materials[m_NumMaterials] ))
		{
			ReleaseResources();
			return false;
		}
	}

	// Geometry pre-processing - just calculating bounding box in this example
	if (!PreProcess())
	{
		ReleaseResources();
		return false;
	}

	m_HasGeometry = true;
	return true;
}