Jo Engine Forum

Sega Saturn Development => Share your code => Topic started by: XL2 on May 29, 2018, 05:51:36 am

Title: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on May 29, 2018, 05:51:36 am
Here is my model converter (and source code) with my custom binary file format I made for my Sonic Z-Treme Engine (ZTP for Z-Treme Polygons).

The code is bad, I just quickly coded this and didn't spend much time cleaning up or removing all the globals.
I will revisit the code and try to add precalculated lightning and per vertex animation support. (done 2018-06-10)
I also added a demo I originaly made for our friend Virtua skimmer.
I would like to ditch OBJ files for DAE, but it's quite hard to implement so I might stick with OBJ for now.

New in version 0.05 : I rotated all the quads 180 degrees and flipped the normals so that the textures are in the proper direction (it was just an annoying issue that didn't cause problems). Updated the demo to add a few features. If you just want to use the converter, update your model loader c file in the ZT folder else you will get alignement issues (the sprites are now in ZTI format).

New in version 0.10 : Animation support! The tool can read a chain of OBJ files and do vertex animation (similar to Quake 2 MD2 format) with interpolation. The normals are also compressed. The demo's animation is bad simply because my own animation is bad, so don't mind it!
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: SkimmingSanshiro on May 29, 2018, 02:58:17 pm
Great work, I didn't even notice the texture issue. Precalculated lighting and per vertex animation would be really useful. I thought the visible workspace was 1200 faces but your demo runs +1500, awesome!
edit: Nevermind its displaying 700
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on May 29, 2018, 04:37:41 pm
The default workspace can process 2000 quads max, but it will display less because of backface culling.
In my FPS demo I could display over 1000 textured quads at 20 fps.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on June 05, 2018, 04:46:02 am
Ok, good news!

I got the vertex animation working with compressed vertices (6 bytes each instead of 12 bytes) and linear interpolation (so that you can display a 60 FPS animation with only 15 frames or less if you wish).
Vertex animation allows you to do animations as complex as you want.

I got 40 frames of animation down to 10 KB with 175 vertices (the Sonic model) at 15 fps interpolated to 60 (so 10 frames of animation instead of 40).
I still need to add normals with (maybe, could be overkill) interpolation as well.
It should be possible to compress the normals to 3 bytes instead of 12, but I'll need to see the results as it could be bad.
For the Sonic model, I could probably have 240 frames worth of animation down to less than 100 KB.
While it's a lot, Sonic moves fast so I need more frames, but for a slow moving caracter (like a human) you could probably get good results at 1/6 animation or less if you dismiss 60 FPS.

I still need to improve everything and the user interface is quite complicated right now (you need both your base OBJ model with material and the animation OBJ files numbered in a linear fashion - but Blender can generate those easily).

I'm also worried about the impact on CPU.
Sadly I don't know assembly so I won't be able to fully optimize the function or offload it to the SCU DSP, but I hope to keep the cost to a minimum.

I also added an option to reorganize the 3D model so that you can easily add bone-animation to it if you wish to (for manual animation only).

I hope to release the new version of the converter tool this week.


Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: SkimmingSanshiro on June 06, 2018, 06:57:54 pm
Fantastic news! Really making projects like mine possible. One thing though excuse my lack of concept but in my Katamari project I ported the PSP level and decimated it and made it quads. When loading the ZTE it missing a few select faces even some simple 4 vertex quad with correct normals, but will let me add more complex things like the plate of snails.

I fixed a lot of the levels glitches by merging the vertices of the separate objects and making sure there isn't a face underneath another. But having a hard time making any more 3d objects show up without being clipped out by the floor or whatever. .

For example of a simple quad clipped: the shopping bag that goes up to the table here
https://i.imgur.com/pa150nf.png

Is clipped on the saturn build but let me add the plate of all this stuff on it, if merged the plates vertices to the ground.
https://www.youtube.com/watch?v=TnBsa35S4MA


Can I make a level this way if I clean it up more or is the Zsorting(?) too much with all the stuff and need a proper map?
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on June 06, 2018, 07:35:37 pm
It depends.
Like I mentionned the tool isn't designed for maps.
It could be that your normals are reversed.
You can use dual plane, but it won't do backface culling so you will cause useless overdraw.
Just make your normals are Ok.
In Blender just activate the backface culling option.
For the clipping : set the zsort to SORT_MAX for the level, SORT_CEN or Min for your entities.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: ponut64 on June 06, 2018, 09:46:13 pm
Looks to me like there are just too many quads, but hey, you've probably done more with this than I have :)
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on June 06, 2018, 09:54:21 pm
Yes, in the video he has 2500 vertices which is the maximum the default workarea supports.
You need to do visibility culling, using an octree/grid/bsp tree at minimum.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: SkimmingSanshiro on June 07, 2018, 04:03:22 am
Ah so seems maybe I can clean this up and have it work. How do I change the attributes in a ZTE without the .h file? I didnt see anything in the SGL documentation other than the .h attributes. Its the same as slZdspLevel();?

The normals are correct one that shopping bag and even replaced it with just a simple plane it doesn't show up looking at both sides. Even with the player removed.  I noticed if I don't draw my player that is 255 vertices it only brings down the count to 2446 so it must just stop drawing the levels vertices at some point and move onto the player. But if I separate the bag to its own ZTE it doesn't draw it either so not really sure what some faces deal are.

Ill just keep messing with it until I get everything now displaying and everything else will be sprite. I tried it out on a real saturn and still runs smooth with the level only missing like three 3d models needed.

Edit: wow I was drawing my level twice lol, now its 1300 vertices but still not drawing the bag.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on June 07, 2018, 04:18:42 am
 The vertices limit depend on the order you send your slputpolygon commands.
If SGL detects you have 2450 vertices and the next object has 60 vertices, it won't draw it at all.
Try only drawing your ball to see if it works.
For the dual plane quads, if you have a texture name starting with DUAL_ it will convert it as dual plane.
I'm not sure if I implemented this already in the demo.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: ponut64 on June 07, 2018, 04:41:44 am
The bag has no depth to it, right? Just a plane?
In that case I would guess there's nothing you can do except make it dual-plane.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: SkimmingSanshiro on June 07, 2018, 04:45:46 am
Ill try out the DUAL_ texture name out. I was actually displaying my level twice and only at 1300 vertices now but still doesn't want to draw certain faces the same way. The bag has no depth and there's also a box missing thats pretty simple. Backface culling is on in blender. Ill try these trouble ones a seperate dual plane models. So weird this plane is having issues.

 Might try out making the floor a seperate model with a lower zsort see if helps the clipping.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on June 07, 2018, 05:26:10 am
Also, what's the texture like? Does it have a width that is a multiple of 8?
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: corvusd on June 07, 2018, 08:37:49 pm
Fantastic news! Really making projects like mine possible. One thing though excuse my lack of concept but in my Katamari project I ported the PSP level and decimated it and made it quads. When loading the ZTE it missing a few select faces even some simple 4 vertex quad with correct normals, but will let me add more complex things like the plate of snails.

I fixed a lot of the levels glitches by merging the vertices of the separate objects and making sure there isn't a face underneath another. But having a hard time making any more 3d objects show up without being clipped out by the floor or whatever. .

For example of a simple quad clipped: the shopping bag that goes up to the table here
https://i.imgur.com/pa150nf.png

Is clipped on the saturn build but let me add the plate of all this stuff on it, if merged the plates vertices to the ground.
https://www.youtube.com/watch?v=TnBsa35S4MA


Can I make a level this way if I clean it up more or is the Zsorting(?) too much with all the stuff and need a proper map?

Amazing project!! Katamari Damacy in SS whit RT Gouraud Shading!!! OOOOOHHHH!!! :D

Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: SkimmingSanshiro on June 08, 2018, 12:43:57 am
 I was so certain the texture was fine but turns out it was the problem for the missing planes. Must forgot to switch back to RGB after indexed or saved compressed. Everything is displaying pretty well now, the floor still wants to clip over a lot of things like the player and 3d objects I put on the ground but probably going to use sprite objects to pick up anyway and make the level nice and 3D. And since this half room is only 1000 vertices I think I can manage to add the other half of the PSP level and have the entire level running even with no culling.
.
Edit: Seems to be a file name problem with 3 letter names.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on June 08, 2018, 01:24:47 am
The floor clipping is because of the z sort not set to max.
Just patch it yourself with a loop function after loading your map.
For the 3 letters names, I don't know what you mean.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: SkimmingSanshiro on June 08, 2018, 01:33:49 am
If your texture is a 3 letter word it wont show up. Was wondering what my deal was
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on June 11, 2018, 04:11:25 am
I haven't tested at the 3 letters textures, but I will look it up at a later time.

Very good news, I got the compressed animation working, including compressed normals!

A Sonic model with 40 frames of animation takes a total of 63 KB (including the textures).
I also got compressed normals working (1 quad now takes only 1 byte for normals instead of 12 bytes!).
The compression can lead to some minor issues where the quad gets clipped when it's in some extreme angles.
The vertices take 6 bytes instead of 12 bytes each.
I could compress the vertices further (4 bytes), but it might become a bit slower to decompress.
So, all in all, 40 frames of animation using vertices should amount to about 180 KB of data while now it's down to about 63 KB (minus the base model of 11-15 KB).
Note that you can interpolate these animations, so you could easily make it 1/4 or less this size!
At a level 2 interpolation (1 out of 4 frames) you would reduce the same model to 27 KB (with only 8 KB worth of animation data), making vertex animation cheap in terms of memory.

I will try to clean up my code and release the demo + updated tool tomorrow, but I'm not promising anything as I should have a very busy day so I might not feel like it in the evening!


 

Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: XL2 on June 11, 2018, 04:39:31 am
Ok, scratch that last one, I just did minimal clean up of the code.

Just remember : you need to have 1 base model, the other models will use that name +  "_000001" to whatever amount of frames you want.
The base model needs to write the material data, but not the animation.
Just make sure you keep the vertices order (I think it does it by default in Blender).

I'm also sharing the source code for the converter, it should be cleaner than last time...but I did make a mess while adding animation support!

Enjoy!
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on June 11, 2018, 05:35:20 am
I'm almost done with some background-ish loading stuff too, I just need it to not-crash.
Title: Re: Model converter (.ZTP) -0.05 - WIP
Post by: corvusd on June 11, 2018, 10:35:06 pm
Ok, scratch that last one, I just did minimal clean up of the code.

Just remember : you need to have 1 base model, the other models will use that name +  "_000001" to whatever amount of frames you want.
The base model needs to write the material data, but not the animation.
Just make sure you keep the vertices order (I think it does it by default in Blender).

I'm also sharing the source code for the converter, it should be cleaner than last time...but I did make a mess while adding animation support!

Enjoy!

Absolutely amazing! :D
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on June 15, 2018, 04:26:14 am
Here is how it looks like in action :

https://youtu.be/9q5zSLxVBAI
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on June 19, 2018, 02:39:28 pm
Hello, I would like to report a bug, and make a suggestion.

The bug is I cannot seem to get the animation conversion process handle more than 1 keyframe.
e.g. if I put in for 2 3 or 4 or 5 or 1,000 keyframes, it will only process and interpolate the first key frame (filename_000001).
It seems to check for the presence of the other keyframes, but doesn't process them.

My other suggestion is variable interpolation rates. This is probably a lot of work, and I am quite grateful for all you have done already. That said the best animations don't necessarily have each keyframe exactly the same number of frames apart. For example, injecting keyframes at critical parts of a walk cycle are essential to getting them to look right. Or, if for a punch animation, you don't want the windup of the punch to have the same number of frames interpolated for it as the throw.

My request for the process is as follows:
1)First, the model converter requests the file name to be used as the base of animation state.
2)Then it asks if this model is animated. If yes, you are requested to input the next keyframe filename. If no, input 0.
3)It then asks how many frames to interpolate up to this keyframe.
4)It then asks for another keyframe file-name. If this is the last keyframe, you can put in "0" and it will execute.
5)It then asks for this keyframe's source frame (the keyframe to interpolate from). You type in a file name. If that file is not a registered keyframe, the program gives an error and exits.
6)Repeat from 3.

7)If execution has started, it asks for the model's scale.

All this really does is simplify the conversion process and save a tiny bit more memory, since I can still just convert every two frames with massive memory savings on the interpolated frames. The downside is that each keyframe is duplicated in the next animated mesh. With these improvements, that would be prevented.

.. And just an addendum, I did update my loading function to work with the new binary files.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on June 19, 2018, 02:55:57 pm
The interpolation factor is mainly for testing.
You can set it to 0 and manually set your interpolation for each animation.
This is what I do in Sonic Z-Treme.
Just do your animation on blender, once you are satisfied just keep the relevant keyframes and use an interpolation factor of 0.
The problem with entering each filename is that it makes the process way too long.

For the bug, you need to have a base model (say Ponut.obj) AND your keyframes (ponut_00001.obj, etc).
The base model must include the materials, but not the others.

I will revisit this tool at a later time to improve it, but you can also play with the source code to add custom features.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on June 19, 2018, 03:04:40 pm
Thanks for the tip about manual interpolation rates. Looking over the animated display code in your demo, I realize that's where the interpolation is handled so that's far simpler than how I thought it was happening. I can handle that

The "bug" is fixed by setting interpolation factor to 0, then it doesn't skip anything.
The number seems to look ahead by the interpolation factor + 1 when looking for the next file.
Sorry about that, I did not know.

Thank you!
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on June 19, 2018, 03:11:51 pm
Yes, I could probably clean up the interface to make it easier to understand.
The interpolation on the converter and in the animation player are different thing, I should just call it "skip frames" or something like that to make it easier to understand (I just changed my interpolation technique as I wrote the demo).
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on June 19, 2018, 03:34:30 pm
Well, it does make sense when one considers the way how Blender exports OBJ files when you tick "Animation" in the export parameters.

The way the program actually does it, though, is a lot better and I am glad that's available.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on June 19, 2018, 08:11:18 pm
I'm still really surprised at how good interpolation looks like.
It feels very smooth and decompressing the data isn't as slow as I thought it would be.
I could probably speed it up at a later time by using assembly.
So I don't think I will be spending time on trying to figure out the DAE file format and I will stick to OBJ for now as vertex animation is quite simple yet it allows very complex motions.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on June 21, 2018, 05:36:42 pm
Hey,

Sorry to bug you again sir, but I have some more questions.

I got your Sonic ZTP and animation to load and play in my environment (which should be a no-brainer because that's all files and code that your wrote), but there seems to be something wrong with my Blender or OBJ files or.. something.

I have tried a couple of different things (certainly not exhaustive, however) and it all seems to end in vomit (once using the animation play function):
https://i.imgur.com/pXOdV5x.png?1
I did however re-convert your OBJ files using the tools with some different parameters and it did work, so I feel like I know how to type things in. Possibly.
I wonder, am I misinterpreting what this tool is for? Does this compress mesh-is-a-bone animation or per vertex animations?
(Looking at your Blender file, per vertex animation is clearly used so I don't know why I even ask)
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on June 21, 2018, 05:42:01 pm
It compresses animations (interpolation ) and vertices (12 to 6 bytes).
You should try to scale down your model to see if it works (I'm sure it will).
That's one issue since I only keep a 7.9 fixed point instead of 16.16.
In other words, if you want a different ratio, you will have to play with the source code.
You can't really avoid loss of precision, so it's all about choosing what you need.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on June 21, 2018, 06:41:49 pm
Reducing the scale (incl. scale done in blender and in converter, but not scale in-engine) did put it back into shape. Thank you.
I guess that highlights the fact that I am running my crap on a pretty big scale, and it is OK to scale up the stuff in-engine for me.

It's not moving yet because I am a fool and somehow my OBJs are exporting as identical to one another. Note to self: Tick "Apply Modifiers", save headache.

Given how patchy the model is, I think I need to take its scale down even more...
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on June 21, 2018, 07:18:18 pm
I am assuming to fix the patchy-ness like this I'm going to have to increase the precision?
Or perhaps DUAL. Hmm.

https://i.imgur.com/4NGPF34.png?1

Really great so far though.

/e: DUAL attribute on the textures sort of gets around it
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on June 21, 2018, 07:25:42 pm
Did you keep the anorm.h file?
Try to comment out the part of the code that updates the normals to see what's wrong.
If it still does it, then maybe the issue is the scale.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on June 21, 2018, 07:43:19 pm
Yeah, it's the normals (at least that part of the code).
I definitely kept (and updated.. or is that a thing you are supposed to do? The generated .h file from converter has an ANORM section, I copy that into an ANORM.H) the anorm file.

If I load it into your demo (even using that demos ANORM file), that doesn't happen. The issue has to be the scale then.

Now I just wonder, how can I get the model visible without clipping into it and it still being the correct size! That is something I can figure out. Thanks for helping me again!

/e: Oh wait. Your demos ANORM file is just the right one. So to anyone reading this thread. Use that anorm file. It worked even if I scaled the model. Sorry.
Everything is peachy now. Have a wonderful day. Any chance I could pass you lunch money over PayPal?  ;D

https://i.imgur.com/QalXkJm.png?1
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on June 21, 2018, 07:53:08 pm
No problem.
There is a learning curve to use it as it's not very user friendly, but it works quite well.
Try also to use the jo_malloc function to allocate the player data to high work ram (for faster performances).
Keep us updated, it's always great to see these tools and functions being used by others!
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on July 23, 2018, 04:44:20 pm
Setting the interpolation to 0 (2^0) makes the program crash.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on July 23, 2018, 05:01:30 pm
I know there was a bug in that version, but as far as I can remember it would still write the file.
Just modify the loop function where it checks all the animation and just change the ending condition to fix this issue.
Make sure also you have all the needed files in your folder else it will crash (so if you are doing 1 to 40, make sure you have 1 to 40, if you're not sure just duplicate the last one for testing - like 40, 41...).
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on July 23, 2018, 05:23:29 pm
It does output a file, yet the last frame is messed up, like the vertices are in random coordinates.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on July 23, 2018, 05:26:44 pm
You can add a buffer frame or you can fix the loop code.
I fixed that in my own version, but I won't have time to fix that here until a couple of weeks.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on July 25, 2018, 08:21:57 pm
Do you think you can add a flag to make the assigned faces be metal (aka, using the green/red goraud bug) ?
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on July 25, 2018, 08:42:59 pm
Yes, it's on my todo list.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: itsstillthinking1999 on July 26, 2018, 06:36:46 am
Hey XL2 it might be too much to ask but could you take a screen shot of your Drill model in a wire frame? All my attempts to recreate some of the enemy's in a really low poly model to the standard need have not too well, might help to see a better example as i would love to get one or two done to help you in anyway i can make Z-Treme win SAGE by a landslide and hopefully give you the credit and attention it deserves. Oh and iv been trying out the model converter and its really interesting, keep up the good work! :)
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on July 26, 2018, 05:05:24 pm
I updated the converter with the drill enemy model, so you can take it there.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on July 26, 2018, 07:21:11 pm
I’ve been trying to make the drill char blink by using shape keys, but you can see where the vertices of one texture move back inside while the other one moves out. I think this is because of the interpolation making the transformation between the two frames smooth, even though it’s not the intended result. I hope there might be a way to specify a ztp file to turn OFF the interpolation for certain animations.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on July 26, 2018, 10:50:52 pm
I’ve been trying to make the drill char blink by using shape keys, but you can see where the vertices of one texture move back inside while the other one moves out. I think this is because of the interpolation making the transformation between the two frames smooth, even though it’s not the intended result. I hope there might be a way to specify a ztp file to turn OFF the interpolation for certain animations.

The way you do this is by changing the animation function itself to be more robust in its parameters.
I haven't gotten around to it yet (stuck in PCM sound) and XL2 may have done it already but words.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on July 26, 2018, 10:51:54 pm
ikr
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on July 27, 2018, 01:21:14 am
You can just say that your start and end keyframe are the same and just use a timer.
Like each frame ++, when it's over 30, you play the blinking animation, when it's over 38, you reset it to zero.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on July 28, 2018, 04:45:45 pm
I made a modification to the framerate code in the my_gamepad function so that it can go over 2.0, yet stay above 0:

Code: [Select]
    if (jo_is_pad1_key_pressed(PER_DGT_TL))
{SynchConst=(Sint8)1; framerate-=1;}

    else if (jo_is_pad1_key_pressed(PER_DGT_TR))
{SynchConst=(Sint8)2; framerate+=1;}
    else if
    (framerate<0)
    {framerate=0;}

The above negative integer prevention part of the code only seems to reset the framerate integer to 0 as soon as the left trigger is released. How would I remove the possibility of negative integers completely?
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on July 28, 2018, 06:41:31 pm
Change the data type of framerate to unsigned instead of signed (Uint instead of Sint).
However, you should be working with the binary file instead of the header files, which use a different function to animate.
I'm pretty close to being entirely done with PCM sound (which is big yay), so maybe in the next few days I can get my own version of the animate function out.
[Yes, I really want my own version, since there could be computational implications different from what XL2 makes and I just want to see what those end up being]
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on July 29, 2018, 07:34:30 pm
I've been trying to counter the distortion of displaying a texture on a triangular polygon, and it seems that there is another factor that comes in...
As an example, I made the Windows logo in Flash, and I skewed it on the X axis at 45 deg, because I was going to put it on an isosceles right triangle. However, when I ran the emulator, the texture seems to be distorted, with a curve to it...

May someone please tell me why this other distortion occurs?
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on July 29, 2018, 07:44:43 pm
The Saturn uses distorted sprites only, so it will distort your image unless it's a perfect square. It doesn't use texture coordinates either, so the way to do it is to distort your triangle texture into a quad, which will then be rendered correctly. It's really just sprites and you distort them by playing with the 4 corners.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on July 29, 2018, 07:58:49 pm
So, it looks MUCH better, with your statement in mind!  8)

But why does the texture on the triangle still have this curved distortion?
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on July 29, 2018, 08:19:14 pm
Because it interpolates the texture across the 4 vertices.
I would say that in your case gouraud shading would look better.
Another thing you can do is have a quad with transparent pixels, but it will be slower to render.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: ponut64 on August 02, 2018, 03:02:51 am
So variable interpolation was simpler than I expected. It's pretty coarse, but it works.

The struct is now like this:
Code: [Select]
typedef struct
{
bool uniform;
Uint8 arate[256];
    Uint16 currentFrm;
    Uint8 currentKeyFrm;
    Uint8 startFrm;
    Uint8 endFrm;
} animationControl;

Note arate, a 256 array of 8-bit values. The array size corresponds with the key frame data sizes.

For each frame of your animation area, if it is of non-uniform interpolation speed, you must define the arate for each key frame.

Code: [Select]
void	anim_defs(void)
{
forward.uniform = false;
forward.arate[0] = 1;
forward.arate[1] = 4;
forward.arate[2] = 1;
forward.arate[3] = 1;
forward.arate[4] = 4;
forward.arate[5] = 1;
forward.arate[6] = 1;
forward.currentKeyFrm = 0;
forward.startFrm = 1;
forward.endFrm=7;

left.uniform = false;
left.arate[8] = 2;
left.arate[9] = 1;
left.arate[10] = 1;
left.arate[11] = 2;
left.currentKeyFrm = 8;
left.startFrm = 8;
left.endFrm = 11;

right.uniform = false;
right.arate[10] = 2;
right.arate[11] = 1;
right.arate[12] = 1;
right.arate[13] = 2;
right.currentKeyFrm = 10;
right.startFrm = 10;
right.endFrm = 13;

idle.uniform = false;
idle.arate[0] = 0;
idle.currentKeyFrm = 8;
idle.startFrm = 7;
idle.endFrm = 7;
}

And here's a slightly changed animation code.

Code: [Select]
/**XL2 Animation Interpolation system with ANORM.h lookup table**/
#include "anorm.h"
void display_animated_model(animationControl * animCtrl, entity_t * currentModel, bool UseRealtimeGouraud)
{
if(currentModel->nbMeshes < 1){
return;
}
Uint8 ANIM_SIZE = 6;
Uint8 ANIM_QUAL = 3;

    XPDATA * currentPDATA = currentModel->pol[0];

    /**Sets the animation data**/
///Variable interpolation set
if(animCtrl->uniform == false){
    animCtrl->currentFrm += animCtrl->arate[animCtrl->currentKeyFrm];
} else {
animCtrl->currentFrm += 2;
}
///MATH: The below line increments the key-frame based on the current frame, which is incremented each frame by the arate.
///The arate in this case is 2. With an arate of 2, the current frame goes up twice for every frame of the game played...
///To compensate for this, we bitshift by 3 instead of 4 to increment the keyframe once every 30 iterations instead of once every 15 iterations.
///The ultimate control is the arate. XL2 set it up this way so it could be related to the game's frame-rate value, which at 30fps, is 2.
///It really does need to be this way or else the compression ratio does not work at all properly.
///This is, for all practical purposes, a fixed-function animation system with only 1 controllable variable of precise operation: the arate. (though creative souls could change the anim size variable)
   animCtrl->currentKeyFrm = (animCtrl->currentFrm>>3);  //should be >>currentModel->AnimInterpolation;
    if (animCtrl->currentKeyFrm >= animCtrl->endFrm)    {
        animCtrl->currentFrm -= (animCtrl->endFrm - animCtrl->startFrm)<<3; //<<currentModel->AnimInterpolation;
        animCtrl->currentKeyFrm = animCtrl->currentFrm>>3;  //>>currentModel->AnimInterpolation;
     } else if(animCtrl->currentKeyFrm < animCtrl->startFrm){
animCtrl->currentKeyFrm = animCtrl->startFrm;
animCtrl->currentFrm += (animCtrl->endFrm-animCtrl->startFrm)<<3;
}

    Uint8 nextKeyFrm = animCtrl->currentKeyFrm+1;
    if (nextKeyFrm >= animCtrl->endFrm){
        nextKeyFrm = animCtrl->startFrm;
} else if (nextKeyFrm <= animCtrl->startFrm){
        nextKeyFrm = animCtrl->startFrm;
}
    compVert * curKeyFrame = (compVert*)currentModel->animation[animCtrl->currentKeyFrm]->cVert;
    compVert * nextKeyFrame = (compVert*)currentModel->animation[nextKeyFrm]->cVert;

///Don't touch this!
Uint32 compHelp = (animCtrl->currentFrm)-(animCtrl->currentKeyFrm<<3);
    /*if (nextKeyFrm>animCtrl->currentKeyFrm) compHelp = animCtrl->currentFrm-(animCtrl->currentKeyFrm<<3);
    else compHelp = animCtrl->currentFrm-(animCtrl->currentKeyFrm<<3);*/

    /**Uncompress the vertices and apply linear interpolation**/
    register Uint32 i;
    Sint32 *dst=currentPDATA->pntbl[0];
    Sint16 *src=curKeyFrame[0];
    Sint16 *nxt=nextKeyFrame[0];
///Decompression
    for (i = 0; i < currentPDATA->nbPoint*sizeof(POINT); i+= sizeof(int)) {
*dst++=(*src+(((*nxt-*src)*compHelp)>>ANIM_QUAL))<<ANIM_SIZE;
*src++; *nxt++;
    }
    *dst=currentPDATA->pltbl[0].norm[0];
    Uint8 *src2=currentModel->animation[animCtrl->currentKeyFrm]->cNorm;
///Interpolation
    for (i = 0; i < currentPDATA->nbPolygon; i++)    {
    /**Not 100% sure which technique is faster**/
        // currentPDATA->pltbl[i].norm[X]=ANORMS[*src2][X];
        // currentPDATA->pltbl[i].norm[Y]=ANORMS[*src2][Y];
        // currentPDATA->pltbl[i].norm[Z]=ANORMS[*src2++][Z];
        *dst++=ANORMS[*src2][X];
        *dst++=ANORMS[*src2][Y];
        *dst++=ANORMS[*src2++][Z];
        *dst++; *dst++;
    }
jo_printf(0, 10, "(anim dat)");
jo_printf(0, 11, "(%i)", dst);
jo_printf(0, 12, "(%i)", src);
jo_printf(0, 13, "(%i)", dst);

jo_printf(0, 15, "(%i)", animCtrl->currentKeyFrm);
jo_printf(0, 16, "(%i)", animCtrl->currentFrm);
jo_printf(0, 17, "(%i)", animCtrl->startFrm);
jo_printf(0, 18, "(%i)", animCtrl->endFrm);
jo_printf(0, 19, "(%i)", compHelp);
    if (UseRealtimeGouraud) slPutPolygonX(currentPDATA, light);
    else slPutPolygon((PDATA*)currentPDATA);
}


http://www.mediafire.com/file/78rr5pc0zbvln52/proj_8118.zip/file
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on August 08, 2018, 07:04:04 pm
So, this is the closest thread that is similar to the ZTP format, but how does the ZTM (Z-Treme Map?) format work? One difference between the two formats is that ZTP files compress the textures to 4bpp, and the ZTM format compresses the textures to at least 8bpp (or, evident by earlier versions, 15bpp).
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on August 08, 2018, 07:17:28 pm
That version (old one) isn't supported by me anymore, it was 16 bpp.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: 20EnderDude20 on August 08, 2018, 07:25:37 pm
May you release the ZTM converter anytime soon? I found a technique to fix the triangular faces.
Title: Re: Model converter (.ZTP) -0.1 - WIP
Post by: XL2 on August 08, 2018, 07:26:30 pm
No, I don't intend to release it