LoLModel<VertexFormat>::LoLModel(const std::string &fileName, const ModelLoadOptions &options /*= ModelLoadOptions()*/) { std::vector<VertexFormat> verts; std::ifstream pFile(fileName.c_str(), std::ios_base::binary); if (pFile.bad() || !pFile.good() || !pFile.is_open()) { throw(("Could not open " + fileName).c_str()); return; } SkinModelHeader header; pFile.read((char*)&header, sizeof(SkinModelHeader)); if (header.numMaterials == 1) { int nMaterials; pFile.read((char*)&nMaterials, 4); header.numMaterials = nMaterials; } std::vector<SkinModelMaterial> materials; materials.resize(header.numMaterials); for (int i = 0; i < header.numMaterials; i++) { pFile.read((char*)&materials[i], sizeof(SkinModelMaterial)); } int nIndices; int nVertices; pFile.read((char*)&nIndices, 4); pFile.read((char*)&nVertices, 4); if (nIndices < 0 || nVertices < 0 || nIndices > 200000000 || nVertices > 200000000) { printf("unable to open %s\n", fileName.c_str()); throw "oops"; } short* _indices = new short[nIndices]; pFile.read((char*)_indices, nIndices * 2); SkinModelVertex* _vertices = new SkinModelVertex[nVertices]; pFile.read((char*)_vertices, nVertices*sizeof(SkinModelVertex)); for (int i = 0; i < nIndices; i++) indices.push_back(_indices[i]); for (int i = 0; i < nVertices; i++) { VertexFormat v; setP3(v, glm::vec3(_vertices[i].position[0], _vertices[i].position[1], _vertices[i].position[2])); setN3(v, glm::vec3(_vertices[i].normal[0], _vertices[i].normal[1], _vertices[i].normal[2])); setT2(v, glm::vec2(_vertices[i].texcoords[0], _vertices[i].texcoords[1])); verts.push_back(v); } if (!verts.empty()) { handleModelLoadOptions(verts, options); for (size_t i = 0; i < verts.size(); i++) vertices.push_back(glm::vec3(verts[i].px, verts[i].py, verts[i].pz)); vbo.bind(); vbo.setData(verts.size(), &verts[0], GL_STATIC_DRAW); vao = NULL; if (!indices.empty()) { vao = new gl::VAO<VertexFormat>(&vbo); vio.bind(); vio.setData(indices.size(), &indices[0], GL_STATIC_DRAW); vao->unBind(); } } else vao = NULL; }
void MidiMessage::setData(uchar aCommand, uchar aP1, uchar aP2, uchar aP3) { setCommand(aCommand); setP1(aP1); setP2(aP2); setP3(aP3); }