Example #1
0
    public static SurfaceComponentGeometry CreateSingleDiamondCenterOctaSplitSquareGeometry(
        float sizeX, float sizeZ, float diamondRatio = 0.6f, int surfaceGroup = 0, RenderGeometry.FaceType faceType = RenderGeometry.FaceType.Polygonal)
    {
        var geometry = new SurfaceComponentGeometry();

        var outerRing = new Vertex[] {
            geometry.CreateVertex(new Vector3(0, 0, -sizeZ / 2)),
            geometry.CreateVertex(new Vector3(-sizeX / 2, 0, -sizeZ / 2)),
            geometry.CreateVertex(new Vector3(-sizeX / 2, 0, 0)),
            geometry.CreateVertex(new Vector3(-sizeX / 2, 0, sizeZ / 2)),
            geometry.CreateVertex(new Vector3(0, 0, sizeZ / 2)),
            geometry.CreateVertex(new Vector3(sizeX / 2, 0, sizeZ / 2)),
            geometry.CreateVertex(new Vector3(sizeX / 2, 0, 0)),
            geometry.CreateVertex(new Vector3(sizeX / 2, 0, -sizeZ / 2))
        };
        var innerRing = outerRing.Select((vertex, index) => geometry.CreateVertex(vertex.p * (index % 2 == 0 ? diamondRatio : diamondRatio / 2))).ToArray();

        for (int i = 0; i < 8; i++)
        {
            geometry.CreateFace(outerRing[i], outerRing[(i + 1) % 8], innerRing[(i + 1) % 8], innerRing[i]);
        }
        geometry.CreateFace(innerRing);

        geometry.DefineBoundaries(outerRing[1], outerRing[3], outerRing[5], outerRing[7]);
        return(geometry);
    }
        /// <summary>
        ///     Determines which types are produced by this mapping.
        /// </summary>
        private Set <EntityType> FindReachableTypes(
            DomainConstraintConversionContext <string, ValueCondition> converter, Vertex[] mappingConditions)
        {
            // For each entity type, create a candidate function that evaluates to true given
            // discriminator assignments iff. all of that type's conditions evaluate to true
            // and its negative conditions evaluate to false.
            var candidateFunctions = new Vertex[MappedEntityTypes.Count];

            for (var i = 0; i < candidateFunctions.Length; i++)
            {
                // Seed the candidate function conjunction with 'true'.
                var candidateFunction = Vertex.One;
                for (var j = 0; j < NormalizedEntityTypeMappings.Count; j++)
                {
                    var entityTypeMapping = NormalizedEntityTypeMappings[j];

                    // Determine if this mapping is a positive or negative case for the current type.
                    if (entityTypeMapping.ImpliedEntityTypes[i])
                    {
                        candidateFunction = converter.Solver.And(candidateFunction, mappingConditions[j]);
                    }
                    else
                    {
                        candidateFunction = converter.Solver.And(candidateFunction, converter.Solver.Not(mappingConditions[j]));
                    }
                }
                candidateFunctions[i] = candidateFunction;
            }

            // Make sure that for each type there is an assignment that resolves to only that type.
            var reachableTypes = new Set <EntityType>();

            for (var i = 0; i < candidateFunctions.Length; i++)
            {
                // Create a function that evaluates to true iff. the current candidate function is true
                // and every other candidate function is false.
                var isExactlyThisTypeCondition = converter.Solver.And(
                    candidateFunctions.Select(
                        (typeCondition, ordinal) => ordinal == i
                                                        ? typeCondition
                                                        : converter.Solver.Not(typeCondition)));

                // If the above conjunction is satisfiable, it means some row configuration exists producing the type.
                if (!isExactlyThisTypeCondition.IsZero())
                {
                    reachableTypes.Add(MappedEntityTypes[i]);
                }
            }

            return(reachableTypes);
        }
Example #3
0
        /// <summary>
        /// Отрисовка полигона
        /// </summary>
        /// <param name="g">Комопнент отрисовки</param>
        public override void Draw(Graphics g)
        {
            var leftSide  = new List <int>();
            var rightSide = new List <int>();
            var ys        = Vertex.Select(p => (int)p.Y).ToList();
            var yMax      = ys.Max();
            var yMin      = ys.Min();
            var pen       = new Pen(FillColor);

            for (var y = yMin; y < yMax; y++)
            {
                Bound(leftSide, rightSide, y);
                for (var i = 0; i < leftSide.Count; i++)
                {
                    g.DrawLine(pen, leftSide[i], y, rightSide[i], y);
                }
            }
        }
Example #4
0
        public void PolygonCollider()
        {
            var tc = new TestCore();

            tc.Init();

            var collider1 = new PolygonCollider
            {
                Position = new Vector2F(30f, 30f),
                Rotation = 10.0f,
            };

            var array_g = new Vertex[]
            {
                new Vertex(new Vector3F(10f, 10f, 10f), new Color(100, 100, 100, 100), new Vector2F(10f, 10f), new Vector2F(100f, 100f)),
                new Vertex(new Vector3F(20f, 20f, 20f), new Color(200, 200, 200, 200), new Vector2F(20f, 20f), new Vector2F(200f, 200f)),
                new Vertex(new Vector3F(30f, 30f, 30f), new Color(300, 300, 300, 300), new Vector2F(30f, 30f), new Vector2F(300f, 300f)),
            };

            var array_a = Altseed.Vector2FArray.Create(array_g.Length);

            Assert.NotNull(array_a);
            array_a.FromArray(array_g.Select(v => new Vector2F(v.Position.X, v.Position.Y)).ToArray());

            collider1.Vertexes = array_a;

            const string path = "Serialization/PolygonCollider.bin";

            Serialize(path, collider1);

            var collider2 = Deserialize <PolygonCollider>(path);

            Assert.NotNull(collider2);

            Assert.AreEqual(collider1.Position, collider2.Position);
            Assert.AreEqual(collider1.Rotation, collider2.Rotation);
            Assert.True(Enumerable.SequenceEqual(collider1.Vertexes.ToArray(), collider2.Vertexes.ToArray()));

            tc.End();
        }
        /// <summary>
        ///     Determines which types are produced by this mapping.
        /// </summary>
        private Set<EntityType> FindReachableTypes(
            DomainConstraintConversionContext<string, ValueCondition> converter, Vertex[] mappingConditions)
        {
            // For each entity type, create a candidate function that evaluates to true given
            // discriminator assignments iff. all of that type's conditions evaluate to true
            // and its negative conditions evaluate to false.
            var candidateFunctions = new Vertex[MappedEntityTypes.Count];
            for (var i = 0; i < candidateFunctions.Length; i++)
            {
                // Seed the candidate function conjunction with 'true'.
                var candidateFunction = Vertex.One;
                for (var j = 0; j < NormalizedEntityTypeMappings.Count; j++)
                {
                    var entityTypeMapping = NormalizedEntityTypeMappings[j];

                    // Determine if this mapping is a positive or negative case for the current type.
                    if (entityTypeMapping.ImpliedEntityTypes[i])
                    {
                        candidateFunction = converter.Solver.And(candidateFunction, mappingConditions[j]);
                    }
                    else
                    {
                        candidateFunction = converter.Solver.And(candidateFunction, converter.Solver.Not(mappingConditions[j]));
                    }
                }
                candidateFunctions[i] = candidateFunction;
            }

            // Make sure that for each type there is an assignment that resolves to only that type.
            var reachableTypes = new Set<EntityType>();
            for (var i = 0; i < candidateFunctions.Length; i++)
            {
                // Create a function that evaluates to true iff. the current candidate function is true
                // and every other candidate function is false.
                var isExactlyThisTypeCondition = converter.Solver.And(
                    candidateFunctions.Select(
                        (typeCondition, ordinal) => ordinal == i
                                                        ? typeCondition
                                                        : converter.Solver.Not(typeCondition)));

                // If the above conjunction is satisfiable, it means some row configuration exists producing the type.
                if (!isExactlyThisTypeCondition.IsZero())
                {
                    reachableTypes.Add(MappedEntityTypes[i]);
                }
            }

            return reachableTypes;
        }
Example #6
0
 private void DeselectVertex(Vertex vertex)
 {
     vertex.Select(false);
     _selectedVertexes.Remove(vertex);
 }
 private static bool[] RunDjikstra(Vertex[] vertices, int source)
 {
     Djikstra.Run(vertices[source]);
     return vertices.Select(v => v.Depth != int.MaxValue).ToArray();
 }
 private static bool[] RunDepthFirstSearch(Vertex[] vertices, int source)
 {
     DepthFirstSearch.Run(vertices[source]);
     return vertices.Select(v => v.Color == Color.Black).ToArray();
 }
 private static bool[] RunBellmanFord(Vertex[] vertices, int source)
 {
     BellmanFord.Run(vertices, source);
     return vertices.Select(v => v.Depth != int.MaxValue).ToArray();
 }
        public static void DecodePrimitives(
            Geometry geo,
            Matrix4 bindMatrix,
            InfluenceDef[] infList,
            out VertexShaderDesc info,
            out List <VertexPrimitive> lines,
            out List <VertexPolygon> faces)
        {
            info  = VertexShaderDesc.JustPositions();
            lines = new List <VertexPrimitive>();
            faces = new List <VertexPolygon>();

            Source src;
            int    boneCount = 0;

            if (infList != null)
            {
                HashSet <string> bones = new HashSet <string>();
                foreach (InfluenceDef inf in infList)
                {
                    for (int i = 0; i < inf.WeightCount; ++i)
                    {
                        bones.Add(inf.Weights[i].Bone);
                    }
                }
                boneCount = bones.Count;
            }
            info.BoneCount = boneCount;

            var m = geo.MeshElement;

            if (m == null)
            {
                return;
            }

            Vertices vertsElem;

            foreach (var prim in m.PrimitiveElements)
            {
                Dictionary <ESemantic, int> semanticCounts = new Dictionary <ESemantic, int>();
                Dictionary <ESemantic, Dictionary <int, Source> > inputSources = new Dictionary <ESemantic, Dictionary <int, Source> >();
                Dictionary <ESemantic, Source> vertexInputSources = new Dictionary <ESemantic, Source>();
                foreach (InputShared inp in prim.InputElements)
                {
                    if (inp.CommonSemanticType == ESemantic.VERTEX)
                    {
                        vertsElem = inp.Source.GetElement <Vertices>(inp.Root);
                        foreach (InputUnshared input in vertsElem.InputElements)
                        {
                            ESemantic semantic = input.CommonSemanticType;
                            if (semanticCounts.ContainsKey(semantic))
                            {
                                ++semanticCounts[semantic];
                            }
                            else
                            {
                                semanticCounts.Add(semantic, 1);
                            }

                            src = input.Source.GetElement <Source>(vertsElem.Root);
                            vertexInputSources[input.CommonSemanticType] = src;
                        }
                        continue;
                    }
                    else
                    {
                        ESemantic semantic = inp.CommonSemanticType;
                        if (semanticCounts.ContainsKey(semantic))
                        {
                            ++semanticCounts[semantic];
                        }
                        else
                        {
                            semanticCounts.Add(semantic, 1);
                        }

                        src = inp.Source.GetElement <Source>(inp.Root);
                        if (src != null)
                        {
                            if (!inputSources.ContainsKey(semantic))
                            {
                                inputSources.Add(semantic, new Dictionary <int, Source>());
                            }

                            int set = (int)inp.Set;
                            if (!inputSources[semantic].ContainsKey(set))
                            {
                                inputSources[semantic].Add(set, src);
                            }
                            else
                            {
                                inputSources[semantic][set] = src;
                            }
                        }
                    }
                }

                info.MorphCount = 0; //Morphs are stored in separate geometry entries, so they need to be combined later
                info.HasNormals = semanticCounts.ContainsKey(ESemantic.NORMAL) && semanticCounts[ESemantic.NORMAL] > 0;

                bool hasTexBinormal = semanticCounts.ContainsKey(ESemantic.TEXBINORMAL) && semanticCounts[ESemantic.TEXBINORMAL] > 0;
                bool hasBinormal    = semanticCounts.ContainsKey(ESemantic.BINORMAL) && semanticCounts[ESemantic.BINORMAL] > 0;
                info.HasBinormals = hasTexBinormal || hasBinormal;

                bool hasTexTangent = semanticCounts.ContainsKey(ESemantic.TEXTANGENT) && semanticCounts[ESemantic.TEXTANGENT] > 0;
                bool hasTangent    = semanticCounts.ContainsKey(ESemantic.TANGENT) && semanticCounts[ESemantic.TANGENT] > 0;
                info.HasTangents = hasTexTangent || hasTangent;

                info.ColorCount    = semanticCounts.ContainsKey(ESemantic.COLOR) ? semanticCounts[ESemantic.COLOR] : 0;
                info.TexcoordCount = semanticCounts.ContainsKey(ESemantic.TEXCOORD) ? semanticCounts[ESemantic.TEXCOORD] : 0;

                int maxSets = Math.Max(info.MorphCount + 1,
                                       Math.Max(info.ColorCount, info.TexcoordCount));

                Vertex[][] vertices = new Vertex[prim.PointCount][];
                int[]      indices  = prim?.IndicesElement?.StringContent?.Values;
                if (indices == null)
                {
                    WriteLine("Mesh has no face indices. Mesh will be empty.");
                    return;
                }

                Matrix4 invTranspBindMatrix = bindMatrix;
                if (info.HasNormals || info.HasBinormals || info.HasTangents)
                {
                    invTranspBindMatrix.Invert();
                    invTranspBindMatrix.Transpose();
                }

                foreach (var inp in prim.InputElements)
                {
                    int set    = (int)inp.Set;
                    int offset = (int)inp.Offset;

                    if (inp.CommonSemanticType == ESemantic.VERTEX)
                    {
                        foreach (ESemantic s in vertexInputSources.Keys)
                        {
                            src = vertexInputSources[s];
                            DecodeSource(src, s, offset, set, maxSets, prim, indices, vertices, infList, bindMatrix, invTranspBindMatrix);
                        }
                    }
                    else
                    {
                        src = inputSources[inp.CommonSemanticType][set];
                        DecodeSource(src, inp.CommonSemanticType, offset, set, maxSets, prim, indices, vertices, infList, bindMatrix, invTranspBindMatrix);
                    }
                }

                int setIndex = 0;
                switch (prim.Type)
                {
                case EColladaPrimitiveType.Lines:

                    VertexLine[] linesTemp = new VertexLine[vertices.Length / 2];
                    for (int i = 0, x = 0; i < vertices.Length; i += 2, ++x)
                    {
                        linesTemp[x] = new VertexLine(vertices[i][setIndex], vertices[i + 1][setIndex]);
                    }
                    lines.AddRange(linesTemp);

                    break;

                case EColladaPrimitiveType.Linestrips:
                    lines.Add(new VertexLineStrip(false, vertices.Select(x => x[setIndex]).ToArray()));
                    break;

                case EColladaPrimitiveType.Triangles:

                    VertexTriangle[] tris = new VertexTriangle[vertices.Length / 3];

                    for (int i = 0, x = 0; i < vertices.Length; i += 3, ++x)
                    {
                        tris[x] = new VertexTriangle(
                            vertices[i][setIndex],
                            vertices[i + 1][setIndex],
                            vertices[i + 2][setIndex]);
                    }

                    faces.AddRange(tris);
                    break;

                case EColladaPrimitiveType.Trifans:
                    faces.Add(new VertexTriangleFan(vertices.Select(x => x[setIndex]).ToArray()));
                    break;

                case EColladaPrimitiveType.Tristrips:
                    faces.Add(new VertexTriangleStrip(vertices.Select(x => x[setIndex]).ToArray()));
                    break;

                case EColladaPrimitiveType.Polylist:
                    Polylist   polyListPrim = (Polylist)prim;
                    PolyCounts countsElem   = polyListPrim.PolyCountsElement;
                    int[]      counts       = countsElem.StringContent.Values;

                    VertexPolygon[] polys = new VertexPolygon[counts.Length];

                    for (int vtxIndex = 0, polyIndex = 0; polyIndex < counts.Length; ++polyIndex)
                    {
                        int      count = counts[polyIndex];
                        Vertex[] verts = new Vertex[count];
                        for (int polyVtxIndex = 0; polyVtxIndex < count; ++polyVtxIndex, ++vtxIndex)
                        {
                            verts[polyVtxIndex] = vertices[vtxIndex][setIndex];
                        }
                        polys[polyIndex] = new VertexPolygon(verts);
                    }

                    faces.AddRange(polys);
                    break;

                default:
                case EColladaPrimitiveType.Polygons:
                    WriteLine($"Primitive type '{prim.Type.ToString()}' not supported. Mesh will be empty.");
                    break;
                }
            }
        }
 private static int[] RunDjikstra(Vertex[] vertices, int source)
 {
     Djikstra.Run(vertices[source]);
     return vertices.Select(v => v.Depth).ToArray();
 }
 private static int[] RunBreadthFirstSearch(Vertex[] vertices, int source)
 {
     BreadthFirstSearch.Run(vertices[source]);
     return vertices.Select(v => v.Depth).ToArray();
 }
 private static int[] RunBellmanFord(Vertex[] vertices, int source)
 {
     BellmanFord.Run(vertices, source);
     return vertices.Select(v => v.Depth).ToArray();
 }
Example #14
0
 public OgreXmlWriter(Vertex[] vertices, Triangle[] triangles, string uri)
 {
     // Look, ma, no semicolons!
     var mesh = new XElement("mesh",
         new XElement("submeshes",
             new XElement("submesh",
                 new XAttribute("material","BaseWhite"),
                 new XAttribute("usesharedvertices","false"),
                 new XElement("faces",
                     new XAttribute("count", triangles.Length.ToString()),
                     from t in triangles
                         select new XElement("face",
                             new XAttribute("v1", t.i),
                             new XAttribute("v2", t.j),
                             new XAttribute("v3", t.k))
                     ),
                 new XElement("geometry",
                     new XAttribute("vertexcount", vertices.Length.ToString()),
                     new XElement("vertexbuffer",
                         new XAttribute("positions", "true"),
                         new XAttribute("normals", "true"),
                         new XAttribute("texture_coords", 1),
                         new XAttribute("texture_coord_dimensions_0", 2),
                         new XAttribute("tangents", "true"),
                         from v in vertices
                             select new XElement("vertex",
                                 new XElement("position",
                                     new XAttribute("x", v.x),
                                     new XAttribute("y", v.y),
                                     new XAttribute("z", v.z)),
                                 new XElement("normal",
                                     new XAttribute("x", Vertex.UnpackNormal(v.normal, 0)),
                                     new XAttribute("y", Vertex.UnpackNormal(v.normal, 1)),
                                     new XAttribute("z", Vertex.UnpackNormal(v.normal, 2))),
                                 new XElement("texcoord",
                                     new XAttribute("u", v.u),
                                     new XAttribute("v", v.v)),
                                 new XElement("tangent",
                                     new XAttribute("x", Vertex.UnpackNormal(v.tangent, 0)),
                                     new XAttribute("y", Vertex.UnpackNormal(v.tangent, 1)),
                                     new XAttribute("z", Vertex.UnpackNormal(v.tangent, 2)))
                                 )
                         )
                     ),
                 new XElement("boneassignments",
                     from pair in vertices.Select((v,index)=>new KeyValuePair<Vertex,int>(v,index))
                         let v = pair.Key
                         let i = pair.Value
                         from a in (from ind in Enumerable.Range(0,4)
                            let bone = (v.packed_bone_indices >> (ind * 8)) & 0xff
                            let weight = (v.packed_bone_weights >> (ind * 8)) & 0xff
                            where weight != 0
                            select new { bone, weight=weight/255.0f })
                         select new XElement("vertexboneassignment",
                             new XAttribute("vertexindex", i),
                             new XAttribute("boneindex", a.bone),
                             new XAttribute("weight", a.weight))
                     )
                 )
             )
         );
     mesh.Save(uri);
 }