mesh_texture refactoring #1

This commit is contained in:
Sandro Sobczyński
2020-10-29 22:19:06 +01:00
parent 8501a85f49
commit 99d4c3633b
12 changed files with 102 additions and 22 deletions
+2 -2
View File
@@ -13,7 +13,7 @@
#include <stdio.h>
#include <tamtypes.h>
#include "../models/texture.hpp"
#include "../models/mesh_texture.hpp"
/** Class responsible for loading images in bmp format */
class BmpLoader
@@ -23,7 +23,7 @@ public:
BmpLoader();
~BmpLoader();
void load(Texture &o_texture, char *t_subfolder, char *t_name, char *t_extension);
void load(MeshTexture &o_texture, char *t_subfolder, char *t_name, char *t_extension);
};
#endif
+6
View File
@@ -16,6 +16,12 @@
#include "math/vector3.hpp"
#include "./mesh_material.hpp"
/**
* Class which contains core mesh data
* which are needed for drawing.
* Static object (not animated), will have
* only one instance of this class.
*/
class MeshFrame
{
+2 -2
View File
@@ -13,9 +13,9 @@
#include <tamtypes.h>
/** Class which contains draw data for mesh part.
/** Class which contains draw instructions for part mesh of mesh.
* Mesh can have many materials.
* For example, car can have three materials:
* For example, car mesh can have three materials:
* body, tires and windows.
*/
class MeshMaterial
+2 -2
View File
@@ -12,7 +12,7 @@
#define _TYRA_OBJECT3D_SPEC_
#include "math/vector3.hpp"
#include "./texture.hpp"
#include "./mesh_texture.hpp"
#include <tamtypes.h>
#include <draw_buffers.h>
#include <draw_sampling.h>
@@ -30,7 +30,7 @@ public:
void allocateMemory();
void setupLodAndClut();
Texture *textures;
MeshTexture *textures;
private:
};
@@ -0,0 +1,53 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#ifndef _TYRA_MESH_TEXTURE_
#define _TYRA_MESH_TEXTURE_
#include <tamtypes.h>
#include <draw_sampling.h>
/**
* Class which contains texture data
* Textures are paired with material via material id.
* Additionaly, you can load two textures for single material
* and switch materialId here to change texture.
*/
class MeshTexture
{
public:
MeshTexture();
~MeshTexture();
// ----
// Getters
// ----
// ----
// Setters
// ----
// ----
// Other
// ----
// TODO
u32 id;
unsigned char *data;
texwrap_t wrapSettings;
char *name;
u8 width, height;
private:
};
#endif
-10
View File
@@ -11,16 +11,6 @@
#ifndef _TYRA_TEXTURE_
#define _TYRA_TEXTURE_
#include <tamtypes.h>
#include <draw_sampling.h>
struct Texture
{
u32 id;
unsigned char *data;
texwrap_t wrapSettings;
char *name;
u8 width, height;
};
#endif
+2 -1
View File
@@ -22,6 +22,7 @@
#include "../models/screen_settings.hpp"
#include "../models/light_bulb.hpp"
#include "../models/render_data.hpp"
#include "../models/mesh_texture.hpp"
/** Class responsible for sending data packets via GIF (PATH3) */
class GifSender
@@ -36,7 +37,7 @@ public:
void addClear(zbuffer_t *t_zBuffer);
void sendPacket();
void sendClear(zbuffer_t *t_zBuffer);
static void sendTexture(Texture &texture, texbuffer_t *t_texBuffer);
static void sendTexture(MeshTexture &texture, texbuffer_t *t_texBuffer);
private:
xyz_t *xyz;
+1 -1
View File
@@ -30,7 +30,7 @@ BmpLoader::~BmpLoader() {}
* @param t_name Without extension. Example "skyfall2"
* @param t_extension With dot and extension. Example ".BMP"
*/
void BmpLoader::load(Texture &o_texture, char *t_subfolder, char *t_name, char *t_extension)
void BmpLoader::load(MeshTexture &o_texture, char *t_subfolder, char *t_name, char *t_extension)
{
char *t_path_part = String::createConcatenated(t_subfolder, t_name);
char *t_path = String::createConcatenated(t_path_part, t_extension);
+4 -3
View File
@@ -14,6 +14,7 @@
#include "../include/loaders/md2_loader.hpp"
#include "../include/loaders/dff_loader.hpp"
#include "../include/loaders/bmp_loader.hpp"
#include "../include/models/mesh_texture.hpp"
#include "../include/utils/debug.hpp"
#include "../include/utils/string.hpp"
@@ -178,7 +179,7 @@ void Mesh::loadTextures(char *t_subfolder, char *t_extension)
BmpLoader bmpLoader = BmpLoader();
if (isObjLoaded)
{
spec->textures = new Texture[obj->frames[0].getMaterialsCount()];
spec->textures = new MeshTexture[obj->frames[0].getMaterialsCount()];
for (u8 i = 0; i < obj->frames[0].getMaterialsCount(); i++)
{
bmpLoader.load(spec->textures[i], t_subfolder, obj->frames[0].getMaterial(i).getName(), t_extension);
@@ -187,13 +188,13 @@ void Mesh::loadTextures(char *t_subfolder, char *t_extension)
}
else if (isMd2Loaded)
{
spec->textures = new Texture[1];
spec->textures = new MeshTexture[1];
bmpLoader.load(spec->textures[0], t_subfolder, md2->filename, t_extension);
setDefaultWrapSettings(spec->textures[0].wrapSettings);
}
else if (isDffLoaded)
{
spec->textures = new Texture[dff->clump.geometryList.geometries[0].materialList.data.materialCount];
spec->textures = new MeshTexture[dff->clump.geometryList.geometries[0].materialList.data.materialCount];
for (u8 i = 0; i < dff->clump.geometryList.geometries[0].materialList.data.materialCount; i++)
for (u8 j = 0; j < dff->clump.geometryList.geometries[0].materialList.materials[i].data.textureCount; j++)
{
+28
View File
@@ -0,0 +1,28 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2020, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "../include/models/mesh_texture.hpp"
#include "../include/utils/debug.hpp"
// ----
// Constructors/Destructors
// ----
MeshTexture::MeshTexture()
{
}
MeshTexture::~MeshTexture()
{
}
// ----
// Methods
// ----
+1 -1
View File
@@ -51,7 +51,7 @@ GifSender::~GifSender()
#include <gs_gp.h>
/** Send texture via GIF */
void GifSender::sendTexture(Texture &texture, texbuffer_t *t_texBuffer)
void GifSender::sendTexture(MeshTexture &texture, texbuffer_t *t_texBuffer)
{
const u16 packetSize = 40;
packet_t *packet = packet_init(packetSize, PACKET_NORMAL);