indexed geometry for vr rendermodels

This commit is contained in:
milek7
2020-10-19 14:14:23 +02:00
parent fb3b735014
commit 5b50a39610
3 changed files with 27 additions and 19 deletions

View File

@@ -2142,15 +2142,14 @@ void TModel3d::LoadFromBinFile(std::string const &FileName, bool dynamic)
WriteLog( "Finished loading 3d model data from \"" + FileName + "\"", logtype::model );
};
TSubModel* TModel3d::AppendChildFromGeometry(const std::string &name, const std::string &parent, const gfx::vertex_array &data)
TSubModel* TModel3d::AppendChildFromGeometry(const std::string &name, const std::string &parent, const gfx::vertex_array &vertices, const gfx::index_array &indices)
{
// todo: indexed geometry
iFlags |= 0x0200;
TSubModel *sm = new TSubModel();
sm->Parent = AddToNamed(parent.c_str(), sm);
sm->m_geometry.vertex_count = data.size();
sm->m_geometry.vertex_count = vertices.size();
sm->m_geometry.index_count = indices.size();
sm->eType = GL_TRIANGLES;
sm->pName = name;
sm->m_material = GfxRenderer->Fetch_Material("colored");
@@ -2158,11 +2157,13 @@ TSubModel* TModel3d::AppendChildFromGeometry(const std::string &name, const std:
sm->fMatrix->Identity();
sm->iFlags |= 0x10;
sm->iFlags |= 0x8000;
sm->WillBeAnimated();
if (data.empty())
sm->WillBeAnimated();
if (vertices.empty())
sm->iFlags &= ~0x3F;
sm->Vertices = data;
m_vertexcount += data.size();
sm->Vertices = vertices;
sm->Indices = indices;
m_vertexcount += vertices.size();
m_indexcount += indices.size();
if (!Root)
Root = sm;

View File

@@ -285,7 +285,7 @@ public:
void LoadFromTextFile(std::string const &FileName, bool dynamic);
void LoadFromBinFile(std::string const &FileName, bool dynamic);
bool LoadFromFile(std::string const &FileName, bool dynamic);
TSubModel *AppendChildFromGeometry(const std::string &name, const std::string &parent, const gfx::vertex_array &data);
TSubModel *AppendChildFromGeometry(const std::string &name, const std::string &parent, const gfx::vertex_array &vertices, const gfx::index_array &indices);
void SaveToBinFile(std::string const &FileName);
uint32_t Flags() const { return iFlags; };
void Init();

View File

@@ -104,7 +104,7 @@ void vr_openvr::begin_frame()
}
controllers[i]->model = std::make_unique<TModel3d>();
controllers[i]->model->AppendChildFromGeometry("__root", "none", gfx::vertex_array());
controllers[i]->model->AppendChildFromGeometry("__root", "none", gfx::vertex_array(), gfx::index_array());
}
}
@@ -115,7 +115,9 @@ void vr_openvr::begin_frame()
char rendermodel_name[256];
char component_name[128];
gfx::vertex_array data;
gfx::vertex_array vertices;
gfx::index_array indices;
std::string submodel_name;
vr::RenderModel_t *model;
vr::EVRRenderModelError ret;
@@ -139,18 +141,23 @@ void vr_openvr::begin_frame()
else if (ret != vr::VRRenderModelError_None)
goto component_done;
data.resize(model->unTriangleCount * 3);
indices.resize(model->unTriangleCount * 3);
for (size_t v = 0; v < model->unTriangleCount * 3; v++)
indices.push_back(model->rIndexData[v]);
for (size_t v = 0; v < model->unTriangleCount * 3; v++) {
const vr::RenderModel_Vertex_t *vertex = &model->rVertexData[model->rIndexData[v]];
data[v] = gfx::basic_vertex(
glm::vec3(vertex->vPosition.v[0], vertex->vPosition.v[1], vertex->vPosition.v[2]),
glm::vec3(vertex->vNormal.v[0], vertex->vNormal.v[1], vertex->vNormal.v[2]),
glm::vec2(vertex->rfTextureCoord[0], vertex->rfTextureCoord[1]));
vertices.resize(model->unVertexCount);
for (size_t v = 0; v < model->unVertexCount; v++) {
const vr::RenderModel_Vertex_t *vertex = &model->rVertexData[v];
vertices.push_back(gfx::basic_vertex(
glm::vec3(vertex->vPosition.v[0], vertex->vPosition.v[1], vertex->vPosition.v[2]),
glm::vec3(vertex->vNormal.v[0], vertex->vNormal.v[1], vertex->vNormal.v[2]),
glm::vec2(vertex->rfTextureCoord[0], vertex->rfTextureCoord[1])));
}
gfx::calculate_tangents(vertices, GL_TRIANGLES);
submodel_name = std::string(component == -1 ? rendermodel_name : component_name);
sm = controllers[i]->model->AppendChildFromGeometry(submodel_name, "__root", data);
sm = controllers[i]->model->AppendChildFromGeometry(submodel_name, "__root", vertices, indices);
if (model->diffuseTextureId >= 0)
controllers[i]->pending_textures.push_back(std::make_pair(sm, model->diffuseTextureId));