mirror of
https://github.com/AntonioND/nitro-engine.git
synced 2025-06-19 09:05:50 -04:00
Make MD2_2_NEA build
Also, rename to md2_to_nea.
This commit is contained in:
parent
dfb8537589
commit
f76185bbd1
2
Tools/Windows/md2_to_nea/.gitignore
vendored
Normal file
2
Tools/Windows/md2_to_nea/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.o
|
||||||
|
md2_2_nea
|
28
Tools/Windows/md2_to_nea/Makefile
Normal file
28
Tools/Windows/md2_to_nea/Makefile
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
#
|
||||||
|
# Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
|
||||||
|
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`
|
||||||
|
CFLAGS := -g -Wall -DBUILD_VERSION_STRING=\"$(VERSION_STRING)\"
|
||||||
|
RM := rm -rf
|
||||||
|
|
||||||
|
# Rules to build the binary
|
||||||
|
|
||||||
|
all: md2_2_nea
|
||||||
|
|
||||||
|
md2_2_nea_obj := md2_2_nea.o dynamic_list.o framemaker.o
|
||||||
|
|
||||||
|
md2_2_nea: $(md2_2_nea_obj)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $(md2_2_nea_obj)
|
||||||
|
|
||||||
|
# Rules to process files
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
# Target used to remove all files generated by other Makefile targets
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) md2_2_nea md2_2_nea.exe $(md2_2_nea_obj)
|
@ -1,5 +1,9 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <malloc.h>
|
|
||||||
#include "dynamic_list.h"
|
#include "dynamic_list.h"
|
||||||
|
|
||||||
void DynamicListNew(DinamicList ** list)
|
void DynamicListNew(DinamicList ** list)
|
@ -1,3 +1,6 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
#ifndef _DYNAMICLIST_H_
|
#ifndef _DYNAMICLIST_H_
|
||||||
#define _DYNAMICLIST_H_
|
#define _DYNAMICLIST_H_
|
@ -1,7 +1,12 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <malloc.h>
|
|
||||||
#include "framemaker.h"
|
|
||||||
#include "dynamic_list.h"
|
#include "dynamic_list.h"
|
||||||
|
#include "framemaker.h"
|
||||||
|
|
||||||
DinamicList *vertices_list;
|
DinamicList *vertices_list;
|
||||||
DinamicList *normal_list;
|
DinamicList *normal_list;
|
||||||
@ -9,11 +14,11 @@ DinamicList *texcoords_list;
|
|||||||
|
|
||||||
unsigned int FrameSize[1024];
|
unsigned int FrameSize[1024];
|
||||||
unsigned short *FramePointer[1024];
|
unsigned short *FramePointer[1024];
|
||||||
int framecount = -1; // -----.
|
int framecount = -1; // ------.
|
||||||
// |
|
// |
|
||||||
void NewFrame(void) // |
|
void NewFrame(void) // |
|
||||||
{ // |
|
{ // |
|
||||||
framecount++; // <------------' For first frame
|
framecount++; // <----' For first frame
|
||||||
|
|
||||||
FramePointer[framecount] = (unsigned short *)malloc(DEFAULT_FRAME_SIZE);
|
FramePointer[framecount] = (unsigned short *)malloc(DEFAULT_FRAME_SIZE);
|
||||||
if (FramePointer[framecount] == NULL) {
|
if (FramePointer[framecount] == NULL) {
|
@ -1,8 +1,11 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
//
|
||||||
|
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
#ifndef _FRAMEMAKER_H_
|
#ifndef FRAMEMAKER_H__
|
||||||
#define _FRAMEMAKER_H_
|
#define FRAMEMAKER_H__
|
||||||
|
|
||||||
#define DEFAULT_FRAME_SIZE (512*1024)
|
#define DEFAULT_FRAME_SIZE (512 * 1024)
|
||||||
|
|
||||||
void NewFrame(void);
|
void NewFrame(void);
|
||||||
void NewFrameData(unsigned short data);
|
void NewFrameData(unsigned short data);
|
||||||
@ -27,4 +30,4 @@ void GetNormal(int index, unsigned short *x, unsigned short *y,
|
|||||||
unsigned short *z);
|
unsigned short *z);
|
||||||
void GetTexCoord(int index, unsigned short *u, unsigned short *v);
|
void GetTexCoord(int index, unsigned short *u, unsigned short *v);
|
||||||
|
|
||||||
#endif
|
#endif // FRAMEMAKER_H__
|
@ -1,17 +1,17 @@
|
|||||||
// MD2_2_NEA.cpp : Defines the entry point for the console application.
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
//
|
//
|
||||||
|
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||||
|
|
||||||
//I used the information in this web to make the converter:
|
// I used the information in this web to make the converter:
|
||||||
//http://tfc.duke.free.fr/coding/md2-specs-en.html
|
// http://tfc.duke.free.fr/coding/md2-specs-en.html
|
||||||
//Thanks.
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <malloc.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "framemaker.h"
|
|
||||||
#include "dynamic_list.h"
|
#include "dynamic_list.h"
|
||||||
|
#include "framemaker.h"
|
||||||
|
|
||||||
#define MAX_PATHLEN 1024
|
#define MAX_PATHLEN 1024
|
||||||
|
|
||||||
@ -22,17 +22,17 @@ typedef unsigned short u16;
|
|||||||
typedef signed char s8;
|
typedef signed char s8;
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
|
|
||||||
inline s32 floattof32(float n)
|
static inline s32 floattof32(float n)
|
||||||
{
|
{
|
||||||
return (s32) (n * (1 << 12));
|
return (s32) (n * (1 << 12));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline s16 floattov16(float n)
|
static inline s16 floattov16(float n)
|
||||||
{
|
{
|
||||||
return (s16) (n * (1 << 12));
|
return (s16) (n * (1 << 12));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline s16 floattov10(float n)
|
static inline s16 floattov10(float n)
|
||||||
{
|
{
|
||||||
if (n > 0.998)
|
if (n > 0.998)
|
||||||
return 0x7FFF;
|
return 0x7FFF;
|
||||||
@ -130,52 +130,64 @@ typedef s16 ds_st_t[2];
|
|||||||
|
|
||||||
void PrintUse(void)
|
void PrintUse(void)
|
||||||
{
|
{
|
||||||
printf("\n\nInstructions:\n\n");
|
printf("\n\n");
|
||||||
printf(" MD2_2_NEA [input.md2] [output.nea] ([float scale])\n");
|
printf("Instructions:\n");
|
||||||
|
printf(" md2_2_nea [input.md2] [output.nea] ([float scale])\n");
|
||||||
printf
|
printf
|
||||||
(" ([float translate x] [float translate x] [float translate x])\n\n");
|
(" ([float translate x] [float translate x] [float translate x])\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 NEA -- -- #\n");
|
|
||||||
printf(" #\\ V2.0 /#\n");
|
|
||||||
printf(" ########################################\n");
|
printf(" ########################################\n");
|
||||||
|
printf(" # #\n");
|
||||||
|
printf(" # -- -- MD2 2 NEA -- -- #\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
|
// DEFAULT VALUES
|
||||||
("\nCopyright (C) 2008 Antonio Ni%co D%caz\nAll rights reserved.\n\n",
|
float general_scale = 1;
|
||||||
164, 161);
|
|
||||||
|
|
||||||
printf(" -- -- -- -- -- -- -- -- -- --\n");
|
|
||||||
|
|
||||||
float general_scale = 1; //DEFAULT VALUES
|
|
||||||
float general_trans[3] = { 0, 0, 0 };
|
float general_trans[3] = { 0, 0, 0 };
|
||||||
|
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
case 2: //Not enough
|
case 2:
|
||||||
|
// Not enough
|
||||||
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:
|
||||||
|
// Use default translation and custom scale
|
||||||
general_scale = atof(argv[3]);
|
general_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:
|
||||||
|
// Custom translation + scale
|
||||||
general_scale = atof(argv[3]);
|
general_scale = atof(argv[3]);
|
||||||
general_trans[0] = atof(argv[4]);
|
general_trans[0] = atof(argv[4]);
|
||||||
general_trans[1] = atof(argv[5]);
|
general_trans[1] = atof(argv[5]);
|
||||||
general_trans[2] = atof(argv[6]);
|
general_trans[2] = atof(argv[6]);
|
||||||
break;
|
break;
|
||||||
default: //The rest...
|
default:
|
||||||
|
// The rest...
|
||||||
PrintUse();
|
PrintUse();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -229,32 +241,20 @@ int main(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!
|
if (!IsValidSize(t_w) || !IsValidSize(t_h)) {
|
||||||
(t_w == 8 || t_w == 16 || t_w == 32 || t_w == 64 || t_w == 128
|
|
||||||
|| t_w == 256 || t_w == 512 || t_w == 1024) || !(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("\nWrong texture size. Must be power of 2.\n");
|
||||||
printf
|
printf
|
||||||
("\nAlthough the model uses an invalid texture size, it will be converted.\n");
|
("\nAlthough the model uses an invalid texture size, it will be converted.\n");
|
||||||
printf("\nResize the texture to nearest valid size.\n\n");
|
printf("\nResize the texture to nearest valid size.\n\n");
|
||||||
//return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (t_w == 8 || t_w == 16 || t_w == 32 || t_w == 64
|
if (IsValidSize(t_w))
|
||||||
|| t_w == 128 || t_w == 256 || t_w == 512 || t_w == 1024)
|
|
||||||
break;
|
break;
|
||||||
t_w++;
|
t_w++;
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
if (t_h == 8 || t_h == 16 || t_h == 32 || t_h == 64
|
if (IsValidSize(t_h))
|
||||||
|| t_h == 128 || t_h == 256 || t_h == 512 || t_h == 1024)
|
|
||||||
break;
|
break;
|
||||||
t_h++;
|
t_h++;
|
||||||
}
|
}
|
||||||
@ -263,11 +263,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
md2_frame_t *frame = NULL;
|
md2_frame_t *frame = NULL;
|
||||||
md2_texCoord_t *texcoord =
|
md2_texCoord_t *texcoord =
|
||||||
(md2_texCoord_t *) ((int)header->offset_st + (int)header);
|
(md2_texCoord_t *) ((uintptr_t)header->offset_st + (uintptr_t)header);
|
||||||
md2_triangle_t *triangle =
|
md2_triangle_t *triangle =
|
||||||
(md2_triangle_t *) ((int)header->offset_tris + (int)header);
|
(md2_triangle_t *) ((uintptr_t)header->offset_tris + (uintptr_t)header);
|
||||||
|
|
||||||
md2_vertex_t *vtx; //Current vertex
|
// Current vertex
|
||||||
|
md2_vertex_t *vtx;
|
||||||
|
|
||||||
printf
|
printf
|
||||||
("\nMD2 Information:\n\n Number of frames: %d\n Texture size: %dx%d",
|
("\nMD2 Information:\n\n Number of frames: %d\n Texture size: %dx%d",
|
||||||
@ -280,11 +281,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
InitDynamicLists();
|
InitDynamicLists();
|
||||||
|
|
||||||
//Everything ready, let's "draw" all frames
|
// Everything ready, let's "draw" all frames
|
||||||
int n;
|
int n;
|
||||||
for (n = 0; n < header->num_frames; n++) {
|
for (n = 0; n < header->num_frames; n++) {
|
||||||
frame =
|
frame =
|
||||||
(md2_frame_t *) ((int)header->offset_frames + (int)header +
|
(md2_frame_t *) ((uintptr_t)header->offset_frames + (uintptr_t)header +
|
||||||
(header->framesize * n));
|
(header->framesize * n));
|
||||||
|
|
||||||
NewFrame();
|
NewFrame();
|
||||||
@ -294,21 +295,21 @@ int main(int argc, char *argv[])
|
|||||||
int t = 0, v = 0;
|
int t = 0, v = 0;
|
||||||
for (t = 0; t < num_tris; t++)
|
for (t = 0; t < num_tris; t++)
|
||||||
for (v = 0; v < 3; v++) {
|
for (v = 0; v < 3; v++) {
|
||||||
vtx = (md2_vertex_t *) ((int)(&(frame->verts)));
|
vtx = (md2_vertex_t *) ((uintptr_t)(&(frame->verts)));
|
||||||
vtx = &vtx[triangle[t].vertex[v]];
|
vtx = &vtx[triangle[t].vertex[v]];
|
||||||
|
|
||||||
//Texture
|
// Texture
|
||||||
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;
|
||||||
|
|
||||||
//This is used to change UVs if using a texture size unsupported by DS
|
// This is used to change UVs if using a texture size unsupported by DS
|
||||||
s_ = (int)((float)(s_ * t_w) /
|
s_ = (int)((float)(s_ * t_w) /
|
||||||
(float)header->skinwidth);
|
(float)header->skinwidth);
|
||||||
t_ = (int)((float)(t_ * t_h) /
|
t_ = (int)((float)(t_ * t_h) /
|
||||||
(float)header->skinheight);
|
(float)header->skinheight);
|
||||||
NewFrameData(AddTexCoord(s_ << 4, t_ << 4)); //(t_h-t_)<<4));
|
NewFrameData(AddTexCoord(s_ << 4, t_ << 4)); // (t_h-t_)<<4));
|
||||||
|
|
||||||
//Normal
|
// Normal
|
||||||
unsigned short norm[3];
|
unsigned short norm[3];
|
||||||
int b;
|
int b;
|
||||||
for (b = 0; b < 3; b++)
|
for (b = 0; b < 3; b++)
|
||||||
@ -318,7 +319,7 @@ int main(int argc, char *argv[])
|
|||||||
NewFrameData(AddNormal
|
NewFrameData(AddNormal
|
||||||
(norm[0], norm[1], norm[2]));
|
(norm[0], norm[1], norm[2]));
|
||||||
|
|
||||||
//Vertex
|
// Vertex
|
||||||
vtxcount++;
|
vtxcount++;
|
||||||
float _v[3];
|
float _v[3];
|
||||||
int a = 0;
|
int a = 0;
|
||||||
@ -361,7 +362,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
printf("\nCreating NEA file...\n");
|
printf("\nCreating NEA file...\n");
|
||||||
|
|
||||||
//Now, let's save them into a NEA file.
|
// Now, let's save them into a NEA 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);
|
||||||
@ -388,7 +389,7 @@ int main(int argc, char *argv[])
|
|||||||
temp_header.offset_vtx + (sizeof(ds_vec3_t) * GetVerticesNumber());
|
temp_header.offset_vtx + (sizeof(ds_vec3_t) * GetVerticesNumber());
|
||||||
fwrite(&temp_header, sizeof(ds_header_t), 1, file);
|
fwrite(&temp_header, sizeof(ds_header_t), 1, file);
|
||||||
|
|
||||||
//Normals...
|
// Normals...
|
||||||
ds_vec3_t temp_vector;
|
ds_vec3_t temp_vector;
|
||||||
int number = GetNormalNumber();
|
int number = GetNormalNumber();
|
||||||
int i_;
|
int i_;
|
||||||
@ -398,7 +399,7 @@ int main(int argc, char *argv[])
|
|||||||
fwrite(&temp_vector, sizeof(ds_vec3_t), 1, file);
|
fwrite(&temp_vector, sizeof(ds_vec3_t), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Texcoords
|
// Texcoords
|
||||||
ds_st_t temp_texcoord;
|
ds_st_t temp_texcoord;
|
||||||
number = GetTexcoordsNumber();
|
number = GetTexcoordsNumber();
|
||||||
for (i_ = 0; i_ < number; i_++) {
|
for (i_ = 0; i_ < number; i_++) {
|
||||||
@ -407,7 +408,7 @@ int main(int argc, char *argv[])
|
|||||||
fwrite(&temp_texcoord, sizeof(ds_st_t), 1, file);
|
fwrite(&temp_texcoord, sizeof(ds_st_t), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Vertices
|
// Vertices
|
||||||
number = GetVerticesNumber();
|
number = GetVerticesNumber();
|
||||||
for (i_ = 0; i_ < number; i_++) {
|
for (i_ = 0; i_ < number; i_++) {
|
||||||
GetVertex(i_, (u16 *) & temp_vector[0],
|
GetVertex(i_, (u16 *) & temp_vector[0],
|
||||||
@ -415,10 +416,10 @@ int main(int argc, char *argv[])
|
|||||||
fwrite(&temp_vector, sizeof(ds_vec3_t), 1, file);
|
fwrite(&temp_vector, sizeof(ds_vec3_t), 1, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\nSize of a frame: %d\n",
|
printf("\nSize of a frame: %ld\n",
|
||||||
GetFrameSize(0) * sizeof(unsigned short));
|
GetFrameSize(0) * sizeof(unsigned short));
|
||||||
|
|
||||||
//Frames
|
// Frames
|
||||||
for (i_ = 0; i_ < header->num_frames; i_++) {
|
for (i_ = 0; i_ < header->num_frames; i_++) {
|
||||||
fwrite((int *)GetFramePointer(i_), 1,
|
fwrite((int *)GetFramePointer(i_), 1,
|
||||||
GetFrameSize(i_) * sizeof(unsigned short), file);
|
GetFrameSize(i_) * sizeof(unsigned short), file);
|
||||||
@ -431,7 +432,7 @@ int main(int argc, char *argv[])
|
|||||||
long int size = ftell(test);
|
long int size = ftell(test);
|
||||||
fclose(test);
|
fclose(test);
|
||||||
|
|
||||||
printf("\nNEA file size: %d bytes", size);
|
printf("\nNEA file size: %ld bytes", size);
|
||||||
|
|
||||||
if (size > 1 * 1024 * 1024)
|
if (size > 1 * 1024 * 1024)
|
||||||
printf(" -- Quite big, isn't it?");
|
printf(" -- Quite big, isn't it?");
|
Loading…
Reference in New Issue
Block a user