Beispiel #1
0
        /// <summary>
        /// Adds vertices to manager
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="data">Vertex list</param>
        /// <param name="dynamic">Add to dynamic buffers</param>
        /// <param name="instances">Add instancing space</param>
        public BufferDescriptor Add(string id, IEnumerable <IVertexData> data, bool dynamic, int instances)
        {
            if (data?.Any() != true)
            {
                return(null);
            }

            VertexTypes vType = data.First().VertexType;

            var keyIndex = this.vertexData.FindIndex(k => k.Type == vType && k.Dynamic == dynamic && (k.Instances > 0 == instances > 0));

            if (keyIndex < 0)
            {
                keyIndex = this.vertexData.Count;

                this.vertexData.Add(new VertexBufferDescription(vType, dynamic)
                {
                    Name = id
                });
            }

            var key = this.vertexData[keyIndex];

            var descriptor = key.AddDescriptor(keyIndex, data, instances);

            if (key.ReallocationNeeded)
            {
                vertexBufferAllocationNeeded = true;
            }

            return(descriptor);
        }
Beispiel #2
0
 /// <summary>
 /// Create the combined mesh entity.
 /// </summary>
 public CombinedMeshesEntity()
 {
     if (typeof(VertexType) == typeof(VertexPosition))
     {
         _vtype = VertexTypes.VertexPosition;
     }
     else if (typeof(VertexType) == typeof(VertexPositionColor))
     {
         _vtype = VertexTypes.VertexPositionColor;
     }
     else if (typeof(VertexType) == typeof(VertexPositionTexture))
     {
         _vtype = VertexTypes.VertexPositionTexture;
     }
     else if (typeof(VertexType) == typeof(VertexPositionNormalTexture))
     {
         _vtype = VertexTypes.VertexPositionNormalTexture;
     }
     else if (typeof(VertexType) == typeof(VertexPositionNormalTangentTexture))
     {
         _vtype = VertexTypes.VertexPositionNormalTangentTexture;
     }
     else
     {
         throw new Exceptions.InvalidValueException("Unsupported vertex type in combined mesh!");
     }
 }
 public SugiVertex(TVertex originalVertex, SKSize size)
 {
     Size           = size;
     OriginalVertex = originalVertex;
     Type           = VertexTypes.Original;
     Segment        = null;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SugiVertex"/> class.
 /// </summary>
 /// <param name="originalVertex">Wrapped vertex.</param>
 /// <param name="type">Vertex type.</param>
 /// <param name="size">Vertex size.</param>
 public SugiVertex(TVertex originalVertex, VertexTypes type, Size size)
 {
     OriginalVertex = originalVertex;
     Type           = type;
     Size           = size;
     Segment        = null;
 }
Beispiel #5
0
        private static Queue <VertexGroup> GetContainerLikeItems(
            [NotNull, ItemNotNull] AlternatingLayer alternatingLayer,
            VertexTypes containerLikeVertexType)
        {
            var queue = new Queue <VertexGroup>();

            foreach (IData item in alternatingLayer)
            {
                var vertex = item as SugiVertex;
                if (vertex != null && vertex.Type == containerLikeVertexType)
                {
                    queue.Enqueue(new VertexGroup(vertex.Position)
                    {
                        Size = 1
                    });
                }
                else if (vertex is null)
                {
                    var container = (ISegmentContainer)item;
                    if (container.Count > 0)
                    {
                        queue.Enqueue(new VertexGroup(container.Position)
                        {
                            Size = container.Count
                        });
                    }
                }
            }

            return(queue);
        }
Beispiel #6
0
        /// <summary>
        /// Gets skinned equivalent for specified non skinning type
        /// </summary>
        /// <param name="vertexType">Vertex type</param>
        /// <returns>Returns skinned equivalent for specified non skinning type</returns>
        public static VertexTypes GetSkinnedEquivalent(VertexTypes vertexType)
        {
            if (vertexType == VertexTypes.Position)
            {
                return(VertexTypes.PositionSkinned);
            }
            if (vertexType == VertexTypes.PositionColor)
            {
                return(VertexTypes.PositionColorSkinned);
            }
            if (vertexType == VertexTypes.PositionNormalColor)
            {
                return(VertexTypes.PositionNormalColorSkinned);
            }
            if (vertexType == VertexTypes.PositionTexture)
            {
                return(VertexTypes.PositionTextureSkinned);
            }
            if (vertexType == VertexTypes.PositionNormalTexture)
            {
                return(VertexTypes.PositionNormalTextureSkinned);
            }
            if (vertexType == VertexTypes.PositionNormalTextureTangent)
            {
                return(VertexTypes.PositionNormalTextureTangentSkinned);
            }

            return(VertexTypes.Unknown);
        }
            public SugiVertex(TVertex originalVertex)
            {
                Contract.Requires(originalVertex != null);

                OriginalVertex = originalVertex;
                Type           = VertexTypes.Original;
                Segment        = null;
            }
Beispiel #8
0
 /// <summary>
 /// Gets whether specified vertex type is skinned or not
 /// </summary>
 /// <param name="vertexTypes">Vertex type</param>
 /// <returns>Returns true if the vertex type contains skinning info</returns>
 public static bool IsSkinned(VertexTypes vertexTypes)
 {
     return
         (vertexTypes == VertexTypes.PositionSkinned ||
          vertexTypes == VertexTypes.PositionColorSkinned ||
          vertexTypes == VertexTypes.PositionNormalColorSkinned ||
          vertexTypes == VertexTypes.PositionTextureSkinned ||
          vertexTypes == VertexTypes.PositionNormalTextureSkinned ||
          vertexTypes == VertexTypes.PositionNormalTextureTangentSkinned);
 }
Beispiel #9
0
        /// <summary>
        /// Submesh grouping optimization
        /// </summary>
        /// <param name="meshArray">Mesh array</param>
        /// <param name="optimizedMesh">Optimized mesh result</param>
        /// <returns>Returns true if the mesh array was optimized</returns>
        public static bool OptimizeMeshes(IEnumerable <SubMeshContent> meshArray, out SubMeshContent optimizedMesh)
        {
            optimizedMesh = null;

            int?count = meshArray?.Count();

            if (count == 1)
            {
                optimizedMesh = meshArray.First();
            }
            else if (count > 1)
            {
                var firstMesh = meshArray.First();

                string      material   = firstMesh.Material;
                Topology    topology   = firstMesh.Topology;
                VertexTypes vertexType = firstMesh.VertexType;
                bool        isTextured = firstMesh.Textured;

                List <VertexData> verts = new List <VertexData>();
                List <uint>       idx   = new List <uint>();

                uint indexOffset = 0;

                foreach (var mesh in meshArray)
                {
                    if (mesh.VertexType != vertexType || mesh.Topology != topology)
                    {
                        optimizedMesh = null;

                        return(false);
                    }

                    if (mesh.Vertices.Length > 0)
                    {
                        verts.AddRange(mesh.Vertices);
                    }

                    if (mesh.Indices.Length > 0)
                    {
                        idx.AddRange(mesh.Indices.Select(i => i + indexOffset));
                    }

                    indexOffset = (uint)verts.Count;
                }

                optimizedMesh = new SubMeshContent(topology, material, isTextured, false);

                optimizedMesh.SetVertices(verts);
                optimizedMesh.SetIndices(idx);
            }

            return(true);
        }
        private SugiVertex AddDummyVertex(VertexTypes type, int layerIndex)
        {
            var vertex = new SugiVertex(type)
            {
                LayerIndex = layerIndex
            };

            _layers[layerIndex].Add(vertex);
            _graph.AddVertex(vertex);

            return(vertex);
        }
Beispiel #11
0
        public override void ReadHeader(Stream stream, long length)
        {
            BinaryReader reader = new BinaryReader(stream);

            Version       = reader.ReadUInt32();
            ShaderName    = Util.ReadString(reader);
            PrimitiveType = (PrimitiveTypes)reader.ReadUInt32();
            VertexType    = (VertexTypes)reader.ReadUInt32();
            NumVertices   = reader.ReadUInt32();
            NumIndices    = reader.ReadUInt32();
            NumMatrices   = reader.ReadUInt32();
        }
Beispiel #12
0
        private void PlaceQVertices(
            [NotNull, ItemNotNull] AlternatingLayer alternatingLayer,
            [NotNull, ItemNotNull] IEnumerable <SugiVertex> nextLayer,
            bool straightSweep)
        {
            Debug.Assert(alternatingLayer != null);
            Debug.Assert(nextLayer != null);

            VertexTypes type      = straightSweep ? VertexTypes.QVertex : VertexTypes.PVertex;
            var         qVertices = new HashSet <SugiVertex>();

            foreach (SugiVertex vertex in nextLayer)
            {
                if (vertex.Type != type)
                {
                    continue;
                }

                qVertices.Add(vertex);
            }

            for (int i = 0; i < alternatingLayer.Count; ++i)
            {
                var segmentContainer = alternatingLayer[i] as SegmentContainer;
                if (segmentContainer is null)
                {
                    continue;
                }

                for (int j = 0; j < segmentContainer.Count; ++j)
                {
                    ThrowIfCancellationRequested();

                    Segment    segment = segmentContainer[j];
                    SugiVertex vertex  = straightSweep ? segment.QVertex : segment.PVertex;
                    if (!qVertices.Contains(vertex))
                    {
                        continue;
                    }

                    alternatingLayer.RemoveAt(i);
                    segmentContainer.Split(segment, out ISegmentContainer container1, out ISegmentContainer container2);
                    container1.Position = segmentContainer.Position;
                    container2.Position = segmentContainer.Position + container1.Count + 1;
                    alternatingLayer.Insert(i, container1);
                    alternatingLayer.Insert(i + 1, vertex);
                    alternatingLayer.Insert(i + 2, container2);
                    ++i;
                    break;
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Gets whether specified vertex type is textured or not
        /// </summary>
        /// <param name="vertexTypes">Vertex type</param>
        /// <returns>Returns true if the vertex type contains texture map info</returns>
        public static bool IsTextured(VertexTypes vertexTypes)
        {
            return
                (vertexTypes == VertexTypes.Billboard ||

                 vertexTypes == VertexTypes.PositionTexture ||
                 vertexTypes == VertexTypes.PositionNormalTexture ||
                 vertexTypes == VertexTypes.PositionNormalTextureTangent ||

                 vertexTypes == VertexTypes.PositionTextureSkinned ||
                 vertexTypes == VertexTypes.PositionNormalTextureSkinned ||
                 vertexTypes == VertexTypes.PositionNormalTextureTangentSkinned);
        }
Beispiel #14
0
 /// <summary>
 /// Get technique by vertex type
 /// </summary>
 /// <param name="vertexType">VertexType</param>
 /// <param name="instanced">Use instancing data</param>
 /// <param name="transparent">Use transparent textures</param>
 /// <returns>Returns the technique to process the specified vertex type</returns>
 public EngineEffectTechnique GetTechnique(
     VertexTypes vertexType,
     bool instanced,
     bool transparent)
 {
     if (transparent)
     {
         return(GetTechniqueTransparent(vertexType, instanced));
     }
     else
     {
         return(GetTechniqueOpaque(vertexType, instanced));
     }
 }
Beispiel #15
0
        private List <SugiVertex> FindVerticesWithSameMeasure(
            [NotNull, ItemNotNull] AlternatingLayer nextAlternatingLayer,
            bool straightSweep,
            [NotNull] out IList <int> ranges,
            out int maxRangeLength)
        {
            Debug.Assert(nextAlternatingLayer != null);

            VertexTypes ignorableVertexType     = straightSweep ? VertexTypes.QVertex : VertexTypes.PVertex;
            var         verticesWithSameMeasure = new List <SugiVertex>();

            SugiVertex[] vertices = nextAlternatingLayer.OfType <SugiVertex>().ToArray();
            int          startIndex;
            int          endIndex;

            maxRangeLength = 0;
            ranges         = new List <int>();
            for (startIndex = 0; startIndex < vertices.Length; startIndex = endIndex + 1)
            {
                ThrowIfCancellationRequested();

                endIndex = FindNearVertexEndIndex(startIndex, vertices);

                if (endIndex > startIndex)
                {
                    int rangeLength = 0;
                    for (int i = startIndex; i <= endIndex; ++i)
                    {
                        ThrowIfCancellationRequested();

                        if (vertices[i].Type == ignorableVertexType || vertices[i].DoNotOptimize)
                        {
                            continue;
                        }

                        ++rangeLength;
                        verticesWithSameMeasure.Add(vertices[i]);
                    }

                    if (rangeLength > 0)
                    {
                        maxRangeLength = Math.Max(rangeLength, maxRangeLength);
                        ranges.Add(rangeLength);
                    }
                }
            }

            return(verticesWithSameMeasure);
        }
        /// <summary>
        /// Adds a dummy vertex to the sparse compaction graph.
        /// </summary>
        /// <param name="type">The type of the dummy vertex (p,q,r).</param>
        /// <param name="layerIndex">The index of the layer of the vertex.</param>
        /// <returns>The new vertex which has been added to the graph and the
        /// layers.</returns>
        private SugiVertex AddDummyVertex(VertexTypes type, int layerIndex)
        {
            Contract.Requires(layerIndex < _layers.Count);
            Contract.Ensures(Contract.Result <SugiVertex>() != null);

            var vertex = new SugiVertex()
            {
                Type       = type,
                LayerIndex = layerIndex
            };

            _layers[layerIndex].Add(vertex);
            _graph.AddVertex(vertex);

            return(vertex);
        }
Beispiel #17
0
        public override void ReadHeader(Stream stream, long length)
        {
            BinaryReader reader = new BinaryReader(stream);

            Version            = reader.ReadUInt32();
            ShaderName         = Util.ReadString(reader, ref ShaderName_padding);
            PrimitiveType      = (PrimitiveTypes)reader.ReadUInt32();
            VertexType         = (VertexTypes)reader.ReadUInt32();
            NumVertices        = reader.ReadUInt32();
            NumIndices         = reader.ReadUInt32();
            NumMatrices        = reader.ReadUInt32();
            MemoryImaged       = reader.ReadUInt32();
            Optimised          = reader.ReadUInt32();
            VertexAnimated     = reader.ReadUInt32();
            VertexAnimatedMask = reader.ReadUInt32();
        }
Beispiel #18
0
 /// <summary>
 /// Get technique by vertex type
 /// </summary>
 /// <param name="vertexType">VertexType</param>
 /// <param name="channel">Color channel</param>
 /// <returns>Returns the technique to process the specified vertex type</returns>
 public EngineEffectTechnique GetTechnique(VertexTypes vertexType, SpriteTextureChannels channel)
 {
     if (vertexType == VertexTypes.PositionColor)
     {
         return(this.PositionColor);
     }
     else if (vertexType == VertexTypes.PositionTexture)
     {
         if (channel == SpriteTextureChannels.All)
         {
             return(this.PositionTexture);
         }
         else if (channel == SpriteTextureChannels.Red)
         {
             return(this.PositionTextureRED);
         }
         else if (channel == SpriteTextureChannels.Green)
         {
             return(this.PositionTextureGREEN);
         }
         else if (channel == SpriteTextureChannels.Blue)
         {
             return(this.PositionTextureBLUE);
         }
         else if (channel == SpriteTextureChannels.Alpha)
         {
             return(this.PositionTextureALPHA);
         }
         else if (channel == SpriteTextureChannels.NoAlpha)
         {
             return(this.PositionTextureNOALPHA);
         }
         else
         {
             return(this.PositionTexture);
         }
     }
     else
     {
         throw new EngineException(string.Format("Bad vertex type for effect: {0}", vertexType));
     }
 }
Beispiel #19
0
        /// <summary>
        /// Replaces the P or Q vertices of the <paramref name="alternatingLayer"/> with their segment on the next layer.
        /// </summary>
        /// <param name="alternatingLayer">The actual alternating layer. It will be modified.</param>
        /// <param name="straightSweep">If true, we are sweeping down else we're sweeping up.</param>
        private static void AppendSegmentsToAlternatingLayer(
            [NotNull, ItemNotNull] AlternatingLayer alternatingLayer,
            bool straightSweep)
        {
            Debug.Assert(alternatingLayer != null);

            VertexTypes type = straightSweep ? VertexTypes.PVertex : VertexTypes.QVertex;

            for (int i = 1; i < alternatingLayer.Count; i += 2)
            {
                var vertex = (SugiVertex)alternatingLayer[i];
                if (vertex.Type == type)
                {
                    var precedingContainer  = (SegmentContainer)alternatingLayer[i - 1];
                    var succeedingContainer = (SegmentContainer)alternatingLayer[i + 1];
                    precedingContainer.Append(vertex.Segment);
                    precedingContainer.Join(succeedingContainer);

                    // Remove the vertex and the succeeding container from the alternating layer
                    alternatingLayer.RemoveRange(i, 2);
                    i -= 2;
                }
            }
        }
 public SugiVertex(TIVertex originalVertex)
 {
     OriginalVertex = originalVertex;
     Type           = VertexTypes.Original;
     Segment        = null;
 }
Beispiel #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SugiVertex"/> class.
 /// </summary>
 /// <param name="type">Vertex type.</param>
 public SugiVertex(VertexTypes type)
     : this(null, type, default(Size))
 {
 }
Beispiel #22
0
        private static Queue <VertexGroup> GetContainerLikeItems(AlternatingLayer alternatingLayer, VertexTypes containerLikeVertexType)
        {
            Queue <VertexGroup> queue = new Queue <VertexGroup>();

            foreach (var item in alternatingLayer)
            {
                var vertex = item as SugiVertex;
                if (vertex != null && vertex.Type == containerLikeVertexType)
                {
                    queue.Enqueue(new VertexGroup()
                    {
                        Position = vertex.Position, Size = 1
                    });
                }
                else if (vertex == null)
                {
                    var container = item as ISegmentContainer;
                    if (container.Count > 0)
                    {
                        queue.Enqueue(new VertexGroup()
                        {
                            Position = container.Position, Size = container.Count
                        });
                    }
                }
            }
            return(queue);
        }
Beispiel #23
0
        /// <summary>
        /// Process the vertex data
        /// </summary>
        /// <param name="description">Decription</param>
        /// <param name="geometry">Geometry</param>
        /// <param name="vertexType">Vertext type</param>
        /// <param name="vertices">Resulting vertices</param>
        /// <param name="indices">Resulting indices</param>
        private static void ProcessVertexData(DrawingDataDescription description, SubMeshContent geometry, VertexTypes vertexType, out VertexData[] vertices, out uint[] indices)
        {
            if (VertexData.IsTangent(vertexType))
            {
                geometry.ComputeTangents();
            }

            if (!description.Constraint.HasValue)
            {
                vertices = geometry.Vertices;
                indices  = geometry.Indices;

                return;
            }

            if (geometry.Indices?.Length > 0)
            {
                ComputeConstraintIndices(
                    description.Constraint.Value,
                    geometry.Vertices, geometry.Indices,
                    out vertices, out indices);
            }
            else
            {
                ComputeConstraintVertices(
                    description.Constraint.Value,
                    geometry.Vertices,
                    out vertices);

                indices = new uint[] { };
            }
        }
Beispiel #24
0
        /// <summary>
        /// Get vertex type from geometry
        /// </summary>
        /// <param name="description">Description</param>
        /// <param name="materials">Material dictionary</param>
        /// <param name="vertexType">Vertex type</param>
        /// <param name="isSkinned">Sets wether the current geometry has skinning data or not</param>
        /// <param name="material">Material name</param>
        /// <returns>Returns the vertex type</returns>
        private static VertexTypes GetVertexType(DrawingDataDescription description, MaterialDictionary materials, VertexTypes vertexType, bool isSkinned, string material)
        {
            var res = vertexType;

            if (isSkinned)
            {
                //Get skinned equivalent
                res = VertexData.GetSkinnedEquivalent(res);
            }

            if (!description.LoadNormalMaps)
            {
                return(res);
            }

            if (VertexData.IsTextured(res) && !VertexData.IsTangent(res))
            {
                var meshMaterial = materials[material];
                if (meshMaterial?.NormalMap != null)
                {
                    //Get tangent equivalent
                    res = VertexData.GetTangentEquivalent(res);
                }
            }

            return(res);
        }
Beispiel #25
0
        static public unsafe bool getVertexTypeFromGranny(granny_data_type_definition *grannyVertType,
                                                          ref int vertMemSize,
                                                          ref granny_data_type_definition[] grnDTD,
                                                          ref VertexDeclaration grnVD,
                                                          ref VertexDeclaration d3dVD)
        {
            List <VertexTypes.eVertexDeclElement> decls   = new List <VertexTypes.eVertexDeclElement>();
            List <granny_data_type_definition>    grndcls = new List <granny_data_type_definition>();

            granny_data_type_definition *def = grannyVertType;

            while (def->memberType != granny_member_type.GrannyEndMember)
            {
                byte *str = (byte *)def->Name;

                IntPtr strPtr = new IntPtr((byte *)str);
                string name   = Marshal.PtrToStringAnsi(strPtr);
                if (name.Equals("FD")) //COMPRESSED VERTEX FORMAT
                {
                    // CoreGlobals.getErrorManager().OnSimpleWarning(String.Format("Granny file {0} is Compressed. The current build of the editor does not support this. \n To view this model in the editor, please re-export uncompressed.", filename));
                    return(false);
                }

                if (def->memberType == granny_member_type.GrannyReal32Member)
                {
                    granny_data_type_definition pdef;
                    pdef.ArrayWidth    = def->ArrayWidth;
                    pdef.Extra0        = def->Extra0;
                    pdef.Extra1        = def->Extra1;
                    pdef.Extra2        = def->Extra2;
                    pdef.memberType    = def->memberType;
                    pdef.Name          = def->Name;
                    pdef.ReferenceType = def->ReferenceType;
                    pdef.TraversalID   = def->TraversalID;

                    //grndcls.Add(pdef);

                    if (def->ArrayWidth == 4)
                    {
                        //  if (name.Equals("DiffuseColor0")) decls.Add(VertexTypes.eVertexDeclElement.cVDE_ColorDWORD);
                    }
                    else if (def->ArrayWidth == 3)
                    {
                        if (name.Equals("Position"))
                        {
                            decls.Add(VertexTypes.eVertexDeclElement.cVDE_Position); grndcls.Add(pdef);
                        }
                        else if (name.Equals("Normal"))
                        {
                            decls.Add(VertexTypes.eVertexDeclElement.cVDE_Normal); grndcls.Add(pdef);
                        }
                        else if (name.Equals("Tangent"))
                        {
                            decls.Add(VertexTypes.eVertexDeclElement.cVDE_Tangent); grndcls.Add(pdef);
                        }
                        else if (name.Equals("Binormal"))
                        {
                            decls.Add(VertexTypes.eVertexDeclElement.cVDE_BiNormal); grndcls.Add(pdef);
                        }
                    }
                    else if (def->ArrayWidth == 2)
                    {
                        if (name.Equals("TextureCoordinates0"))
                        {
                            decls.Add(VertexTypes.eVertexDeclElement.cVDE_TexCoord2); grndcls.Add(pdef);
                        }
                        else if (name.Equals("TextureCoordinates1"))
                        {
                            decls.Add(VertexTypes.eVertexDeclElement.cVDE_TexCoord2); grndcls.Add(pdef);
                        }
                        else if (name.Equals("TextureCoordinates2"))
                        {
                            decls.Add(VertexTypes.eVertexDeclElement.cVDE_TexCoord2); grndcls.Add(pdef);
                        }
                        else if (name.Equals("TextureCoordinates3"))
                        {
                            decls.Add(VertexTypes.eVertexDeclElement.cVDE_TexCoord2); grndcls.Add(pdef);
                        }
                    }
                }

                /* else if (def->memberType == granny_member_type.GrannyNormalUInt8Member)
                 * {
                 *
                 * //   CoreGlobals.getErrorManager().OnSimpleWarning(String.Format("Granny file {0} has an unsupported vertex structure", filename));
                 * //   return false;
                 *
                 *  if (name.Equals("BoneWeights"))
                 *  {
                 *     if (def->ArrayWidth == 4)
                 *        decls.Add(VertexTypes.eVertexDeclElement.cVDE_BlendWeight4);
                 *  }
                 *  else if (name.Equals("BoneIndices"))
                 *     decls.Add(VertexTypes.eVertexDeclElement.cVDE_BlendIndicies);
                 * }*/

                def++;
            }

            //create our granny vertex

            grnDTD = new granny_data_type_definition[grndcls.Count + 1];
            for (int k = 0; k < grndcls.Count; k++)
            {
                grnDTD[k] = grndcls[k];
            }
            grnDTD[decls.Count]            = new granny_data_type_definition();
            grnDTD[decls.Count].memberType = granny_member_type.GrannyEndMember;


            //get our D3D Version of things
            short val = 0;

            grnVD       = VertexTypes.genVertexDecl(decls, false, ref val);
            vertMemSize = (int)val;
            d3dVD       = VertexTypes.genVertexDecl(decls, true, ref val);

            return(true);
        }
Beispiel #26
0
        /// <summary>
        /// Get technique by vertex type
        /// </summary>
        /// <param name="vertexType">VertexType</param>
        /// <param name="instanced">Use instancing data</param>
        /// <returns>Returns the technique to process the specified vertex type</returns>
        public EngineEffectTechnique GetTechnique(
            VertexTypes vertexType,
            bool instanced)
        {
            if (!instanced)
            {
                switch (vertexType)
                {
                case VertexTypes.PositionColor:
                    return(this.PositionColor);

                case VertexTypes.PositionTexture:
                    return(this.PositionTexture);

                case VertexTypes.PositionNormalColor:
                    return(this.PositionNormalColor);

                case VertexTypes.PositionNormalTexture:
                    return(this.PositionNormalTexture);

                case VertexTypes.PositionNormalTextureTangent:
                    return(this.PositionNormalTextureTangent);

                case VertexTypes.PositionColorSkinned:
                    return(this.PositionColorSkinned);

                case VertexTypes.PositionTextureSkinned:
                    return(this.PositionTextureSkinned);

                case VertexTypes.PositionNormalColorSkinned:
                    return(this.PositionNormalColorSkinned);

                case VertexTypes.PositionNormalTextureSkinned:
                    return(this.PositionNormalTextureSkinned);

                case VertexTypes.PositionNormalTextureTangentSkinned:
                    return(this.PositionNormalTextureTangentSkinned);

                default:
                    throw new EngineException(string.Format("Bad vertex type for effect: {0}", vertexType));
                }
            }
            else
            {
                switch (vertexType)
                {
                case VertexTypes.PositionColor:
                    return(this.InstancingPositionColor);

                case VertexTypes.PositionTexture:
                    return(this.InstancingPositionTexture);

                case VertexTypes.PositionNormalColor:
                    return(this.InstancingPositionNormalColor);

                case VertexTypes.PositionNormalTexture:
                    return(this.InstancingPositionNormalTexture);

                case VertexTypes.PositionNormalTextureTangent:
                    return(this.InstancingPositionNormalTextureTangent);

                case VertexTypes.PositionColorSkinned:
                    return(this.InstancingPositionColorSkinned);

                case VertexTypes.PositionTextureSkinned:
                    return(this.InstancingPositionTextureSkinned);

                case VertexTypes.PositionNormalColorSkinned:
                    return(this.InstancingPositionNormalColorSkinned);

                case VertexTypes.PositionNormalTextureSkinned:
                    return(this.InstancingPositionNormalTextureSkinned);

                case VertexTypes.PositionNormalTextureTangentSkinned:
                    return(this.InstancingPositionNormalTextureTangentSkinned);

                default:
                    throw new EngineException(string.Format("Bad instanced vertex type for effect: {0}", vertexType));
                }
            }
        }
Beispiel #27
0
        internal void BuildDrawInfo(PathGraph graph)
        {
            FreeVBs();

            List <Vector3> verts      = new List <Vector3>();
            List <Vector3> norms      = new List <Vector3>();
            List <UInt32>  indexes    = new List <UInt32>();
            List <int>     vertCounts = new List <int>();

            graph.GetNodePolys(verts, indexes, norms, vertCounts);

            if (verts.Count == 0)
            {
                return;
            }

            VPosNormCol0    [] nodeVerts = new VPosNormCol0[verts.Count];
            for (int i = 0; i < nodeVerts.Length; i++)
            {
                nodeVerts[i].Position = verts[i] + Vector3.UnitY;                       //boost up 1
                nodeVerts[i].Normal.X = norms[i].X;
                nodeVerts[i].Normal.Y = norms[i].Y;
                nodeVerts[i].Normal.Z = norms[i].Z;
                nodeVerts[i].Normal.W = 1f;
            }

            int idx = 0;

            for (int i = 0; i < vertCounts.Count; i++)
            {
                Color col = Mathery.RandomColor(mRand);

                for (int j = 0; j < vertCounts[i]; j++)
                {
                    nodeVerts[idx + j].Color0 = col;
                }
                idx += vertCounts[i];
            }

            mVBNodes  = VertexTypes.BuildABuffer(mGD.GD, nodeVerts, VertexTypes.GetIndex(nodeVerts[0].GetType()));
            mIBNodes  = VertexTypes.BuildAnIndexBuffer(mGD.GD, indexes.ToArray());
            mVBBNodes = VertexTypes.BuildAVBB(VertexTypes.GetIndex(nodeVerts[0].GetType()), mVBNodes);

            mNodeIndexCount = indexes.Count;

            //connexions
            List <PathGraph.LineSeg> segz = graph.GetNodeConnections();

            if (segz.Count <= 0)
            {
                return;
            }
            VPosNormCol0    [] segVerts = new VPosNormCol0[segz.Count * 3];

            UInt32 index = 0;

            indexes.Clear();
            foreach (PathGraph.LineSeg seg in segz)
            {
                Color col = Mathery.RandomColor(mRand);

                //endpoint
                segVerts[index].Position = seg.mB;

                Vector3 lineVec = seg.mB - seg.mA;

                //get a perpindicular axis to the a to b axis
                //so the back side of the connection can flare out a bit
                Vector3 crossVec = Vector3.Cross(lineVec, Vector3.UnitY);

                crossVec.Normalize();

                Vector3 normVec = Vector3.Cross(crossVec, lineVec);

                normVec.Normalize();

                crossVec *= 2f;

                segVerts[index + 1].Position = seg.mA - crossVec + Mathery.RandomDirectionXZ(mRand);
                segVerts[index + 2].Position = seg.mA + crossVec + Mathery.RandomDirectionXZ(mRand);

                segVerts[index].Color0     = col;
                segVerts[index + 1].Color0 = col;
                segVerts[index + 2].Color0 = col;

                //adjust up
                segVerts[index].Position     += Vector3.UnitY * 2f;
                segVerts[index + 1].Position += Vector3.UnitY * 1.7f;
                segVerts[index + 2].Position += Vector3.UnitY * 1.7f;

                Half4 norm;
                norm.X = normVec.X;
                norm.Y = normVec.Y;
                norm.Z = normVec.Z;
                norm.W = 1f;
                segVerts[index].Normal     = norm;
                segVerts[index + 1].Normal = norm;
                segVerts[index + 2].Normal = norm;

                indexes.Add(index);
                indexes.Add(index + 1);
                indexes.Add(index + 2);

                index += 3;
            }

            mVBCons  = VertexTypes.BuildABuffer(mGD.GD, segVerts, VertexTypes.GetIndex(segVerts[0].GetType()));
            mIBCons  = VertexTypes.BuildAnIndexBuffer(mGD.GD, indexes.ToArray());
            mVBBCons = VertexTypes.BuildAVBB(VertexTypes.GetIndex(segVerts[0].GetType()), mVBCons);

            mConIndexCount = indexes.Count;
        }
Beispiel #28
0
        internal void BuildPathDrawInfo(List <Vector3> path, Vector3 boxMiddleOffset)
        {
            if (mVBPath != null)
            {
                mVBPath.Dispose();
            }
            if (mIBPath != null)
            {
                mIBPath.Dispose();
            }

            if (path.Count < 2)
            {
                return;
            }

            VPosNormCol0    [] segVerts = new VPosNormCol0[(path.Count - 1) * 3];

            UInt32        index   = 0;
            List <UInt32> indexes = new List <UInt32>();

            for (int i = 0; i < (path.Count - 1); i++)
            {
                Color col = Mathery.RandomColor(mRand);

                col = Color.Red;

                //endpoint
                segVerts[index].Position = path[i + 1];

                Vector3 lineVec = path[i + 1] - path[i];

                //get a perpindicular axis to the a to b axis
                //so the back side of the connection can flare out a bit
                Vector3 crossVec = Vector3.Cross(lineVec, Vector3.UnitY);

                crossVec.Normalize();

                Vector3 normVec = Vector3.Cross(crossVec, lineVec);

                normVec.Normalize();

                crossVec *= 2f;

                segVerts[index + 1].Position = path[i] - crossVec + Mathery.RandomDirectionXZ(mRand);
                segVerts[index + 2].Position = path[i] + crossVec + Mathery.RandomDirectionXZ(mRand);

                segVerts[index].Color0     = col;
                segVerts[index + 1].Color0 = col;
                segVerts[index + 2].Color0 = col;

                //adjust up
                segVerts[index].Position     += boxMiddleOffset;
                segVerts[index + 1].Position += boxMiddleOffset;
                segVerts[index + 2].Position += boxMiddleOffset;

                Half4 norm;
                norm.X = normVec.X;
                norm.Y = normVec.Y;
                norm.Z = normVec.Z;
                norm.W = 1f;
                segVerts[index].Normal     = norm;
                segVerts[index + 1].Normal = norm;
                segVerts[index + 2].Normal = norm;

                indexes.Add(index);
                indexes.Add(index + 1);
                indexes.Add(index + 2);

                index += 3;
            }

            mVBPath  = VertexTypes.BuildABuffer(mGD.GD, segVerts, VertexTypes.GetIndex(segVerts[0].GetType()));
            mIBPath  = VertexTypes.BuildAnIndexBuffer(mGD.GD, indexes.ToArray());
            mVBBPath = VertexTypes.BuildAVBB(VertexTypes.GetIndex(segVerts[0].GetType()), mVBPath);

            mPathIndexCount = indexes.Count;
        }
Beispiel #29
0
        /// <summary>
        /// Get technique by vertex type for transparent objects
        /// </summary>
        /// <param name="vertexType">VertexType</param>
        /// <param name="instanced">Use instancing data</param>
        /// <returns>Returns the technique to process the specified vertex type</returns>
        private EngineEffectTechnique GetTechniqueTransparent(
            VertexTypes vertexType,
            bool instanced)
        {
            if (!instanced)
            {
                switch (vertexType)
                {
                case VertexTypes.PositionColor:
                    return(this.ShadowMapPositionColor);

                case VertexTypes.PositionColorSkinned:
                    return(this.ShadowMapPositionColorSkinned);

                case VertexTypes.PositionTexture:
                    return(this.ShadowMapPositionTextureTransparent);

                case VertexTypes.PositionTextureSkinned:
                    return(this.ShadowMapPositionTextureTransparentSkinned);

                case VertexTypes.PositionNormalColor:
                    return(this.ShadowMapPositionNormalColor);

                case VertexTypes.PositionNormalColorSkinned:
                    return(this.ShadowMapPositionNormalColorSkinned);

                case VertexTypes.PositionNormalTexture:
                    return(this.ShadowMapPositionNormalTextureTransparent);

                case VertexTypes.PositionNormalTextureSkinned:
                    return(this.ShadowMapPositionNormalTextureTransparentSkinned);

                case VertexTypes.PositionNormalTextureTangent:
                    return(this.ShadowMapPositionNormalTextureTangentTransparent);

                case VertexTypes.PositionNormalTextureTangentSkinned:
                    return(this.ShadowMapPositionNormalTextureTangentTransparentSkinned);

                default:
                    throw new EngineException(string.Format("Bad vertex type for effect. {0}; Instaced: {1}; Transparent", vertexType, instanced));
                }
            }
            else
            {
                switch (vertexType)
                {
                case VertexTypes.PositionColor:
                    return(this.ShadowMapPositionColorInstanced);

                case VertexTypes.PositionColorSkinned:
                    return(this.ShadowMapPositionColorSkinnedInstanced);

                case VertexTypes.PositionTexture:
                    return(this.ShadowMapPositionTextureTransparentInstanced);

                case VertexTypes.PositionTextureSkinned:
                    return(this.ShadowMapPositionTextureTransparentSkinnedInstanced);

                case VertexTypes.PositionNormalColor:
                    return(this.ShadowMapPositionNormalColorInstanced);

                case VertexTypes.PositionNormalColorSkinned:
                    return(this.ShadowMapPositionNormalColorSkinnedInstanced);

                case VertexTypes.PositionNormalTexture:
                    return(this.ShadowMapPositionNormalTextureTransparentInstanced);

                case VertexTypes.PositionNormalTextureSkinned:
                    return(this.ShadowMapPositionNormalTextureTransparentSkinnedInstanced);

                case VertexTypes.PositionNormalTextureTangent:
                    return(this.ShadowMapPositionNormalTextureTangentTransparentInstanced);

                case VertexTypes.PositionNormalTextureTangentSkinned:
                    return(this.ShadowMapPositionNormalTextureTangentTransparentSkinnedInstanced);

                default:
                    throw new EngineException(string.Format("Bad vertex type for effect. {0}; Instaced: {1}; Transparent", vertexType, instanced));
                }
            }
        }
Beispiel #30
0
 public VertexModel(VertexTypes type, string vertexId, string fullName, string addressImage, string standardPhone) : this(type, vertexId)
 {
     FullName      = fullName;
     AddressImage  = addressImage;
     StandardPhone = standardPhone;
 }