コード例 #1
0
 /// <summary>
 /// Create a ManagedVertexDeclaration.
 /// </summary>
 /// <param name="device">The graphics device.</param>
 /// <param name="elements">The vertex elements.</param>
 public ManagedVertexDeclaration(GraphicsDevice device, VertexElement[] elements)
 {
     this.elements = elements;
     this.device = device;
     vertexDeclaration = CreateVertexDeclaration();
     device.DeviceReset += device_DeviceReset;
 }
コード例 #2
0
        /// <summary>
        /// Static constructor.
        /// </summary>
        static MercuryVertex()
        {
            VertexElement posElement = new VertexElement();
            VertexElement colorElement = new VertexElement();
            VertexElement scaleElement = new VertexElement();
            VertexElement rotationElement = new VertexElement();

            VertexElements = new VertexElement[4];

            posElement.VertexElementFormat = VertexElementFormat.Vector2;
            posElement.VertexElementMethod = VertexElementMethod.Default;
            posElement.VertexElementUsage = VertexElementUsage.Position;

            colorElement.Offset = 8;
            colorElement.VertexElementFormat = VertexElementFormat.Vector4;
            colorElement.VertexElementMethod = VertexElementMethod.Default;
            colorElement.VertexElementUsage = VertexElementUsage.Color;

            scaleElement.Offset = 24;
            scaleElement.VertexElementFormat = VertexElementFormat.Single;
            scaleElement.VertexElementMethod = VertexElementMethod.Default;
            scaleElement.VertexElementUsage = VertexElementUsage.PointSize;

            rotationElement.Offset = 28;
            rotationElement.VertexElementFormat = VertexElementFormat.Single;
            rotationElement.VertexElementMethod = VertexElementMethod.Default;
            rotationElement.VertexElementUsage = VertexElementUsage.Color;
            rotationElement.UsageIndex = 1;

            VertexElements[0] = posElement;
            VertexElements[1] = colorElement;
            VertexElements[2] = scaleElement;
            VertexElements[3] = rotationElement;
        }
コード例 #3
0
 private void init()
 {
     desc = new VertexElement[ElementCount];
     int i = 0;
     foreach (BufferLayoutElement element in Elements)
     {
         desc[i] = new VertexElement();
         switch (element.Usage)
         {
             case BufferLayoutElementUsages.Position: desc[i].VertexElementUsage = VertexElementUsage.Position; break;
             case BufferLayoutElementUsages.Color: desc[i].VertexElementUsage = VertexElementUsage.Color; break;
             case BufferLayoutElementUsages.UV: desc[i].VertexElementUsage = VertexElementUsage.TextureCoordinate; break;
             case BufferLayoutElementUsages.Normal: desc[i].VertexElementUsage = VertexElementUsage.Normal; break;
             case BufferLayoutElementUsages.Index: desc[i].VertexElementUsage = VertexElementUsage.BlendIndices; break;
             case BufferLayoutElementUsages.IndexClassic: desc[i].VertexElementUsage = VertexElementUsage.BlendIndices; break;
         }
         switch (element.Type)
         {
             case BufferLayoutElementTypes.Float: desc[i].VertexElementFormat = VertexElementFormat.Single; break;
             case BufferLayoutElementTypes.Vector2: desc[i].VertexElementFormat = VertexElementFormat.Vector2; break;
             case BufferLayoutElementTypes.Vector3: desc[i].VertexElementFormat = VertexElementFormat.Vector3; break;
             case BufferLayoutElementTypes.Vector4: desc[i].VertexElementFormat = VertexElementFormat.Vector4; break;
             case BufferLayoutElementTypes.RGBAx8: desc[i].VertexElementFormat = VertexElementFormat.Color; break;
         }
         desc[i].UsageIndex = (int)element.UsageIndex;
         desc[i].Offset = element.ByteOffset;
         ++i;
     }
 }
コード例 #4
0
 static VertexPositionVectorColorTexture()
 {
     VertexElement[] elements = new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Color, 0), new VertexElement(28, VertexElementFormat.HalfVector2, VertexElementUsage.TextureCoordinate, 0) };
     VertexDeclaration declaration = new VertexDeclaration(elements);
     declaration.Name = "VertexPositionVectorColorTexture.VertexDeclaration";
     VertexDeclaration = declaration;
 }
コード例 #5
0
ファイル: Vertex.cs プロジェクト: lodossDev/xnamugen
 static Vertex()
 {
     s_elements = new VertexElement[3];
     s_elements[0] = new VertexElement(0, 0, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.Position, 0);
     s_elements[1] = new VertexElement(0, 8, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0);
     s_elements[2] = new VertexElement(0, 16, VertexElementFormat.Color, VertexElementMethod.Default, VertexElementUsage.Color, 0);
 }
コード例 #6
0
        static Particle()
        {
            // Position vertex element...
            VertexElement positionElement       = new VertexElement();
            positionElement.VertexElementFormat = VertexElementFormat.Vector2;
            positionElement.VertexElementUsage  = VertexElementUsage.Position;

            // Scale vertex element...
            VertexElement scaleElement          = new VertexElement();
            scaleElement.Offset                 = 8;
            scaleElement.VertexElementFormat    = VertexElementFormat.Single;
            scaleElement.VertexElementUsage     = VertexElementUsage.PointSize;

            // Rotation vertex element...
            VertexElement rotationElement       = new VertexElement();
            rotationElement.Offset              = 12;
            rotationElement.VertexElementFormat = VertexElementFormat.Single;
            rotationElement.VertexElementUsage  = VertexElementUsage.TextureCoordinate;

            // Color vertex element...
            VertexElement colourElement         = new VertexElement();
            colourElement.Offset                = 16;
            colourElement.VertexElementFormat   = VertexElementFormat.Vector4;
            colourElement.VertexElementUsage    = VertexElementUsage.Color;

            // Vertex element array...
            Particle.VertexElements = new VertexElement[]
            {
                positionElement,
                scaleElement,
                rotationElement,
                colourElement
            };
        }
コード例 #7
0
ファイル: XnaHelper.cs プロジェクト: terrynoya/DigitalRune
 /// <summary>
 /// Converts the specified XNA <see cref="Microsoft.Xna.Framework.Graphics.VertexElement"/> to
 /// the DigitalRune <see cref="VertexElement"/>.
 /// </summary>
 /// <param name="element">
 /// The <see cref="Microsoft.Xna.Framework.Graphics.VertexElement"/>.
 /// </param>
 /// <returns>The <see cref="VertexElement"/>.</returns>
 internal static VertexElement ToDR(this Microsoft.Xna.Framework.Graphics.VertexElement element)
 {
     return(new VertexElement(
                element.VertexElementUsage.ToVertexElementSemantic(),
                element.UsageIndex,
                element.VertexElementFormat.ToDataFormat(),
                element.Offset));
 }
コード例 #8
0
ファイル: RenderHelper.cs プロジェクト: yxrkt/outbreak
        /// <summary>
        /// 頂点宣言クラスに新しい頂点要素を追加する
        /// </summary>
        /// <param name="vertexDeclaration">追加先の頂点宣言</param>
        /// <param name="extraElements">追加する頂点要素</param>
        /// <returns>新要素追加後の頂点宣言</returns>
        public static VertexDeclaration ExtendVertexDeclaration(
            VertexDeclaration vertexDeclaration, VertexElement[] extraElements)
        {
            VertexElement[] originalElements = vertexDeclaration.GetVertexElements();

              return ExtendVertexDeclaration( vertexDeclaration.GraphicsDevice,
                                          originalElements, extraElements );
        }
コード例 #9
0
 static VertexPositionColor()
 {
     VertexElement[] elements = new VertexElement[]
     {
         new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position,0),
         new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Color,0)
     };
     VertexDeclaration = new VertexDeclaration(elements);
 }
コード例 #10
0
 /// <summary>
 /// CTOR. Creates a new instance
 /// </summary>
 /// <param name="i_Game">hosting game</param>
 /// <param name="i_VertexElements">The vertex elements defining the component.
 /// This is in order to load VertexDeclaration.
 /// Valid values are: null, VertexPositionTexture.VertexElements,
 /// VertexPositionColor</param>
 /// <param name="i_NeedTexture">Defines if a 2D texture is needed by the component</param>
 public BaseDrawableComponent(
     Game i_Game,
     VertexElement[] i_VertexElements,
     bool i_NeedTexture)
     : base(i_Game)
 {
     m_VertexElements = i_VertexElements;
     NeedTexture = i_NeedTexture;
 }
コード例 #11
0
 static VertexPositionColorTexture()
 {
     var elements = new VertexElement[] 
     { 
         new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), 
         new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0), 
         new VertexElement(16, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) 
     };
     VertexDeclaration = new VertexDeclaration(elements);
 }
コード例 #12
0
        static ShadowHullVertex()
        {
            VertexElement[] elements = new VertexElement[]
            {
                new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.Position, 0),
                new VertexElement(8, VertexElementFormat.Vector2, VertexElementUsage.Normal,0),
                new VertexElement(16, VertexElementFormat.Color, VertexElementUsage.Color,0),
            };

            mVertexDeclaration = new VertexDeclaration(elements);
        }
コード例 #13
0
 static VertexPositionNormalColor()
 {
     VertexElement[] elements = new VertexElement[]
     {
         new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
         new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
         new VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 0)
     };
     VertexDeclaration declaration = new VertexDeclaration(elements);
     VertexDeclaration = declaration;
 }
コード例 #14
0
ファイル: VertexDeclaration.cs プロジェクト: Zeludon/FEZ
 private static int GetVertexStride(VertexElement[] elements)
 {
   int num1 = 0;
   for (int index = 0; index < elements.Length; ++index)
   {
     int num2 = elements[index].Offset + GraphicsExtensions.GetTypeSize(elements[index].VertexElementFormat);
     if (num1 < num2)
       num1 = num2;
   }
   return num1;
 }
コード例 #15
0
		private static int GetVertexStride(VertexElement[] elements)
		{
			int max = 0;
			for (var i = 0; i < elements.Length; i++)
			{
                var start = elements[i].Offset + elements[i].VertexElementFormat.GetSize();
				if (max < start)
					max = start;
			}

			return max;
		}
コード例 #16
0
ファイル: Cube.cs プロジェクト: nthfloor/Nebulon12
        /// <summary>
        /// Creates all required variables at load time
        /// </summary>
        /// <param name="game"></param>
        public void LoadContent(GraphicsDevice gd)
        {
            vBuffer = new VertexBuffer(gd, typeof(vertexPos), numV, BufferUsage.WriteOnly);

            VertexElement[] elements = new VertexElement[2];
            elements[0] = new VertexElement(0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0);
            elements[1] = new VertexElement(0, 12, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0);

            vDecl = new VertexDeclaration(gd, elements);

            vBuffer.SetData<vertexPos>(vertices);
        }
コード例 #17
0
ファイル: VertexDeclaration.cs プロジェクト: adison/Tank-Wars
        private static int getVertexStride(VertexElement[] elements)
        {
            int max = 0;
            for (int i = 0; i < elements.Length; i++)
            {
                int start = elements[i].Offset + elements[i].VertexElementFormat.GetTypeSize();
                if (max < start)
                {
                    max = start;
                }
            }

            return max;
        }
コード例 #18
0
ファイル: RenderHelper.cs プロジェクト: yxrkt/outbreak
        /// <summary>
        /// 複数の頂点要素を合成する
        /// </summary>
        /// <param name="graphicsDevice">頂点宣言を生成する為のGraphicsDevice</param>
        /// <param name="originalElements">元の頂点要素</param>
        /// <param name="extraElements">追加する頂点要素</param>
        /// <returns>新要素追加後の頂点宣言</returns>
        public static VertexDeclaration ExtendVertexDeclaration(
            GraphicsDevice graphicsDevice,
            VertexElement[] originalElements,
            VertexElement[] extraElements)
        {
            int length = originalElements.Length + extraElements.Length;

              VertexElement[] elements = new VertexElement[length];

              originalElements.CopyTo( elements, 0 );
              extraElements.CopyTo( elements, originalElements.Length );

              return new VertexDeclaration( graphicsDevice, elements );
        }
コード例 #19
0
ファイル: Geometry.cs プロジェクト: bryanedds/Xi
 /// <summary>
 /// Create a Geometry object.
 /// </summary>
 /// <param name="device">The graphics device that the geometry will be created on.</param>
 /// <param name="vertexElements">The vertex elements that define the vertices that make up the geometry.</param>
 /// <param name="primitiveType">The type of primitive used to draw the geometry.</param>
 /// <param name="vertexBuffer">The vertex buffer that holds the geometry's vertices.</param>
 /// <param name="vertexSize">The size of each vertex in bytes.</param>
 /// <param name="vertexCount">The number of vertices in the vertex buffer.</param>
 /// <param name="indexBuffer">The index buffer that holds the geomety's indices.</param>
 /// <param name="indexCount">The number of indices in the index buffer.</param>
 public Geometry(
     GraphicsDevice device,
     VertexElement[] vertexElements,
     PrimitiveType primitiveType,
     VertexBuffer vertexBuffer,
     int vertexSize,
     int vertexCount,
     IndexBuffer indexBuffer,
     int indexCount)
     : this(device, vertexElements, primitiveType, vertexBuffer, vertexSize, vertexCount)
 {
     XiHelper.ArgumentNullCheck(device, vertexElements, vertexBuffer, indexBuffer);
     this.indexBuffer = indexBuffer;
     this.indexCount = indexCount;
     primitiveCount = primitiveType.GetPrimitiveCount(indexCount);
 }
コード例 #20
0
        internal CircleHardwareInstancingData()
        {
            Effect =
                FlatRedBallServices.Load<Effect>(@"Assets\Shaders\HardwareInstancedLine.fx");

            Vector2[] vertices =
                new Vector2[21];

            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i] = new Vector2(
                    (float)System.Math.Cos(2 * System.Math.PI * ((float)i / (float)(vertices.Length))),
                    (float)System.Math.Sin(2 * System.Math.PI * ((float)i / (float)(vertices.Length))));
            }

            HardwareInstancedGeometry = new VertexBuffer(
                FlatRedBallServices.GraphicsDevice,
                21 * (2 * 4), // 21 points @ 2 floats per vertex @ 4 bytes each
                BufferUsage.None);

            HardwareInstancedGeometry.SetData<Vector2>(vertices);

            HardwareInstancedIndexBuffer = new IndexBuffer(
                FlatRedBallServices.GraphicsDevice,
                21 * 2, // two floats per point
                BufferUsage.None,
                IndexElementSize.SixteenBits);

            HardwareInstancedIndexBuffer.SetData<short>(
                new short[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 
                            11, 12, 13, 14, 15, 16, 17, 18, 19, 20 });

            VertexElement[] elements = new VertexElement[
                2]; // Position the individual vertex + offset position per instance
            elements[0] = new VertexElement(0, 0, 
                VertexElementFormat.Vector2, 
                VertexElementMethod.Default, 
                VertexElementUsage.Position, 1);

            elements[1] = new VertexElement(1, 0,
                VertexElementFormat.Vector3, 
                VertexElementMethod.Default, 
                VertexElementUsage.Position, 1);

            VertexDeclaration = new VertexDeclaration(
                FlatRedBallServices.GraphicsDevice, elements);
        }
コード例 #21
0
ファイル: Geometry.cs プロジェクト: bryanedds/Xi
 /// <summary>
 /// Create a Geometry object.
 /// </summary>
 /// <param name="device">The graphics device that the geometry will be created on.</param>
 /// <param name="vertexElements">The vertex elements that define the vertices that make up the geometry.</param>
 /// <param name="primitiveType">The type of primitive used to draw the geometry.</param>
 /// <param name="vertexBuffer">The vertex buffer that holds the geometry's vertices.</param>
 /// <param name="vertexSize">The size of each vertex in bytes.</param>
 /// <param name="vertexCount">The number of vertices in the vertex buffer.</param>
 public Geometry(
     GraphicsDevice device,
     VertexElement[] vertexElements,
     PrimitiveType primitiveType,
     VertexBuffer vertexBuffer,
     int vertexSize,
     int vertexCount)
 {
     XiHelper.ArgumentNullCheck(device, vertexElements, vertexBuffer);
     this.device = device;
     this.vertexBuffer = vertexBuffer;
     this.vertexSize = vertexSize;
     this.vertexCount = vertexCount;
     this.primitiveType = primitiveType;
     primitiveCount = primitiveType.GetPrimitiveCount(vertexCount);
     vertexDeclaration = new ManagedVertexDeclaration(device, vertexElements);
 }
コード例 #22
0
        /// <summary>
        /// Helper function used by the CustomModelProcessor
        /// to add new ModelPart information.
        /// </summary>
        public void AddModelPart( int triangleCount, int vertexCount, int vertexStride,
            VertexElement[] vertexElements,
            VertexBufferContent vertexBufferContent,
            IndexCollection indexCollection,
            MaterialContent materialContent)
        {
            ModelPart modelPart = new ModelPart();

              modelPart.TriangleCount = triangleCount;
              modelPart.VertexCount = vertexCount;
              modelPart.VertexStride = vertexStride;
              modelPart.VertexElements = vertexElements;
              modelPart.VertexBufferContent = vertexBufferContent;
              modelPart.IndexCollection = indexCollection;
              modelPart.MaterialContent = materialContent;

              modelParts.Add( modelPart );
        }
コード例 #23
0
ファイル: ContentUtil.cs プロジェクト: vchelaru/FlatRedBall
        public static SkinningType GetSkinningType(VertexElement[] elements)
#endif
        {
            int numIndexChannels = 0;
            int numWeightChannels = 0;
            foreach (VertexElement e in elements)
            {
                if (e.VertexElementUsage == VertexElementUsage.BlendIndices)
                    numIndexChannels++;
                else if (e.VertexElementUsage == VertexElementUsage.BlendWeight)
                    numWeightChannels++;
            }
            if (numIndexChannels == 3 || numWeightChannels == 3)
                return SkinningType.TwelveBonesPerVertex;
            else if (numIndexChannels == 2 || numWeightChannels == 2)
                return SkinningType.EightBonesPerVertex;
            else if (numIndexChannels == 1 || numWeightChannels == 1)
                return SkinningType.FourBonesPerVertex;
            return SkinningType.None;

        }
コード例 #24
0
ファイル: HWInstancePart.cs プロジェクト: yxrkt/outbreak
        void InitializeHardwareInstancing( VertexElement[] instanceElements )
        {
            #if XBOX360
              if ( !( indexBuffer is InstancedIndexBuffer ) )
              {
            IndexBuffer newIB = InstancedIndexBuffer.Create( indexBuffer,
                                LeastInstances, Allow32BitIndexBuffer );
            indexBuffer.Dispose();
            indexBuffer = newIB;
              }

              MaxInstances = ( (InstancedIndexBuffer)indexBuffer ).MaxInstances;

            #else

              MaxInstances = 500;

            #endif

              vertexDeclaration = RenderHelper.ExtendVertexDeclaration(
                                          vertexBuffer.GraphicsDevice,
                                          originalVertexDeclaration,
                                          instanceElements );
        }
コード例 #25
0
 /// <summary>
 /// Generate vertex declaration
 /// </summary>
 private static VertexElement[] GenerateVertexElements()
 {
     VertexElement[] decl = new VertexElement[]
         {
             // Construct new vertex declaration with tangent info
             // First the normal stuff (we should already have that)
             new VertexElement(0, 0, VertexElementFormat.Vector3,
                 VertexElementMethod.Default, VertexElementUsage.Position, 0),
             new VertexElement(0, 12, VertexElementFormat.Vector2,
                 VertexElementMethod.Default, VertexElementUsage.TextureCoordinate,
                 0),
             new VertexElement(0, 20, VertexElementFormat.Vector3,
                 VertexElementMethod.Default, VertexElementUsage.Normal, 0),
             // And now the tangent
             new VertexElement(0, 32, VertexElementFormat.Vector3,
                 VertexElementMethod.Default, VertexElementUsage.Tangent, 0),
         };
     return decl;
 }
コード例 #26
0
        /// <summary>
        /// Returns true if declaration is tangent vertex declaration.
        /// </summary>
        public static bool IsTangentVertexDeclaration(
			VertexElement[] declaration)
        {
            return
                declaration.Length == 4 &&
                declaration[0].VertexElementUsage == VertexElementUsage.Position &&
                declaration[1].VertexElementUsage ==
                VertexElementUsage.TextureCoordinate &&
                declaration[2].VertexElementUsage == VertexElementUsage.Normal &&
                declaration[3].VertexElementUsage == VertexElementUsage.Tangent;
        }
コード例 #27
0
        public Cube( GraphicsDevice p_GraphicsDevice,
            Vector3 p_Minimum, Vector3 p_Maximum, Color p_Colour)
        {
            CUBE_VERTEX [ ] Vertices = new CUBE_VERTEX[ 8 ];

            for( int i = 0; i < 8; ++i )
            {
                Vertices[ i ].Colour = p_Colour;
            }

            // Bottom
            Vertices[ 0 ].Position = p_Minimum;
            Vertices[ 1 ].Position = p_Minimum;
            Vertices[ 1 ].Position.Z = p_Maximum.Z;
            Vertices[ 2 ].Position = p_Maximum;
            Vertices[ 2 ].Position.Y = p_Minimum.Y;
            Vertices[ 3 ].Position = p_Minimum;
            Vertices[ 3 ].Position.X = p_Maximum.X;

            // Top
            Vertices[ 4 ].Position = p_Minimum;
            Vertices[ 4 ].Position.Y = p_Maximum.Y;
            Vertices[ 5 ].Position = p_Maximum;
            Vertices[ 5 ].Position.X = p_Minimum.X;
            Vertices[ 6 ].Position = p_Maximum;
            Vertices[ 7 ].Position = p_Maximum;
            Vertices[ 7 ].Position.Z = p_Minimum.Z;

            int Stride = ( 4 * 3 ) + 4;
            m_VertexData = new byte[ Stride * 8 ];

            VertexElement [ ] Elements = new VertexElement[ 2 ];

            Elements[ 0 ] = new VertexElement( 0, VertexElementFormat.Vector3,
                VertexElementUsage.Position, 0 );
            Elements[ 1 ] = new VertexElement( 12, VertexElementFormat.Color,
                VertexElementUsage.Color, 0 );

            VertexDeclaration Declaration = new VertexDeclaration( Stride,
                Elements );

            m_VertexBuffer = new VertexBuffer( p_GraphicsDevice,
                Declaration, 8, BufferUsage.None );

            m_VertexBuffer.SetData< CUBE_VERTEX >( Vertices );

            m_IndexBuffer = new IndexBuffer( p_GraphicsDevice,
                IndexElementSize.SixteenBits, 36, BufferUsage.None );

            m_IndexData = new UInt16[ 36 ];

            for( int i = 0; i < 36; ++i )
            {
                m_IndexData[ i ] = 0;
            }

            // Bottom
            m_IndexData[ 0 ] = 0;
            m_IndexData[ 1 ] = 1;
            m_IndexData[ 2 ] = 2;
            m_IndexData[ 3 ] = 2;
            m_IndexData[ 4 ] = 3;
            m_IndexData[ 5 ] = 0;

            // Top
            m_IndexData[ 6 ] = 4;
            m_IndexData[ 7 ] = 5;
            m_IndexData[ 8 ] = 6;
            m_IndexData[ 9 ] = 6;
            m_IndexData[ 10 ] = 7;
            m_IndexData[ 11 ] = 4;

            // Back
            m_IndexData[ 18 ] = 2;
            m_IndexData[ 19 ] = 6;
            m_IndexData[ 20 ] = 5;
            m_IndexData[ 21 ] = 5;
            m_IndexData[ 22 ] = 1;
            m_IndexData[ 23 ] = 2;

            // Front
            m_IndexData[ 12 ] = 0;
            m_IndexData[ 13 ] = 4;
            m_IndexData[ 14 ] = 7;
            m_IndexData[ 15 ] = 7;
            m_IndexData[ 16 ] = 3;
            m_IndexData[ 17 ] = 0;

            // Left
            m_IndexData[ 24 ] = 1;
            m_IndexData[ 25 ] = 5;
            m_IndexData[ 26 ] = 4;
            m_IndexData[ 27 ] = 4;
            m_IndexData[ 28 ] = 0;
            m_IndexData[ 29 ] = 1;

            // Right
            m_IndexData[ 30 ] = 3;
            m_IndexData[ 31 ] = 7;
            m_IndexData[ 32 ] = 6;
            m_IndexData[ 33 ] = 6;
            m_IndexData[ 34 ] = 2;
            m_IndexData[ 35 ] = 3;

            m_IndexBuffer.SetData< UInt16 >( m_IndexData );
        }
コード例 #28
0
        /// <summary>
        /// Returns true if declaration is tangent vertex declaration.
        /// </summary>
        public static bool IsTangentVertexDeclaration(
			VertexElement[] declaration)
        {
            if (declaration == null)
                throw new ArgumentNullException("declaration");

            return
                declaration.Length == 4 &&
                declaration[0].VertexElementUsage == VertexElementUsage.Position &&
                declaration[1].VertexElementUsage ==
                VertexElementUsage.TextureCoordinate &&
                declaration[2].VertexElementUsage == VertexElementUsage.Normal &&
                declaration[3].VertexElementUsage == VertexElementUsage.Tangent;
        }
コード例 #29
0
ファイル: ccTypes.cs プロジェクト: CILP/cocos2d-xna
 static CCV3F_C4B_T2F_Quad()
 {
     var elements = new VertexElement[]
         {
             new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
             new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0),
             new VertexElement(0x10, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
         };
     VertexDeclaration = new VertexDeclaration(elements);
 }
コード例 #30
0
        private static void ExtractData(ref Vector3[] vert, ref int[] ind, ref Vector2[] tex, IModelo model, XNA.Vector3 scale)
        {
            List<Vector3> vertices = new List<Vector3>();
            List<Vector2> texcoords = new List<Vector2>();
            List<int> indices = new List<int>();

            for (int i = 0; i < model.MeshNumber; i++)
            {

                BatchInformation[] bi = model.GetBatchInformation(i);
                for (int j = 0; j < bi.Length; j++)
                {
                    BatchInformation info = bi[j];
                    int offset = vertices.Count;
                    Microsoft.Xna.Framework.Vector3[] a = new Microsoft.Xna.Framework.Vector3[info.NumVertices];

                    // Read the format of the vertex buffer  
                    VertexDeclaration declaration = bi[j].VertexBuffer.VertexDeclaration;
                    VertexElement[] vertexElements = declaration.GetVertexElements();
                    // Find the element that holds the position  
                    VertexElement vertexPosition = new VertexElement();
                    foreach (VertexElement elem in vertexElements)
                    {
                        if (elem.VertexElementUsage == VertexElementUsage.Position &&
                            elem.VertexElementFormat == VertexElementFormat.Vector3)
                        {
                            vertexPosition = elem;
                            // There should only be one  
                            break;
                        }
                    }
                    // Check the position element found is valid  
                    if (vertexPosition == null ||
                        vertexPosition.VertexElementUsage != VertexElementUsage.Position ||
                        vertexPosition.VertexElementFormat != VertexElementFormat.Vector3)
                    {
                        throw new Exception("Model uses unsupported vertex format!");
                    }
                    // This where we store the vertices until transformed                      
                    // Read the vertices from the buffer in to the array  
                    bi[j].VertexBuffer.GetData<Microsoft.Xna.Framework.Vector3>(
                        bi[j].BaseVertex * declaration.VertexStride + vertexPosition.Offset,
                        a,
                        0,
                        bi[j].NumVertices,
                        declaration.VertexStride);

                    for (int k = 0; k != a.Length; ++k)
                    {
                        XNA.Matrix tra = info.ModelLocalTransformation * XNA.Matrix.CreateScale(scale);
                        Microsoft.Xna.Framework.Vector3.Transform(ref a[k], ref tra, out a[k]);
                        vertices.Add(a[k].AsPhysX());
                    }                    

                    foreach (VertexElement elem in vertexElements)
                    {
                        if (elem.VertexElementUsage == VertexElementUsage.TextureCoordinate &&
                            elem.VertexElementFormat == VertexElementFormat.Vector2)
                        {
                            vertexPosition = elem;
                            // There should only be one  
                            break;
                        }
                    }
                    Microsoft.Xna.Framework.Vector2[] b = new Microsoft.Xna.Framework.Vector2[info.NumVertices];
                    // This where we store the vertices until transformed                      
                    // Read the vertices from the buffer in to the array  
                    bi[j].VertexBuffer.GetData<Microsoft.Xna.Framework.Vector2>(
                        bi[j].BaseVertex * declaration.VertexStride + vertexPosition.Offset,
                        b,
                        0,
                        bi[j].NumVertices,
                        declaration.VertexStride);

                    for (int k = 0; k != b.Length; ++k)
                    {                        
                        texcoords.Add(b[k].AsPhysX());                        
                    }                    

                    
                    if (info.IndexBuffer.IndexElementSize != IndexElementSize.SixteenBits)
                    {
                        int[] s = new int[info.PrimitiveCount * 3];
                        info.IndexBuffer.GetData<int>(info.StartIndex * 2, s, 0, info.PrimitiveCount * 3);
                        for (int k = 0; k != info.PrimitiveCount; ++k)
                        {
                            indices.Add(s[k * 3 + 2] + offset);
                            indices.Add(s[k * 3 + 1] + offset);
                            indices.Add(s[k * 3 + 0] + offset);
                        }
                    }
                    else
                    {
                        short[] s = new short[info.PrimitiveCount * 3];
                        info.IndexBuffer.GetData<short>(info.StartIndex * 2, s, 0, info.PrimitiveCount * 3);
                        for (int k = 0; k != info.PrimitiveCount; ++k)
                        {
                            indices.Add(s[k * 3 + 2] + offset);
                            indices.Add(s[k * 3 + 1] + offset);
                            indices.Add(s[k * 3 + 0] + offset);
                        }
                    }
                }
            }

            ind = indices.ToArray();
            vert = vertices.ToArray();
            tex =  texcoords.ToArray();
        }
コード例 #31
0
ファイル: CCTypes.cs プロジェクト: haithemaraissia/CocosSharp
 static CCV3F_C4B ()
 {
     var elements = new VertexElement[]
         {
             new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
             new VertexElement(12, VertexElementFormat.Color, VertexElementUsage.Color, 0),
         };
     VertexDeclaration = new VertexDeclaration(elements);
 }
コード例 #32
0
ファイル: XNAHelper.cs プロジェクト: chuz/tesla-engine
        internal static XFG.VertexDeclaration ToXNAVertexDeclaration(VertexDeclaration decl)
        {
            VertexElement[]     elems       = decl.VertexElements;
            XFG.VertexElement[] xnaElements = new XFG.VertexElement[elems.Length];
            for (int i = 0; i < elems.Length; i++)
            {
                VertexElement     elem    = elems[i];
                XFG.VertexElement xnaElem = new XFG.VertexElement();
                xnaElem.Offset     = elem.Offset;
                xnaElem.UsageIndex = elem.SemanticIndex;
                switch (elem.SemanticName)
                {
                case VertexSemantic.Position:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.Position;
                    break;

                case VertexSemantic.Normal:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.Normal;
                    break;

                case VertexSemantic.Binormal:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.Binormal;
                    break;

                case VertexSemantic.BlendIndices:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.BlendIndices;
                    break;

                case VertexSemantic.BlendWeight:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.BlendWeight;
                    break;

                case VertexSemantic.Color:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.Color;
                    break;

                case VertexSemantic.Depth:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.Depth;
                    break;

                case VertexSemantic.Fog:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.Fog;
                    break;

                case VertexSemantic.PointSize:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.PointSize;
                    break;

                case VertexSemantic.Tangent:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.Tangent;
                    break;

                case VertexSemantic.TextureCoordinate:
                    xnaElem.VertexElementUsage = XFG.VertexElementUsage.TextureCoordinate;
                    break;
                }

                switch (elem.Format)
                {
                case VertexFormat.Vector4:
                    xnaElem.VertexElementFormat = XFG.VertexElementFormat.Vector4;
                    break;

                case VertexFormat.Vector3:
                    xnaElem.VertexElementFormat = XFG.VertexElementFormat.Vector3;
                    break;

                case VertexFormat.Vector2:
                    xnaElem.VertexElementFormat = XFG.VertexElementFormat.Vector2;
                    break;

                case VertexFormat.Single:
                    xnaElem.VertexElementFormat = XFG.VertexElementFormat.Single;
                    break;

                case VertexFormat.Color:
                    xnaElem.VertexElementFormat = XFG.VertexElementFormat.Color;
                    break;
                }
                xnaElements[i] = xnaElem;
            }
            return(new XFG.VertexDeclaration(decl.VertexStride, xnaElements));
        }
コード例 #33
0
ファイル: ObjParser.cs プロジェクト: Antr0py/VoxelRTS
 static void WriteElement <T>(StreamWriter writer, VertexElement ve, MeshPart mp, Func <T, string> formatter, ref ParsingFlags ps) where T : struct
 {
     T[] data = new T[mp.NumVertices];
     mp.VBuffer.GetData(ve.Offset + mp.VertexOffset * mp.VertexStride, data, 0, data.Length, mp.VertexStride);
     WriteElementByUsage(writer, data, ve, formatter, ref ps);
 }
コード例 #34
0
ファイル: ObjParser.cs プロジェクト: Antr0py/VoxelRTS
        static void WriteElementByUsage <T>(StreamWriter writer, T[] data, VertexElement ve, Func <T, string> formatter, ref ParsingFlags ps)
        {
            switch (ve.VertexElementUsage)
            {
            case VertexElementUsage.Position:
                if (ve.UsageIndex == 0)
                {
                    WriteAllElements(writer, data, "v", formatter);
                }
                else
                {
                    WriteAllElements(writer, data, "v" + ve.UsageIndex, formatter);
                }
                break;

            case VertexElementUsage.Normal:
                ps |= ParsingFlags.WriteNorms;
                if (ve.UsageIndex == 0)
                {
                    WriteAllElements(writer, data, "vn", formatter);
                }
                else
                {
                    WriteAllElements(writer, data, "vn" + ve.UsageIndex, formatter);
                }
                break;

            case VertexElementUsage.TextureCoordinate:
                ps |= ParsingFlags.WriteUV;
                if (ps.HasFlag(ParsingFlags.FlipTexCoordV))
                {
                    Vector2[] vt = data as Vector2[];
                    if (vt != null)
                    {
                        for (int i = 0; i < vt.Length; i++)
                        {
                            vt[i].Y = 1 - vt[i].Y;
                        }
                        data = vt as T[];
                    }
                }
                if (ve.UsageIndex == 0)
                {
                    WriteAllElements(writer, data, "vt", formatter);
                }
                else
                {
                    WriteAllElements(writer, data, "vt" + ve.UsageIndex, formatter);
                }
                break;

            case VertexElementUsage.Color:
                ps |= ParsingFlags.WriteColor;
                if (ve.UsageIndex == 0)
                {
                    WriteAllElements(writer, data, "vc", formatter);
                }
                else
                {
                    WriteAllElements(writer, data, "vc" + ve.UsageIndex, formatter);
                }
                break;
            }
        }