Home > xna > Creating Primitives and Model from Texture2D Xna 4.0

Creating Primitives and Model from Texture2D Xna 4.0

January 12Hits:1
Advertisement

So I was playing around with XNA working on a 3d engine with 2d sprites as characters and objects. After a while I became very unhappy with the way the sprites were being scaled and billboarded so I created a GameSprite class that takes all the information from the texture2D(pngs) and turns it into VertexPositionColor quads on init.

these are drawn with a basic effect, a struct quad, and a quadList.

basicEffect.CurrentTechnique.Passes[0].Apply();         foreach (ColorQuad quad in currentFrame.quadList)         {             graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(                 PrimitiveType.TriangleList,                 quad.Vertices,                 0,                 quad.Vertices.Length,                 quad.Indices,                 0,                 quad.Indices.Length / 3);         } 

(frames are different quads chopped up from the original image for animation, like a sprite sheet)

This creates a great 3D recreation of the sprite that can be zoom entirely with no blur.

Each GameSprite has its own basic effect file.

I was wondering if there was a way, maybe during LoadContent, that I could create these vertices and turn them into models for easier drawing and rendering in this 3D world and if this is even a good way to go about this and if I might experience longerterm problems using lots of these GameSprites and their many quads.

Thanks for reading!

Tags:xna, models

Related Articles

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.545 s.