Beispiel #1
0
    public void Build()
    {
        if (Initialized == false)
        {
            throw new Exception("You forgot to call 'Initialise(...)'");
        }
        m_manualObject.BeginUpdate(0);
        if (lineVertices.Count > 0 && isEnabled)
        {
            m_manualObject.EstimateVertexCount(System.Convert.ToUInt32(lineVertices.Count));
            m_manualObject.EstimateIndexCount(System.Convert.ToUInt32(lineIndices.Count));
            LinkedList <KeyValuePair <Vector3, ColourValue> > .Enumerator i = lineVertices.GetEnumerator();
            while (i.MoveNext())
            {
                m_manualObject.Position(i.Current.Key);
                m_manualObject.Colour(i.Current.Value);
            }
            LinkedList <int> .Enumerator i2 = lineIndices.GetEnumerator();
            while (i2.MoveNext())
            {
                m_manualObject.Index(System.Convert.ToUInt16(i2.Current));
            }
        }
        m_manualObject.End();

        m_manualObject.BeginUpdate(1);
        if (triangleVertices.Count > 0 && isEnabled)
        {
            m_manualObject.EstimateVertexCount(System.Convert.ToUInt16((triangleVertices.Count)));
            m_manualObject.EstimateIndexCount(System.Convert.ToUInt16(triangleIndices.Count));
            LinkedList <KeyValuePair <Vector3, ColourValue> > .Enumerator i = triangleVertices.GetEnumerator();
            while (i.MoveNext())
            {
                m_manualObject.Position(i.Current.Key);
                m_manualObject.Colour(i.Current.Value.r, i.Current.Value.g, i.Current.Value.b, fillAlpha);
            }
            LinkedList <int> .Enumerator i2 = triangleIndices.GetEnumerator();
            while (i2.MoveNext())
            {
                m_manualObject.Index(System.Convert.ToUInt16(i2.Current));
            }
        }
        m_manualObject.End();
    }
Beispiel #2
0
			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 );
				}
			}