Created
October 1, 2015 03:09
-
-
Save Tzeentchful/c071559d67db64bdea0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::vector<tinyobj::shape_t> shapes; | |
std::vector<tinyobj::material_t> materials; | |
std::string err = tinyobj::LoadObj(shapes, materials, m_Filename.c_str(), "../Res/Models/"); | |
if (!err.empty()) | |
{ | |
// fail | |
} | |
mNumFaces = shapes[0].mesh.indices.size() / 3; | |
verts = new Vertex[shapes[0].mesh.positions.size() / 3]; | |
indices = new int[shapes[0].mesh.indices.size()]; | |
for (int i = 0; i < int(shapes[0].mesh.indices.size()); ++i) | |
{ | |
indices[i] = shapes[0].mesh.indices[i]; | |
} | |
for (int i = 0; i < int(shapes[0].mesh.positions.size() / 3); ++i) | |
{ | |
int ri = i * 3; | |
int rui = i * 2; | |
verts[i].pos = D3DXVECTOR3(-shapes[0].mesh.positions[ri], shapes[0].mesh.positions[ri + 1], shapes[0].mesh.positions[ri + 2]); | |
verts[i].pos *= m_Scale; | |
verts[i].Normal = D3DXVECTOR3(shapes[0].mesh.normals[ri], shapes[0].mesh.normals[ri + 1], shapes[0].mesh.normals[ri + 2]); | |
verts[i].UV = D3DXVECTOR2(shapes[0].mesh.texcoords[rui], -shapes[0].mesh.texcoords[rui + 1]); | |
} | |
D3D10_BUFFER_DESC vbd; | |
vbd.Usage = D3D10_USAGE_IMMUTABLE; | |
vbd.ByteWidth = sizeof(Vertex) * shapes[0].mesh.positions.size() / 3; | |
vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER; | |
vbd.CPUAccessFlags = 0; | |
vbd.MiscFlags = 0; | |
D3D10_SUBRESOURCE_DATA vinitData; | |
vinitData.pSysMem = verts; | |
HR(_device->CreateBuffer(&vbd, &vinitData, &mVB)); | |
D3D10_BUFFER_DESC ibd; | |
ibd.Usage = D3D10_USAGE_IMMUTABLE; | |
ibd.ByteWidth = (sizeof(DWORD) * shapes[0].mesh.indices.size()); | |
ibd.BindFlags = D3D10_BIND_INDEX_BUFFER; | |
ibd.CPUAccessFlags = 0; | |
ibd.MiscFlags = 0; | |
D3D10_SUBRESOURCE_DATA iinitData; | |
iinitData.pSysMem = indices; | |
HR(_device->CreateBuffer(&ibd, &iinitData, &mIB)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment