1
\$\begingroup\$

Until now, I've always used sprites to draw in 2D:

spriteBatch.Draw(myTexture, rectangle, color);

(I suppose the texture is bound internally to 2 triangles and then scaled.)

Now, I'm porting my game to 3D and I have to draw several planes (walls, floor, roof,..). Do I need to manually bind a texture to a geometry (for example using VertexPositionColorTexture with VertexBuffer and IndexBuffer), or is there any simpler way to do that?

I'm looking for something like spriteBatch.Draw with the rectangle clip specified in 3D space:

spriteBatch.Draw(myTexture, rectangleIn3D, color);
\$\endgroup\$
2
  • 3
    \$\begingroup\$ You need a manual implementation, Google 'billboards' - unfortunately SpriteBatch is built exclusively for 2D stuff. \$\endgroup\$ Commented Nov 24, 2011 at 15:51
  • \$\begingroup\$ While you can "kind of" use SpriteBatch in 3D (starting point), you probably shouldn't for what you're doing. \$\endgroup\$ Commented Nov 25, 2011 at 6:45

2 Answers 2

2
\$\begingroup\$

As a complement to Andrew's link, here's a more recent post Shawn wrote on this:

Link

But I don't recommend it either. That technique might be neat to create billboards and impostors, or placing text within a 3D world. But not to generate the floors and walls of an entire level.

If you're thinking about taking your 2D level data and procedurally generating a 3D level, I think you'd be better off writing an algorithm to generate all of the geometry from it (i.e. create and fill vertex index buffers, etc.).

\$\endgroup\$
2
  • \$\begingroup\$ Thanks.. that's what I was looking for. I know that isn't a good approach using 2d to simulate 3d, but I need it only for debug purposes. It saves me a lot of time. \$\endgroup\$
    – Heisenbug
    Commented Dec 8, 2011 at 12:26
  • \$\begingroup\$ Always good to have some shortcuts at hand for prototyping. :) \$\endgroup\$ Commented Dec 8, 2011 at 20:28
2
\$\begingroup\$

Model and texturize your scenario with a 3d modeler like blender or 3ds max, export it to fbx, and load it as a 3d model in xna.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .