mirror of
https://github.com/AntonioND/nitro-engine.git
synced 2025-06-19 00:55:38 -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"
|
||||
|
||||
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_
|
||||
#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 "framemaker.h"
|
||||
|
||||
DinamicList *vertices_list;
|
||||
DinamicList *normal_list;
|
||||
@ -9,11 +14,11 @@ DinamicList *texcoords_list;
|
||||
|
||||
unsigned int FrameSize[1024];
|
||||
unsigned short *FramePointer[1024];
|
||||
int framecount = -1; // -----.
|
||||
int framecount = -1; // ------.
|
||||
// |
|
||||
void NewFrame(void) // |
|
||||
{ // |
|
||||
framecount++; // <------------' For first frame
|
||||
framecount++; // <----' For first frame
|
||||
|
||||
FramePointer[framecount] = (unsigned short *)malloc(DEFAULT_FRAME_SIZE);
|
||||
if (FramePointer[framecount] == NULL) {
|
@ -1,6 +1,9 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// Copyright (c) 2008-2011, 2019, Antonio Niño Díaz
|
||||
|
||||
#ifndef _FRAMEMAKER_H_
|
||||
#define _FRAMEMAKER_H_
|
||||
#ifndef FRAMEMAKER_H__
|
||||
#define FRAMEMAKER_H__
|
||||
|
||||
#define DEFAULT_FRAME_SIZE (512 * 1024)
|
||||
|
||||
@ -27,4 +30,4 @@ void GetNormal(int index, unsigned short *x, unsigned short *y,
|
||||
unsigned short *z);
|
||||
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:
|
||||
// http://tfc.duke.free.fr/coding/md2-specs-en.html
|
||||
//Thanks.
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "framemaker.h"
|
||||
#include "dynamic_list.h"
|
||||
#include "framemaker.h"
|
||||
|
||||
#define MAX_PATHLEN 1024
|
||||
|
||||
@ -22,17 +22,17 @@ typedef unsigned short u16;
|
||||
typedef signed char s8;
|
||||
typedef unsigned char u8;
|
||||
|
||||
inline s32 floattof32(float n)
|
||||
static inline s32 floattof32(float n)
|
||||
{
|
||||
return (s32) (n * (1 << 12));
|
||||
}
|
||||
|
||||
inline s16 floattov16(float n)
|
||||
static inline s16 floattov16(float n)
|
||||
{
|
||||
return (s16) (n * (1 << 12));
|
||||
}
|
||||
|
||||
inline s16 floattov10(float n)
|
||||
static inline s16 floattov10(float n)
|
||||
{
|
||||
if (n > 0.998)
|
||||
return 0x7FFF;
|
||||
@ -130,52 +130,64 @@ typedef s16 ds_st_t[2];
|
||||
|
||||
void PrintUse(void)
|
||||
{
|
||||
printf("\n\nInstructions:\n\n");
|
||||
printf(" MD2_2_NEA [input.md2] [output.nea] ([float scale])\n");
|
||||
printf("\n\n");
|
||||
printf("Instructions:\n");
|
||||
printf(" md2_2_nea [input.md2] [output.nea] ([float scale])\n");
|
||||
printf
|
||||
(" ([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[])
|
||||
{
|
||||
printf("\n\n ########################################\n");
|
||||
printf(" #/ \\#\n");
|
||||
printf(" # -- -- MD2 2 NEA -- -- #\n");
|
||||
printf(" #\\ V2.0 /#\n");
|
||||
printf("\n\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
|
||||
("\nCopyright (C) 2008 Antonio Ni%co D%caz\nAll rights reserved.\n\n",
|
||||
164, 161);
|
||||
|
||||
printf(" -- -- -- -- -- -- -- -- -- --\n");
|
||||
|
||||
float general_scale = 1; //DEFAULT VALUES
|
||||
// DEFAULT VALUES
|
||||
float general_scale = 1;
|
||||
float general_trans[3] = { 0, 0, 0 };
|
||||
|
||||
switch (argc) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2: //Not enough
|
||||
case 2:
|
||||
// Not enough
|
||||
PrintUse();
|
||||
return -1;
|
||||
case 3: //Use default modifications
|
||||
case 3:
|
||||
// Use default modifications
|
||||
break;
|
||||
case 4: //Use default translation and custom scale
|
||||
case 4:
|
||||
// Use default translation and custom scale
|
||||
general_scale = atof(argv[3]);
|
||||
break;
|
||||
case 5:
|
||||
case 6: //Custom translation, not enough
|
||||
case 6:
|
||||
// Custom translation, not enough
|
||||
printf("You must set 3 coordinates for translation, not less.");
|
||||
PrintUse();
|
||||
return -1;
|
||||
case 7: //Custom translation + scale
|
||||
case 7:
|
||||
// Custom translation + scale
|
||||
general_scale = atof(argv[3]);
|
||||
general_trans[0] = atof(argv[4]);
|
||||
general_trans[1] = atof(argv[5]);
|
||||
general_trans[2] = atof(argv[6]);
|
||||
break;
|
||||
default: //The rest...
|
||||
default:
|
||||
// The rest...
|
||||
PrintUse();
|
||||
return -1;
|
||||
}
|
||||
@ -229,32 +241,20 @@ int main(int argc, char *argv[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
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) || !(t_h == 8
|
||||
|| t_h == 16
|
||||
|| t_h == 32
|
||||
|| t_h == 64
|
||||
|| t_h == 128
|
||||
|| t_h == 256
|
||||
|| t_h == 512
|
||||
|| t_h == 1024)) {
|
||||
if (!IsValidSize(t_w) || !IsValidSize(t_h)) {
|
||||
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 (t_w == 8 || t_w == 16 || t_w == 32 || t_w == 64
|
||||
|| t_w == 128 || t_w == 256 || t_w == 512 || t_w == 1024)
|
||||
if (IsValidSize(t_w))
|
||||
break;
|
||||
t_w++;
|
||||
}
|
||||
while (1) {
|
||||
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)
|
||||
if (IsValidSize(t_h))
|
||||
break;
|
||||
t_h++;
|
||||
}
|
||||
@ -263,11 +263,12 @@ int main(int argc, char *argv[])
|
||||
|
||||
md2_frame_t *frame = NULL;
|
||||
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 *) ((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
|
||||
("\nMD2 Information:\n\n Number of frames: %d\n Texture size: %dx%d",
|
||||
@ -284,7 +285,7 @@ int main(int argc, char *argv[])
|
||||
int n;
|
||||
for (n = 0; n < header->num_frames; n++) {
|
||||
frame =
|
||||
(md2_frame_t *) ((int)header->offset_frames + (int)header +
|
||||
(md2_frame_t *) ((uintptr_t)header->offset_frames + (uintptr_t)header +
|
||||
(header->framesize * n));
|
||||
|
||||
NewFrame();
|
||||
@ -294,7 +295,7 @@ int main(int argc, char *argv[])
|
||||
int t = 0, v = 0;
|
||||
for (t = 0; t < num_tris; t++)
|
||||
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]];
|
||||
|
||||
// Texture
|
||||
@ -415,7 +416,7 @@ int main(int argc, char *argv[])
|
||||
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));
|
||||
|
||||
// Frames
|
||||
@ -431,7 +432,7 @@ int main(int argc, char *argv[])
|
||||
long int size = ftell(test);
|
||||
fclose(test);
|
||||
|
||||
printf("\nNEA file size: %d bytes", size);
|
||||
printf("\nNEA file size: %ld bytes", size);
|
||||
|
||||
if (size > 1 * 1024 * 1024)
|
||||
printf(" -- Quite big, isn't it?");
|
Loading…
Reference in New Issue
Block a user