8 Replies - 3420 Views - Last Post: 25 October 2012 - 07:59 AM

#1 snaynay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 10 October 2012 - 08:57 AM

Hello!

This is a little problem that has been bugging me, mainly because I'm not sure if it is or isn't possible to do. Please bear with me if my understanding of meshes/models is a bit vague.

We're trying to develop a "icosahedron geodesic sphere" world for our game, or a shere made up of triangles to simplify things!

Now, here is our problem... Whilst the game we would like to "extrude" faces of the sphere in order to procedurally create terrain. "Extrude" was used as that is the term for the function in Maya/3ds Max. Is it possible to somehow select a face/poly of a model and manipulate it? Ideally to be done in realtime?
(I have attached a picture of a model in Max. The extrusions, or transforms, are what we would like to do in realtime in XNA)

I can't find any information on this anywhere, so I cant tell if I'm searching in the wrong direction. Is there a keyword I can use to search for information that I might be missing?

Also, if I haven't made any sense, I'll do my best to re-explain what we're after.

Thank you,
Nay.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible to manipulate meshes/3D objects in XNA ingame?

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 10 October 2012 - 09:09 AM

The term you're looking for is "procedural generation". This is generally used to create terrains from heightmaps or cubemaps rather than using a static mesh, since a static mesh is, as it's name suggests, static. Static means that it doesn't change. Importing a model from 3DS Max or Maya, will take a static mesh and allow you to draw it to the screen and create simple transformations such as rotation, translation, and scaling.

If you want to create a world with somewhat realistic terrain that is generated procedurally, or even give the player the ability to modify the terrain, you're going to need to research procedural generation. This is by far an easy task. Procedural generation takes a ton of knowledge of GPU manipulation.

If you want the terrain to be more detailed the closer you are to it, or Level of Detail / LOD, to prevent the higher detailed terrains from bogging down your game and causing framerates to suffer, you're getting into even more complex and advanced systems. For LOD, you'll want to implement a quadtree system and there is a hefty amount of knowledge necessary for that as well.

There aren't really any start to finish tutorials that you will find anywhere for creating a procedurally generated planet, but you can easily find tutorials on procedurally generated flat terrains. Most planet generation is done using a cube since there are 6 flat sides that you can procedurally generate terrain on, then you will need to implement an algorithm to turn that cube into a spherical object to more closely resemble a planet.

Try not to let this discourage you as it is possible, but I want you to understand the massive undertaking that this can become before you get into it and become frustrated. It is possible, but it will take a lot of time, research, reading, learning and hard work.
Was This Post Helpful? 0
  • +
  • -

#3 snaynay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 10 October 2012 - 09:28 AM

Thank you for the quick reply Kilorn! I can image this will be tricky, but its for my 3rd year commercial game module, and its a group module so work load overall will be split!

As for the LoD, this is a low poly project, so there wont be an excessive amount of polygons on the whole "planet" anyway. TBH, not many more than the picture I posted. Probably the next geosphere up from the one I just modelled.

Procedually generating a standard geosphere isn't too much of an issue, as there is plenty of information on that, it is the possibility of raising or lowering a "transform" in realtime.

If we could procedually generate a terrained/terraformed sphere, but cant change it in real time, then that is a sacrifice we could deal with.

Our original concept involved prebuilding a decence number of pre populated equalateral triangles, then randomising which one to instance, and translating it to its position within the sphere, using a geodesic algorithm... however for our dynamic map requirements, that makes things trickier.
Was This Post Helpful? 0
  • +
  • -

#4 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 586
  • View blog
  • Posts: 1,302
  • Joined: 24-April 12

Re: Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 10 October 2012 - 10:20 AM

I agree with everything Kilorn said.

But I wanted to mention this book I found recently. I think it was just published last year.

3D Engine Design for Virtual Globes

Take a look at the "Search Inside" this book option at the math chapter of the book. That should give you a pretty good idea of what you may be getting yourself into here.

I've been thinking of buying a copy of the book just because it looks really interesting, but I've got several far more "high priority" projects at the moment.

Pulling in a model from 3D Max and manipulating it is not going to be easy by any means. I haven't really played with 3D annimation in XNA beyond just moving entire objects. But it sounds like you are really wanting to warp the model procedurally.

So, essentially, you should not start the model in 3D Max. You should build the model in XNA "procedurally". You should do this by defining your vertices and indices. Then, like Kilorn said, you could procedurally warp your sphere.

Starting the model in 3D Max is a problem for a couple of reasons. The primary reason is that there's nothing built into XNA to allow you to manually load content. The XNA built in Content Manager will load .X or .FBX models (not 3D Max models, but you can convert to those file formats). But it doesn't give you any real control over that load or the data once it's loaded. In fact, it compiles that data into it's own proprietary data file which is what actually gets used in the game. So, your real access to that data at that point is mainly through the Model class and I doubt you're going to be able to get at the vertices themselves.

I'm not 100% certain it can't be done. But it would be ugly, I believe. If it's even possible. The Content Manager can be extended to allow additional functionality. You might even be able to extend Content Manager to load a 3D Max file into your own custom class that has the vertex data. All that's way beyond my abilities (although I hope to study models and the Content Manager soon and get more knowledgable about all that).

But anyway you look at it, it's got to be 1,000 times easier to write a method that builds your sphere using parameters and defining the sphere as a set of vertices and indices. That's what you would normally do for a flat 3D terrain. I don't think the fact that it's spherical really changes that.



Of course it's a sphere, so that may be more easily said than done. Generally, terrains are completely 100% flat and so they conform nicely to 2D flat heightmaps and such.

Are you trying to extrude faces or vertices? Normally, you do a 3D terrain by setting the height value of a vertex (extruding it). The X and Z positions of the vertices are premenantly fixed. Height (Y for a flat terrain) is controlled by "extruding" it, usually by using data from a height map.

In the case of a sphere, you have a much bigger problem because x,y, and z will all change by moving outward in the direction that the vertex normal faces. So, the direction will be a fixed vector and the position will be permenantly fixed along the ray that that vector represents.

Honestly, it kind of sounds like that you will know exactly what approach to take, once you are ready for this project; and if there's any question of how to make this happen - you're probably not ready to tackle this. (I'm not sure I am ready to tackle that.)

This post has been edited by BBeck: 10 October 2012 - 10:26 AM

Was This Post Helpful? 0
  • +
  • -

#5 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 586
  • View blog
  • Posts: 1,302
  • Joined: 24-April 12

Re: Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 10 October 2012 - 10:51 AM

I got to thinking about it a little more. I'm not sure exactly what you're trying to do. If you were trying to do something like planets for a space game, you probably wouldn't take that approach at all.

What you would typically do is create very low poly spheres in 3D Max. You won't have near enough vertices to define anything beyond a perfectly smooth sphere. In fact, you'll be fighting between using enough vertices to make it smooth rather using too few and then having pointy edges all over it but improved preformance due to fewer polygons.

Then you will UV unwrap the sphere and paint it with a 2D texture map. Then the key step in making the continents look like they have actual terrain will be to use a 2D Bump map and possibly normal maps or other such techniques as well.

Normally, you would do all of that in 3D Max or some other program and then import all of them into XNA, possibly as seperate files.

XNA supports HLSL, so you can do bump mapping and such. But it's not particularly easy if you're not familiar with all the math and such.

You could "probably" take that one step further and write an XNA program that allows you to "draw" on a 3D sphere visually, but in reality it's drawing on the 2D bump map. Sounds like a WHOLE lot of vector math to me, but I think it could be done. Really, you would probably want experience doing this on 2D flat surfaces before trying it on a spherical surface, because working spherically is going to give you all kinds of problems. I mean just the UV wrap is going to be a big problem. You're probably going to have to learn all of the math behind UV wrap and UV unwrap, because your 3D "paint brush" is going to know how to travel around the 2D bump map as if it were actually working in 3D. For example, when it's unwrapped you'll un-attach two polygons and place them in 2 totally different positions on the 2D bump map image. But your paint brush code will need to know how to mathematically put them back together so that when you draw on the edge between them it draws on both polygons (that are now completely seperate) instead of just one or the other which will look completely wrong in 3D.
Was This Post Helpful? 0
  • +
  • -

#6 snaynay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 10 October 2012 - 01:33 PM

Thank you for the detailed responses!

The plan was to procedurally generate the sphere. As for texturing, thats not involved. We will be shading via code, which I believe is possible by using HLSL. Unless all of our work is static mesh imports, then it will be a case of shading in the relevant modelling program.

As for the reason, we are making a "flight simulation battle arena game" believe it or not! But a major criteria for the project is procedural map generation. Originally, we were intending to use preset triangle "tiles" and use a geodesic algorithm to place randomised tiles. Which works for a large portion, but actual manipulation of faces would allow us to do a lot more.

If you youtube "Super StarDust HD", its similar to that, however the theme will be more along the lines of "Geometry Wars".

Well, I'll definately be looking into creating models/meshes in code as that is something I haven't touched in XNA, and maybe I might stumble across a solution :)
Was This Post Helpful? 0
  • +
  • -

#7 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 10 October 2012 - 03:00 PM

I've got a few links you might want to check out:

Procedural terrain with LOD implementation

Procedural planet generation thesis

Procedural planet generation report

I've probably got a few more buried in my bookmarks, but these should give you a rough idea of the massive undertaking and hopefully point you in the right direction.
Was This Post Helpful? 0
  • +
  • -

#8 snaynay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 11 October 2012 - 11:03 AM

Thanks for the info Kilorn! Although our approach now has been tweaked, the links you posted are very helpful to group members who are looking into planet/solor system generation. I'm sure there will plenty for them to digest...

Anyway, I know it doesn't solve my question if people are looking for answers, but we are (possibly) going to create a cone with an equilatural triangle base that fits the dimensions/scale of a geodesic sphere, instance them, and use xna to scale them up or down and ensure the tip of the cone is always at the center. This will give the effect we need, providing we get the matrix math correct! :)

And for the record, it is possible to code a simple or complex shape by creating and positioning all the verticies, draw lines between them, shade the faces and manipulate groups of verticies for realtime transform via code. The major difficulty with this is you would need a pretty spot on mind when it comes to working with matrices, providing you already understand how to deal with arrays... There are tutorials out there on coding a 3D primative such as a cube, which should make perfect sense, and its a straightforward case of repositioning the vertices. So essentially its the shape we're dealing with that makes this problem difficult!

Thank you for your help guys!
Was This Post Helpful? 0
  • +
  • -

#9 snaynay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 10-October 12

Re: Is it possible to manipulate meshes/3D objects in XNA ingame?

Posted 25 October 2012 - 07:59 AM

I thought I post this up for anyone interested...

We managed to finish our prototype, which creates an icosahedron out of (squished) tetrahedrons which are coded primitives, not imported meshes. Scaling each primitive allows us to create the affect we were after, rather than actually messing with the individual vertices. Although I haven't tested it, I still believe this is possible with a bit of work to the core code we smashed up...

Btw, the picture is of the standard icosahedron, and the same shape with its faces randomly "extruded" as to scale so they always stay in line. This can be done in game, in real time to show the change in terrain, mainly aimed for the procedural generation at the beginning.

Now to go and neaten all of this project into respectable code... then continue onto an algorithm to start turning this into a more acceptable geodesic sphere...

Thanks for the all the help and advice!

Ah, I think I didn't actually add the picture!

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1