I have been attempting to use the Jo Map Editor to convert basic 3D objects into the appropriate header files and drawing them in Jo Engine.
The model is a basic 3d cube using a single image texture. I've exported the model as both a Collada (.dae) and Wavefront (.obj) file.
Importing the .dae and attempting to draw it results in nothing being shown on screen, but the coordinates appear to be massive. They don't change no matter what size I make the cube in blender.
static POINT PointCube[] =
{
{3276800, 3276800, -3276800},
{3276800, -3276800, -3276800},
{-3276800, -3276799, -3276800},
{-3276799, 3276800, -3276800},
{3276800, 3276798, 3276800},
{3276798, -3276803, 3276800},
{-3276800, -3276799, 3276800},
{-3276800, 3276800, 3276800},
};
The .obj fair even worse. Attempts at importing these files simply crash my game before anything can display.
Is there a guide or pipeline I can use for guidance on how to get my 3D models into Jo Engine?
I don't know what's going on. I recommend you start over from "demo - advanced 3D". I tried a few things, black screen, unending. Of course we all wish we knew what was wrong...
Another good starting point is a demo XL2 gave me.
http://forum.jo-engine.org/index.php?action=dlattach;topic=864.0;attach=121
A few things I noticed in the code that is going to cause problems in the future:
void move_cam(void)
{
jo_3d_camera_set_viewpoint(&cam,cam_pos[0],cam_pos[1],cam_pos[2]);
jo_3d_camera_set_target(&cam,cam_tar[0],cam_tar[1],cam_tar[2]);
}
Do not do this! These are not 3D functions, they change where the projection plane is. They do not navigate the camera in 3D space. Just don't change these values.
A good way to set display parameters. I first got this snippet from XL2.
void initCamera(jo_camera * curCam)
{
(*curCam).viewpoint[X] = toFIXED(0.0);
(*curCam).viewpoint[Y] = toFIXED(0.0);
(*curCam).viewpoint[Z] = toFIXED(5.0);
(*curCam).z_angle = DEGtoANG(0.0);
(*curCam).target[X] = toFIXED(0.0);
(*curCam).target[Y] = toFIXED(0.0);
(*curCam).target[Z] = toFIXED(0.0);
slWindow(0, 0, JO_TV_WIDTH-1, JO_TV_HEIGHT-1, draw_distance, JO_TV_WIDTH_2, JO_TV_HEIGHT_2);
slPerspective(DEGtoANG(90)); //FOV
}
You don't need to set slZdspLevel(7); with that above snippet. slPerspective does that.
int index;
for(index = 0; index < num_object; index++)
{
draw_object(&object[index]);
}
Can you explain that one? The whole game is already a loop, it isn't going to miss an object when it needs to render it. Unless this is some anachronism of you needing to display a hard-coded mesh. (that's probably it)
Also, 3D objects need to be pushed into a matrix, and then populated. Changing that doesn't fix your problem but it's likely part of it. (display_mesh_mesh needs to be part of a matrix)
Also, the saturn does not support texture coordinates. Thus, you can't texture map with UV. Texture mapping for the Saturn basically amounts to assigning a texture to a polygon then changing the texture until it looks right. If you have a large texture and want to span it over multiple polygons, you have to break that texture down manually into the pieces that will be assigned to their specific polygons.
I've had a change to play with the blender files for XL2's model converter. So none of the models are actually textured, just labelled, and the converter applies the specified TGA files based on the name of the material. From what I can tell, the workflow is:
1 ) Create the model in blender. Materials act as a label for applied TGA textures of the same name. Correct orientation and deformation of textures will rely on a combination of experience and trial and error.
2 ) Export model as .obj file. Place .obj and .tga files in a sub-directory of the converter and run the batch script.
3 ) Header files and the .ZTP files are created in the /OUT/ directory of the converter. Copy over to your program's directory, preserving the relative file structure.
4 ) Copy over ZT folder with headers into your program's directory.
5 ) Include "ZT/ZT_COMMON.h" and the header file for your model.
6 ) Create a void pointer and asign it the memory location LWRAM as defined in ZT_COMMON.h, like so:
void * currentAddress = (void*)LWRAM;
7 ) Write your model to LWRAM using ztLoad3Dmodel() as defined in ZT_LOAD_MODEL.c like so:
currentAddress = ztLoad3Dmodel((Sint8*)"MODEL_NAME.ZTP", currentAddress, &entities[0], 1);
This will load your model in the entities array index 0 as defined in ZT_LOAD_MODEL.c
8 ) Preferably inside a function, define a pointer to an entity_t and loop through displaying polygons based on the number of meshes property of the entity_t struct, like so:
entity_t * model = &entities[0];
for (i=0; i<model->nbMeshes; i++)
{
slPutPolygon((PDATA*)model->pol[i]);
}
Does this all look correct as a basic workflow of Blender model to in game render?
Well I have tried again, and these steps are not sufficient to display a model on the screen. I've attempted to make a simple quad based ball appear on screen using the code described, given your corrections.
Attempting to load this figure in a test code results in my code hanging. I also tried to display the SONIC.ZTP in XL2's code example, and that also hung.
I attempted to simply input my ball into XL2's example code:
//currentAddress = ztLoad3Dmodel((Sint8*)"SONIC.ZTP", currentAddress, &entities[0], 1);
currentAddress = ztLoad3Dmodel((Sint8*)"BALL.ZTP", currentAddress, &entities[0], 1);
My attempt to display a ball in XL2's code resulted in the attached screenshot.
Clearly there is more to displaying this model than the steps I described. Please tell me what I am missing.
This isn't even to mention the problem I am having even generating TGA files. I attempted to make 8x1 TGA files of single colors exported from gimp. They seem to have introduced some further error, as I could not even get as far as a broken ball render in XL2's code with them, so I had to use XL2's colors. I was really hoping to be able to get this problem solved before tomorrow so I could move forward with displaying multiple 3D objects on screen.
You may very well have just saved my ass.
Using Paint.net to make .TGA's with 24-bit color depth and no compression gives me valid textures.
Exporting quad based blender objects to .obj Wavefront files with with materials named identical to said .TGA's allows me to use the model converter.
Using the model converter with 0 keyframes (for a still model) and the same scale as the corresponding line of code:
jo_3d_set_scale(14,14,14);
gives me a valid model that will actually display in your test program.
I will be taking your program apart on my stream tonight to figure out what is needed and what isn't and transferring the appropriate portions to my main code (with attribution.)
Thank you so much. Hopefully the first half of tonight's stream can serve as a guide for others here. I'll try to be as thorough as my understanding allows so others can follow along when they're starting out.