http://code.google.com/p/gendev/source/ ... bj2mesh.py
# python obj2mesh.py -f afile.obj > meshs.h
This works with a slightly modified cube_flat sample program from SGDK with the following patch:
Code: Select all
Index: main.c
===================================================================
--- main.c (revision 194)
+++ main.c (working copy)
@@ -2,7 +2,7 @@
#include "meshs.h"
-#define MAX_POINTS 256
+#define MAX_POINTS 512
Vect3D_f16 pts_3D[MAX_POINTS];
@@ -47,7 +47,7 @@
JOY_setEventHandler(handleJoyEvent);
- BMP_init(TRUE, PAL0, FALSE);
+ BMP_init(TRUE, PAL1, FALSE);
camdist = FIX16(15);
@@ -99,9 +99,9 @@
void updatePointsPos()
{
// transform 3D point
- M3D_transform(&transformation, cube_coord, pts_3D, 8);
+ M3D_transform(&transformation, cube_coord, pts_3D, verts);
// project 3D point (f16) to 2D point (s16)
- M3D_project_s16(pts_3D, pts_2D, 8);
+ M3D_project_s16(pts_3D, pts_2D, verts);
}
void drawPoints(u8 col)
@@ -108,7 +108,7 @@
{
if (flatDrawing)
{
- Vect2D_s16 v[4];
+ Vect2D_s16 v[3];
const Vect3D_f16 *norm;
const u16 *poly_ind;
u16 i;
@@ -116,7 +116,8 @@
norm = cube_face_norm;
poly_ind = cube_poly_ind;
- i = 6;
+ // # of polygon faces
+ i = faces;
while (i--)
{
@@ -124,9 +125,10 @@
fix16 dp;
u8 col = 2;
+ // Cycle through number of indices in polygon face
*pt_dst++ = pts_2D[*poly_ind++];
*pt_dst++ = pts_2D[*poly_ind++];
- *pt_dst++ = pts_2D[*poly_ind++];
+ //*pt_dst++ = pts_2D[*poly_ind++];
*pt_dst = pts_2D[*poly_ind++];
dp = fix16Mul(transformation.lightInv.x, norm->x) +
@@ -136,8 +138,8 @@
if (dp > 0) col += (dp >> (FIX16_FRAC_BITS - 2));
- if (!BMP_isPolygonCulled(v, 4))
- BMP_drawPolygon(v, 4, col);
+ if (!BMP_isPolygonCulled(v, 3))
+ BMP_drawPolygon(v, 3, col);
}
}
else
@@ -148,9 +150,10 @@
l.col = col;
line_ind = cube_line_ind;
+
+ // Number of lines
+ i = edges;
- i = 12;
-
while (i--)
{
l.pt1 = pts_2D[*line_ind++];
Here's the current result:
https://dl.dropboxusercontent.com/u/101 ... huttle.bin
Made quickly from https://www.3dtin.com
Some things I've noticed:
*Not sure if the culling is working properly. Is this due to me changing the quads to triangles?
*The script reduces duplicate points, but is still less efficient due to the increased number of lines from triangles. Is there a better 3d drawing tool/format to use?
* The Y axis appears to be reversed between the formats.