Skip to: Site menu | Main content


Welcome to PSP-Programming.com, a place for developers to get together.

Welcome to the forums. Here you can find other user tutorials as well as homebrew releases and the source code repository. You can also ask for help with your code here and post your own homebrew!

PSP-Programming.com Forums
March 11, 2010, 08:41:54 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

News: Welcome to PSP-Programming.com
Home Help Search Shop Login Register
Digg This!
Pages: [1]
Print
Author Topic: [C++] BETA: .X Loader and Renderer  (Read 5926 times)
Vincent
Mudkips
C/C++ Developer
Hero Member
*

Karma: +75/-2
Offline Offline

Posts: 1374
9999999.99 points

View Inventory
Send Money to Vincent

Me and my 'Vette


View Profile WWW
« on: April 09, 2008, 07:34:38 PM »

This is a BETA version of my up-and-coming .x file loader and renderer. I am releasing this version to collect bug reports for any that would like to test it out. I'm hoping to get plenty of people loading .x files from different exporter plugins from different modeling packages with different settings. That way, I can adjust my .x loader code if needed. The code does not appear to be buggy, at least in the extensive tests I've done, but the code itself may not be that clean if you want to search through it. I am currently in the middle of developing this so far.

When exporting your .x file, make sure you have these settings enabled:
-Right-hand coordinate system
-The file MUST BE text-based (ASCII)
-If animations are being exported, make sure they are stored as quaternion, scale, position keys, and not matrix keys (I removed most of the matrix key support although it will load)
-Make sure your .x file is as un-optimized as possible, and does not use vertex weights. Although the .x loader loads the index lists, I do not support them entirely when drawing because it causes some conflict with animations at the moment.
-The file needs to contain frames, otherwise, the data will not be drawn (that is actually an bug I need to fix)
-Make sure that all meshes in the file is linked to a single root bone-- this only applies to files with animation data in them (I'm having trouble with multiple root bone support at the moment;)

Also, only one texture can be placed to these objects, that is not handled by the .x loader. The loader does handle texture coordinates. The rendering class handles setting the textures. See the tutorial for a better explanation.

Please note that some of your models may be rotated differently on the PSP than in your editor. This will cause your models to position differently than normal as well when moving them with the object::move() function. This is probably due to the coordinate system used in the modeling package you are using. I am using 3Ds Max, and its y and z axis are swapped. If your exporter allows you to export certain key frames, and not the whole key frame list, then take advantage of that because this exporter supports interpolated animations. It does not support vertex skinning (vertices attached to multiple bones). If anyone has any models that require multiple vertex weights, and wouldn't mind sharing, please donate them to me in .3ds form. Wink

The release is in demo-form, and has some other parts of my engine in it (the stuff in early stages). The demo should show a biped skeleton made with Character Studio doing a crappy version of Super Mario's long jump with a bunch of boxes attached to various bones (I was still learning). Razz There should also be a box attached to the biped's left hand which can be rotated by holding the up or down directional buttons.

Any comments, suggestions, or optimizations on any of the code are welcome! Wink

Special Thanks to:
IWN & Raphael for all their help, and for Raph's vram manager which is used is required to run this. You can get it here: http://www.psp-programming.com/forums/index.php?topic=1840.0

That library must be in the same directory as the rest of the source code. Enjoy!

EDIT: I'll be putting up some screenshots of other tests I've been doing. They are pretty good. I made am animated jail cell based off of the ones in Crisis Core! Also, the current release is built for 1.5 PSPs right now. I can't get my PSP to an m33 version just yet... I'll be there one of these days when I get Linux figured out.
« Last Edit: April 10, 2008, 08:45:43 PM by Vincent » Logged



PaulC
Newbie
*

Karma: +2/-1
Offline Offline

Posts: 49
1661.44 points

View Inventory
Send Money to PaulC

View Profile
« Reply #1 on: April 23, 2008, 05:33:07 AM »

Good stuff, Vincent. As far as I'm concerned, there can never be enough model loaders.

What application do you use to export to ASCII?
Logged
Vincent
Mudkips
C/C++ Developer
Hero Member
*

Karma: +75/-2
Offline Offline

Posts: 1374
9999999.99 points

View Inventory
Send Money to Vincent

Me and my 'Vette


View Profile WWW
« Reply #2 on: April 23, 2008, 08:49:56 PM »

I use 3Ds Max for modeling, and I use the PandaSoft Direct3D plugin. It is free and legit to download at:
http://www.andytather.co.uk/Panda/directxmax.aspx

That link looks about right. I think there's an exporter out there for 3Ds Max 9 now although my wallet says I am completely happy with 3Ds Max 7. Razz

There should be an option to for either binary or ASCII (also noted as "text" in some exporters). You could also download Milkshape 3D. There is a good .x exporter there as well. Also, while looking through a few .x files, keep in mind that interpolation must be synchronized. In other words, if you interpolate between frames 0 and 20, make sure that all animation key types in your animation has keys 0 and 20. I've gotta add asynchonous interpolation, but that'll have to wait until tomorrow!
Logged

Seagate
Newbie
*

Karma: +1/-0
Offline Offline

Posts: 25
1308.74 points

View Inventory
Send Money to Seagate

天下风云出我辈,一入江湖岁月催


View Profile WWW
« Reply #3 on: July 15, 2008, 06:32:18 AM »

i had just learning skinning on psp, thanks for your work and code! Razz
Logged
Keikura
Full Member
***

Karma: +10/-1
Offline Offline

Posts: 103
7113.06 points

View Inventory
Send Money to Keikura

View Profile
« Reply #4 on: July 15, 2008, 03:25:51 PM »

Quick question Vincent, have you or anyone else for that matter tried .x files exported from Blender to see if they work?

Great work btw. Very Happy
Logged
Seagate
Newbie
*

Karma: +1/-0
Offline Offline

Posts: 25
1308.74 points

View Inventory
Send Money to Seagate

天下风云出我辈,一入江湖岁月催


View Profile WWW
« Reply #5 on: July 15, 2008, 08:52:16 PM »

hi Vincent, I build you demo with vram.c .h code. but it can not run on my psp. It report error as:

Load/Start host0:/xDemo/XDEMO.prx UID: 0x04603411 Name: "X_DEMO"
host0:/xDemo/> allocating 557056 bytes, in 1088 blocks
allocating 557056 bytes, in 1088 blocks
allocating 278528 bytes, in 544 blocks
image has been loaded
idLength:        0
colorMapType:    0
dataTypeCode:    2
colorMapOrigin:  0
colorMapLength:  0
colorMapDepth:   0
xOrigin:         0
yOrigin:         0
width:           128
height:          128
bitsPerPixel:    16
imageDescriptor: 1
bit 1 is set
stride: 128
texture size: 32768 bytes
model file has been openned
terminate called after throwing an instance of 'std::bad_alloc'
  what():  St9bad_alloc

I have no idea with this Sad, My psp version is 3.71, btw.
Logged
Vincent
Mudkips
C/C++ Developer
Hero Member
*

Karma: +75/-2
Offline Offline

Posts: 1374
9999999.99 points

View Inventory
Send Money to Vincent

Me and my 'Vette


View Profile WWW
« Reply #6 on: July 16, 2008, 10:12:00 AM »

@Keikura: I have not tried it with Blender yet. If you can, could you uploada the .x file to this thread, and I'll take a look at it. I have not looked at my .x code in about 2 months due to graduation and summer sessions at college. I am finished with classes for about a month now. Lately, I have been looking at the XNA Framework for 360 and WiiWare, but I will get back to work with this exporter now that I have time.

@Seagate: Are you using Raphael's vram manager? Nevermind, you should get compiler errors with Raphael's vram manager. Wink I think I know what the issue is. See, I think this build was when I was still working on firmware 1.5. That was back when we used .php eboots. Now, we have to compile into .prx's (forgot that recently when trying to play Metal Gear Solid on my PSP). Prx's only have somewhere like 256kb of space allocated to them by default. What you need to add is I think PSP_HEAP_SIZE_MAX() at the top of main.cpp, and I believe that will fix it! Wink I loaded up a Half-Life model on the PSP without skinning and the geometry loaded fine, but texturing was incorrect. That is weird because I have never had that problem before, but this is the first model that has multiple textures on it (currently not supported).

I have not been working with the PSP for a while now, so I will have to look at a few things. I need to finish full targa texture support, and perfect its shortcomings (I have a list of them for just the targa loader I need to find). If any of you have any ideas on how to get the .x file loader to support hardware skinning on the PSP, I'm all ears. The way is does is hard to work with due to how the .x file skins DirectX models. What you artists will have to do in the future is make sure that each primitive in your model has up to bones associated with them. If not, you will have to divide the mesh up drawing-wise. Also, make sure that your geometry is unoptimized if you can. The geometry has to be drawn with GU_TRIANGLES without the use of indices, which I do support, but is not "on" by default.

EDIT: Haha, I forgot I don't have Windows on my computer anymore, and most of my test models are erased. I can't use 3Ds Max due to only having Linux on my computer, so I'm going to work with Blender now! That would be the best way to go about this because I think way more people are using Blender than 3Ds Max anyway.
« Last Edit: July 16, 2008, 10:17:57 AM by Vincent » Logged

Seagate
Newbie
*

Karma: +1/-0
Offline Offline

Posts: 25
1308.74 points

View Inventory
Send Money to Seagate

天下风云出我辈,一入江湖岁月催


View Profile WWW
« Reply #7 on: July 16, 2008, 05:45:31 PM »

@Vincent: I add PSP_HEAP_SIZE_MAX() in main.c. Very Happy. It is works!
I can use Vextex Shader to calculate skinning on D3D9, It support 70 bones. And I want  to know how to show skeleton with hardware skinning too.  Only 8 bones can be used in one draw call on PSP:?: maybe you can give me some help, thanks Smile
Logged
Vincent
Mudkips
C/C++ Developer
Hero Member
*

Karma: +75/-2
Offline Offline

Posts: 1374
9999999.99 points

View Inventory
Send Money to Vincent

Me and my 'Vette


View Profile WWW
« Reply #8 on: July 17, 2008, 10:00:58 PM »

@Vincent: I add PSP_HEAP_SIZE_MAX() in main.c. Very Happy. It is works!
I can use Vextex Shader to calculate skinning on D3D9, It support 70 bones. And I want  to know how to show skeleton with hardware skinning too.  Only 8 bones can be used in one draw call on PSP:?: maybe you can give me some help, thanks Smile
Glad to hear it worked! The 70 bones sounds like you can have up to 70 bones in a skeleton. DirectX 9 can only support up to 5 vertex weights so up to 5 bones can be attached to one vertex. DirectX and the GU work very similarly (but not identically) when working with basic operations such as using geometric data, texturing, and even setting up bone sets (skeletons) for the most part. However, once the topic of skinning has been reached, the convenient similarities begin to end...

You are also right, the PSP can only reference 8 bones per draw call. So, the group of vertices that are drawn can only use up to 8 different bones. So, some vertices might be connected to "right_shoulder" while some are connected to "right_arm" and some might be connected to both. Some might not be connected to either. Even though some vertices do not use these bones, they must be connected to them because the other vertices in the drawing set are because we apply bone skinning to all vertices at once on the PSP. If the bones are not really attached, we can just set the weighing factor to 0.0f, and it will make both us and the PSP happy. I explain this in depth below...

The following is hard for me to explain:
The thing is that DirectX not only stores the vertex weight, but a pointer to the bone as a reference within the vertex structure. This is true if you look through the skinning data throughout the .x file. No vertex has more than 5 different bones attached to it. Now, the PSP's vertices can hold up to 8 weights per vertex... The problem is that each vertex does not reference each specific bone to each vertex. It handles the vertices as a group. The vertex weighting factors will be defined in the vertex structure. So, you may ask, how do I tell the PSP which weights belong to which bones? Well, after a bunch of research and testing, there is a function that is called before sceGumDrawArray(). This function is called sceGuBone() (I think). This function will reference the vertex weight to the bone. There are two parameters: index number of the weight the bone, and a pointer to the bone in the skeleton.

I have this all worked out in my head for how it should work. The problem is that the skeleton has to add a special skinning matrix on top of all the other stuff. So, my skeleton has to orientate itself, apply the skinning factors to the corresponding bones, then multiply each vertex position by the offset matrix in the DirectX file. This is just as slow as my 3D collision detection code (which is partly integrated into object.cpp).

I hope this clears it up, and I am going to start implementing this back in once I get my texture loader to render a model with multiple textures per drawing set. I am starting to think that I will have to do most of this via software like I had originally planned. I may not use any of the hardware skinning at all.
« Last Edit: July 17, 2008, 10:06:44 PM by Vincent » Logged

Seagate
Newbie
*

Karma: +1/-0
Offline Offline

Posts: 25
1308.74 points

View Inventory
Send Money to Seagate

天下风云出我辈,一入江湖岁月催


View Profile WWW
« Reply #9 on: July 22, 2008, 07:15:34 AM »

Hi Vincent, Thanks for your reply. I will try to do it. Btw, i learn more stuff from your posts in the forums Smile
Logged
Vincent
Mudkips
C/C++ Developer
Hero Member
*

Karma: +75/-2
Offline Offline

Posts: 1374
9999999.99 points

View Inventory
Send Money to Vincent

Me and my 'Vette


View Profile WWW
« Reply #10 on: July 22, 2008, 02:21:35 PM »

Quote
Hi Vincent, Thanks for your reply. I will try to do it. Btw, i learn more stuff from your posts in the forums Smile
I am way glad to hear it! All of my questions are paying off. I am currently working on ironing out some other issues with the .x loader so that adding skinning support won't be such a pain. It appears that my bone data-to-skeleton code is not fully bug-free and it is hard to track down the issues. I do have a 'concept' of how to implement the skinning data which should definitely work, but be really slow due to .x file's lack of similarity to the GU in that area. I'm going to have to simulate some things in the code...
Logged

Vincent
Mudkips
C/C++ Developer
Hero Member
*

Karma: +75/-2
Offline Offline

Posts: 1374
9999999.99 points

View Inventory
Send Money to Vincent

Me and my 'Vette


View Profile WWW
« Reply #11 on: July 29, 2009, 03:58:22 AM »

Wow, my post has gotten old. So anyway, I was able to get software skinning up and running on OpenGL. It turns out that my worse fears were correct in finding that it is best to do software skinning. Not that hardware skinning couldn't be possible, but it's just too damn complex! Like I said a year ago, the only way for hardware skinning to work is when the artist splits the model up into sections where no more than 8 bones are associated with the vertices in each section of the model. Still, I have a software renderer that does the job just fine. The only problem I have had, although, it texturing. See, I can only support 1 texture per mesh in the model. For example, if I have a fighter jet that is composed of two separate meshes: the cockpit and the rest of the fighter jet, the cockpit can have its own texture while the rest of the fighter jet will have its own. They two pieces can also share the same texture as well which would most-likely save on uploads depending on how you would order texture atlases. The only downside of texture atlases is texture wrapping! You couldn't tile a section of a texture within one giant quad unless the field you are tiling extends to both extents of the map.

If there are any still interested, I may boot up Ubuntu again like old times, and build a PSP version. I'll include a nice little tutorial with screenshots all embedded into an html page for a nice presentation too! All I need is a really nice-looking model animated model with a skeleton with some cool texturing (only 1 texture though). I'll do the rest from there.
« Last Edit: July 29, 2009, 04:00:39 AM by Vincent » Logged

Pages: [1]
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.43 seconds with 35 queries.
Sister Sites: Guitar Hero 4   BrokeniTouch.com