Manual triangle mesh

alberts

03-12-2005 17:56:05

Hi!

I'm trying to create a simple triangle with the MeshBuilderHelper class, but i can't. I donĀ“t know what is the problem. :cry:

Here is the code:


class ManualMesh : ExampleApplication
{
protected override void CreateScene()
{
createTriangle("myTriangle");
Entity ent1 = mSceneManager.CreateEntity("1", "myTriangle");
SceneNode node1 = mSceneManager.GetRootSceneNode().CreateChildSceneNode("TriangleNode");
node1.AttachObject(ent1);
}

void createTriangle(string name)
{

OgreDotNet.MeshBuilderHelper mbh = new MeshBuilderHelper(
name,"General", false, 0, 3 );

UInt32 offPos = mbh.addElement( VertexElementType.VET_FLOAT3 , VertexElementSemantic.VES_POSITION ).getOffset();
UInt32 offDiff = mbh.addElement( VertexElementType.VET_FLOAT3 , VertexElementSemantic.VES_DIFFUSE ).getOffset();

mbh.createVertexBuffer ( 3 , HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY );

mbh.setVertFloat( 0, offPos, 0, 0, 0 ); //position
mbh.setVertFloat( 0, offDiff, 0, 1, 0 ); //color

mbh.setVertFloat( 1, offPos, 0, 1,0 ); //position
mbh.setVertFloat( 1, offDiff, 0, 0, 1 ); //color

mbh.setVertFloat( 2, offPos, 1, 0, 0 ); //position
mbh.setVertFloat( 2, offDiff, 1, 0, 0 ); //color

mbh.createIndexBuffer ( 1, HardwareIndexBuffer.IndexType.IT_16BIT, HardwareBuffer.Usage.HBU_STATIC_WRITE_ONLY);

mbh.setIndex16bit( 0, (UInt16)0, (UInt16)2, (UInt16)1 );


}

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
using(ManualMesh app = new ManualMesh() )
{
app.Start();
}
}
}


The program runs, but I can't see the triangle. What's wrong?

Thanks a lot!!!

rastaman

03-12-2005 20:00:24

ok first you need to call mbh.Load("material") with a materal to apply to the mesh.
Also it seems you need to call mesh._setBounds() and mesh._setBoundingSphereRadius().

like :
MeshPtr m = mbh.Load( "Examples/Rockwall" );
m._setBounds( new AxisAlignedBox(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f), false );
m._setBoundingSphereRadius( (float)Math.Sqrt(1.0f * 1.0f + 1.0f * 1.0f) );


also it is vary small at a size of 1x1x0 the default ExampleApp mCamera starts at Vector3( 0, 0, -200 ) and look at (0,0,0).
It is facing bacwards i think so define the triangel indexs the other way around (0, 1, 2) or add this code to spin it :
protected override bool FrameStarted( FrameEvent e )
{
if (!base.FrameStarted( e ))
return false;

SceneNode n = mSceneManager.GetSceneNode("TriangleNode");
n.Yaw( new Radian(10.0f));

return true;
}

alberts

04-12-2005 10:32:03

Thanks a lot rastaman!!

It works now. :D

Kodachi_Garou

04-08-2006 09:48:18

Hello there :)

I've been trying to get this MeshBuilderHelper example to work on OgreDotNet but I find that a few functions are missing. Namely, from the MeshPtr I don't get the _setBounds and _setBoundingSphereRadius methods.

Have they moved elsewhere?

Thanks for the help

Kodachi_Garou

04-08-2006 10:10:48

Ok, found them. Hadn't realize that they were in the Mesh class now, so you really just have to dereference the pointer to get to the Mesh and use it, like this:

MeshPtr mPtr = mbh.Load( "Examples/Rockwall" );
Mesh m = mPtr.Get();
m._setBounds( new AxisAlignedBox(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f), false );
m._setBoundingSphereRadius( (float)Math.Sqrt(1.0f * 1.0f + 1.0f * 1.0f) );


Will try it soon. Thanks anyway :)