Example #1
0
	void Mesh::InitMesh()
	{
		auto& device = static_cast<D3D12Device&>(Game::GetEngine().GetRenderer().GetDevice());

		D3D11_SUBRESOURCE_DATA vertexBufferData = { 0 };
		vertexBufferData.pSysMem = &vertices[0];
		vertexBufferData.SysMemPitch = 0;
		vertexBufferData.SysMemSlicePitch = 0;
		CD3D11_BUFFER_DESC vertexBufferDesc(static_cast<UINT>(sizeof(Vertex) * vertices.size()), D3D11_BIND_VERTEX_BUFFER);
		DX::ThrowIfFailed(
			device.GetD3DDevice()->CreateBuffer(
				&vertexBufferDesc,
				&vertexBufferData,
				&m_vertexBuffer
			)
		);

		m_indexCount = static_cast<unsigned int>(indices.size());

		D3D11_SUBRESOURCE_DATA indexBufferData = { 0 };
		indexBufferData.pSysMem = &indices[0];
		indexBufferData.SysMemPitch = 0;
		indexBufferData.SysMemSlicePitch = 0;
		CD3D11_BUFFER_DESC indexBufferDesc(sizeof(unsigned int) * m_indexCount, D3D11_BIND_INDEX_BUFFER);
		DX::ThrowIfFailed(
			device.GetD3DDevice()->CreateBuffer(
				&indexBufferDesc,
				&indexBufferData,
				&m_indexBuffer
			)
		);
	}
Example #2
0
File: Mesh.cpp Project: pipmix/Game
Mesh::Mesh(ID3D11Device* d, wstring fn) : fileName(fn){


	wstring completePathAndName = gPath + gMeshPath + fileName + L".mesh";
	string completeName(completePathAndName.begin(), completePathAndName.end());




	ifstream file(completePathAndName);




	if (file) {

		file >> materialName >> textureName >> numOfIndices >> numOfVertices;

		unsigned short* indices = new unsigned short[numOfIndices];

		for (int i = 0; i < numOfIndices; i++) file >> indices[i];
		

		VERTEXPNU* vertices = new VERTEXPNU[numOfVertices];

		for (int i = 0; i < numOfVertices; i++) {

			file >> vertices[i].pos.x
				>> vertices[i].pos.y
				>> vertices[i].pos.z
				>> vertices[i].normal.x
				>> vertices[i].normal.y
				>> vertices[i].normal.z
				>> vertices[i].uv.x
				>> vertices[i].uv.y;
		}
		file.close();



		D3D11_SUBRESOURCE_DATA vertexBufferData = { 0 };
		vertexBufferData.pSysMem = vertices;
		vertexBufferData.SysMemPitch = 0;
		vertexBufferData.SysMemSlicePitch = 0;

		CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
		

		D3D11_SUBRESOURCE_DATA indexBufferData = { 0 };
		indexBufferData.pSysMem = indices;
		indexBufferData.SysMemPitch = 0;
		indexBufferData.SysMemSlicePitch = 0;
		CD3D11_BUFFER_DESC indexBufferDesc(sizeof(indices), D3D11_BIND_INDEX_BUFFER);

		d->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &mVertexBuffer);
		d->CreateBuffer(&indexBufferDesc, &indexBufferData, &mIndexBuffer);

		delete[] vertices;
		delete[] indices;



	}





}