Importing a blender model into a DirectX 11.2 C++ application - c++

I'm new to DirectX applications, with a decent knowledge of C++ and some experience in working with Blender. So for starters i would like to know how could i import, say, a UV sphere from Blender into a DirectX 11.2 C++ application. I'm using november edition compiler. Is there a tutorial for working with Blender models in DirectX applications that is up to date? Because i read that the .X format is not supported anymore after DirectX 10, and i need to use it in a DirectX 11.2 enviroment. I'm pretty much clueless about what to do and in what direction to go, so any help would be much appreciated.

If you 'just' want to display some 3D objects using native DirectX there is no other way than doing all the initialization stuff, writing a file loader for some kind of format that Blender is able to export and setting up a respective render pipeline. Indeed the way is long until you can see your Blender model in your own application. But if you intend to write your own graphics engine eventually it is a way you have to take. If this is not your goal I recommend you to use an open source 3D engine of your choice.
I used a very good online tutorial on a web page which unfortunately does not exist any more and of course the MSDN libraray to learn about DirectX 11. You can still find these tutorials at an internet archive. Additionally I found another tutorial which seems to look good at a first glance.
If you don't need to do very special things which Blender must write into the file you are exporting, I suggest using the .obj format since it is easy to understand and to load.
By chance I'm writing my own graphics engine in the moment. So if you have any further questions concerning this topic feel free to contact me.

You can always make your own format if its, i dont know, just for some school project or something like that (wild guess). Format your data the way you want, for example:
X,Y,Z,R,G,B\n
X,Y,Z,R,G,B\n
X,Y,Z,R,G,B\n...
for vertices and after you list all your vertices you could use some char like '$' or '%' or something like that which will signify end of vertices and start of indices which will make it easier to parse later. You can assume it is always TriangleList topology but you may also dedicate first line of file to configuration and have int 1 for instance represent that you will use trinagleList and so on...
Hope it helps!
P.S.: Julians answer is better in my opinion, its always good to learn new useful stuff for future projects (like in Bioware :D ), just proposing alternative here.

Related

3D model files & creating triangle meshes from it

I'm new here. I'm learning C++ yet so I don't have a big knowledge about things ( well, I have a lot of experience with programming but with other languages. I also know how to work with a computer xD ). I decided to start working on a game engine. I know it ain't easy but that's one reason why I want to do it - trying/getting experience is the best way for me to learn.
So, I'm starting with the renderer but I have no idea how could I make a 3D model file which as it says in the name it would have a 3d model and it could be loaded into a triangle mesh in the C++ engine and I could use it with Direct3D. I don't want you to do anything except giving me an idea how to start.
Thank you very much if you decided to read this & help.
This is a great question and rings so true because you are in exactly the same place that I was 3 years ago. I looked around at various applications that I could use to generate 3D content. I didn't want to spend time learning various applications because I wanted to get coding my game engine. I couldn't find anything quick enough to learn to make it worth my while (that was free of charge) so in the end I put some scripts together to create the 3D models (vertex arrays). These developed into a GUI driven interface which developed into my own fully functioning 3D Modelling Tool. Now, after 3 years, my Game Engine is on the back burner and MeshCreator (check out http://www.MeshCreator.co.uk) is now my ongoing project.
You need a way of loading in Vertex arrays. OBJ files (wavefront) are Text Based and fairly easy to read. The output from MeshCreator is also ASCII based and there are details on the website on how to interpret the file format.
The File output from MeshCreator is designed for easy import into any 3D project. You could also look at .OBJ files as they are supported by most 3D apps (including mine). OBJ files can get a little complex though.
In short, you need an easy to use tool. It took me 3 years to write my own so I wouldn't recommend it. Try out MeshCreator, MilkShape 3D and maybe Google Shetchup. Also, there are many sites that have royalty free 3D content that you can use in your projects and many are available in OBJ format.
3D model file formats can be very complicated, mostly in the sheer amount of types of things they can contain (meshes, primitives, curved surfaces, materials, lighting, etc. etc.). Which also means that it can be very hard to come up with your own format too. So, there are really two options here: find off-the-shelf libraries to handle the loading of models; or, pick pre-existing formats and write your own code to load those files (and use a standard editor to create them).
The main problem with using an off-the-shelf library to load the models is often that these libraries are often intimately tied to a particular renderer and usually very complex in the (possible) data structures that are generated when loading the files. So, this is often a better solution only if you are prepared to adopt the renderer of which this model-loading-library is a part of or tied to. There are options like Irrlicht, Ogre3D, Coin3D, etc., which all have reasonable capabilities at loading fairly standard 3D model file formats.
If you are going to pick a pre-existing file format and create the loading code yourself (and thus, tied to your own renderer), then you should pick carefully. The 3ds file format is very widely used and its internal structure is nice and fairly simple, with the advantage that you can easily skip elements that you can't support yet (this is useful when you are incrementally writing your rendering code). Most other formats have similar features (forward and backward compatibility, and ability to skip "unsupported" elements). There are also important open-standard formats, vrml and x3d, that you might want to take a look at. Also, there are some simpler formats associated to some open-source 3D editors like Blender. It is important to have a good 3D editor that can output in a file format that you can load. That's why you shouldn't create your own file format, because you will have a lot of extra work to do, either in creating custom "export" scripts (or plugins) for some 3D editor, or in creating your own editor (a monumental task).
Search around. If you want to base your engine on DirectX, I believe the SDK comes with code samples explaining the basics, like loading meshes.
If you're just learning C++, I'd recommend you start with a much simpler project like making a simple game with an engine like Irrlicht or OGRE, but that's up to you.
I think you need something like obj files. You can find online free files to play with. If you want to generate your own, I think you need some 3D rendering software. You can also search how to parse them and load their content in your programs.

I'm trying to integrate a 3D model viewer into my GUI, but have not found a single library that will allow me to do this easily. Any suggestions?

I've tried with VTK, PCL and Qt (using the QVTKWidget.h), however, using CMake is incredibly inconvenient, as the second I update any one of the many libraries that my GUI uses, I have to spend at least another day trying to sort out the linker issues. Additionally, a lot of the time, a lot of information is lost from the 3D models using these libraries.
Note: I am focusing on using PLY as it holds color and geometry information in the same file, but any other format that does the same would be fine
I am currently trying to create a Meshlab plugin, but the support for this library is sparse, and I am yet to successfully compile the Meshlab source.
Any input or direction would be really appreciated. If you guys want to know anything more, please do let me know.
If it wasn't clear in the beginning, I am using Qt (C++) to create the GUI.
Use the QT OpenGL widget and write some OpenGL code to display your model.
PLY textural format is really simple and you can write a parser yourself.
Have you tried Coin3D? This is a Free implementation of OpenInventor wich was made by SGI back in the day as a C++ wrapper around OpenGL.
As for integration with Qt there is a library called SoQt (in the same site). They also have a newer library called Quarter that integrates more like a Qt component.
I've had greatest success with Coin + SoQt + Qt.

Using Blender for physics simulations

I've been looking at different ways of creating a certain physics simulation. What I am trying to do is to 3D model the motion of a body under the effects of various forces over time. I was originally looking at coding something in c++ using a physics engine (Bullet) and a 3d engine (Irrlicht). However, I noticed that Blender already allows one to do physical simulations since Bullet is integrated with it (correct me if I'm wrong). This seems like it would make it much easier to design the simulation exactly how I want it (with Blender's extensive GUI).
My issue is that I would like to use the results from the simulation (basically x,y,z,pitch,roll,yaw of the body at each timestep) for input into c/c++ code (or another language if its much easier for this). Can this be done with Blender? Is there a better software package for this that I am overlooking? Thanks, any advice is appreciated.
I would use a Python script for that task, as Blender has a nice interface getting/setting the objects and their properties programmatically through .py files.
So after you are done with your animation you can call a script to walk through the frames and save the required data into a file.
A getting started doc can be found here: http://wiki.blender.org/index.php/Doc:Manual/Extensions/Python or here: http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro
There is a huge list of scripts worth browsing for similar routines you need. http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts
As mentioned before, it would be very easy to use python for this. For more specific use if using Blender, perhaps you should consult the main Blender forum www.blenderartists.org
Blenderartists python support: http://blenderartists.org/forum/forumdisplay.php?11-Python-Support
Blender 2.5 code snippets (Introduction to scripting for Blender 2.5): http://blenderartists.org/forum/showthread.php?193908-Code-snippets.-Introduction-to-Python-scripting-in-Blender-2.5x

Rudimentary 3D graphics in C++ .NET

I am looking to implement an extremely rudimentary FPS game with extremely rudimentary 3D graphics using C++ .NET and DirectX.
I'm not interested in any third party libraries or anything special like that.
Having never done graphics based programming besides 2D stuff I don't really know where to get started or even how to find the right resources online.
I have a few weeks to build this game so im trying to keep it simple.
Can anyone give me a little guidance on how to get started?
This looks as though it may give you a push in the right direction:
http://zophusx.byethost11.com/tutorial.php?lan=dx9&num=0
I always found that OpenGL was easier to learn though. So unless it's necessary for you to use DirectX, I'd suggest you have a quick look at GL and see what you think.
If you download DirectX SDK you can find plenty of samples there in C++ and C#.
May I recommend "Introduction to Game Programming in DirectX 9" by "Wordware" Publishing. I know you just want something very simple like the rotating cube classic, so do not be put off by the 'game' element. I got 3/4 the way through and wrote a screen saver! DX10 is now available but I stick to 9 - card backward compatibility.
The maths can get silly in 3D, but if you can get the basics, the rest will follow very quickly.
If you haven't done so already the "DirectX SDK" download is also a must - it contains (most important) the help files for the methods, functions etc. and a few not so helpful getting started stuff.
You might want to have a look at SlimDX, even if you're not interested in third-party libraries.
Although I don't have Visual C++ 2008/2010 Express installed, you could add SlimDX as a reference to your project. Be sure you check out the tutorial section, even though it's in C#, but if you know C++/CLI pretty well, you should be able to convert the code to C++/CLI.

3d max integration with c++, Cal3D where to start?

okay i'm making a game using c++ (for the engine) and openGL, now i've had lots of trouble using cal3d library for importing my 3d max models into my c++ project,
as a matter of fact i dunno where to even start, i can't find any decent guide and their documentation is pure shit really. i've been searching and trying stuff in this for over a month, but i don't even understand the file structure it uses so far :S
i really need some help, r there any other libraries? any decent guide i can use? i'm stuck
thnx alot
Rather than write your own exporter, consider using one of the built-in exporters for FBX, COLLADA, Crosswalk (.XSI), the Quake/Doom3 .MD3/.MD4 format, or even OBJ. It'll be much easier to parse the resulting file format on your end than to write and maintain a brand-new exporter.
Max is a complete pain for any kind of scripting or plugin. I'd suggest using maya instead if at all possible. You'll get better results for animation and rigging, too. I know it's not a direct answer to your question but part of the problem is the info for stuff like this is not easy to come by.