Author Topic: Trouble with 3D Objects  (Read 6506 times)

Emerald Nova

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Trouble with 3D Objects
« on: January 16, 2019, 01:48:51 am »
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.

Code: [Select]
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?

Emerald Nova

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Trouble with 3D Objects
« Reply #1 on: January 16, 2019, 01:54:18 am »
I've attached the blender, wavefront, and collada files in case that helps explain my problem.

ponut64

  • Full Member
  • ***
  • Posts: 220
  • Karma: +22/-1
    • View Profile
Re: Trouble with 3D Objects
« Reply #2 on: January 16, 2019, 02:27:32 am »
Compare your OBJs with this OBJ.

I did export your model in Blender then import it with the editor, and while I did not check the model, the header file seemed to check out.

Also, as a sanity check, see how your code handles this header file.

Here is a screenshot of my export params:
https://i.imgur.com/6S8VFpi.png?1

Emerald Nova

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Trouble with 3D Objects
« Reply #3 on: January 16, 2019, 02:53:35 am »
I see you aren't using UV maps. I map my textures with UV, should I not?

Also, while I can import your header and run the code, attempts to draw using
Code: [Select]
display_bpony_mesh();
inside the main loop doesn't seem to do anything. I also see that the coordinates appear rather large. I tried moving back to -1000000 along the z but still saw nothing.

Emerald Nova

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Trouble with 3D Objects
« Reply #4 on: January 16, 2019, 03:19:58 am »
I've attached my code in a .7z file.

I include the header on line 40, and draw on line 179 inside my main loop.

ponut64

  • Full Member
  • ***
  • Posts: 220
  • Karma: +22/-1
    • View Profile
Re: Trouble with 3D Objects
« Reply #5 on: January 16, 2019, 03:55:28 am »
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:

Code: [Select]
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.

Code: [Select]
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.

Code: [Select]
	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.
« Last Edit: January 16, 2019, 04:04:00 am by ponut64 »

Emerald Nova

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Trouble with 3D Objects
« Reply #6 on: January 16, 2019, 04:26:52 am »
This is really helpful and will give me some stuff to consider over the next few nights while I go over the code.

As for the object loop code: I have a list of game_objects (maximum capacity 100) that can be created or destroyed. Each game_object has coordinates, rotations, speed, and pointers to vectors and quads to be used for rendering. Only the first num_object in the list of object[] are active, and are drawn via that draw function. You refer to objects as being drawn automatically by the game loop, but I have no idea what functionality you are referring to. The only working model I have of rendering 3D objects is from the 3D demo sample from Jo Engine itself, using the so called hard coded cubes.

The reason I'm using UV mapping is because when I originally tried to use per face images, Jo Map Editor complained about multiple texture files. It seems like the pipeline from object modelling to rendering in engine is not exactly covered in the documentation. If I ever figure this out, I may have to make a video just so there is some definitive guide to doing so.

I see inside the advanced 3D demo there are collada and wavefront files. After I make your prescribed code fixes, I'll try to import these into blender and see the exact structure I should be aping and exporting to get these to work properly.

Thank you.

ponut64

  • Full Member
  • ***
  • Posts: 220
  • Karma: +22/-1
    • View Profile
Re: Trouble with 3D Objects
« Reply #7 on: January 16, 2019, 04:43:48 am »
Quote
The reason I'm using UV mapping is because when I originally tried to use per face images, Jo Map Editor complained about multiple texture files. It seems like the pipeline from object modelling to rendering in engine is not exactly covered in the documentation. If I ever figure this out, I may have to make a video just so there is some definitive guide to doing so.

To put it simply, it's incomplete.
I stopped using Jo Map Editor to convert models awhile ago. I never tried to use any textures with it, so what do I know? In any case it probably complained about multiple texture files because you've only got 512KB of video memory to work with.

I do hope to be helpful. Thank you for reading.

Check out this thread: http://forum.jo-engine.org/index.php?topic=874.0
XL2's converter has some bugs, but once you do figure it out, it can be a big help. Or a big headache. I don't know, do you want both? You'll probably get both...
« Last Edit: January 16, 2019, 04:49:58 am by ponut64 »

XL2

  • Sr. Member
  • ****
  • Posts: 360
  • Karma: +88/-3
    • View Profile
Re: Trouble with 3D Objects
« Reply #8 on: January 16, 2019, 04:48:42 am »
Just use my model converter, it even supports animations, allows realtime light, writes to binary and I released the source code.

As for zdsplevel, it's actually the near clipping level. Set it to 3, which makes it 1/8 your screen distance (which you can set with slscreendist and slPerspective - both do the same, one is the fixed distance, the other is your fov....which just changes the screen distance in fact.
Important thing, because it took me 3 days to properly write a fristum culling function using the geometric approach and using the fov as a way to calculate my frustum planes, until I noticed that sgl doesn't even have any kind of real projection matrix.

XL2

  • Sr. Member
  • ****
  • Posts: 360
  • Karma: +88/-3
    • View Profile
Re: Trouble with 3D Objects
« Reply #9 on: January 16, 2019, 04:50:45 am »
Quote
The reason I'm using UV mapping is because when I originally tried to use per face images, Jo Map Editor complained about multiple texture files. It seems like the pipeline from object modelling to rendering in engine is not exactly covered in the documentation. If I ever figure this out, I may have to make a video just so there is some definitive guide to doing so.

To put it simply, it's incomplete.
I stopped using Jo Map Editor to convert models awhile ago. I never tried to use any textures with it, so what do I know? In any case it probably complained about multiple texture files because you've only got 512KB of video memory to work with.

I do hope to be helpful. Thank you for reading.

Check out this thread: http://forum.jo-engine.org/index.php?topic=874.0
XL2's converter is old and has some bugs, but once you do figure it out, it can be a big help. Or a big headache. I don't know, do you want both? You'll probably get both...

What bug?
I might revisit it later to precalculate the lighting and - hopefully - auto generate a LOD model.

ponut64

  • Full Member
  • ***
  • Posts: 220
  • Karma: +22/-1
    • View Profile
Re: Trouble with 3D Objects
« Reply #10 on: January 16, 2019, 04:53:23 am »
It's been awhile since I've needed to convert any model. The bug is with the # of frames processed. I don't remember exactly (to process a base model with 62 animated frames, i'd have to command it to process 65 frames, after duplicating the last frame, for a total of 64 files--it might just be i have a misplaced expectation; its ok). When/if you do get back around to it, I'm sure you'll either notice or not notice because I was just using it wrong. Anyway, thank you again for making that model converter. Any tools you share mean a lot.

And, definitely use it over the jo engine converter, for now.
« Last Edit: January 16, 2019, 04:56:22 am by ponut64 »

XL2

  • Sr. Member
  • ****
  • Posts: 360
  • Karma: +88/-3
    • View Profile
Re: Trouble with 3D Objects
« Reply #11 on: January 16, 2019, 05:06:07 am »
Ah, yes, it was because of improper rounding I guess or something like take. I always use 1, but indeed it's a bug. Anyway, I won't update it anytime soon, but if I do I will add an OpenGL preview to see the results before trying it on the Saturn each time.
I do that now with my bsp compiler and it makes testing way more efficient than booting an emulator each time.
Also getting rid of the normals in SGL would be a really great thing.
« Last Edit: January 16, 2019, 05:38:57 am by XL2 »

Emerald Nova

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Trouble with 3D Objects
« Reply #12 on: January 17, 2019, 03:09:52 am »
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:

Code: [Select]
void * currentAddress = (void*)LWRAM;

7 ) Write your model to LWRAM using ztLoad3Dmodel() as defined in ZT_LOAD_MODEL.c like so:
Code: [Select]
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:

Code: [Select]
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?
« Last Edit: January 17, 2019, 03:15:00 am by sbf2009 »

ponut64

  • Full Member
  • ***
  • Posts: 220
  • Karma: +22/-1
    • View Profile
Re: Trouble with 3D Objects
« Reply #13 on: January 17, 2019, 10:15:45 am »
The header file and .ZTP file contain the same data. (Correction: The ZTP file has the textures in addition to the model and any encoded animation frames. The header file does not have any textures nor any animation frames)

The header file is simply a reference point for what is in the ZTP. The ZTP is a binary file which can be loaded into memory from CD, rather than being included all the time.
You only need the ZTP file. You should only use the ZTP file.

As far as step 3 goes, you need only put the .ZTP file into the CD directory somewhere. If you don't put it in any folders on the CD, you won't have to change directory. If you do, you will need to change directory before that file can be loaded.

« Last Edit: January 17, 2019, 10:20:08 am by ponut64 »

Emerald Nova

  • Newbie
  • *
  • Posts: 19
  • Karma: +2/-0
    • View Profile
    • Emerald Nova Games
Re: Trouble with 3D Objects
« Reply #14 on: January 18, 2019, 03:37:54 am »
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:

Code: [Select]
//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.

 

Sitemap 1 2 3 4 5 6 7 8 9 10