Skip to content

Commit

Permalink
Added proper submesh rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Borf committed Oct 10, 2019
1 parent 21ab700 commit a75c2be
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 19 deletions.
4 changes: 4 additions & 0 deletions brolib/BroLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
<ClCompile Include="BroLib\grflib\grfcrypt.c" />
<ClCompile Include="BroLib\grflib\grfsupport.c" />
<ClCompile Include="BroLib\grflib\rgz.c" />
<ClCompile Include="BroLib\IRsm.cpp" />
<ClCompile Include="BroLib\Map.cpp" />
<ClCompile Include="BroLib\MapRenderer.cpp" />
<ClCompile Include="BroLib\Rsm.cpp" />
<ClCompile Include="BroLib\Rsm2.cpp" />
<ClCompile Include="BroLib\Rsw.cpp" />
</ItemGroup>
<ItemGroup>
Expand All @@ -58,10 +60,12 @@
<ClInclude Include="BroLib\grflib\grfsupport.h" />
<ClInclude Include="BroLib\grflib\grftypes.h" />
<ClInclude Include="BroLib\grflib\rgz.h" />
<ClInclude Include="BroLib\IRsm.h" />
<ClInclude Include="BroLib\Map.h" />
<ClInclude Include="BroLib\MapRenderer.h" />
<ClInclude Include="BroLib\Renderer.h" />
<ClInclude Include="BroLib\Rsm.h" />
<ClInclude Include="BroLib\Rsm2.h" />
<ClInclude Include="BroLib\Rsw.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
Expand Down
12 changes: 12 additions & 0 deletions brolib/BroLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<ClCompile Include="BroLib\Gat.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BroLib\Rsm2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BroLib\IRsm.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BroLib\Map.h">
Expand Down Expand Up @@ -173,5 +179,11 @@
<ClInclude Include="BroLib\Gat.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BroLib\Rsm2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BroLib\IRsm.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
8 changes: 5 additions & 3 deletions brolib/BroLib/IRsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class IRsm
std::vector<Face*> faces;
std::vector<IMesh*> children;

glm::mat4 matrix1;
glm::mat4 matrix2;

RsmMeshRenderInfo* renderer;
IMesh* parent;

Expand All @@ -52,7 +55,8 @@ class IRsm
child->foreach(callback);
}

virtual void makeVirtual() {}
virtual void calcMatrix1() {}
virtual void calcMatrix2() {}
};

template<class T>
Expand All @@ -63,8 +67,6 @@ class IRsm

inline Mesh<T>* child(int i) { return (Mesh<T>*)children[i]; }

virtual void calcMatrix1() {}
virtual void calcMatrix2() {}
void foreach(const std::function<void(Mesh<T>*)>& callback)
{
callback(this);
Expand Down
13 changes: 2 additions & 11 deletions brolib/BroLib/MapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,17 +853,8 @@ void MapRenderer::renderMesh(IRsm::IMesh* mesh, const glm::mat4 &matrix, RsmMode
mesh->renderer->vbo->setVertexFormat<blib::VertexP3T2N3>();
renderer->setVbo(mesh->renderer->vbo, allVerts);
}
Rsm::Mesh* rsmMesh = dynamic_cast<Rsm::Mesh*>(mesh);
if (rsmMesh)
{
mesh->renderer->matrix = matrix * rsmMesh->matrix1 * rsmMesh->matrix2;
mesh->renderer->matrixSub = matrix * rsmMesh->matrix1;
}
if (rsm2Mesh)
{
mesh->renderer->matrix = matrix;
mesh->renderer->matrixSub = matrix;
}
mesh->renderer->matrix = matrix * mesh->matrix1 * mesh->matrix2;
mesh->renderer->matrixSub = matrix * mesh->matrix1;
}

if (rsmMesh && (!rsmMesh->frames.empty() || rsmMesh->matrixDirty))
Expand Down
4 changes: 2 additions & 2 deletions brolib/BroLib/Rsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ void Rsm::updateMatrices()
bbrange = (bbmin + bbmax) / 2.0f;


dynamic_cast<Mesh*>(rootMesh)->calcMatrix1();
dynamic_cast<Mesh*>(rootMesh)->calcMatrix2();
rootMesh->calcMatrix1();
rootMesh->calcMatrix2();



Expand Down
2 changes: 0 additions & 2 deletions brolib/BroLib/Rsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class Rsm : public IRsm
glm::vec3 bbmax;
glm::vec3 bbrange;

glm::mat4 matrix1;
glm::mat4 matrix2;
void calcMatrix1();
void calcMatrix2();
bool matrixDirty = true;
Expand Down
26 changes: 26 additions & 0 deletions brolib/BroLib/Rsm2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Rsm2::Rsm2(const std::string& fileName)
this->fileName = fileName;
renderer = NULL;
loaded = false;
rootMesh = nullptr;
if (fileName.substr(fileName.size() - 5) != ".rsm2")
return;

Expand Down Expand Up @@ -44,6 +45,12 @@ Rsm2::Rsm2(const std::string& fileName)
loaded = true;
}

if (rootMesh)
{
rootMesh->calcMatrix1();
rootMesh->calcMatrix2();
}



}
Expand Down Expand Up @@ -185,6 +192,25 @@ void Rsm2::load0203(blib::util::StreamInFile* rsmFile)



void Rsm2::Mesh::calcMatrix1()
{
matrix1 = glm::mat4();
matrix1 = glm::translate(matrix1, pos);
for (unsigned int i = 0; i < children.size(); i++)
child(i)->calcMatrix1();
}
void Rsm2::Mesh::calcMatrix2()
{
matrix2 = glm::mat4();


matrix2 *= offset;

for (unsigned int i = 0; i < children.size(); i++)
child(i)->calcMatrix2();
}


std::string Rsm2::readString(blib::util::StreamInFile* file)
{
int len = file->readInt();
Expand Down
5 changes: 4 additions & 1 deletion brolib/BroLib/Rsm2.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
class Rsm2 : public IRsm
{
public:
class Mesh : public IMesh
class Mesh : public IRsm::Mesh<Rsm2>
{
public:
std::vector<int> textures;

void calcMatrix1();
void calcMatrix2();
};
class Face : public IRsm::Face
{
Expand Down
Binary file modified vs2015/Release/Browedit.exe
Binary file not shown.

0 comments on commit a75c2be

Please sign in to comment.