Example #1
0
ModelPtr AssetLoader::LoadAnimatedModel(std::string fileName)
{
    FILE * f = nullptr;
    fopen_s(&f,fileName.c_str(),"rb");
    if(f != nullptr)
    {
        unsigned int number;
        fread_s(&number,4,4,1,f);
        if(number != 50)
        {
            fclose(f);
            return ModelPtr(true);
        }

        unsigned int meshesCount;
        fread_s(&meshesCount,4,4,1,f);

        ModelPtr ptr(Heap::GetPtr()->Models.New());
        Model * model = ptr.Get();

        for(unsigned int iMesh = 0; iMesh < meshesCount; iMesh++)
        {
            fread_s(&animatedMeshData.numOfVerts,4,4,1,f);

            fread_s(animatedMeshData.verts,sizeof(AnimatedVert) * animatedMeshData.numOfVerts,sizeof(AnimatedVert),animatedMeshData.numOfVerts,f);
            fread_s(&animatedMeshData.numOfIndecies,4,4,1,f);

            fread_s(animatedMeshData.indecies,sizeof(unsigned int) * animatedMeshData.numOfIndecies, 4 ,animatedMeshData.numOfIndecies,f);

            MeshPtr meshPtr = factory->CreateMesh();
            Mesh * mesh = meshPtr.Get();
            mesh->Init();
            mesh->SetDrawMethod(DM_DRAW_INDEXED);

            mesh->InitVertexBuffer(animatedMeshData.numOfVerts * sizeof(AnimatedVert),sizeof(AnimatedVert),animatedMeshData.verts);
            mesh->InitIndexBuffer(animatedMeshData.numOfIndecies,animatedMeshData.indecies);

            model->AddMesh(meshPtr);

        }


        fclose(f);

        return ptr;
    }
    else return nullptr;
}
Example #2
0
ModelPtr AssetLoader::LoadStaticModel(std::string fileName)
{
    std::ifstream file(fileName.c_str(),std::ios::binary);

    if(file.is_open())
    {
        unsigned int number;
        file.read((char*)&number,sizeof(unsigned int));
        if(number != 0)
            return ModelPtr(true);

        unsigned int numberOfMeshes;
        file.read((char*)&numberOfMeshes,4);

        ModelPtr ptr(Heap::GetPtr()->Models.New());
        Model * model = ptr.Get();

        for(unsigned int iMesh = 0; iMesh < numberOfMeshes; iMesh++)
        {
            file.read((char*)&staticMeshData.numberOfVerts,sizeof(unsigned int));

            file.read((char*)staticMeshData.vertecies,sizeof(StaticVert) * staticMeshData.numberOfVerts);
            file.read((char*)&staticMeshData.numberOfIndecies,sizeof(unsigned int));

            file.read((char*)staticMeshData.indecies,sizeof(unsigned int) * staticMeshData.numberOfIndecies);

            MeshPtr meshPtr = factory->CreateMesh();
            Mesh * mesh = meshPtr.Get();
            mesh->Init();
            mesh->SetDrawMethod(DM_DRAW_INDEXED);

            mesh->InitVertexBuffer(staticMeshData.numberOfVerts * sizeof(StaticVert),sizeof(StaticVert),staticMeshData.vertecies);
            mesh->InitIndexBuffer(staticMeshData.numberOfIndecies,staticMeshData.indecies);

            model->AddMesh(meshPtr);

        }

        file.close();

        return ptr;
    }
    else return ModelPtr(true);

}
void AnimatedEntity::Draw(EffectBinder * binder)
{
	SetUpShaderData();

	BindAnimationData(binder);
	BindEntityData(binder);

	Model * model = modelHandler.Get().Get();

	for(unsigned int i = 0;i < model->GetNumberOfMeshes();i++)
	{
		Material mat = materials[i];
		BindMaterialData(binder,mat);
		binder->BindAllSections();


		MeshPtr ptr = model->GetMeshAt(i);
		Mesh * mesh = ptr.Get();
		mesh->DrawIndexed();
	}

}