Posted: Thu Sep 29, 2011 1:20 am
Joined: 29 Sep 2011
Posts: 8
Hey,
I was writing a .blend parser for a new game engine, but I ran into a little problem. I am able to find the structures for the things I need and associate them with a pointer, but the problem comes when trying to find the address of another pointer in that structure.
Here is an example of what I mean:
| Code: |
/* snippet from blend_sdna.h */
#define SDNA_MESH 52
typedef struct sdna_mesh_s {
sdna_id_t id;
sdna_boundbox_t *bb;
sdna_listbase_t effect;
sdna_ipo_t *ipo;
sdna_key_t *key;
sdna_material_t **mat;
sdna_mface_t *mface;
sdna_mtface_t *mtface;
sdna_tface_t *tface;
sdna_mvert_t *mvert;
sdna_medge_t *medge;
sdna_mdeformvert_t *dvert;
sdna_mcol_t *mcol;
sdna_msticky_t *msticky;
sdna_mesh_t *texcomesh;
sdna_mselect_t *mselect;
sdna_customdata_t vdata;
sdna_customdata_t edata;
sdna_customdata_t fdata;
int totvert;
int totedge;
int totface;
int totselect;
int act_face;
int texflag;
float loc[3];
float size[3];
float rot[3];
float cubemapsize;
float pad;
short smoothresh;
short flag;
short subdiv;
short subdivr;
short totcol;
short subsurftype;
void *mr; // sdna_multires_t *mr;
void *pv; // sdna_partialvisibility_t *pv;
void *vnode;
} sdna_mesh_t;
/* snippet from main.cpp */
.... some more code .....
blend_file_t blend;
block_t block;
if(!blend_load("test.blend", &blend)) // custom function
{
std::cout << "Could not find test.blend";
return 0;
}
do
{
blend_readblock(&block, &blend);
} while(block.header.SDNA_index != SDNA_MESH);
sdna_mesh_t *mesh = (sdna_mesh_t *)block.code;
std::cout << mesh->id.name; // prints out MECube just fine.
|
The above works just fine. the problem is when I try to get another pointer inside the sdna_mesh_t struct (such as mesh->key->elemstr).
How would I go about mapping mesh->key to the correct location in the blend file?
Sorry about this question (I am sure it has been asked many times before), but I am on a deadline and need to focus on more than just this.
Any help would be much appreciated!
Thank you!
Christian Modas
Posted: Thu Sep 29, 2011 4:22 am
Joined: 29 Sep 2011
Posts: 8
Actually I think I just figured it out.
| Code: |
blend_file_t *blend = new blend_file_t;
block_t block;
if(!blend_open("test.blend", blend))
{
std::cout << "Could not load test.blend!";
return 0;
}
std::cout << "Pointer Size: " << blend->header.pointer_size << "\nEndianness: " << blend->header.endianness << "\nBlender Version: " << blend->header.version_number << "\n\n";
blend_skipblocks(6, blend);
do
{
blend_readblock(&block, blend);
} while(block.header.SDNA_index != SDNA_MESH);
sdna_mesh_t *mesh = (sdna_mesh_t *)block.code;
do
{
blend_readblock(&block, blend);
} while(block.header.SDNA_index != SDNA_MVERT && block.header.old_memory_address != mesh->mvert);
mesh->mvert = (sdna_mvert_t *)block.code;
std::cout << mesh->mvert->co[0];
blend_close(blend);
|
I'll post the code in case anybody else needs help. Its not near complete to read everything, but I just needed something to convert .blend files into other formats (levels, models, animations, ect.).
http://www.megafileupload.com/en/file/328028/blend-reader-zip.html
Posted: Thu Sep 29, 2011 3:40 pm
Joined: 30 Aug 2010
Posts: 63
sounds like the reason I needed to know the file format.
I'm working on a model converter of my own to support a variety of file formats based on the plugins
(like winamp)
_________________
Posted: Thu Sep 29, 2011 5:46 pm
Joined: 05 Aug 2003
Posts: 3489
The Crystal Space project did some work (C++, iirc) on a reader for .blend files. The Blender file format is a little tricky to deal with because:
* .blend files are designed to be forward & backward compatible betweenversions
* the .blend format was not designed as a file interchange format and is essentially a memory dump from a running instance of Blender
* the structure can (and does!) change between Blender versions to support new features.
The Blender DNA stuff is your friend here.
Posted: Fri Sep 30, 2011 12:37 am
Joined: 30 Aug 2010
Posts: 63
>.>
are you telling me that, or him?
cause I think you've already told me that...
if not you, then I know somebody has >_>
is there any documentation on blender DNA that's not in C++??
_________________
Posted: Fri Sep 30, 2011 2:22 am
Joined: 29 Sep 2011
Posts: 8
Posted: Fri Sep 30, 2011 6:45 am
Joined: 29 Sep 2011
Posts: 8
Actually all the stuff from the last link was using blender version 2.49. I would like to use version 2.59. I think the SDNA index is changed for the objects. Does anybody know how one would go about finding this? I think its somewhere stored in the blend file, but I really would just like some numbers.
Posted: Fri Sep 30, 2011 8:52 am
Joined: 29 Sep 2011
Posts: 8
well once again, the mystery has been solved. Here is the solution if anybody else is having the same problem:
Posted: Fri Sep 30, 2011 1:19 pm
Joined: 30 Aug 2010
Posts: 63
YES!
thank you
just in the exact language I can read XDD
_________________
Posted: Thu Dec 08, 2011 9:26 pm
Joined: 08 Dec 2011
Posts: 3
i need really help i completely parsed the .blend file but now i have problems to interpret the data.
can u please send me your code?
Posted: Sat Feb 25, 2012 7:36 pm
Joined: 29 Sep 2011
Posts: 8
| Quote: |
marik89
Posted: Thu Dec 08, 2011 9:26 pm Post subject:
FakeMajor wrote:
Actually I think I just figured it out.
...
I'll post the code in case anybody else needs help. Its not near complete to read everything, but I just needed something to convert .blend files into other formats (levels, models, animations, ect.).
http://www.megafileupload.com/en/file/328028/blend-reader-zip.html
i need really help i completely parsed the .blend file but now i have problems to interpret the data.
can u please send me your code? |
Do you still need the code? its been a while since this was posted
Posted: Sun Feb 26, 2012 6:56 am
Joined: 07 Nov 2010
Posts: 544
Posted: Wed May 16, 2012 10:23 am
Joined: 08 Dec 2011
Posts: 3
| FakeMajor wrote: |
| Quote: |
marik89
Posted: Thu Dec 08, 2011 9:26 pm Post subject:
FakeMajor wrote:
Actually I think I just figured it out.
...
I'll post the code in case anybody else needs help. Its not near complete to read everything, but I just needed something to convert .blend files into other formats (levels, models, animations, ect.).
http://www.megafileupload.com/en/file/328028/blend-reader-zip.html
i need really help i completely parsed the .blend file but now i have problems to interpret the data.
can u please send me your code? |
Do you still need the code? its been a while since this was posted |
My Importer is running well but only with 32bit files.
Does your code Support 64Bit files?
If Yes i still need the code.