public DebugRenderable( Node parent )
{
_parent = parent;
string materialName = "Axiom/Debug/AxesMat";
_material = (Material)MaterialManager.Instance[ materialName ];
if ( _material == null )
{
_material = (Material)MaterialManager.Instance.Create( materialName, ResourceGroupManager.InternalResourceGroupName );
Pass p = _material.GetTechnique( 0 ).GetPass( 0 );
p.LightingEnabled = false;
//TODO: p.PolygonModeOverrideable = false;
p.VertexColorTracking = TrackVertexColor.Ambient;
p.SetSceneBlending( SceneBlendType.TransparentAlpha );
p.CullingMode = CullingMode.None;
p.DepthWrite = false;
}
string meshName = "Axiom/Debug/AxesMesh";
_mesh = MeshManager.Instance[ meshName ];
if ( _mesh == null )
{
ManualObject mo = new ManualObject( "tmp" );
mo.Begin( Material.Name, OperationType.TriangleList );
/* 3 axes, each made up of 2 of these (base plane = XY)
* .------------|\
* '------------|/
*/
mo.EstimateVertexCount( 7 * 2 * 3 );
mo.EstimateIndexCount( 3 * 2 * 3 );
Quaternion[] quat = new Quaternion[ 6 ];
ColorEx[] col = new ColorEx[ 3 ];
// x-axis
quat[ 0 ] = Quaternion.Identity;
quat[ 1 ] = Quaternion.FromAxes( Vector3.UnitX, Vector3.NegativeUnitZ, Vector3.UnitY );
col[ 0 ] = ColorEx.Red;
col[ 0 ].a = 0.8f;
// y-axis
quat[ 2 ] = Quaternion.FromAxes( Vector3.UnitY, Vector3.NegativeUnitX, Vector3.UnitZ );
quat[ 3 ] = Quaternion.FromAxes( Vector3.UnitY, Vector3.UnitZ, Vector3.UnitX );
col[ 1 ] = ColorEx.Green;
col[ 1 ].a = 0.8f;
// z-axis
quat[ 4 ] = Quaternion.FromAxes( Vector3.UnitZ, Vector3.UnitY, Vector3.NegativeUnitX );
quat[ 5 ] = Quaternion.FromAxes( Vector3.UnitZ, Vector3.UnitX, Vector3.UnitY );
col[ 2 ] = ColorEx.Blue;
col[ 2 ].a = 0.8f;
Vector3[] basepos = new Vector3[ 7 ]
{
// stalk
new Vector3(0f, 0.05f, 0f),
new Vector3(0f, -0.05f, 0f),
new Vector3(0.7f, -0.05f, 0f),
new Vector3(0.7f, 0.05f, 0f),
// head
new Vector3(0.7f, -0.15f, 0f),
new Vector3(1f, 0f, 0f),
new Vector3(0.7f, 0.15f, 0f)
};
// vertices
// 6 arrows
for ( int i = 0; i < 6; ++i )
{
// 7 points
for ( int p = 0; p < 7; ++p )
{
Vector3 pos = quat[ i ] * basepos[ p ];
mo.Position( pos );
mo.Color( col[ i / 2 ] );
}
}
// indices
// 6 arrows
for ( int i = 0; i < 6; ++i )
{
ushort baseIndex = (ushort)( i * 7 );
mo.Triangle( (ushort)( baseIndex + 0 ), (ushort)( baseIndex + 1 ), (ushort)( baseIndex + 2 ) );
mo.Triangle( (ushort)( baseIndex + 0 ), (ushort)( baseIndex + 2 ), (ushort)( baseIndex + 3 ) );
mo.Triangle( (ushort)( baseIndex + 4 ), (ushort)( baseIndex + 5 ), (ushort)( baseIndex + 6 ) );
}
mo.End();
_mesh = mo.ConvertToMesh( meshName, ResourceGroupManager.InternalResourceGroupName );
}
}