How to render a batch of seperated triangles?

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

How to render a batch of seperated triangles?

Postby lazy on Fri Jun 01, 2007 4:31 pm

I want to render some seperated triangles with the same texture, which class should i use? I tried the BrumeSquareMeshTextured, but it look as if the Subdivs have to be set correctly or there will be a problem.so which class should i use?
thank you all.
lazy
Brume Rookie
 
Posts: 15
Joined: Sat Apr 21, 2007 10:15 am

Postby Silmaryls on Fri Jun 01, 2007 5:12 pm

Hi Lazy,


I think that the BrumeSquareMeshTextured object is good for terrains and triangles but if you wants something more specific there is another good solution.
Just take the class below (it's the current BrumeTriangleMeshTextured class) and modify it to meet your needs. It's the best sample for a triangle list.

Code: Select all
using System;
using System.Collections;
using System.Drawing;
using System.Text;


namespace Lazy
{
    public class BrumeTriangleMeshTextured : BrumeSimpleMesh
    {
        public BrumeVertex_PosNormTex1[] vertices = null;


        public BrumeTriangleMeshTextured(Brume brume, string name, BrumeVector pt1, BrumeVector pt2, BrumeVector pt3)
            : base(brume, name)
        {
            this.NbrVertices = 3;

            VertexDeclaration = brume.GraphicApi.CreateVertexDeclaration();
            this.VertexDeclaration.AddElement(0, BrumeVertexElementType.Position);
            this.VertexDeclaration.AddElement(0, BrumeVertexElementType.Normal);
            this.VertexDeclaration.AddElement(0, BrumeVertexElementType.TexCoords, 0);

            this.PrimitiveType = BrumePrimitiveType.TriangleList;
            this.PrimitiveCount = 1;

            brume.Meshes.Add(name,this);

            if (vertices == null)
            {

                vertices = new BrumeVertex_PosNormTex1[NbrVertices];


                vertices[0].Position = pt1;
                vertices[0].Normal = new BrumeVector(0, 0, -1.0f);
                vertices[0].Tu = 0.0f;
                vertices[0].Tv = 1.0f;

                vertices[1].Position = pt2;
                vertices[1].Normal = new BrumeVector(0, 0, -1.0f);
                vertices[1].Tu = 0.5f;
                vertices[1].Tv = 0.0f;

                vertices[2].Position = pt3;
                vertices[2].Normal = new BrumeVector(0, 0, -1.0f);
                vertices[2].Tu = 1.0f;
                vertices[2].Tv = 1.0f;

            }
        }

        // TODO: à descendre dans la mesh générique (les vertices statiques seront à passer en variables d'instance ou creer globalVertices/vertices)
        public override void Init()
        {
            Init(vertices, null);
        }

    }
}


You will notice that the constructor takes 3 points : you will have to change it in order to pass an array of vertices (your triangles).
NbrVertices should also be updated.
The PrimitiveCount is also set to 1 : you will have to modify that too.

Adding indexes is up to you depending on your triangle list (are all triangles different or are they sharing some vertices)

Hope it helped.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Postby lazy on Tue Jun 05, 2007 2:12 am

OK~~i understood~~Thank you!
Will this "Triangle List Mesh" be implemented in latter version? i think it may be useful in drawing some repeated objects in the scene, e.g. trees \buildings
lazy
Brume Rookie
 
Posts: 15
Joined: Sat Apr 21, 2007 10:15 am

Postby Silmaryls on Tue Jun 05, 2007 9:08 am

Well I'm not sure it's the best way to design trees and buildings.

In fact you should use Meshes. Like .x mesh designed in 3ds max or in blender.

A mesh is already an object split in triangle lists and it adds many more like materials, textures, skinning info, animations and effects.

I'm planning to add hardware instancing in the future so that it will solve the repeat problem.

For the moment I won't add a new primitive class but the primitive types are designed to be easily extended to make your own implementations.
By the way if you manage to make such a class I will be happy to add it to Brume (you can post it in the 'contrib' forum)
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron