mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 18:39:18 +02:00
indexed geometry for vr rendermodels
This commit is contained in:
17
Model3d.cpp
17
Model3d.cpp
@@ -2142,15 +2142,14 @@ void TModel3d::LoadFromBinFile(std::string const &FileName, bool dynamic)
|
|||||||
WriteLog( "Finished loading 3d model data from \"" + FileName + "\"", logtype::model );
|
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;
|
iFlags |= 0x0200;
|
||||||
|
|
||||||
TSubModel *sm = new TSubModel();
|
TSubModel *sm = new TSubModel();
|
||||||
sm->Parent = AddToNamed(parent.c_str(), sm);
|
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->eType = GL_TRIANGLES;
|
||||||
sm->pName = name;
|
sm->pName = name;
|
||||||
sm->m_material = GfxRenderer->Fetch_Material("colored");
|
sm->m_material = GfxRenderer->Fetch_Material("colored");
|
||||||
@@ -2158,11 +2157,13 @@ TSubModel* TModel3d::AppendChildFromGeometry(const std::string &name, const std:
|
|||||||
sm->fMatrix->Identity();
|
sm->fMatrix->Identity();
|
||||||
sm->iFlags |= 0x10;
|
sm->iFlags |= 0x10;
|
||||||
sm->iFlags |= 0x8000;
|
sm->iFlags |= 0x8000;
|
||||||
sm->WillBeAnimated();
|
sm->WillBeAnimated();
|
||||||
if (data.empty())
|
if (vertices.empty())
|
||||||
sm->iFlags &= ~0x3F;
|
sm->iFlags &= ~0x3F;
|
||||||
sm->Vertices = data;
|
sm->Vertices = vertices;
|
||||||
m_vertexcount += data.size();
|
sm->Indices = indices;
|
||||||
|
m_vertexcount += vertices.size();
|
||||||
|
m_indexcount += indices.size();
|
||||||
|
|
||||||
if (!Root)
|
if (!Root)
|
||||||
Root = sm;
|
Root = sm;
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ public:
|
|||||||
void LoadFromTextFile(std::string const &FileName, bool dynamic);
|
void LoadFromTextFile(std::string const &FileName, bool dynamic);
|
||||||
void LoadFromBinFile(std::string const &FileName, bool dynamic);
|
void LoadFromBinFile(std::string const &FileName, bool dynamic);
|
||||||
bool LoadFromFile(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);
|
void SaveToBinFile(std::string const &FileName);
|
||||||
uint32_t Flags() const { return iFlags; };
|
uint32_t Flags() const { return iFlags; };
|
||||||
void Init();
|
void Init();
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ void vr_openvr::begin_frame()
|
|||||||
}
|
}
|
||||||
|
|
||||||
controllers[i]->model = std::make_unique<TModel3d>();
|
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 rendermodel_name[256];
|
||||||
char component_name[128];
|
char component_name[128];
|
||||||
|
|
||||||
gfx::vertex_array data;
|
gfx::vertex_array vertices;
|
||||||
|
gfx::index_array indices;
|
||||||
|
|
||||||
std::string submodel_name;
|
std::string submodel_name;
|
||||||
vr::RenderModel_t *model;
|
vr::RenderModel_t *model;
|
||||||
vr::EVRRenderModelError ret;
|
vr::EVRRenderModelError ret;
|
||||||
@@ -139,18 +141,23 @@ void vr_openvr::begin_frame()
|
|||||||
else if (ret != vr::VRRenderModelError_None)
|
else if (ret != vr::VRRenderModelError_None)
|
||||||
goto component_done;
|
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++) {
|
vertices.resize(model->unVertexCount);
|
||||||
const vr::RenderModel_Vertex_t *vertex = &model->rVertexData[model->rIndexData[v]];
|
for (size_t v = 0; v < model->unVertexCount; v++) {
|
||||||
data[v] = gfx::basic_vertex(
|
const vr::RenderModel_Vertex_t *vertex = &model->rVertexData[v];
|
||||||
glm::vec3(vertex->vPosition.v[0], vertex->vPosition.v[1], vertex->vPosition.v[2]),
|
vertices.push_back(gfx::basic_vertex(
|
||||||
glm::vec3(vertex->vNormal.v[0], vertex->vNormal.v[1], vertex->vNormal.v[2]),
|
glm::vec3(vertex->vPosition.v[0], vertex->vPosition.v[1], vertex->vPosition.v[2]),
|
||||||
glm::vec2(vertex->rfTextureCoord[0], vertex->rfTextureCoord[1]));
|
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);
|
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)
|
if (model->diffuseTextureId >= 0)
|
||||||
controllers[i]->pending_textures.push_back(std::make_pair(sm, model->diffuseTextureId));
|
controllers[i]->pending_textures.push_back(std::make_pair(sm, model->diffuseTextureId));
|
||||||
|
|||||||
Reference in New Issue
Block a user