mirror of
https://github.com/AntonioND/nitro-engine.git
synced 2025-06-19 09:05:50 -04:00
Fix style of md2_2_bin
Run `dos2unix` and `indent -linux` on the files and some other minor fixes.
This commit is contained in:
parent
bd0ce8d9a0
commit
8fe1bfce3c
2
Tools/Windows/md2_to_bin/.gitignore
vendored
Normal file
2
Tools/Windows/md2_to_bin/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.o
|
||||||
|
md2_2_bin
|
@ -2,7 +2,9 @@
|
|||||||
//
|
//
|
||||||
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "dlmaker.h"
|
#include "dlmaker.h"
|
||||||
#include "nds.h"
|
#include "nds.h"
|
||||||
|
|
||||||
@ -21,7 +23,8 @@ void NewDL(void)
|
|||||||
command[0] = command[1] = command[2] = command[3] = 0;
|
command[0] = command[1] = command[2] = command[3] = 0;
|
||||||
param[0] = param[1] = param[2] = param[3] = 0;
|
param[0] = param[1] = param[2] = param[3] = 0;
|
||||||
param[4] = param[5] = param[6] = param[7] = 0;
|
param[4] = param[5] = param[6] = param[7] = 0;
|
||||||
commands = 0; params = 0;
|
commands = 0;
|
||||||
|
params = 0;
|
||||||
|
|
||||||
DLPointer[DLcount] = (unsigned int *)malloc(DEFAULT_DL_SIZE);
|
DLPointer[DLcount] = (unsigned int *)malloc(DEFAULT_DL_SIZE);
|
||||||
DLSize[DLcount] = 1;
|
DLSize[DLcount] = 1;
|
||||||
@ -32,22 +35,25 @@ void NewCommandDL(int id)
|
|||||||
command[commands] = id;
|
command[commands] = id;
|
||||||
commands++;
|
commands++;
|
||||||
|
|
||||||
if(commands == 4) //Save data to display list
|
if (commands == 4) {
|
||||||
{
|
// Save data to display list
|
||||||
commands = 0;
|
commands = 0;
|
||||||
unsigned int temp;
|
unsigned int temp;
|
||||||
temp = COMMAND_PACK(command[0],command[1],command[2],command[3]);
|
temp =
|
||||||
|
COMMAND_PACK(command[0], command[1], command[2],
|
||||||
|
command[3]);
|
||||||
command[0] = command[1] = command[2] = command[3] = 0;
|
command[0] = command[1] = command[2] = command[3] = 0;
|
||||||
unsigned int * pointer = &((DLPointer[DLcount])[DLSize[DLcount]]);
|
unsigned int *pointer =
|
||||||
*pointer = temp; //Save commands
|
&((DLPointer[DLcount])[DLSize[DLcount]]);
|
||||||
|
// Save commands
|
||||||
|
*pointer = temp;
|
||||||
DLSize[DLcount]++;
|
DLSize[DLcount]++;
|
||||||
if(param > 0)
|
if (param > 0) {
|
||||||
{
|
|
||||||
pointer = &((DLPointer[DLcount])[DLSize[DLcount]]);
|
pointer = &((DLPointer[DLcount])[DLSize[DLcount]]);
|
||||||
int a;
|
int a;
|
||||||
for(a = 0; a < params; a ++)
|
for (a = 0; a < params; a++) {
|
||||||
{
|
// Save commands
|
||||||
pointer[a] = param[a]; //Save commands
|
pointer[a] = param[a];
|
||||||
DLSize[DLcount]++;
|
DLSize[DLcount]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,10 +61,10 @@ if(commands == 4) //Save data to display list
|
|||||||
param[4] = param[5] = param[6] = param[7] = 0;
|
param[4] = param[5] = param[6] = param[7] = 0;
|
||||||
params = 0;
|
params = 0;
|
||||||
|
|
||||||
if(DLSize[DLcount] >= DEFAULT_DL_SIZE)
|
if (DLSize[DLcount] >= DEFAULT_DL_SIZE) {
|
||||||
{
|
|
||||||
printf("\n\nDisplay list buffer overflow.\n\n");
|
printf("\n\nDisplay list buffer overflow.\n\n");
|
||||||
while(1); //TODO: Exit in a better way.
|
// TODO: Exit in a better way.
|
||||||
|
while (1) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,15 +77,16 @@ params++;
|
|||||||
|
|
||||||
void FinishDL(void)
|
void FinishDL(void)
|
||||||
{
|
{
|
||||||
if(commands > 0) //Add NOP commands to fill packed commands
|
if (commands > 0) {
|
||||||
{
|
// Add NOP commands to fill packed commands
|
||||||
while(1)
|
while (1) {
|
||||||
{
|
|
||||||
NewCommandDL(ID_NOP);
|
NewCommandDL(ID_NOP);
|
||||||
if(commands == 0) break;
|
if (commands == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*DLPointer[DLcount] = DLSize[DLcount] - 1; //DL real size in 4 bytes packs
|
// DL real size in 4 bytes packs
|
||||||
|
*DLPointer[DLcount] = DLSize[DLcount] - 1;
|
||||||
DLcount++;
|
DLcount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,4 +99,3 @@ unsigned int * GetDLPointer(int num)
|
|||||||
{
|
{
|
||||||
return DLPointer[num];
|
return DLPointer[num];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
//
|
//
|
||||||
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
#ifndef _DLMAKER_H_
|
#ifndef DLMAKER_H__
|
||||||
#define _DLMAKER_H_
|
#define DLMAKER_H__
|
||||||
|
|
||||||
#define DEFAULT_DL_SIZE (512 * 1024)
|
#define DEFAULT_DL_SIZE (512 * 1024)
|
||||||
|
|
||||||
@ -15,4 +15,4 @@ void FinishDL(void);
|
|||||||
int GetDLSize(int num);
|
int GetDLSize(int num);
|
||||||
unsigned int *GetDLPointer(int num);
|
unsigned int *GetDLPointer(int num);
|
||||||
|
|
||||||
#endif
|
#endif // DLMAKER_H__
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <malloc.h>
|
|
||||||
|
|
||||||
#include "nds.h"
|
#include "nds.h"
|
||||||
#include "dlmaker.h"
|
#include "dlmaker.h"
|
||||||
@ -21,90 +20,128 @@
|
|||||||
|
|
||||||
typedef float vec3_t[3];
|
typedef float vec3_t[3];
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
int ident;
|
||||||
int ident; int version;
|
int version;
|
||||||
|
|
||||||
int skinwidth; int skinheight;
|
int skinwidth;
|
||||||
|
int skinheight;
|
||||||
int framesize;
|
int framesize;
|
||||||
int num_skins; int num_vertices; int num_st; int num_tris; int num_glcmds; int num_frames;
|
int num_skins;
|
||||||
int offset_skins; int offset_st; int offset_tris; int offset_frames; int offset_glcmds;
|
int num_vertices;
|
||||||
|
int num_st;
|
||||||
|
int num_tris;
|
||||||
|
int num_glcmds;
|
||||||
|
int num_frames;
|
||||||
|
int offset_skins;
|
||||||
|
int offset_st;
|
||||||
|
int offset_tris;
|
||||||
|
int offset_frames;
|
||||||
|
int offset_glcmds;
|
||||||
int offset_end;
|
int offset_end;
|
||||||
} md2_header_t;
|
} md2_header_t;
|
||||||
|
|
||||||
typedef struct { short s; short t; } md2_texCoord_t;
|
typedef struct {
|
||||||
|
short s;
|
||||||
typedef struct { unsigned short vertex[3]; unsigned short st[3]; } md2_triangle_t;
|
short t;
|
||||||
|
} md2_texCoord_t;
|
||||||
typedef struct { unsigned char v[3]; unsigned char normalIndex; } md2_vertex_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
vec3_t scale; vec3_t translate;
|
unsigned short vertex[3];
|
||||||
|
unsigned short st[3];
|
||||||
|
} md2_triangle_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned char v[3];
|
||||||
|
unsigned char normalIndex;
|
||||||
|
} md2_vertex_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
vec3_t scale;
|
||||||
|
vec3_t translate;
|
||||||
char name[16];
|
char name[16];
|
||||||
md2_vertex_t *verts;
|
md2_vertex_t *verts;
|
||||||
} md2_frame_t;
|
} md2_frame_t;
|
||||||
|
|
||||||
typedef struct { float s; float t; int index; } md2_glcmd_t;
|
typedef struct {
|
||||||
|
float s;
|
||||||
|
float t;
|
||||||
|
int index;
|
||||||
|
} md2_glcmd_t;
|
||||||
|
|
||||||
float anorms[162][3] = {
|
float anorms[162][3] = {
|
||||||
#include "anorms.h"
|
#include "anorms.h"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void PrintUse(void)
|
void PrintUse(void)
|
||||||
{
|
{
|
||||||
printf("\n\nInstructions:\n\n");
|
printf("\n\n");
|
||||||
printf(" MD2_2_BIN [input.md2] [output.bin] ([float scale])\n");
|
printf("Instructions:\n");
|
||||||
printf(" ([float translate x] [float translate x] [float translate x])\n\n");
|
printf(" md2_2_bin [input.md2] [output.bin] <[float scale]>\n");
|
||||||
|
printf(" <[float translate x] [float translate x] [float translate x]>\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int floattovtx10(float n)
|
int floattovtx10(float n)
|
||||||
{
|
{
|
||||||
int value = ((v10) ((n) * (1 << 6))) & 0x3FF;
|
int value = ((v10) ((n) * (1 << 6))) & 0x3FF;
|
||||||
if(n < 0) value |= (1 << 10);
|
if (n < 0)
|
||||||
else value &= 0x1FF;
|
value |= (1 << 10);
|
||||||
|
else
|
||||||
|
value &= 0x1FF;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int IsValidSize(int size)
|
||||||
|
{
|
||||||
|
return (size == 8 || size == 16 || size == 32 || size == 64 ||
|
||||||
|
size == 128 || size == 256 || size == 512 || size == 1024);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
printf("\n\n ########################################\n");
|
printf("\n\n");
|
||||||
printf(" #/ \\#\n");
|
|
||||||
printf(" # -- -- MD2 2 BIN -- -- #\n");
|
|
||||||
printf(" #\\ v2.0 /#\n");
|
|
||||||
printf(" ########################################\n");
|
printf(" ########################################\n");
|
||||||
|
printf(" # #\n");
|
||||||
|
printf(" # -- -- MD2 2 BIN -- -- #\n");
|
||||||
|
printf(" # v2.0 #\n");
|
||||||
|
printf(" ########################################\n");
|
||||||
|
printf("\n");
|
||||||
|
printf("Copyright (c) 2008-2011, 2019 Antonio Nino Diaz\n");
|
||||||
|
printf("All rights reserved.\n\n");
|
||||||
|
|
||||||
printf("\nCopyright (C) 2008 Antonio Ni%co D%caz\nAll rights reserved.\n\n", 164, 161);
|
// Default values
|
||||||
|
float global_scale = 1;
|
||||||
|
float global_translation[3] = { 0, 0, 0 };
|
||||||
|
|
||||||
printf(" -- -- -- -- -- -- -- -- -- --\n");
|
switch (argc) {
|
||||||
|
|
||||||
float general_scale = 1; //DEFAULT VALUES
|
|
||||||
float general_trans[3] = {0, 0, 0};
|
|
||||||
|
|
||||||
switch(argc)
|
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
case 2: //Not enough
|
case 2:
|
||||||
|
// Not enough arguments
|
||||||
PrintUse();
|
PrintUse();
|
||||||
return -1;
|
return -1;
|
||||||
case 3: //Use default modifications
|
case 3:
|
||||||
|
// Use default modifications
|
||||||
break;
|
break;
|
||||||
case 4: //Use default translation and custom scale
|
case 4:
|
||||||
general_scale = atof(argv[3]);
|
// Use default translation and custom scale
|
||||||
|
global_scale = atof(argv[3]);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
case 6: //Custom translation, not enough
|
case 6:
|
||||||
|
// Custom translation, not enough
|
||||||
printf("You must set 3 coordinates for translation, not less.");
|
printf("You must set 3 coordinates for translation, not less.");
|
||||||
PrintUse();
|
PrintUse();
|
||||||
return -1;
|
return -1;
|
||||||
case 7: //Custom translation + scale
|
case 7:
|
||||||
general_scale = atof(argv[3]);
|
// Custom translation + scale
|
||||||
general_trans[0] = atof(argv[4]);
|
global_scale = atof(argv[3]);
|
||||||
general_trans[1] = atof(argv[5]);
|
global_translation[0] = atof(argv[4]);
|
||||||
general_trans[2] = atof(argv[6]);
|
global_translation[1] = atof(argv[5]);
|
||||||
|
global_translation[2] = atof(argv[6]);
|
||||||
break;
|
break;
|
||||||
default: //The rest...
|
default:
|
||||||
|
// Too many arguments
|
||||||
PrintUse();
|
PrintUse();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -115,8 +152,7 @@ int main(int argc, char* argv[])
|
|||||||
strcpy(inputfilepath, argv[1]);
|
strcpy(inputfilepath, argv[1]);
|
||||||
strcpy(outputfilepath, argv[2]);
|
strcpy(outputfilepath, argv[2]);
|
||||||
|
|
||||||
if(general_scale == 0)
|
if (global_scale == 0) {
|
||||||
{
|
|
||||||
printf("\nScale can't be 0!!");
|
printf("\nScale can't be 0!!");
|
||||||
PrintUse();
|
PrintUse();
|
||||||
return -1;
|
return -1;
|
||||||
@ -124,58 +160,68 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
char *md2data;
|
char *md2data;
|
||||||
|
|
||||||
printf("\nScale: %f\n",general_scale);
|
printf("\n");
|
||||||
printf("Translate: %f, %f, %f\n",general_trans[0],general_trans[1],general_trans[2]);
|
printf("Scale: %f\n", global_scale);
|
||||||
|
printf("Translate: %f, %f, %f\n", global_translation[0],
|
||||||
|
global_translation[1], global_translation[2]);
|
||||||
|
|
||||||
printf("\nLoading MD2 model...\n");
|
printf("\n");
|
||||||
|
printf("Loading MD2 model...\n");
|
||||||
|
|
||||||
FILE *datafile = fopen(inputfilepath, "r");
|
FILE *datafile = fopen(inputfilepath, "r");
|
||||||
if(datafile != NULL)
|
if (datafile != NULL) {
|
||||||
{
|
|
||||||
fseek(datafile, 0, SEEK_END);
|
fseek(datafile, 0, SEEK_END);
|
||||||
long int tamano = ftell (datafile);
|
long int size_ = ftell(datafile);
|
||||||
rewind(datafile);
|
rewind(datafile);
|
||||||
md2data = (char*) malloc (sizeof(char)*tamano);
|
md2data = (char *)malloc(sizeof(char) * size_);
|
||||||
fread (md2data,1,tamano,datafile);
|
fread(md2data, 1, size_, datafile);
|
||||||
fclose(datafile);
|
fclose(datafile);
|
||||||
|
} else {
|
||||||
|
fclose(datafile);
|
||||||
|
printf("\n\nCouldn't open %s!!\n\n", inputfilepath);
|
||||||
|
PrintUse();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{ fclose (datafile); printf("\n\nCouldn't open %s!!\n\n", inputfilepath);
|
|
||||||
PrintUse(); return -1; }
|
|
||||||
|
|
||||||
md2_header_t *header = (md2_header_t *) md2data;
|
md2_header_t *header = (md2_header_t *) md2data;
|
||||||
|
|
||||||
if ((header->ident != 844121161) || (header->version != 8))
|
if ((header->ident != 844121161) || (header->version != 8)) {
|
||||||
{ printf("\n\nWrong file type or version!!\n\n"); return -1; }
|
printf("\n\nWrong file type or version!!\n\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int t_w = header->skinwidth, t_h = header->skinheight;
|
int t_w = header->skinwidth, t_h = header->skinheight;
|
||||||
|
|
||||||
if(t_w > 1024 || t_h > 1024) { printf("\n\nTexture too big!!\n\n"); return -1; }
|
if (t_w > 1024 || t_h > 1024) {
|
||||||
|
printf("\n\nTexture too big!!\n\n");
|
||||||
if(!(t_w==8||t_w==16||t_w==32||t_w==64||t_w==128||t_w==256||t_w==512||t_w==1024) ||
|
return -1;
|
||||||
!(t_h==8||t_h==16||t_h==32||t_h==64||t_h==128||t_h==256||t_h==512||t_h==1024))
|
|
||||||
{
|
|
||||||
printf("\nWrong texture size. Must be power of 2.\n");
|
|
||||||
printf("\nAlthough the model uses an invalid texture size, it will be converted.\n");
|
|
||||||
printf("\nResize the texture to nearest valid size.\n\n");
|
|
||||||
//return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while(1)
|
if (!IsValidSize(t_w) || !IsValidSize(t_h)) {
|
||||||
{ if(t_w==8||t_w==16||t_w==32||t_w==64||t_w==128||t_w==256||t_w==512||t_w==1024) break;
|
printf("\nWrong texture size. It must be a power of 2.\n");
|
||||||
t_w ++; }
|
printf("\nAlthough the model uses an invalid texture size, it will be converted.\n");
|
||||||
while(1)
|
printf("\nResize the texture to nearest valid size.\n\n");
|
||||||
{ if(t_h==8||t_h==16||t_h==32||t_h==64||t_h==128||t_h==256||t_h==512||t_h==1024) break;
|
}
|
||||||
t_h ++; }
|
|
||||||
|
while (!IsValidSize(t_w)) {
|
||||||
|
t_w++;
|
||||||
|
}
|
||||||
|
while (!IsValidSize(t_h)) {
|
||||||
|
t_h++;
|
||||||
|
}
|
||||||
|
|
||||||
int num_tris = header->num_tris;
|
int num_tris = header->num_tris;
|
||||||
|
|
||||||
md2_frame_t *frame = NULL;
|
md2_frame_t *frame = NULL;
|
||||||
md2_texCoord_t * texcoord = (md2_texCoord_t*)((uintptr_t)header->offset_st + (uintptr_t)header);
|
md2_texCoord_t *texcoord =
|
||||||
md2_triangle_t * triangle = (md2_triangle_t*)((uintptr_t)header->offset_tris + (uintptr_t)header);
|
(md2_texCoord_t *) ((uintptr_t) header->offset_st +
|
||||||
|
(uintptr_t) header);
|
||||||
|
md2_triangle_t *triangle =
|
||||||
|
(md2_triangle_t *) ((uintptr_t) header->offset_tris +
|
||||||
|
(uintptr_t) header);
|
||||||
|
|
||||||
md2_vertex_t * vtx; //Current vertex
|
// Current vertex
|
||||||
|
md2_vertex_t *vtx;
|
||||||
|
|
||||||
printf("\nMD2 texture size: %dx%d", t_w, t_h);
|
printf("\nMD2 texture size: %dx%d", t_w, t_h);
|
||||||
|
|
||||||
@ -184,119 +230,136 @@ int main(int argc, char* argv[])
|
|||||||
float bigvalue = 0;
|
float bigvalue = 0;
|
||||||
|
|
||||||
// Everything ready, let's "draw" the display list
|
// Everything ready, let's "draw" the display list
|
||||||
frame = (md2_frame_t*)((uintptr_t)header->offset_frames + (uintptr_t)header);
|
frame =
|
||||||
|
(md2_frame_t *) ((uintptr_t) header->offset_frames +
|
||||||
|
(uintptr_t) header);
|
||||||
|
|
||||||
NewDL();
|
NewDL();
|
||||||
NewParamDL(0); // 0 = GL_TRIANGLES
|
|
||||||
|
// Send GL_TRIANGLES command
|
||||||
|
NewParamDL(0);
|
||||||
NewCommandDL(ID_BEGIN);
|
NewCommandDL(ID_BEGIN);
|
||||||
|
|
||||||
int olds_ = -1, oldt_ = -1; //Used to avoid useless command repeating
|
// Keep track of the last command to avoid useless repetition
|
||||||
|
int olds_ = -1, oldt_ = -1;
|
||||||
int oldnormindex = -1;
|
int oldnormindex = -1;
|
||||||
|
|
||||||
int vtxcount = 0;
|
int vtxcount = 0;
|
||||||
|
|
||||||
int t = 0, v = 0;
|
int t = 0, v = 0;
|
||||||
for(t = 0; t < num_tris; t ++) for(v = 0; v < 3; v++)
|
for (t = 0; t < num_tris; t++)
|
||||||
{
|
for (v = 0; v < 3; v++) {
|
||||||
vtx = (md2_vertex_t *) ((uintptr_t) (&(frame->verts)));
|
vtx = (md2_vertex_t *) ((uintptr_t) (&(frame->verts)));
|
||||||
vtx = &vtx[triangle[t].vertex[v]];
|
vtx = &vtx[triangle[t].vertex[v]];
|
||||||
|
|
||||||
//Texture
|
// Texture coordinates
|
||||||
short s_ = texcoord[triangle[t].st[v]].s;
|
short s_ = texcoord[triangle[t].st[v]].s;
|
||||||
short t_ = texcoord[triangle[t].st[v]].t;
|
short t_ = texcoord[triangle[t].st[v]].t;
|
||||||
if(olds_ != s_ || oldt_ != t_)
|
if (olds_ != s_ || oldt_ != t_) {
|
||||||
{
|
|
||||||
olds_ = s_;
|
olds_ = s_;
|
||||||
oldt_ = t_;
|
oldt_ = t_;
|
||||||
|
|
||||||
//This is used to change UVs if using a texture size unsupported by DS
|
// This is used to scale UVs if using a texture
|
||||||
s_ = (int)((float)(s_ * t_w) / (float)header->skinwidth);
|
// size unsupported by DS
|
||||||
t_ = (int)((float)(t_ * t_h) / (float)header->skinheight);
|
s_ = (int)((float)(s_ * t_w) /
|
||||||
|
(float)header->skinwidth);
|
||||||
|
t_ = (int)((float)(t_ * t_h) /
|
||||||
|
(float)header->skinheight);
|
||||||
NewParamDL(TEXTURE_PACK(s_ << 4, t_ << 4)); // (t_h-t_)<<4));
|
NewParamDL(TEXTURE_PACK(s_ << 4, t_ << 4)); // (t_h-t_)<<4));
|
||||||
NewCommandDL(ID_TEX_COORD);
|
NewCommandDL(ID_TEX_COORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normal
|
// Normal
|
||||||
float norm[3];
|
float norm[3];
|
||||||
if(oldnormindex != vtx->normalIndex)
|
if (oldnormindex != vtx->normalIndex) {
|
||||||
{
|
|
||||||
oldnormindex = vtx->normalIndex;
|
oldnormindex = vtx->normalIndex;
|
||||||
int b;
|
int b;
|
||||||
for(b = 0; b < 3; b++) norm[b] = anorms[vtx->normalIndex][b];
|
for (b = 0; b < 3; b++)
|
||||||
NewParamDL(NORMAL_PACK(floattov10(norm[0]), floattov10(norm[1]), floattov10(norm[2])));
|
norm[b] = anorms[vtx->normalIndex][b];
|
||||||
|
NewParamDL(NORMAL_PACK
|
||||||
|
(floattov10(norm[0]),
|
||||||
|
floattov10(norm[1]),
|
||||||
|
floattov10(norm[2])));
|
||||||
NewCommandDL(ID_NORMAL);
|
NewCommandDL(ID_NORMAL);
|
||||||
}
|
}
|
||||||
// Vertex
|
// Vertex
|
||||||
float _v[3];
|
float _v[3];
|
||||||
int a = 0;
|
int a = 0;
|
||||||
int vtx10 = false;
|
int vtx10 = false;
|
||||||
for(a = 0; a < 3; a++)
|
for (a = 0; a < 3; a++) {
|
||||||
{
|
|
||||||
vtxcount++;
|
vtxcount++;
|
||||||
_v[a] = ((float)frame->scale[a] * (float)(vtx->v[a])) + (float)frame->translate[a];
|
_v[a] =
|
||||||
_v[a] += general_trans[a];
|
((float)frame->scale[a] *
|
||||||
_v[a] *= general_scale;
|
(float)(vtx->v[a])) +
|
||||||
|
(float)frame->translate[a];
|
||||||
|
_v[a] += global_translation[a];
|
||||||
|
_v[a] *= global_scale;
|
||||||
// 7.9997 for VTX_16, 7.98 for VTX_10
|
// 7.9997 for VTX_16, 7.98 for VTX_10
|
||||||
if((absf(_v[a]) > (float)7.9997) && ( absf(bigvalue) < absf(_v[a])))
|
if ((absf(_v[a]) > (float)7.9997)
|
||||||
|
&& (absf(bigvalue) < absf(_v[a])))
|
||||||
bigvalue = _v[a];
|
bigvalue = _v[a];
|
||||||
//Test if OK to use VTX_10
|
// Test to see if it is more accurate to use
|
||||||
if(absf(_v[a]) < (float)7.98)
|
// VTX_10 or VTX_16
|
||||||
{
|
if (absf(_v[a]) < (float)7.98) {
|
||||||
float aux = (float)1 / (float)64;
|
float aux = (float)1 / (float)64;
|
||||||
float tempvtx = _v[a] / aux;
|
float tempvtx = _v[a] / aux;
|
||||||
tempvtx = absf(tempvtx - (float)(int)tempvtx);
|
tempvtx =
|
||||||
aux = (float)0.2; //You can try changing it, but 0.2 is OK
|
absf(tempvtx - (float)(int)tempvtx);
|
||||||
if(tempvtx < aux || tempvtx > ((float)1 - aux)) vtx10 = true;
|
// Arbitrary threshold
|
||||||
|
aux = (float)0.2;
|
||||||
|
if (tempvtx < aux
|
||||||
|
|| tempvtx > ((float)1 - aux))
|
||||||
|
vtx10 = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(vtx10)
|
if (vtx10) {
|
||||||
{
|
NewParamDL(VERTEX_10_PACK
|
||||||
NewParamDL(VERTEX_10_PACK(floattovtx10(_v[0]),floattovtx10(_v[2]),
|
(floattovtx10(_v[0]),
|
||||||
|
floattovtx10(_v[2]),
|
||||||
floattovtx10(_v[1])));
|
floattovtx10(_v[1])));
|
||||||
NewCommandDL(ID_VERTEX10);
|
NewCommandDL(ID_VERTEX10);
|
||||||
}
|
} else {
|
||||||
else
|
NewParamDL((floattov16(_v[2]) << 16) |
|
||||||
{
|
(floattov16(_v[0]) & 0xFFFF));
|
||||||
NewParamDL((floattov16(_v[2]) << 16) | (floattov16(_v[0]) & 0xFFFF));
|
|
||||||
NewParamDL((floattov16(_v[1]) & 0xFFFF));
|
NewParamDL((floattov16(_v[1]) & 0xFFFF));
|
||||||
NewCommandDL(ID_VERTEX16);
|
NewCommandDL(ID_VERTEX16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FinishDL();
|
FinishDL();
|
||||||
|
|
||||||
if(absf(bigvalue) > 0)
|
if (absf(bigvalue) > 0) {
|
||||||
{
|
|
||||||
printf("\nModel too big for DS! Scale it down.\n");
|
printf("\nModel too big for DS! Scale it down.\n");
|
||||||
printf("\nDS max. allowed value: +/-7,9997\nModel max. detected value: %f\n\n",bigvalue);
|
printf
|
||||||
|
("\nDS max. allowed value: +/-7,9997\nModel max. detected value: %f\n\n",
|
||||||
|
bigvalue);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vtxcount > 6144)
|
if (vtxcount > 6144) {
|
||||||
{
|
|
||||||
printf("\nModel has too many vertices!\n");
|
printf("\nModel has too many vertices!\n");
|
||||||
printf("\nDS can only render 6144 vertices per frame.\nYour model has %d vertices.\n",vtxcount);
|
printf
|
||||||
//return -1;
|
("\nDS can only render 6144 vertices per frame.\nYour model has %d vertices.\n",
|
||||||
|
vtxcount);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nCreating BIN file...\n");
|
printf("\nCreating BIN file...\n");
|
||||||
|
|
||||||
// Now, let's save them into a BIN file.
|
// Now, let's save them into a BIN file.
|
||||||
FILE *file = fopen(outputfilepath, "wb+");
|
FILE *file = fopen(outputfilepath, "wb+");
|
||||||
if(file == NULL)
|
if (file == NULL) {
|
||||||
{
|
|
||||||
printf("\nCouldn't create %s file!", outputfilepath);
|
printf("\nCouldn't create %s file!", outputfilepath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fwrite((int*)GetDLPointer(0),GetDLSize(0) * sizeof(unsigned int),1,file);
|
fwrite((int *)GetDLPointer(0), GetDLSize(0) * sizeof(unsigned int), 1,
|
||||||
|
file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
FILE *test = fopen(outputfilepath, "rb");
|
FILE *test = fopen(outputfilepath, "rb");
|
||||||
fseek(test, 0, SEEK_END);
|
fseek(test, 0, SEEK_END);
|
||||||
long int size = ftell(test);
|
long int size = ftell(test);
|
||||||
fclose(test);
|
fclose(test);
|
||||||
printf("\nBIN file size: %zd bytes", size);
|
printf("\nBIN file size: %zd bytes\n", size);
|
||||||
|
|
||||||
printf("\n\nReady!\n\n");
|
printf("\nReady!\n\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
//
|
//
|
||||||
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
#ifndef _NDS_H_
|
#ifndef NDS_H__
|
||||||
#define _NDS_H_
|
#define NDS_H__
|
||||||
|
|
||||||
//From libnds/gbatek
|
//From libnds/gbatek
|
||||||
|
|
||||||
@ -15,8 +15,10 @@ typedef short int vtx10;
|
|||||||
|
|
||||||
static inline short int floattov10(float n)
|
static inline short int floattov10(float n)
|
||||||
{
|
{
|
||||||
if(n > 0.998) return 0x1FF;
|
if (n > 0.998)
|
||||||
if(n < -0.998) return 0x3FF;
|
return 0x1FF;
|
||||||
|
if (n < -0.998)
|
||||||
|
return 0x3FF;
|
||||||
return (short int)(n * (1 << 9));
|
return (short int)(n * (1 << 9));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,4 +37,4 @@ static inline short int floattov10(float n)
|
|||||||
#define ID_NORMAL 0x21
|
#define ID_NORMAL 0x21
|
||||||
#define ID_BEGIN 0x40
|
#define ID_BEGIN 0x40
|
||||||
|
|
||||||
#endif
|
#endif // NDS_H__
|
||||||
|
Loading…
Reference in New Issue
Block a user