Jump to content
  • Advertisement
Sign in to follow this  
xucaen

using blender models in direct3d?

This topic is 2166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I found a tutorial on the web that goes over some basics of direct 3d 11 using visual studio 2010. So far, it just describes how to make a cube by typing all the vertexes into a text file and then reading in the text file. I wanted to play around with other shapes and so I was wondering how to use a blender model instead of typing all the vertexes manually. Is anyone one else here able to use blender models in direct3d? if so, how?

Share this post


Link to post
Share on other sites
Advertisement
You can export your meshes to a file in blender or any other 3D authoring tool, if you want to use these in your program using a graphics API like direct3d you'll need a system for loading these files into your application so you can use them. The D3DX libraries provide some of this functionality I believe (not sure since I've never used any of the D3D helper libraries), so that could be a starting point.
Another more general purpose library to do this would be assimp.

You could also always write your own importers, but that may be somewhat too complicated at this stage.

Share this post


Link to post
Share on other sites
I was hoping for a simpler solution rather than using a 3rd party library. The author of the tutorial I mentioned suggested writing a tool that can convert the output from the modeling software into a text file of vertexes. This to me sounds like the simplest solution, but I would require the file format (in a struct or class) of one of those export formats to be able to extract the vertexes.

I'll try digging through the code of assimp, but this is looking like a dead end to me. I am surprised that Microsoft didn't already build some kind of modeling tool for use with direct3d. Maybe we're not expected to use 3rd party 3d modeling software? Is there some other way to design 3d models in direct3d?

Share this post


Link to post
Share on other sites
maybe I was asking the wrong question. I found this forum post: http://forums.create...368/488555.aspx

And in it, a user posted:

As far as I know, the DirectX SDK no longer maintains support for meshes and .x files. In d3d11, there is not even an ID3DX11Mesh anymore. I believe this is because game companies didn't use them.
[/quote]

So let me put this another way: How are game companies creating their 3d models? And how can I duplicate that process?

Share this post


Link to post
Share on other sites

So let me put this another way: How are game companies creating their 3d models? And how can I duplicate that process?


Use Maya or Blender. Define your own file format that fulfills your requirements. For converting from Blender output, Assimp is the easiest way. Depending on whether you want animations or just static models, you can choose from different file export formats. For example, the obj format is really simple to understand, and you don't even need something like Assimp to load it. For animations, the word "play around" isn't applicable.

Blender is a good start, cheaper (free) than Maya, but be prepared to spend some days on tutorials and learning.

Share this post


Link to post
Share on other sites

For example, the obj format is really simple to understand, and you don't even need something like Assimp to load it.


You are right! the .obj format is easy, it's practically the same format of the text file from the tutorial I mentioned in my first post. Thank you!!

Share this post


Link to post
Share on other sites

I was hoping for a simpler solution rather than using a 3rd party library. The author of the tutorial I mentioned suggested writing a tool that can convert the output from the modeling software into a text file of vertexes. This to me sounds like the simplest solution, but I would require the file format (in a struct or class) of one of those export formats to be able to extract the vertexes.

I'll try digging through the code of assimp, but this is looking like a dead end to me. I am surprised that Microsoft didn't already build some kind of modeling tool for use with direct3d. Maybe we're not expected to use 3rd party 3d modeling software? Is there some other way to design 3d models in direct3d?

There is a Direct3D mesh format, it's called ".x" format. It's deprecated though AFAIK.

The problem is that mesh model formats quickly scalates into bigger issues and can't be flexible enough to adapt to your specifics needs.

For a begginer the OBJ format is just what you're looking for. But for a real game, you may want to use multiple UVs, multiple vertex colour streams, custom data layouts. Then there's animation: Skeletal animation, morph per-vertex animation, pose per-vertex animation. Then there's RGBA vs ARGB colour modes, endianess, generating edge lists for stencil shadows, generating tangents for normal mapping. Then you may need other data, including: Custom "tag" data for your engine, materials, physics data, motion extraction data, IK hierachy, etc.

Collada format is an xml specification which aims at solving & covering all that in a standard way, and is probably the best one.
Nevertheless, Collada is thought as an intermediate format (i.e. to export-import between 3DS Max, ZBrush, Blender, Adobe After Effects) rather than a final format to be used in your game; but it's not impossible.

This is way there is little effort in a "Direct3D model format". Because you may only need skeletal animation, and forget about the other types. You may only need RGBA colour layout, not ARGB. You probably won't do stencil shadowing, so you're not gonna need edge lists, etc. Microsoft on the other hand, would need to cover all corner cases and still can't cover them all; not to mention they would be reinventing the wheel (a mesh model format to use with Direct3D is no different than a format thought to be used with OpenGL; as long as you know how to read it)

You'll get tons of recomendations about using 3rd party libraries because rolling your own can be quite hard (assuming you cover the cool animation stuff) and honestly, it just gets in way of making a game. We want to get into displaying it and start using that mesh, not spending quite some time getting a basic animation to play the same way it looks in Blender.

However, if you're into learning stuff; it's a really great exercise to look into the obj format and roll your own; you'll get deep valuable knowledge of how triangles are stored, how they're rendered, how they can be optimized and most importantly how GPUs (& graphics rasterization in general) work. What's the difference between skeletal animation & per-vertex animation, pros & cons of each. Why in the 90's it was all about per vertex animation and now it isn't, what means transformed and lit vertices and how can they be preprocessed for static meshes, how is it that the data you're exporting plays a role on the lighting and texturing, etc.
Once you learn that, Vertex Shaders will look so obvious to you that you'll wonder how is it that some people have a hard time understanding them.
When I was younger, I coded my own. It was very exciting. Crappy, but exciting. And I learned a lot. Today, I use Ogre's format. It's a big relief. But the knowledge I obtained from those times was gigantic.

Cheers
Matias

Share this post


Link to post
Share on other sites
Blender can export to DirectX's deprecated X file format. You may have to download and install a plugin to do it, but it's certainly possible. And while there is no ID3DX11Mesh interface, there is nothing stopping you from using ID3DX10Mesh.

Share this post


Link to post
Share on other sites
Most professional tools use the FBX format these days. Blender has an excellent FBX exporter (but ironically, no importer...). Writing an FBX reader is pretty simple, alternatively, AutoDesk provides a free SDK that does it for you.

Other formats are Wavefront OBJ (even easier to parse), .X (due to inclusion in previous DirectX SDKs) and Collada (which fails quite spectacularly in its intended role as the #1 exchange format).

There has also been a small library called "ReadBlend" which allowed you to directly load Blender files. Since the Blender developers are extremely careful to keep up- and downward compatibility, if Blender is your tool of choice, this would be a viable option, too.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!