Skip to content

Commit 8ce2c4c

Browse files
authored
Merge pull request #101 from ReyeMe/feature/update-nya-samples
Update(Samples): Updated model loader in samples
2 parents 366802d + 09bb962 commit 8ce2c4c

File tree

4 files changed

+152
-12
lines changed

4 files changed

+152
-12
lines changed

Samples/VDP1 - 3D - Animation/src/modelObject.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ class ModelObject
134134
*/
135135
uint8_t IsWireframe : 1;
136136

137+
/** @brief Render faces without any light applied
138+
*/
139+
uint8_t NoLight : 1;
140+
137141
/** @brief Reserved for future use
138142
*/
139-
uint8_t Reserved : 7;
143+
uint8_t Reserved : 6;
140144

141145
/** @brief This field is set if HasTexture field is false
142146
*/
@@ -218,7 +222,7 @@ class ModelObject
218222
(attributeHeader->HasTransparency != 0 ? CL_Trans : 0) |
219223
(attributeHeader->HasHalfBrightness != 0 ? CL_Half : 0),
220224
(attributeHeader->IsWireframe != 0 ? sprPolyLine : (attributeHeader->HasTexture != 0 ? sprNoflip : sprPolygon)),
221-
UseLight);
225+
(attributeHeader->NoLight != 0 ? No_Option : UseLight));
222226
#pragma GCC diagnostic pop
223227
}
224228

@@ -273,7 +277,7 @@ class ModelObject
273277
(attributeHeader->HasTransparency != 0 ? CL_Trans : 0) |
274278
(attributeHeader->HasHalfBrightness != 0 ? CL_Half : 0),
275279
(attributeHeader->IsWireframe != 0 ? sprPolyLine : (attributeHeader->HasTexture != 0 ? sprNoflip : sprPolygon)),
276-
(attributeHeader->HasFlatShading != 0 ? UseLight : UseGouraud));
280+
(attributeHeader->NoLight != 0 ? No_Option : (attributeHeader->HasFlatShading != 0 ? UseLight : UseGouraud)));
277281
#pragma GCC diagnostic pop
278282

279283
*gouraudIterator += 1;

Samples/VDP1 - 3D - Flat teapot/src/main.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ int main()
1515

1616
// Load teapot
1717
// Original model file can be found in the models folder in root of the sample
18-
// Model was converted with ModelConverter (see https://github.com/ReyeMe/ModelConverter-linux), command parameters were: ModelConverter -i "D:\teapot.obj" -o "D:\FPOT.NYA" -s 1.0
18+
// Model was converted with ModelConverter (see https://github.com/ReyeMe/ModelConverter-linux), command parameters were: ModelConverter -i "D:\teapot.obj" -o "D:\FPOT.NYA" -t Flat -s 1.0
1919
ModelObject teapot = ModelObject("FPOT.NYA");
2020

2121
// Setup camera location

Samples/VDP1 - 3D - Flat teapot/src/modelObject.hpp

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ class ModelObject
134134
*/
135135
uint8_t IsWireframe : 1;
136136

137+
/** @brief Render faces without any light applied
138+
*/
139+
uint8_t NoLight : 1;
140+
137141
/** @brief Reserved for future use
138142
*/
139-
uint8_t Reserved : 7;
143+
uint8_t Reserved : 6;
140144

141145
/** @brief This field is set if HasTexture field is false
142146
*/
@@ -213,12 +217,12 @@ class ModelObject
213217
textureIndex,
214218
color,
215219
CL32KRGB,
216-
CL32KRGB | ECdis |
220+
CL32KRGB |
217221
(attributeHeader->HasMeshEffect != 0 ? MESHon : MESHoff) |
218222
(attributeHeader->HasTransparency != 0 ? CL_Trans : 0) |
219223
(attributeHeader->HasHalfBrightness != 0 ? CL_Half : 0),
220224
(attributeHeader->IsWireframe != 0 ? sprPolyLine : (attributeHeader->HasTexture != 0 ? sprNoflip : sprPolygon)),
221-
UseLight);
225+
(attributeHeader->NoLight != 0 ? No_Option : UseLight));
222226
#pragma GCC diagnostic pop
223227
}
224228

@@ -267,13 +271,13 @@ class ModelObject
267271
textureIndex,
268272
color,
269273
(attributeHeader->HasFlatShading != 0 ? CL32KRGB : *gouraudIterator),
270-
CL32KRGB | ECdis |
274+
CL32KRGB |
271275
(attributeHeader->HasMeshEffect != 0 ? MESHon : MESHoff) |
272276
(attributeHeader->HasFlatShading != 0 ? 0 : CL_Gouraud) |
273277
(attributeHeader->HasTransparency != 0 ? CL_Trans : 0) |
274278
(attributeHeader->HasHalfBrightness != 0 ? CL_Half : 0),
275279
(attributeHeader->IsWireframe != 0 ? sprPolyLine : (attributeHeader->HasTexture != 0 ? sprNoflip : sprPolygon)),
276-
(attributeHeader->HasFlatShading != 0 ? UseLight : UseGouraud));
280+
(attributeHeader->NoLight != 0 ? No_Option : (attributeHeader->HasFlatShading != 0 ? UseLight : UseGouraud)));
277281
#pragma GCC diagnostic pop
278282

279283
*gouraudIterator += 1;
@@ -288,6 +292,70 @@ class ModelObject
288292

289293
public:
290294

295+
/** @brief Initializes a new empty model object
296+
*/
297+
298+
ModelObject()
299+
{
300+
// empty constructor
301+
}
302+
303+
/** @brief Loads a model object from a file
304+
* @param modelFile Model file
305+
* @param gouraudTableStart Offset in gouraud table (used only with smooth meshes)
306+
*/
307+
308+
void LoadFile(const char* modelFile, size_t gouraudTableStart = 0)
309+
{
310+
SRL::Cd::File file = SRL::Cd::File(modelFile);
311+
312+
char* fileBuffer = new char[file.Size.Bytes];
313+
file.LoadBytes(0, file.Size.Bytes, fileBuffer);
314+
315+
char* iterator = fileBuffer;
316+
317+
ModelHeader* header = GetAndIterate<ModelHeader>(iterator);
318+
319+
// Set defaults
320+
this->startTextureIndex = -1;
321+
this->textureCount = header->TextureCount;
322+
this->meshCount = header->MeshCount;
323+
this->type = header->Type;
324+
this->gouraudOffset = gouraudTableStart;
325+
size_t gouraudIterator = 0xe000 + this->gouraudOffset;
326+
327+
this->meshes = header->Type == 1 ? (void*)new SRL::Types::SmoothMesh[this->meshCount] : (void*)new SRL::Types::Mesh[this->meshCount];
328+
329+
if (header->Type == 1)
330+
{
331+
for (size_t meshIndex = 0; meshIndex < this->meshCount; meshIndex++)
332+
{
333+
this->LoadSmoothMesh(&iterator, &gouraudIterator, meshIndex, header);
334+
}
335+
}
336+
else
337+
{
338+
for (size_t meshIndex = 0; meshIndex < this->meshCount; meshIndex++)
339+
{
340+
this->LoadFlatMesh(&iterator, meshIndex, header);
341+
}
342+
}
343+
344+
// Load textures
345+
for (size_t textureIndex = 0; textureIndex < this->textureCount; textureIndex++)
346+
{
347+
// Get header
348+
TextureHeader* textureHeader = GetAndIterate<TextureHeader>(iterator);
349+
350+
// Get texture data
351+
int32_t spriteIndex = SRL::VDP1::TryLoadTexture(textureHeader->Width, textureHeader->Height, SRL::CRAM::TextureColorMode::RGB555, 0, textureHeader->Data());
352+
}
353+
354+
// Free the read file
355+
delete fileBuffer;
356+
}
357+
358+
291359
/** @brief Initializes a new model object from a file
292360
* @param modelFile Model file
293361
* @param gouraudTableStart Offset in gouraud table (used only with smooth meshes)

Samples/VDP1 - 3D - Smooth teapot/src/modelObject.hpp

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ class ModelObject
134134
*/
135135
uint8_t IsWireframe : 1;
136136

137+
/** @brief Render faces without any light applied
138+
*/
139+
uint8_t NoLight : 1;
140+
137141
/** @brief Reserved for future use
138142
*/
139-
uint8_t Reserved : 7;
143+
uint8_t Reserved : 6;
140144

141145
/** @brief This field is set if HasTexture field is false
142146
*/
@@ -218,7 +222,7 @@ class ModelObject
218222
(attributeHeader->HasTransparency != 0 ? CL_Trans : 0) |
219223
(attributeHeader->HasHalfBrightness != 0 ? CL_Half : 0),
220224
(attributeHeader->IsWireframe != 0 ? sprPolyLine : (attributeHeader->HasTexture != 0 ? sprNoflip : sprPolygon)),
221-
UseLight);
225+
(attributeHeader->NoLight != 0 ? No_Option : UseLight));
222226
#pragma GCC diagnostic pop
223227
}
224228

@@ -273,7 +277,7 @@ class ModelObject
273277
(attributeHeader->HasTransparency != 0 ? CL_Trans : 0) |
274278
(attributeHeader->HasHalfBrightness != 0 ? CL_Half : 0),
275279
(attributeHeader->IsWireframe != 0 ? sprPolyLine : (attributeHeader->HasTexture != 0 ? sprNoflip : sprPolygon)),
276-
(attributeHeader->HasFlatShading != 0 ? UseLight : UseGouraud));
280+
(attributeHeader->NoLight != 0 ? No_Option : (attributeHeader->HasFlatShading != 0 ? UseLight : UseGouraud)));
277281
#pragma GCC diagnostic pop
278282

279283
*gouraudIterator += 1;
@@ -288,6 +292,70 @@ class ModelObject
288292

289293
public:
290294

295+
/** @brief Initializes a new empty model object
296+
*/
297+
298+
ModelObject()
299+
{
300+
// empty constructor
301+
}
302+
303+
/** @brief Loads a model object from a file
304+
* @param modelFile Model file
305+
* @param gouraudTableStart Offset in gouraud table (used only with smooth meshes)
306+
*/
307+
308+
void LoadFile(const char* modelFile, size_t gouraudTableStart = 0)
309+
{
310+
SRL::Cd::File file = SRL::Cd::File(modelFile);
311+
312+
char* fileBuffer = new char[file.Size.Bytes];
313+
file.LoadBytes(0, file.Size.Bytes, fileBuffer);
314+
315+
char* iterator = fileBuffer;
316+
317+
ModelHeader* header = GetAndIterate<ModelHeader>(iterator);
318+
319+
// Set defaults
320+
this->startTextureIndex = -1;
321+
this->textureCount = header->TextureCount;
322+
this->meshCount = header->MeshCount;
323+
this->type = header->Type;
324+
this->gouraudOffset = gouraudTableStart;
325+
size_t gouraudIterator = 0xe000 + this->gouraudOffset;
326+
327+
this->meshes = header->Type == 1 ? (void*)new SRL::Types::SmoothMesh[this->meshCount] : (void*)new SRL::Types::Mesh[this->meshCount];
328+
329+
if (header->Type == 1)
330+
{
331+
for (size_t meshIndex = 0; meshIndex < this->meshCount; meshIndex++)
332+
{
333+
this->LoadSmoothMesh(&iterator, &gouraudIterator, meshIndex, header);
334+
}
335+
}
336+
else
337+
{
338+
for (size_t meshIndex = 0; meshIndex < this->meshCount; meshIndex++)
339+
{
340+
this->LoadFlatMesh(&iterator, meshIndex, header);
341+
}
342+
}
343+
344+
// Load textures
345+
for (size_t textureIndex = 0; textureIndex < this->textureCount; textureIndex++)
346+
{
347+
// Get header
348+
TextureHeader* textureHeader = GetAndIterate<TextureHeader>(iterator);
349+
350+
// Get texture data
351+
int32_t spriteIndex = SRL::VDP1::TryLoadTexture(textureHeader->Width, textureHeader->Height, SRL::CRAM::TextureColorMode::RGB555, 0, textureHeader->Data());
352+
}
353+
354+
// Free the read file
355+
delete fileBuffer;
356+
}
357+
358+
291359
/** @brief Initializes a new model object from a file
292360
* @param modelFile Model file
293361
* @param gouraudTableStart Offset in gouraud table (used only with smooth meshes)

0 commit comments

Comments
 (0)