5 Replies - 1521 Views - Last Post: 27 February 2016 - 05:12 PM

#1 basteagui  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 08-September 13

model as triangle list?

Posted 18 February 2016 - 12:42 AM

i need to convert my model during runtime to a triangle list to do some testing to the triangles (trying to make stencil shadows) , but i don't even know how to do this. it's kind of embarrassing


i know i have to take the indexbuffer and the vertexbuffer and use their values to construct the triangles,
but what's the formula to do this lol... i have no clue, i couldn't come up with anything searching online -

i know the format of the output has to be something like

//triangle1:
[vertex1 vector3] [vertex2 vector3] [vertex3 vector3]
//triangle2:
[vertex1 vector3] [vertex2 vector3] [vertex3 vector3]
etc.

and i know some of these vertices will repeat and these 'index verts' are stored in the index list.. but what is the pattern that it follows??

do i just grab the first 2 vertices and the first index and send it out? and then do the same with the next 2 verts + 1 index? i don't know!!

This post has been edited by basteagui: 18 February 2016 - 12:45 AM


Is This A Good Question/Topic? 0
  • +

Replies To: model as triangle list?

#2 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: model as triangle list?

Posted 19 February 2016 - 07:37 PM

I'm not even sure you can. I don't think the model class actually contains triangle information per sae. You might be able to get at the vertex and index buffer, but even that's pretty iffy. If there's only one model, the index buffer should be pretty straight forward. It's when you start storing more than one model in a buffer that things get a bit more complicated with the index buffer. It's just the order of the vertices to be drawn and can reuse vertices. (And probably does.) Figuring out the vertex data is a bit more tricky.

In theory the vertices can contain just about anything. It's basically an infinite number of combinations. In practice, I think they use a very strict vertex definition in the XNA model class that probably never changes. It really depends on how smart the model class is. I haven't really dug into it deep enough to tell you. In theory, some of those setting you give the class could determine a vertex format. And maybe for maximum efficiency it should. But they also, may have just gone with something like a position, color, UV, normal format for everything and anything that doesn't get used is just wasted space. I think most of the values tend to be floats or tuples of floats. Position is the only value that all vertices must have. Everything else is optional.

If you can get a copy of the vertex buffer, the hard part is figuring out what the vertex layout is. Once you have that, it should be just reading vertices until the end. Then you can use the Index buffer to string them back together.

They are "probably" using a triangle list rather than something more advanced, such as a triangle strip. So, it probably follows the index rules for a triangle list, which is the most basic. So, every 3 indices make a triangle. Pretty straight forward. Work with a model that is one mesh to get started, because things get more ugly with multiple meshes.
Was This Post Helpful? 0
  • +
  • -

#3 basteagui  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 08-September 13

Re: model as triangle list?

Posted 27 February 2016 - 05:35 AM

lol well thanks for the info and recommendation; implementing several meshes was a pain!

i found out you need the vertex stride, whatever that is!! however it works.

after many sleepless nights i finally got the final code now; if anyone wants to try it or wanted to convert a mesh to triangle lists and then draw it in a very simple way this is the code i have, you paste this code and import the dude model from the xna sample
http://xbox.create.m...hadow_mapping_1
(should work with any model though, though i have only tested this one so far.)

and this is the code


using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace DrawingTriangles
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        VertexBuffer vertexBuffer;


        int meshpartnumber = 0;

        List<VertexPositionColor[]> allbuffers;





        Vector3[] allVertex;

        short[] indexElements;

        BasicEffect basicEffect;
        Matrix world = Matrix.CreateTranslation(0, -60, 0) * Matrix.CreateScale(0.05f);
        Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 3), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
        Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.01f, 100f);

        //SpriteFont spriteFont;

        Model dudeModel;




        double angle = 0;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {

            dudeModel = Content.Load<Model>("dude");

            //spriteFont = Content.Load<SpriteFont>("SpriteFont1");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            basicEffect = new BasicEffect(GraphicsDevice);



            foreach (ModelMesh mesh in dudeModel.Meshes)
            {

                meshpartnumber += mesh.MeshParts.Count;
                allbuffers = new List<VertexPositionColor[]>(meshpartnumber);

                            foreach(ModelMeshPart part in mesh.MeshParts)
                            {


                                VertexDeclaration declaration = part.VertexBuffer.VertexDeclaration;
                                VertexElement[] vertexElements = declaration.GetVertexElements();

                                VertexElement vertexPosition = new VertexElement();


                                // This where we store the vertices until transformed  
                                allVertex = new Vector3[part.NumVertices];
                                // Read the vertices from the buffer in to the array  
                                part.VertexBuffer.GetData<Vector3>(
                                    part.VertexOffset * declaration.VertexStride + vertexPosition.Offset,
                                    allVertex,
                                    0,
                                    part.NumVertices,
                                    declaration.VertexStride);

                                // Each primitive is a triangle  
                                indexElements = new short[part.PrimitiveCount * 3];
                                part.IndexBuffer.GetData<short>(
                                    part.StartIndex * 2,
                                    indexElements,
                                    0,
                                    part.PrimitiveCount * 3);


                                VertexPositionColor[] borrowVerts = new VertexPositionColor[indexElements.Length];

                                Random r = new Random();

                                for (int i = 0; i < indexElements.Length; i++)
                                {
                                    //int index = indices[i];
                                    borrowVerts[i].Position.X = allVertex[indexElements[i]].X;
                                    borrowVerts[i].Position.Y = allVertex[indexElements[i]].Y;
                                    borrowVerts[i].Position.Z = allVertex[indexElements[i]].Z;
                                    borrowVerts[i].Color = Color.Black;
                                }

                                allbuffers.Add(borrowVerts);
                            }
            }



        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            angle += 0.01f;
            view = Matrix.CreateLookAt(
                new Vector3(5 * (float)Math.Sin(angle), -2, 5 * (float)Math.Cos(angle)),
                new Vector3(0, 0, 0),
                Vector3.UnitY);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {






            //string fps = string.Format("numberofparts: {0}", meshpartnumber);
           
            GraphicsDevice.Clear(Color.CornflowerBlue);

            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.VertexColorEnabled = true;



            RasterizerState rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            GraphicsDevice.RasterizerState = rasterizerState;



                foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    for (int i = 0; i < allbuffers.Count; i++)
                    {
                    vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), allbuffers[i].Length, BufferUsage.WriteOnly);
                    GraphicsDevice.SetVertexBuffer(null);

                    vertexBuffer.SetData<VertexPositionColor>(allbuffers[i]);
                    GraphicsDevice.SetVertexBuffer(vertexBuffer);
                    GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, allbuffers[i].Length / 3);
                    }
                }

            //            spriteBatch.Begin();
            //spriteBatch.DrawString(spriteFont, fps, new Vector2(32, 32), Color.White);
            //spriteBatch.End();
            base.Draw(gameTime);

            }

        }
    }


Was This Post Helpful? 0
  • +
  • -

#4 basteagui  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 08-September 13

Re: model as triangle list?

Posted 27 February 2016 - 05:58 AM

OOPS! the previous code runs out of memory because it creates a vertexbuffer every frame!
silly me i pasted older code!!!

HERE IS THE CORRECT CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace DrawingTriangles
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        VertexBuffer vertexBuffer;

        int[] n;

        int max;
        List<VertexPositionColor[]> allbuffers;






        BasicEffect basicEffect;
        Matrix world = Matrix.CreateTranslation(0, -60, 0) * Matrix.CreateScale(0.05f);
        Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 3), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
        Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.01f, 100f);

        //SpriteFont spriteFont;

        Model dudeModel;




        double angle = 0;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {

            dudeModel = Content.Load<Model>("dude");

            //spriteFont = Content.Load<SpriteFont>("SpriteFont1");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            basicEffect = new BasicEffect(GraphicsDevice);



            foreach (ModelMesh mesh in dudeModel.Meshes)
            {

                
                allbuffers = new List<VertexPositionColor[]>(mesh.MeshParts.Count);

                foreach (ModelMeshPart part in mesh.MeshParts)
                {


                    VertexDeclaration declaration = part.VertexBuffer.VertexDeclaration;
                    VertexElement[] vertexElements = declaration.GetVertexElements();

                    VertexElement vertexPosition = new VertexElement();


                    // This where we store the vertices until transformed  
                    Vector3[] allVertex = new Vector3[part.NumVertices];
                    // Read the vertices from the buffer in to the array  
                    part.VertexBuffer.GetData<Vector3>(
                        part.VertexOffset * declaration.VertexStride + vertexPosition.Offset,
                        allVertex,
                        0,
                        part.NumVertices,
                        declaration.VertexStride);

                    // Each primitive is a triangle  
                    short[] indexElements = new short[part.PrimitiveCount * 3];
                    part.IndexBuffer.GetData<short>(
                        part.StartIndex * 2,
                        indexElements,
                        0,
                        part.PrimitiveCount * 3);


                    VertexPositionColor[] borrowVerts = new VertexPositionColor[indexElements.Length];


                    for (int i = 0; i < indexElements.Length; i++)
                    {
                        borrowVerts[i].Position.X = allVertex[indexElements[i]].X;
                        borrowVerts[i].Position.Y = allVertex[indexElements[i]].Y;
                        borrowVerts[i].Position.Z = allVertex[indexElements[i]].Z;
                        borrowVerts[i].Color = Color.Black;
                    }

                    allbuffers.Add(borrowVerts);
                }
            }

            n = new int[allbuffers.Count];

            for (int i = 0; i < allbuffers.Count; i++)
            {
                n[i] = allbuffers[i].Length;

            }

            max = n.Max();

            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), max, BufferUsage.WriteOnly);

        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            angle += 0.01f;
            view = Matrix.CreateLookAt(
                new Vector3(5 * (float)Math.Sin(angle), -2, 5 * (float)Math.Cos(angle)),
                new Vector3(0, 0, 0),
                Vector3.UnitY);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {






            //string fps = string.Format("numberofparts: {0}", meshpartnumber);

            GraphicsDevice.Clear(Color.CornflowerBlue);

            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.VertexColorEnabled = true;



            RasterizerState rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            GraphicsDevice.RasterizerState = rasterizerState;



            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                for (int i = 0; i < allbuffers.Count; i++)
                {

                    GraphicsDevice.SetVertexBuffer(null);

                    vertexBuffer.SetData<VertexPositionColor>(allbuffers[i]);
                    GraphicsDevice.SetVertexBuffer(vertexBuffer);
                    GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, allbuffers[i].Length / 3);
                }
            }

            //            spriteBatch.Begin();
            //spriteBatch.DrawString(spriteFont, fps, new Vector2(32, 32), Color.White);
            //spriteBatch.End();
            base.Draw(gameTime);

        }

    }
}



This post has been edited by basteagui: 27 February 2016 - 06:11 AM

Was This Post Helpful? 0
  • +
  • -

#5 BBeck  Icon User is offline

  • Here to help.
  • member icon


Reputation: 792
  • View blog
  • Posts: 1,886
  • Joined: 24-April 12

Re: model as triangle list?

Posted 27 February 2016 - 07:54 AM

Thanks for the followup and posting your results!

I believe the vertex stride is the width in bytes of a single vertex in the buffer. Vertices can be custom defined. They have no fixed size. And so to find one vertex to the next, you need to know the width. But the width is dependent on what you put in the vertex.

A vertex must have a position, but everything after that is pretty much optional. It can have a color. It can have UV coordinates (and may not need both but can have both if you wish). It can have a vertex normal. I believe there are two additional normals for bump mapping including a tangent normal. Or you can throw in anything else you want by making a custom vertex.

So, to navigate the vertex buffer you are going to need to know the width in bytes of a single vertex and I believe that is called the "stride" of the vertex. You can also shove multiple models into the vertex. Actually, they will probably be sub-meshes of a single model. The wheels of a car, for example, may be a separate model as a submesh that are parented to the body model. Likewise, a humanoid model may have eyes that are separate models so that you can animate them looking in different directions. It makes good sense to store those in the same vertex buffer together. But then you need to know where one model begins and another ends.

Another catch is that there may be memory alignment issues. So, you may put in blank spaces in your vertex to make the size of a vertex align in memory. I know I've done that but I think it was on a constant buffer rather than a vertex buffer. Normally I use the built in vertex types anyway or stick with something pretty standard.

I'm trying to look up the definition of stride and came across this. Here what it's talking about is not a vertex stride, but a buffer stride from reading the documentation. I think I wrote something up on this once.

This post has been edited by BBeck: 27 February 2016 - 08:01 AM

Was This Post Helpful? 1
  • +
  • -

#6 basteagui  Icon User is offline

  • D.I.C Head

Reputation: 14
  • View blog
  • Posts: 60
  • Joined: 08-September 13

Re: model as triangle list?

Posted 27 February 2016 - 05:12 PM

ok thanks again for the input, i wasn't sure that you could do 1 vertexbuffer for all parts because that was the first thing i tried but my model was messed up!

but i managed to fix it now that you informed me it is possible; here's the code for all the model loaded into one buffer only at load time

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace DrawingTriangles
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        VertexBuffer vertexBuffer;

        VertexPositionColor[] borrowVerts;


        int modelindexes = 0;


        VertexPositionColor[] vertices;

        //List<VertexPositionColor[]> allbuffers;





        BasicEffect basicEffect;
        Matrix world = Matrix.CreateTranslation(0, -60, 0) * Matrix.CreateScale(0.05f);
        Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 3), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
        Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.01f, 100f);

        //SpriteFont spriteFont;

        Model dudeModel;




        double angle = 0;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {

            dudeModel = Content.Load<Model>("dude");

            //spriteFont = Content.Load<SpriteFont>("SpriteFont1");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            basicEffect = new BasicEffect(GraphicsDevice);



            foreach (ModelMesh mesh in dudeModel.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    modelindexes += part.IndexBuffer.IndexCount;
                }
            }

            vertices = new VertexPositionColor[modelindexes];


            int offset = 0;

            foreach (ModelMesh mesh in dudeModel.Meshes)
            {

                
                //allbuffers = new List<VertexPositionColor[]>(mesh.MeshParts.Count);

                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    

               

                    VertexDeclaration declaration = part.VertexBuffer.VertexDeclaration;
                    VertexElement[] vertexElements = declaration.GetVertexElements();

                    VertexElement vertexPosition = new VertexElement();


                    // This where we store the vertices until transformed  
                    Vector3[] allVertex = new Vector3[part.NumVertices];
                    // Read the vertices from the buffer in to the array  
                    part.VertexBuffer.GetData<Vector3>(
                        part.VertexOffset * declaration.VertexStride + vertexPosition.Offset,
                        allVertex,
                        0,
                        part.NumVertices,
                        declaration.VertexStride);

                    // Each primitive is a triangle  
                    short[] indexElements = new short[part.PrimitiveCount * 3];
                    part.IndexBuffer.GetData<short>(
                        part.StartIndex * 2,
                        indexElements,
                        0,
                        part.PrimitiveCount * 3);



                    borrowVerts = new VertexPositionColor[indexElements.Length];


                    for (int i = 0; i < indexElements.Length; i++)
                    {
                        borrowVerts[i].Position.X = allVertex[indexElements[i]].X;
                        borrowVerts[i].Position.Y = allVertex[indexElements[i]].Y;
                        borrowVerts[i].Position.Z = allVertex[indexElements[i]].Z;
                        borrowVerts[i].Color = Color.Black;

                        vertices[offset + i].Position = borrowVerts[i].Position; 
                        vertices[offset + i].Color = Color.Black;
                    }

                    offset += indexElements.Length; 

                }

            }


            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), vertices.Length, BufferUsage.WriteOnly);
            vertexBuffer.SetData<VertexPositionColor>(vertices);
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            angle += 0.01f;
            view = Matrix.CreateLookAt(
                new Vector3(5 * (float)Math.Sin(angle), -2, 5 * (float)Math.Cos(angle)),
                new Vector3(0, 0, 0),
                Vector3.UnitY);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {






            //string fps = string.Format("numberofparts: {0}", modelindexes);

            GraphicsDevice.Clear(Color.CornflowerBlue);

            basicEffect.World = world;
            basicEffect.View = view;
            basicEffect.Projection = projection;
            basicEffect.VertexColorEnabled = true;



            RasterizerState rasterizerState = new RasterizerState();
            //rasterizerState.CullMode = CullMode.None;
            GraphicsDevice.RasterizerState = rasterizerState;


            GraphicsDevice.SetVertexBuffer(vertexBuffer);

            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
               pass.Apply();


               GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, modelindexes / 3);

            }

            //spriteBatch.Begin();
            //spriteBatch.DrawString(spriteFont, fps, new Vector2(32, 32), Color.White);
            //spriteBatch.End();
            base.Draw(gameTime);

        }

    }
}








the one thing i do not like of this code i have now is that i have to go through the models meshes and parts once to get the totalnumber of indices of allparts combined so i can set up a buffer, and then go thru the loop again to actually assign the values - i can't figure out a way to use a single foreach(mesh/meshpart) bracket. maybe if i check for the variable to be set up in the first go? but i think that might be slower. and i could set up a buffer of an arbitrary big value but the perfectionist in me experiences literal pain when i even consider this option.
although this is all done in the load function so it's not like framerate even matters but it still bothers me to no end having to write something redundant like that

This post has been edited by basteagui: 27 February 2016 - 05:20 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1