Skip to content

Commit

Permalink
#5576: Parsing ASE files using the old C code is functional now, exce…
Browse files Browse the repository at this point in the history
…pt for the shader name.
  • Loading branch information
codereader committed Apr 5, 2021
1 parent d5025a3 commit fa47412
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
34 changes: 31 additions & 3 deletions radiantcore/model/import/AseModel.cpp
@@ -1,5 +1,8 @@
#include "AseModel.h"

#include <fmt/format.h>
#include "parser/ParseException.h"

/* -----------------------------------------------------------------------------
PicoModel Library
Expand Down Expand Up @@ -511,6 +514,18 @@ static void _ase_submit_triangles( model::AseModel& model , aseMaterial_t* mater
}

/* submit the triangle to the model */
auto& surface = model.ensureSurface(subMtl->shader->name);

auto nextIndex = static_cast<unsigned int>(surface.indices.size());

surface.vertices.emplace_back(ArbitraryMeshVertex{ Vertex3f(*(xyz[0])), Normal3f(*(normal[0])), TexCoord2f(st[0]) });
surface.vertices.emplace_back(ArbitraryMeshVertex{ Vertex3f(*(xyz[1])), Normal3f(*(normal[1])), TexCoord2f(st[1]) });
surface.vertices.emplace_back(ArbitraryMeshVertex{ Vertex3f(*(xyz[2])), Normal3f(*(normal[2])), TexCoord2f(st[2]) });

surface.indices.emplace_back(nextIndex++);
surface.indices.emplace_back(nextIndex++);
surface.indices.emplace_back(nextIndex++);

// TODO PicoAddTriangleToModel ( model , xyz , normal , 1 , stRef, 1 , color , subMtl->shader, smooth );
}
}
Expand All @@ -532,9 +547,22 @@ static void shadername_convert(char* shaderName)
namespace model
{

AseModel::Surface& AseModel::addSurface()
AseModel::Surface& AseModel::addSurface(const std::string& name)
{
return _surfaces.emplace_back(Surface{name});
}

AseModel::Surface& AseModel::ensureSurface(const std::string& name)
{
return _surfaces.emplace_back();
for (auto& surface : _surfaces)
{
if (surface.material == name)
{
return surface;
}
}

return addSurface(name);
}

std::vector<AseModel::Surface>& AseModel::getSurfaces()
Expand Down Expand Up @@ -566,7 +594,7 @@ std::shared_ptr<AseModel> AseModel::CreateFromStream(std::istream& stream)
/* helper */
#define _ase_error_return(m) \
{ \
_pico_printf( PICO_ERROR,"%s in ASE, line %d.",m,p->curLine); \
throw parser::ParseException(fmt::format("{0} in ASE, line {0:d}.", m ,p->curLine)); \
_pico_free_parser( p ); \
return model; \
}
Expand Down
4 changes: 3 additions & 1 deletion radiantcore/model/import/AseModel.h
Expand Up @@ -21,7 +21,9 @@ class AseModel
std::vector<Surface> _surfaces;

public:
Surface& addSurface();
Surface& addSurface(const std::string& name);

Surface& ensureSurface(const std::string& name);

// Read/Write access
std::vector<Surface>& getSurfaces();
Expand Down

0 comments on commit fa47412

Please sign in to comment.