Using Blender for physics simulations - c++

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

Related

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

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.

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.

Python modules for visualization of C++ code

I'm looking for python modules that can help with grepping C++ code. I have a large code base that I would like to do some analysis on. Ultimately I would like to come up with a graphical map of the software. There is lots of message passing going on amongst apps so I would like to be able to capture that information and present it visually. I have been looking around at some of the data visualization packages but have only stumbled on math and plotting related ones.
What are the best tools for this job, preferably in python?
Your best tool for the job is Graphviz. If you look at their gallery you'll find the sort of thing that you're interested in along with links to projects.
Under the language bindings section here there are a few python entries. Personally I don't use them as the dot language format is simple enough that you can build up fairly complex graphs from Python just using print statements.
You ca look at doxygen and see if it does (at least some part of) what you want. It generates call graph and class diagrams directly in html or xml format (I believe you need to have dot installed for fancy graphs).

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.

Choosing a 3D game engine [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to start this as a hobby in developing a desktop game. I have found several engines, but I am not sure whether it does the initial job I am looking at.
Initially I want to do the following:
Create a figure (avatar), and let the user dress the avatar
Load the avatar in the game
In later stages, I want to develop this as a multi-player game.
What should I do?
I also recommend Ogre. Ogre can do this, it provides everything needed in regards of mesh and animation support, but not as a drop-in solution. You have to write lots of code for this to be done.
For our project we implemented something like you do. The main character and any other character can be dressed with different weapons and armor and the visuals of the character avatar change accordingly.
As a start hint for how to go about this: In your modeling tool (Blender, Maya, 3ds max, etc.) you model your avatar and all its clothes you need and rig them to the same skeleton. Then export everything individually to Ogre's mesh format.
At runtime you can then attach the clothing meshes the user chooses to the skeleton instance so that they together form the avatar. This is not hard to do via Ogre-API, but for even easier access to this you can use MeshMagick Ogre extension's meshmerge tool. It has been developed for exactly this purpose.
If you want to change other characteristics like facial features, this is possible too, as Ogre supports vertex pose animations out of the box, so you can prepare pathes for certain characteristics of the face and let the user change the face by sliders or somthing like this. (e.g like in Oblivion)
One thing to be aware regarding Ogre: It is a 3d graphics engine, not a game engine. So you can draw stuff to the screen with it and animate and light and in any way change the visuals, but it doesn't do input or physics or sound. For this you have to use other libs and integrate them. Several pre-bundled game engines based on Ogre are available though.
If you are good with C++ you should use Ogre, it's the best open-source engine, continuously been updated by it's creators, with a lot of tutorials and a very helpful community.
http://www.ogre3d.org/
It's more of a GFX engine, but it has all the prerequisites you desire.
Good luck!
No engine is likely to do this for you. What they do is generally allow you to load and render 3d models. But combining them, the way you'd need to do to "dress them" is up to you. And creating them, or letting the user do so, is ultimately up to you. The engine might offer a number of tools to make the task easier (for example, rendering the model while the user is designing it), but a game engine is not a magic "make a game" box where you just have to press a button, and your custom game comes out.
A couple of people have said Ogre3D, I'll offer up Irrlicht as an alternative.
You might want to take a look at http://www.crystalspace3d.org/ - I have to admit it was more of an exploratory matter for me, but it seemed like a pretty nice engine - with physics and scripting included. They have an project which shows the avatar walking in the spacestation-like building with very smooth camera effects.
OTOH: depending on how far you want to push this, you might find yourself recreating the SecondLife(tm)-like kind of environment. If that's a fair assumption, then you might take a look at OpenSimulator and the associated opensource viewer projects and see if this may be of interest to you - and work there with the existing team to develop the code further, rather than working on your own.
If you good with C++, I suggest the C4 Engine. From my experiences, existing game engines are either too rigid or just nothing more than a collection of libraries.
Ogre is a good way to go if you are just interested in getting something to show. As some have already stated here, Ogre is a rendering engine. There are lots of add-ons and functions to complete common tasks like Audio, Input and whatnot. This is perfectly fine if your just aiming at playing around or creating a prototype.
Should you want to start a long-term project that will be developed over a longer period of time (which would be pretty likely considering you probably being the only developer and games being complex applications), you should really start thinking about what it is that you want to do. Then, based on you're goals, look for several engines that can tackle your needs (there's always some API to accomplish XYZ). Then it's up to you how you manage your game and where you use existing libraries - you'd basically tie up your own engine according to your needs.
It get's a bit more difficult if you start looking for a real game engine in terms of "engine for all my game-dev needs". Check out the nice list of 3d game engines at devmasters (http://www.devmaster.net/engines/), you'll find lots of alpha status game engines trying to accomplish this, although you should keep in mind that support and documentation usually isn't first class in those cases.
I personally never used it, but I evaluated the open source engine Delta3D (delta3d.org) for my project and was impressed by it's cool architecture. It encapsulates a whole bunch of other quality open source frameworks for stuff like graphics (OpenSceneGraph: openscenegraph.org) or physics (ODE: ode.org). That's probably as close as you'll get to a free and flexible game engine as far as I know. It was developed at an air force university, and due to it's academic background comes with lots of detailed documentation.
If you're good with C++ you can write your own engine :P
Ogre is the best of Irrlicht and Crystalspace, and the reasoning behind that is simple - Ogre has actually been used in a production pipeline by the game industry. It actually has a lot of weight behind it, whereas Irrlicht and Crystalspace are more or less applications that don't do a lot out of the box. Crystalspace however has a branch project that implements a game engine right into Blender 3d allowing the artist to play the role of programmer without leaving the actual software.
I'm not very big on Irrlicht - there is a lot of sneakiness behind its motives. For an open source project it branches out into many different derivatives that are either complete game engines or WYSWYG editors and they find ways to lock you into paying somehow.
Ogre excels at being a graphics engine rather than a library, and it has to be compiled to individual needs. The tradeoff is you can implement Ogre into any design work flow or even create a new one. Where it takes the load off your shoulders is having to write graphics code of any kind thus making it a very slick rapid prototyping engine in its basic form.
One engine that you could try is the Torque 3D game engine www.garagegames.com which, although not being freeware, allows for out of the box usability. While the functionality that you seek in terms of being able to fully customise the character is not instantly available within the engine, if you are willing to create the models yourself it should not be too hard to add them into the game and the utilise the game engine to change the 'skins' of the avatar. One thing that I feel will set this apart from the other engines is the fact that it comes with networking functionality pre-installed (from what you have described in your question I am guessing that you are attempting to either make an RTS or MMO, and if so I wish you good luck).
While it may seem strange that the engine is based around a shooting game, there are guides witin the Torque forums that allow you to add the coding for sword based combat and other things associated with a fantasy based game (if, that is, what you are planing on making).
But anyway... good luck with your project. If you are attempting what I think you are attempting it is no easy feat. But I'm sure you know what you are doing =)
Hope this helped
If you are interested in using the Irrlicht 3D engine, you can find a number of tutorials that step you through the process of creating simple 3D applications here.
I also suggest Irrlicht. It's easier to begin with, but it does not have half of the Ogre3D support though.