3D Primitive rendering problem

rated by 0 users
This post has 3 Replies | 2 Followers

Top 500 Contributor
Posts 3
SunBurn_Pro_Licensee
manuelparente Posted: 06-14-2012 6:50 AM

Hi I'm having a problem rendering a primitive generate through vertex and index buffers.

The problem is this:

 

Is this a common issue that i'm not seeing or is it more complex? Do you know how to solve it?

I'll put in some code if needed.

Thanks!

Top 10 Contributor
Posts 5,368
Employee
SunBurn_Studio_Licensee

Hi manuel,

Is the object using a SunBurn material / effect?  If so please make sure to populate the mesh's tangent space information by calling:


VertexPositionNormalTextureBump.BuildTangentSpaceDataForTriangleList();


Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Top 500 Contributor
Posts 3
SunBurn_Pro_Licensee

Hi Bob,

thanks for your help but it didn't work.

The vertex buffer and index buffer are set using: 

 

        /// <summary>
        /// Once all the geometry has been specified by calling AddVertex and AddIndex,
        /// this method copies the vertex and index data into GPU format buffers, ready
        /// for efficient rendering.
        protected void InitializePrimitive(GraphicsDevice graphicsDevice)
        {
            // Create a vertex declaration, describing the format of our vertex data.
 
            // Create a vertex buffer, and copy our vertex data into it.
            vertexBuffer = new VertexBuffer(graphicsDevice,
                                            typeof(VertexPositionNormalTextureBump),
                                            vertices.Count, BufferUsage.WriteOnly);
 
            ushort[] indices_array = indices.ToArray();
 
            VertexPositionNormalTextureBump[] vertices_array = vertices.ToArray();
 
            VertexPositionNormalTextureBump.BuildTangentSpaceDataForTriangleList<ushort>(indices_array, vertices_array);
 
            vertexBuffer.SetData(vertices_array);
            
 
            // Create an index buffer, and copy our index data into it.
            indexBuffer = new IndexBuffer(graphicsDevice, typeof(ushort),
                                          indices.Count, BufferUsage.WriteOnly);
 
            indexBuffer.SetData(indices_array);
}

and the Primitive is being generated by:

public TorusPrimitive(GraphicsDevice graphicsDevice,
                              float diameter, float thickness, int tessellation)
        {
            if (tessellation < 3)
                throw new ArgumentOutOfRangeException("tessellation");
 
            // First we loop around the main ring of the torus.
            for (int i = 0; i < tessellation; i++)
            {
                float outerAngle = i * MathHelper.TwoPi / tessellation;
 
                // Create a transform matrix that will align geometry to
                // slice perpendicularly though the current ring position.
                Matrix transform = Matrix.CreateTranslation(diameter / 2, 0, 0) *
                                   Matrix.CreateRotationY(outerAngle);
 
                // Now we loop along the other axis, around the side of the tube.
                for (int j = 0; j < tessellation; j++)
                {
                    float innerAngle = j * MathHelper.TwoPi / tessellation;
 
                    float dx = (float)Math.Cos(innerAngle);
                    float dy = (float)Math.Sin(innerAngle);
 
                    // Create a vertex.
                    Vector3 normal = new Vector3(dx, dy, 0);
                    Vector3 position = normal * thickness / 2;
 
                    position = Vector3.Transform(position, transform);
                    normal = Vector3.TransformNormal(normal, transform);
 
                    AddVertex(position, normal);
 
                    // And create indices for two triangles.
                    int nextI = (i + 1) % tessellation;
                    int nextJ = (j + 1) % tessellation;
 
                    AddIndex(i * tessellation + j);
                    AddIndex(i * tessellation + nextJ);
                    AddIndex(nextI * tessellation + j);
 
                    AddIndex(i * tessellation + nextJ);
                    AddIndex(nextI * tessellation + nextJ);
                    AddIndex(nextI * tessellation + j);
                }
            }
            
 
            InitializePrimitive(graphicsDevice);
        }

Top 500 Contributor
Posts 3
SunBurn_Pro_Licensee

Also the Torus is being added to the scene by:

 

            TorusPrimitive torus = new TorusPrimitive(this.GraphicsDevice,100,20,50);
 
            SunBurnBasicEffect be = new SunBurnBasicEffect(this.GraphicsDevice) {
                 
                AmbientLightColor = new Vector3(1,0,0),
                TransparencyMode = SynapseGaming.LightingSystem.Core.TransparencyMode.Blend,
                Alpha =.5f,
                LightingEnabled=true,
                //PreferPerPixelLighting = true,
                DoubleSided=true,
                DiffuseColor = new Vector3(0,1,0),
                TextureEnabled = false
            };
 
            be.EnableDefaultLighting();
 
            SceneObject so = new SceneObject(
                "torusinho"true,
                be,
                new BoundingSphere(),
                new BoundingBox(),
                Matrix.Identity,
                torus.indexBuffer,
                torus.vertexBuffer,
                0,
                PrimitiveType.TriangleList,
                torus.indices.Count,
                0,
                torus.vertices.Count,
                0
 
                );

 
 
            sceneInterface.ObjectManager.Submit(so);

 

Page 1 of 1 (4 items) | RSS