Skip to content

Commit

Permalink
#5576: Quick fix to get the materials loading again
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 4, 2021
1 parent 840802c commit 4a082fd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 167 deletions.
165 changes: 1 addition & 164 deletions radiantcore/model/import/AseModel.cpp
Expand Up @@ -189,26 +189,6 @@ static void _ase_free_materials( aseMaterial_t **list )
(*list) = NULL;
}

#ifdef DEBUG_PM_ASE
static void _ase_print_materials( aseMaterial_t *list )
{
aseMaterial_t* mtl = list;
aseSubMaterial_t* subMtl = NULL;

while ( mtl )
{
_pico_printf ( PICO_NORMAL , "ASE Material %i" , mtl->mtlId );
subMtl = mtl->subMtls;
while ( subMtl )
{
_pico_printf ( PICO_NORMAL , " -- ASE SubMaterial %i - %s\n" , subMtl->subMtlId , subMtl->shader->name );
subMtl = subMtl->next;
}
mtl = mtl->next;
}
}
#endif //DEBUG_PM_ASE

/* todo:
* - apply material specific uv offsets to uv coordinates
*/
Expand Down Expand Up @@ -316,149 +296,6 @@ picoSurface_t* PicoModelFindOrAddSurface( picoModel_t *model, picoShader_t* shad
}
}

/* _ase_submit_triangles - jhefty
use the surface and the current face list to look up material/submaterial IDs
and submit them to the model for proper processing
The following still holds from ydnar's _ase_make_surface:
indexes 0 1 2 = vert indexes
indexes 3 4 5 = st indexes
indexes 6 7 8 = color indexes (new)
*/

#if 0
typedef picoIndex_t* picoIndexIter_t;

typedef struct aseUniqueIndices_s aseUniqueIndices_t;
struct aseUniqueIndices_s
{
picoIndex_t* data;
picoIndex_t* last;

aseFace_t* faces;
};

size_t aseUniqueIndices_size(aseUniqueIndices_t* self)
{
return self->last - self->data;
}

void aseUniqueIndices_reserve(aseUniqueIndices_t* self, picoIndex_t size)
{
self->data = self->last = (picoIndex_t*)_pico_calloc(size, sizeof(picoIndex_t));
}

void aseUniqueIndices_clear(aseUniqueIndices_t* self)
{
_pico_free(self->data);
}

void aseUniqueIndices_pushBack(aseUniqueIndices_t* self, picoIndex_t index)
{
*self->last++ = index;
}

picoIndex_t aseFaces_getVertexIndex(aseFace_t* faces, picoIndex_t index)
{
return faces[index / 3].indices[index % 3];
}

picoIndex_t aseFaces_getTexCoordIndex(aseFace_t* faces, picoIndex_t index)
{
return faces[index / 3].indices[(index % 3) + 3];
}

picoIndex_t aseFaces_getColorIndex(aseFace_t* faces, picoIndex_t index)
{
return faces[index / 3].indices[(index % 3) + 6];
}

int aseUniqueIndex_equal(aseFace_t* faces, picoIndex_t index, picoIndex_t other)
{
return aseFaces_getVertexIndex(faces, index) == aseFaces_getVertexIndex(faces, other)
&& aseFaces_getTexCoordIndex(faces, index) == aseFaces_getTexCoordIndex(faces, other)
&& aseFaces_getColorIndex(faces, index) == aseFaces_getColorIndex(faces, other);
}

picoIndex_t aseUniqueIndices_insertUniqueVertex(aseUniqueIndices_t* self, picoIndex_t index)
{
picoIndexIter_t i = self->data;
for(; i != self->last; ++i)
{
picoIndex_t other = (picoIndex_t)(i - self->data);
if(aseUniqueIndex_equal(self->faces, index, other))
{
return other;
}
}

aseUniqueIndices_pushBack(self, index);
return (picoIndex_t)(aseUniqueIndices_size(self) - 1);
}

static void _ase_submit_triangles_unshared ( picoModel_t* model , aseMaterial_t* materials , aseVertex_t* vertices, aseTexCoord_t* texcoords, aseColor_t* colors, aseFace_t* faces, int numFaces, int meshHasNormals )
{
aseFacesIter_t i = faces, end = faces + numFaces;

aseUniqueIndices_t indices;
aseUniqueIndices_t remap;
aseUniqueIndices_reserve(&indices, numFaces * 3);
aseUniqueIndices_reserve(&remap, numFaces * 3);
indices.faces = faces;

for(; i != end; ++i)
{
/* look up the shader for the material/submaterial pair */
aseSubMaterial_t* subMtl = _ase_get_submaterial_or_default( materials, (*i).materialId, (*i).subMaterialId );
if( subMtl == NULL )
{
return;
}

{
picoSurface_t* surface = PicoModelFindOrAddSurface(model, subMtl->shader);
int j;
/* we pull the data from the vertex, color and texcoord arrays using the face index data */
for ( j = 0 ; j < 3 ; j ++ )
{
picoIndex_t index = (picoIndex_t)(((i - faces) * 3) + j);
picoIndex_t size = (picoIndex_t)aseUniqueIndices_size(&indices);
picoIndex_t unique = aseUniqueIndices_insertUniqueVertex(&indices, index);

picoIndex_t numVertexes = PicoGetSurfaceNumVertexes(surface);
picoIndex_t numIndexes = PicoGetSurfaceNumIndexes(surface);

aseUniqueIndices_pushBack(&remap, numIndexes);

PicoSetSurfaceIndex(surface, numIndexes, remap.data[unique]);

if(unique == size)
{
PicoSetSurfaceXYZ(surface, numVertexes, vertices[(*i).indices[j]].xyz);
PicoSetSurfaceNormal(surface, numVertexes, vertices[(*i).indices[j]].normal);
PicoSetSurfaceST(surface, 0, numVertexes, texcoords[(*i).indices[j + 3]].texcoord);

if ( (*i).indices[j + 6] >= 0 )
{
PicoSetSurfaceColor(surface, 0, numVertexes, colors[(*i).indices[j + 6]].color);
}
else
{
PicoSetSurfaceColor(surface, 0, numVertexes, white);
}

PicoSetSurfaceSmoothingGroup(surface, numVertexes, (vertices[(*i).indices[j]].id * (1 << 16)) + (*i).smoothingGroup);
}
}
}
}

aseUniqueIndices_clear(&indices);
aseUniqueIndices_clear(&remap);
}

#endif

static void _ase_submit_triangles( model::AseModel& model , aseMaterial_t* materials , aseVertex_t* vertices, aseTexCoord_t* texcoords, aseColor_t* colors, aseFace_t* faces, int numFaces )
{
aseFacesIter_t i = faces, end = faces + numFaces;
Expand Down Expand Up @@ -514,7 +351,7 @@ 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& surface = model.ensureSurface(subMtl->shader->mapName ? subMtl->shader->mapName : "");

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

Expand Down
3 changes: 2 additions & 1 deletion radiantcore/model/import/AseModelLoader.cpp
Expand Up @@ -8,6 +8,7 @@

#include "../StaticModel.h"
#include "parser/ParseException.h"
#include "../picomodel/PicoModelLoader.h"

namespace model
{
Expand Down Expand Up @@ -44,7 +45,7 @@ IModelPtr AseModelLoader::loadModelFromPath(const std::string& path)
auto& staticSurface = staticSurfaces.emplace_back(std::make_shared<StaticModelSurface>(
std::move(aseSurface.vertices), std::move(aseSurface.indices)));

staticSurface->setDefaultMaterial(aseSurface.material);
staticSurface->setDefaultMaterial(PicoModelLoader::CleanupShaderName(aseSurface.material));
}

auto staticModel = std::make_shared<StaticModel>(staticSurfaces);
Expand Down
3 changes: 1 addition & 2 deletions radiantcore/model/picomodel/PicoModelLoader.h
Expand Up @@ -26,10 +26,9 @@ class PicoModelLoader :
static std::vector<StaticModelSurfacePtr> CreateSurfaces(picoModel_t* picoModel, const std::string& extension);

static std::string DetermineDefaultMaterial(picoSurface_t* picoSurface, const std::string& extension);

private:
static std::string CleanupShaderName(const std::string& inName);

private:
static StaticModelSurfacePtr CreateSurface(picoSurface_t* picoSurface, const std::string& extension);
};

Expand Down

0 comments on commit 4a082fd

Please sign in to comment.