2

Basically, I'm trying to cover a slot machine reel (white cylinder model) with multiple evenly spaced textures around the exterior. The program will be Windows only and the textures will be dynamically loaded at run-time instead of using the content pipeline. (Windows based multi-screen setup with XNA from the Microsoft example)

Most of the examples I can find online are for XNA3 and are still seemingly gibberish to me at this point.

So I'm looking for any help someone can provide on the subject of in-game texturing of objects like cylinders with multiple textures.

Maybe there is a good book out there that can properly describe how texturing works in XNA (4.0 specifically)?

Thanks

Scott
  • 145
  • 1
  • 10
  • You should probably clarify your question: Are you asking about applying multiple textures to the one model? (Interesting, tricky problem). Or are you also asking how to load textures from file rather than the content pipeline? (Trivial, best asked separately, or just read the documentation). – Andrew Russell Aug 18 '11 at 04:25
  • I'm asking about applying 11 separate textures to a single cylinder model at run-time. The difficult requirement here is that the slot machine reel will need different symbols on it depending on if the user changes them in a utility program before the slot machine program is executed. I think I have loading of textures working already, but I won't know if it works properly until I can figure out texturing... – Scott Aug 18 '11 at 16:17

1 Answers1

2

You have a few options. It depends two things: whether the model is loaded or generated at runtime, and whether your multiple textures get combined into one or kept individual.

If you have art skills or know an artist, probably the easiest approach is to get them to texture map the cylinder with as many textures as you want (multiple materials). You'd want your Model to have one mesh (ModelMesh) and one material (ModelMeshPart) per texture required. This is assuming the cylinders always have a fixed number of textures!. Then, to swap the textures at runtime you'd iterate through the ModelMesh.Effects collection, cast each to a BasicEffect and set it's Texture property.

If you can't modify the model, you'll have to generate it. There's an example of this on the AppHub site: http://create.msdn.com/en-US/education/catalog/sample/primitives_3d. It probably does not generate texture coordinates so you'd need to add them. If you wanted 5 images per cylinder, you should make sure the number of segments is a multiple of 5 and the V coordinate should go from 0 to 1, 5 times as it wraps around the cylinder. To keep your textures individual with this technique, you'd need to draw the cylinder in 5 chunks, each time setting the GraphicsDevice.Textures[0] to your current texture.

With both techniques it would be possible to draw the cylinder in a single draw call, but you'd need to merge your textures into a single one using Texture2D.GetData and Texture2D.SetData. This is going to be more efficient, but really isn't worth the trouble. Well not unless you making some kind of crazy slot machine particle system anyway.

Aranda
  • 855
  • 8
  • 17
  • The way I have it working right now is the model is loaded the standard way through the content pipeline. I thought about writing a program to generate a texture wrap, but I was hoping to avoid the extra work. Each reel will have 11 symbols on it. By dynamically loading the textures, I mean that when the slot machine window is started, it will load the 11 symbols, which will only be different when the user decides they want new ones. The changing of symbols doesn't happen at run-time, but before the program is run by a utility program. – Scott Aug 18 '11 at 16:10
  • Your idea of splitting up the reel model into separate meshes sounds like a good idea. I'll look into how to do that. Right now I'm using Google SketchUp for simple model creation. – Scott Aug 18 '11 at 16:22
  • Right. You will need to get the texture coordinates in there somehow, and I'm not sure if Sketchup will provide the control you need. It can probably be done but I wouldn't have the foggiest. This might help? http://www.youtube.com/watch?v=ILnIbp509cY&feature=related. Attempting to apply texture coordinates to a model loaded through the content pipeline is going to be much harder than just building the cylinder yourself. Truly, if SketchUp is giving you a headache, I'd start with that Primitives 3D link and add texturing to that. – Aranda Aug 18 '11 at 17:06
  • On second thoughts, if you can get SketchUp to apply 11 different textures, it should output with 11 different materials and then you can go with my initial suggestion. – Aranda Aug 18 '11 at 17:09
  • I appreciate your help. If you think that's the better route, I'll check out that XNA example for building primitives in code first. – Scott Aug 18 '11 at 18:07