Esempio n. 1
0
	ModelShape::ModelShape(IGraphicsDevice *device, Model *model) :
		Shape(device, "model"),
		mModel(model)
	{
		TMeshList &meshes = model->GetMeshes();
		for(int i = 0; i < meshes.size(); i++) {
			ModelMesh *mesh = meshes[i];

			VERTEX_BUFFER_DESC desc;
			desc.Stride = sizeof(ModelVertex);
			IVertexBuffer *meshBuffer = device->CreateVertexBuffer(desc);
			meshBuffer->SetData(mesh->GetBuffer(), sizeof(ModelVertex) * mesh->GetTotalFaces());

			mMeshVertexBuffers.push_back(meshBuffer);

			ModelAnimationMaterialProperties *properties = new ModelAnimationMaterialProperties();
			mMeshMaterials.push_back(new Material(device, properties));
		}

		TMaterialList &materials = mModel->GetMaterials();
		for(int i = 0; i < materials.size(); i++) {
			ModelMaterial *material = materials[i];
			Image *image = material->GetImage(MaterialTextureDiffuse, 0);

			ITexture *texture = device->CreateTexture();
			texture->Initialize(image->GetBits(), CSize(image->GetWidth(), image->GetHeight()));

			mTextures.push_back(texture);
		}
	}