OBJ importer?
Blitz3D Forums/Blitz3D Programming/OBJ importer?
| ||
I've haad a quick look around the site but can't find any - does anyone have any OBJ importing code? |
| ||
All I can offer you is a commandline tool that is capable of converting some formats, including OBJ to 3DS. Includes C Sourcecode, so you may port it to Blitz, or use the binary by the commandline in a hidden mode: http://www.melog.ch/dl/ivcon_3dconvert_win32bin.zip |
| ||
Thanks jfk, but I've been asked the dreaded question 'How difficult would it be...' (- Don't you just hate that from non-programmers.) So I guess it would have to be Blitz3D code - possibly a routine that would internally build a mesh from a .Obj file? Anyone? |
| ||
I've got some at home (Posting from work), I'll dig it out when I get back. |
| ||
Thanks Lee, that would be much appreciated. I'll look forward to it. |
| ||
Sorry it took so long. A Simple function which returns a mesh, as pulled from Tattoo. :) This one handles scientific notation in the text of the .OBJ file. Caught me out that one! |
| ||
Cool !!!! Great!! Is a function savetex() missing ? /Alienforce |
| ||
Yep, SaveTex is Tattoo specific. Basicly it saves out a texture in preparation to painting it. Normally you wouldn't need it. Just load the textures that are there. |
| ||
Ok, thanks alot for sharing this. /Alienforce |
| ||
Can I copy it to the Archives? |
| ||
Can I copy it to the Archives? Sure. Why not. |
| ||
Lee, at the risk of sounding petty (since you've done so much work on this) I'm afraid that I have not succesfully loaded a single obj file. Three obj files gave a 'Vertex index out of bounds' error, and the four that did load appeared to have lost their textures. Fancy doing a little more work on this? (Pretty please.... I can zip up the meshes and send them to you if you like?) |
| ||
The .OBJ file format doesn't appear to use textures the same way as Blitz. It uses material files. If you send them over I'll take a look. But you should have enough there to get the textures showing without much effort. |
| ||
Lee, rather than ask you to do any more work, can I ask you a few questions? I'm trying to satisfy a client who wants to import OBJ files. What I have just noticed is that none of the editors that I use export a .obj with textures specs! I've looked at all the .obj files I have in Notepad, and none of them have internal texture specifications. Does this mean that the .obj file format does not include textures? The client's main gripe was that .3DS meshes have a face limit which might be too low for them. Do you know the face limit of a .3DS file? |
| ||
I guess its a 64k thing - as usual. But AFAIK it's DirectX that has such a limit and therefor cannot be used for larger meshes (well I think it was max 64k Vertices and Tris each Surface) |
| ||
The texture refs are to Materials. These appear to be external files (.MTL I think). These would likely have surface information in them including any bitmaps. I don't know what the face limit on a .3DS is, but if you have any 3D Packages that export .3DS keep subdividing a sphere until it complains, then you'll know. .3DS is limited in other way as far as I know. Things like 8.4 Filenames etc. I suppose the question is, where are the models coming from and what formats can it output? |
| ||
I think we've narrowed this down to the following: 1) The guy uses 'SketchUp' - an architect/designer's favourite (about £230?) - said designers like .obj because they've decided it 'outputs more accurately'. 2) They are interested in the possibility of a B3D-based 'viewer' prog since they're not happy with what they have. 3) As you say .obj's use .mtl files which describe the textures. 5) Interestingly I have no 3D modeller which acknowledges or outputs .mtl files, but obviously the designers do, so I've asked him to send me a textured cube so I can look at the file structure and the mtl file. Don't suppose you'd be interested in adding .mtl capability to your code? |
| ||
This is a textured cube in .obj file format, which is as you can see, from Gile[s]. If I were you, I would go for Gile[s]. It can import/export .obj with materials and has the capability to bake lightmaps which makes architectural walk-throughs much prettier. Esp. Gile[s] can save to .b3d. This leaves you with writing a viewer for .b3d which is fairly straight forward. # cobe.obj # Exported by gile[s] mtllib cube.mtl o Scene #Begin Vertices v 1.000000 1.000000 -1.000000 v -1.000000 1.000000 -1.000000 v -1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 1.000000 v -1.000000 -1.000000 1.000000 v -1.000000 1.000000 1.000000 v 1.000000 1.000000 1.000000 v 1.000000 1.000000 -1.000000 v 1.000000 -1.000000 -1.000000 v 1.000000 -1.000000 1.000000 v 1.000000 1.000000 1.000000 v -1.000000 1.000000 1.000000 v -1.000000 -1.000000 1.000000 v -1.000000 -1.000000 -1.000000 v -1.000000 1.000000 -1.000000 v 1.000000 -1.000000 -1.000000 v -1.000000 -1.000000 -1.000000 v -1.000000 -1.000000 1.000000 v 1.000000 -1.000000 1.000000 v 1.000000 1.000000 1.000000 v -1.000000 1.000000 1.000000 v -1.000000 1.000000 -1.000000 v 1.000000 1.000000 -1.000000 #End Vertices #Begin Vertex Normals vn 0.000000 0.000000 -1.000000 vn 0.000000 0.000000 -1.000000 vn 0.000000 0.000000 -1.000000 vn 0.000000 0.000000 -1.000000 vn 0.000000 0.000000 1.000000 vn 0.000000 0.000000 1.000000 vn 0.000000 0.000000 1.000000 vn 0.000000 0.000000 1.000000 vn 1.000000 0.000000 0.000000 vn 1.000000 0.000000 0.000000 vn 1.000000 0.000000 0.000000 vn 1.000000 0.000000 0.000000 vn -1.000000 0.000000 0.000000 vn -1.000000 0.000000 0.000000 vn -1.000000 0.000000 0.000000 vn -1.000000 0.000000 0.000000 vn 0.000000 -1.000000 0.000000 vn 0.000000 -1.000000 0.000000 vn 0.000000 -1.000000 0.000000 vn 0.000000 -1.000000 0.000000 vn 0.000000 1.000000 0.000000 vn 0.000000 1.000000 0.000000 vn 0.000000 1.000000 0.000000 vn 0.000000 1.000000 0.000000 #End Vertex Normals #Begin Vertex Texture Coords vt 0.000000 1.000000 0.000000 vt 1.000000 1.000000 0.000000 vt 1.000000 0.000000 0.000000 vt 0.000000 0.000000 0.000000 vt 0.000000 0.000000 0.000000 vt -1.000000 0.000000 0.000000 vt -1.000000 1.000000 0.000000 vt 0.000000 1.000000 0.000000 vt 0.000000 1.000000 0.000000 vt 1.000000 1.000000 0.000000 vt 1.000000 0.000000 0.000000 vt 0.000000 0.000000 0.000000 vt 0.000000 0.000000 0.000000 vt -1.000000 0.000000 0.000000 vt -1.000000 1.000000 0.000000 vt 0.000000 1.000000 0.000000 vt 0.000000 1.000000 0.000000 vt 1.000000 1.000000 0.000000 vt 1.000000 0.000000 0.000000 vt 0.000000 0.000000 0.000000 vt 0.000000 0.000000 0.000000 vt -1.000000 0.000000 0.000000 vt -1.000000 1.000000 0.000000 vt 0.000000 1.000000 0.000000 #End Vertex Texture Coords #Begin Polygons g usemtl tex f 1/1/1 3/3/3 2/2/2 f 1/1/1 4/4/4 3/3/3 f 5/5/5 7/7/7 6/6/6 f 5/5/5 8/8/8 7/7/7 f 9/9/9 11/11/11 10/10/10 f 9/9/9 12/12/12 11/11/11 f 13/13/13 15/15/15 14/14/14 f 13/13/13 16/16/16 15/15/15 f 17/17/17 19/19/19 18/18/18 f 17/17/17 20/20/20 19/19/19 f 21/21/21 23/23/23 22/22/22 f 21/21/21 24/24/24 23/23/23 #End PolygonsAnd the material file: # cube.mtl newmtl tex Ka 1 1 1 Kd 1.000000 1.000000 1.000000 Ks 0.000000 0.000000 0.000000 map_Kd tex.png |
| ||
I think you've hit on it, Dirk. So the simple answer is to tell these people to buy Giles as part of their pipeline. Then they still have a choice (I assume) to export finaly as .3DS, .X, .B3D for use in a viewer. Unless Lee fancies do some more work on his code. (Lee growls quietly.) Which would make me look very good, and of course Lee would be included in the credits. Sorry, did you say 'Money'? You know, I have this reoccuring problem with my hearing (-waggles finger in ear). Only kidding! (BTW Decorator is brilliant!) |
| ||
Actually Dirk hit the nail on the head. The reason I didn't do this already is that Tattoo creates it's own textures for imported .OBJ files, so the MTL files were not needed. Still, it's not too much hassle to put it in. I take it the file name for the Material file was tex.mtl ? Or was it one file called cube.mtl with different texture references in it? Actually, Dirk, can you send me the .OBJ and the .MTL file? |
| ||
Nice one Lee. Thanks for going for it. |
| ||
sure. |
| ||
Got em. I'll post the update soon. |
| ||
Ok. Done it. This Version scans the associated .mtl file and loads referenced textures. If there are any problems then let me know. It loads Dirk's one fine. You will probably need to tweak the code to your own purposes. At the moment, it adds blank textures to surfaces without references. For Tattoo it makes sense, for a viewing program it doesn't, so you might want to rem out that bit (I put the comments in to show you where) and optionally scan for plain colors etc. If you have any 'vertex out of range' problems or models that don't load properly, send them to me to have a look at. Without proper specs on the file format you need lots of examples. |
| ||
Yes, your new version works fine, thanks. Lee, I've zipped up 2 meshes that give a 'vertex out of range' error, for your interest. But to be honest, even I'm getting tired of this. There appears to be so much variation in the .obj format (or the way that different programs export it) that despite your sterling efforts I think for safety's sake I'll end up advising the client to use something like 3D Exploration to convert .obj to .3ds or .x, if they must dabble with that format. Don't get the wrong impression - I know you're a genius - I use Decorator! It's the other buggers we can't trust. I just can't in all conscience ask you to do any more work on this. Thanks. |
| ||
Some interesting stuff going on in those files. :) Importers are tricky as you need up to date information about the file format and all its quirks. I'll have a look at trying to sort out the problem (I'm missing something, as it loads into LightWave 8). Most of the documentation I can find seems to be a bit light on details and often quite old. If I make any progress I'll post it here. |
| ||
Thanks, Lee. Remember 'What doesn't destroy us, makes us stronger.' (Easy for me to say. :) |
| ||
Alrighty then.. Fixed it... Download the new version Here. It appears that they write some additional spaces between fields sometimes (a bad practice, but not too much of a problem). So I added a function to clear out multiple spaces between fields and viola. This loads both examples you sent. Hope that sorts it for you. ;) |
| ||
Very cool, Lee. |
| ||
Outstanding, Lee! Everybody, shout Lee's genius from the rooftops! I owe you one. Thanks. |
| ||
No problem. It gave me a better understanding of the File Format than I had before, so can't grumble. :) When the BlitzMax 3D Module is produced, I'll be making a slightly improved version of a number of things. DecoratorMax anyone! Muahahah. ;) |
| ||
Hey, Lee. Why isn't Decorator on your website? All I can find is Tattoo. You must have done other things... Decorator surely didn't spring fully formed. |
| ||
Tattoo was the only commercial one I've done, so the only one with its' own website. Decorator and other things are scattered around in the Tools Section. My Lightwave and TrueSpace to .B3D convertors are on the 'Specs and Utilities' tab. Other bits are in the Blitzplus package, couple of bits in the BlitzMax package. Some bits on BlitzCoder. A bit disorganised, but most things were just for fun. :) |