示例#1
0
bool Model :: Load(std :: string name,ModelLoader &loader,Texture &tex)
{
	// attempt to load the file
	if(!loader.Load(name))
		return false;

	// do we have to clean up?
	if(frames)
		this->Clear();

	// get the model information
	int		modelframes=loader.GetNumFrames();
	int		nummeshes=loader.GetNumMeshes();
	float	modelfps=(float)loader.GetFPS();

	// tidy up the values
	if(modelframes<=0)
		return false;
	if(modelfps==0.0f)
		modelfps=1.0f;

	// and setup our model
	if(!this->Setup(modelframes,modelfps))
		return false;
	
	// now set up the frames
	for(int ct=0; ct<numframes; ct++)
	{
		// setup the frame
		if(!frames[ct].Setup(nummeshes))
		{
			this->Clear();
			return false;
		}
		
		// add the meshes
		for(int ct2=0; ct2<nummeshes; ct2++)
		{
			Mesh msh;	// temporary mesh
			
			// get the mesh
			if(!loader.Get(ct,ct2,&tex,&msh))
				return false;

			// and set it to the frame
			frames[ct].SetMesh(ct2,msh);
		}
	}

	// success
	return true;
}
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void EffectImplemented::ReloadResources( const EFK_CHAR* materialPath )
{
	UnloadResources();

	const EFK_CHAR* matPath = materialPath != NULL ? materialPath : m_materialPath.c_str();
	
	Setting* loader = GetSetting();

	{
		TextureLoader* textureLoader = loader->GetTextureLoader();
		if( textureLoader != NULL )
		{
			for( int32_t ind = 0; ind < m_ImageCount; ind++ )
			{
				EFK_CHAR fullPath[512];
				PathCombine( fullPath, matPath, m_ImagePaths[ ind ] );
				m_pImages[ind] = textureLoader->Load( fullPath, TextureType::Color );
			}
		}
	}

	{
		TextureLoader* textureLoader = loader->GetTextureLoader();
		if (textureLoader != NULL)
		{
			for (int32_t ind = 0; ind < m_normalImageCount; ind++)
			{
				EFK_CHAR fullPath[512];
				PathCombine(fullPath, matPath, m_normalImagePaths[ind]);
				m_normalImages[ind] = textureLoader->Load(fullPath, TextureType::Normal);
			}
		}

	}
		{
			TextureLoader* textureLoader = loader->GetTextureLoader();
			if (textureLoader != NULL)
			{
				for (int32_t ind = 0; ind < m_distortionImageCount; ind++)
				{
					EFK_CHAR fullPath[512];
					PathCombine(fullPath, matPath, m_distortionImagePaths[ind]);
					m_distortionImages[ind] = textureLoader->Load(fullPath, TextureType::Distortion);
				}
			}
		}

	

	{
		SoundLoader* soundLoader = loader->GetSoundLoader();
		if( soundLoader != NULL )
		{
			for( int32_t ind = 0; ind < m_WaveCount; ind++ )
			{
				EFK_CHAR fullPath[512];
				PathCombine( fullPath, matPath, m_WavePaths[ ind ] );
				m_pWaves[ind] = soundLoader->Load( fullPath );
			}
		}
	}

	{
		ModelLoader* modelLoader = loader->GetModelLoader();
		
		if( modelLoader != NULL )
		{
			for( int32_t ind = 0; ind < m_modelCount; ind++ )
			{
				EFK_CHAR fullPath[512];
				PathCombine( fullPath, matPath, m_modelPaths[ ind ] );
				m_pModels[ind] = modelLoader->Load( fullPath );
			}
		}
	}
}
示例#3
0
Model::Model(ID3D11Device* device, TextureManager& texMgr, const std::string& modelFilename, const std::string& texturePath)
{
	//std::vector<M3dMaterial> mats;
	std::vector<MaterialLoader> mats;

	//M3DLoader m3dLoader;
	//m3dLoader.LoadM3d(modelFilename, Vertices, Indices, Subsets, mats);

	ModelLoader loader;
	loader.Load(modelFilename, Vertices, Indices, Subsets, mats, SkinnedData);



	ModelMesh.SetVertices(device, &Vertices[0], Vertices.size());
	ModelMesh.SetIndices(device, &Indices[0], Indices.size());
	ModelMesh.SetSubsetTable(Subsets);

	SubsetCount = mats.size();

	TPM = mats[0].DiffuseMapNames.size();
	for(UINT i = 0; i < SubsetCount; ++i)
	{
		Mat.push_back(mats[i].Mat);

		for (int j = 0; j < mats[i].DiffuseMapNames.size(); ++j)
		{
			if (mats[i].DiffuseMapNames[j] != "")
			{
				ID3D11ShaderResourceView* diffuseMapSRV = texMgr.CreateTexture(texturePath + mats[i].DiffuseMapNames[j]);
				if (diffuseMapSRV)
					DiffuseMapSRV.push_back(diffuseMapSRV);
			}
		}

		for (int j = 0; j < mats[i].NormalMapNames.size(); ++j)
		{
			if (mats[i].NormalMapNames[j] != "")
			{
				ID3D11ShaderResourceView* normalMapSRV = texMgr.CreateTexture(texturePath + mats[i].NormalMapNames[j]);
				if (normalMapSRV)
					NormalMapSRV.push_back(normalMapSRV);
			}
		}
		/*
		if (mats[i].DiffuseMapName != "")
		{
			ID3D11ShaderResourceView* diffuseMapSRV = texMgr.CreateTexture(texturePath + mats[i].DiffuseMapName);
			if (diffuseMapSRV)
				DiffuseMapSRV.push_back(diffuseMapSRV);
		}

		if (mats[i].NormalMapName != "")
		{
			ID3D11ShaderResourceView* normalMapSRV = texMgr.CreateTexture(texturePath + mats[i].NormalMapName);
			if (normalMapSRV)
				NormalMapSRV.push_back(normalMapSRV);
		}*/
	}
	
	m_BoneBoxes = SkinnedData.CreateBoneBoxes(Vertices);

	if (m_BoneBoxes.size() == 0)
	{
		//BoundingSphere::CreateFromPoints(m_BoundingSphere, Vertices.size(), &Vertices[0].Pos, sizeof(Vertex::PosNormalTexTanSkinned));

		BoundingBox AABB;
		BoundingBox::CreateFromPoints(AABB, Vertices.size(), &Vertices[0].Pos, sizeof(Vertex::PosNormalTexTanSkinned));

		BoundingOrientedBox::CreateFromBoundingBox(m_BoundingOrientedBox, AABB);

		XMFLOAT3 Extents = m_BoundingOrientedBox.Extents;
		m_SmallestRadiusInBox =	( Extents.x > Extents.z ) ? Extents.z : Extents.x;

		BoundingSphere::CreateFromBoundingBox(m_BoundingSphere, m_BoundingOrientedBox);
	}

	else
	{
		AnimationClip* AC = SkinnedData.GetAnimation("ALL");

		if (AC)
		{
			UINT numKeyFrames = AC->BoneAnimations[0].Keyframes.size();

			std::vector<XMFLOAT3> bigBoxPoints;
			m_SmallestRadiusInBox = 99999;
			for (int i = 0; i < numKeyFrames; ++i)
			{
				float time = AC->BoneAnimations[0].Keyframes[i].TimePos;

				std::vector<XMFLOAT4X4> FinalTransforms(AC->BoneAnimations.size());
				SkinnedData.GetFinalTransforms("ALL", time, FinalTransforms);

				std::vector<DirectX::BoundingOrientedBox>	tempboxes(m_BoneBoxes.size());
				for (int i = 0; i < m_BoneBoxes.size(); ++i)
				{
					m_BoneBoxes[i].Transform(tempboxes[i], XMLoadFloat4x4(&FinalTransforms[i]));
				}

				std::vector<XMFLOAT3> points;
				for (int i = 0; i < tempboxes.size(); ++i)
				{
					XMFLOAT3 corners[BoundingOrientedBox::CORNER_COUNT];
					tempboxes[i].GetCorners(&corners[0]);

					for each (XMFLOAT3 point in corners)
					{
						points.push_back(point);
						bigBoxPoints.push_back(point);
					}
				}
				BoundingBox AABB;
				BoundingBox::CreateFromPoints(AABB, points.size(), &points[0], sizeof(XMFLOAT3));

				XMFLOAT3 Extents = AABB.Extents;
				m_SmallestRadiusInBox = min(m_SmallestRadiusInBox, min(min(Extents.x, Extents.z), Extents.y));
			}

			BoundingBox AABB;
			BoundingBox::CreateFromPoints(AABB, bigBoxPoints.size(), &bigBoxPoints[0], sizeof(XMFLOAT3));

			BoundingOrientedBox::CreateFromBoundingBox(m_BoundingOrientedBox, AABB);
			BoundingSphere::CreateFromBoundingBox(m_BoundingSphere, m_BoundingOrientedBox);
		}

		
		//m_SmallestRadiusInBox = 10;
		/*
		BoundingSphere::CreateFromBoundingBox(m_BoundingSphere, m_BoundingOrientedBox);
		BoundingOrientedBox::CreateFromBoundingBox(m_BoundingOrientedBox, AABB);
		BoundingSphere::CreateFromBoundingBox(m_BoundingSphere, m_BoundingOrientedBox);
		*/
	}