本文整理汇总了C++中ObjModel::addMeshData方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjModel::addMeshData方法的具体用法?C++ ObjModel::addMeshData怎么用?C++ ObjModel::addMeshData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjModel
的用法示例。
在下文中一共展示了ObjModel::addMeshData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bindToMesh
void ObjLoader::bindToMesh(ObjModel &model, bool invertUV)
{
const int vertSize = _positions->size();
const int normSize = _normals->size();
const int uvSize = _texCoords->size();
Mesh &mesh = model.getMesh();
// calculate the vertex data stride
int stride = 0;
if (vertSize > 0)
{
mesh.addAttribute(VertexAttribute(0, 3));
stride += 3;
}
if (normSize > 0)
{
mesh.addAttribute(VertexAttribute(1, 3));
stride += 3;
}
if (uvSize > 0)
{
mesh.addAttribute(VertexAttribute(2, 2));
stride += 2;
}
std::vector<float> buffer;
int offset = 0;
std::map<std::string, MeshData>::iterator meshIter;
for (meshIter = _meshes->begin(); meshIter != _meshes->end(); ++meshIter)
{
const std::string &meshName = (*meshIter).first;
MeshData &mesh = (*meshIter).second;
std::vector<Face> &faces = mesh.faces;
// set mesh data
int drawCount = faces.size() * 3; // each face is a triangle (3 vertices)
model.addMeshData(meshName, offset, drawCount);
offset += drawCount;
std::vector<Face>::iterator iter;
for (iter = faces.begin(); iter != faces.end(); ++iter)
{
Face& face = (*iter);
int i;
for (i = 0; i < 3; ++i)
{
int vIdx = face.vertices[i] - 1;
int nIdx = face.normal[i] - 1;
int tIdx = face.texCoord[i] - 1;
if (vertSize > 0)
{
Vector3& v = _positions->at(vIdx);
buffer.push_back(v.x);
buffer.push_back(v.y);
buffer.push_back(v.z);
}
if (normSize > 0)
{
Vector3& n = _normals->at(nIdx);
buffer.push_back(n.x);
buffer.push_back(n.y);
buffer.push_back(n.z);
}
if (uvSize > 0)
{
Vector2 &uv = _texCoords->at(tIdx);
buffer.push_back(uv.x);
buffer.push_back(invertUV ? 1.0f - uv.y : uv.y);
}
}
}
}
// faces times 3 vertices per triangle
int drawCount = offset;
// bind vertex data to mesh
Buffer& vbo = mesh.getVBO();
vbo.bind();
vbo.setData(&buffer[0], buffer.size() * sizeof(float));
vbo.unbind();
mesh.setDrawCount(drawCount);
mesh.create(stride * sizeof(float));
}