Пример #1
0
        private void testTriangulate()
        {
            CadFigure tfig = GetTargetFigure();

            if (tfig == null || tfig.Type != CadFigure.Types.POLY_LINES)
            {
                return;
            }

            if (tfig.PointCount < 3)
            {
                return;
            }

            VertexList vl = tfig.GetPoints(12);

            CadMesh m = IglW.Triangulate(vl, "a1000q");

            HeModel hem = HeModelConverter.ToHeModel(m);

            CadFigureMesh fig = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH);

            fig.SetMesh(hem);

            Controller.CurrentLayer.AddFigure(fig);
        }
Пример #2
0
        public static VertexArray Billboard()
        {
            var shader = Resources.TheResources.GetShader("default-tex");
            var bb     = new VertexList(VertexLayout.TextureVertex);

            bb.AddTextureVertex(
                new Vector2(-5, -5),
                Color4.White,
                new Vector2(0, 1)
                );
            bb.AddTextureVertex(
                new Vector2(-5, 5),
                Color4.White,
                new Vector2(0, 0)
                );
            bb.AddTextureVertex(
                new Vector2(5, 5),
                Color4.White,
                new Vector2(1, 0)
                );
            bb.AddTextureVertex(
                new Vector2(5, -5),
                Color4.White,
                new Vector2(1, 1)
                );
            var indices = new uint[] {
                0, 1, 2,
                0, 2, 3,
            };

            return(new VertexArray(shader, bb, idxs: indices));
        }
Пример #3
0
            public PMDFormat(BinaryReader bin, GameObject caller, string path)
            {
                EntryPathes(path);

                this.caller = caller;

                try {
                    this.head              = new Header(bin);
                    this.vertex_list       = new VertexList(bin);
                    this.face_vertex_list  = new FaceVertexList(bin);
                    this.material_list     = new MaterialList(bin);
                    this.bone_list         = new BoneList(bin);
                    this.ik_list           = new IKList(bin); read_count++;
                    this.skin_list         = new SkinList(bin); read_count++;
                    this.skin_name_list    = new SkinNameList(bin);
                    this.bone_name_list    = new BoneNameList(bin);
                    this.bone_display_list = new BoneDisplayList(bin);
                    this.eg_head           = new EnglishHeader(bin);
                    if (this.eg_head.english_name_compatibility != 0)
                    {
                        this.eg_bone_name_list    = new EnglishBoneNameList(bin, bone_list.bone_count);
                        this.eg_skin_name_list    = new EnglishSkinNameList(bin, skin_list.skin_count);
                        this.eg_bone_display_list = new EnglishBoneDisplayList(bin, bone_name_list.bone_disp_name_count);
                    }
                    this.toon_texture_list    = new ToonTextureList(bin);
                    this.rigidbody_list       = new RigidbodyList(bin);
                    this.rigidbody_joint_list = new RigidbodyJointList(bin);
                } catch {
                    Debug.Log("Don't read full format");
                }
            }
Пример #4
0
        public static CadRect GetContainsRectScrn(DrawContext dc, VertexList list)
        {
            CadRect rect = default(CadRect);

            double minx = CadConst.MaxValue;
            double miny = CadConst.MaxValue;

            double maxx = CadConst.MinValue;
            double maxy = CadConst.MinValue;

            list.ForEach(p =>
            {
                CadVertex v = dc.WorldPointToDevPoint(p);

                minx = Math.Min(minx, v.X);
                miny = Math.Min(miny, v.Y);

                maxx = Math.Max(maxx, v.X);
                maxy = Math.Max(maxy, v.Y);
            });

            rect.p0 = default(CadVertex);
            rect.p1 = default(CadVertex);

            rect.p0.X = minx;
            rect.p0.Y = miny;
            rect.p0.Z = 0;

            rect.p1.X = maxx;
            rect.p1.Y = maxy;
            rect.p1.Z = 0;

            return(rect);
        }
Пример #5
0
        // 法線の代表値を求める
        //public static CadVertex RepresentativeNormal(VertexList points)
        //{
        //    if (points.Count < 3)
        //    {
        //        return CadVertex.Zero;
        //    }

        //    int idx = FindMaxDistantPointIndex(points[0], points);

        //    int idxA = idx - 1;
        //    int idxB = idx + 1;

        //    if (idxA < 0)
        //    {
        //        idxA = points.Count - 1;
        //    }

        //    if (idxB >= points.Count)
        //    {
        //        idxB = idxB - points.Count;
        //    }

        //    CadVertex normal = CadMath.Normal(points[idx], points[idxA], points[idxB]);

        //    return normal;
        //}

        public static Vector3d TypicalNormal(VertexList points)
        {
            if (points.Count < 3)
            {
                return(Vector3d.Zero);
            }

            int idx = FindMaxDistantPointIndex(points[0], points);

            int idxA = idx - 1;
            int idxB = idx + 1;

            if (idxA < 0)
            {
                idxA = points.Count - 1;
            }

            if (idxB >= points.Count)
            {
                idxB = idxB - points.Count;
            }

            Vector3d normal = CadMath.Normal(points[idx].vector, points[idxA].vector, points[idxB].vector);

            return(normal);
        }
Пример #6
0
        public static CadMesh CreateFrom(VertexList vl)
        {
            if (vl.Count < 2)
            {
                return(null);
            }

            CadMesh m = new CadMesh(vl.Count, 1);

            m.VertexStore.AddRange(vl);

            int i;

            FlexArray <int> nl = new FlexArray <int>(vl.Count);

            for (i = 0; i < vl.Count; i++)
            {
                nl.Add(i);
            }

            CadFace face = new CadFace(nl);

            m.FaceStore.Add(face);

            return(m);
        }
Пример #7
0
        // Add a new line into the simple layout struct, new vertices and a new edge

        public void AddEdge(PointF WorldFrom, PointF WorldTo, int Width, int Height)
        {
            int nextindex = FindNextIndex();

            Vertex vP1 = new Vertex();

            vP1.Index = nextindex++;
            vP1.X     = WorldFrom.X;
            vP1.Y     = WorldFrom.Y;
            VertexList.Add(vP1);

            Vertex vP2 = new Vertex();

            vP2.Index = nextindex++;
            vP2.X     = WorldTo.X;
            vP2.Y     = WorldTo.Y;
            VertexList.Add(vP2);

            // Now add a segment

            Edge oEdge = new Edge();

            oEdge.Height      = 30;
            oEdge.Width       = 10;
            oEdge.p1          = vP1.Index;
            oEdge.p2          = vP2.Index;
            oEdge.ID          = "";
            oEdge.HoleGroupID = "";

            EdgeList.Add(oEdge);
        }
Пример #8
0
        public static VertexArray FilledRectCenter(double cx, double cy, double w, double h, Color4 color)
        {
            float halfW     = (float)(w / 2);
            float halfH     = (float)(h / 2);
            var   positions = new Vector2[] {
                new Vector2((float)cx - halfW, (float)cy - halfH),
                new Vector2((float)cx - halfW, (float)cy + halfH),
                new Vector2((float)cx + halfW, (float)cy + halfH),
                new Vector2((float)cx + halfW, (float)cy - halfH),
            };

            var indices = new uint[] {
                0, 1, 2,
                0, 2, 3,
            };

            var shader = Resources.TheResources.GetShader("default");
            var bb     = new VertexList(VertexLayout.ColorVertex);

            foreach (var pos in positions)
            {
                bb.AddColorVertex(pos, color);
            }
            return(new VertexArray(shader, bb, idxs: indices));
        }
Пример #9
0
        public void GraphicalClear()
        {
            VertexList.Clear();
            IndexList.Clear();

            VertexCount = 0;
        }
Пример #10
0
        public void Eval(VertexList vl)
        {
            double u;
            double v;

            for (int j = 0; j <= VBSpline.DivCnt; ++j)
            {
                v = j * VBSpline.Step + VBSpline.LowKnot;
                if (v >= VBSpline.HighKnot)
                {
                    v = VBSpline.HighKnot - BSpline.Epsilon;
                }

                for (int i = 0; i <= UBSpline.DivCnt; ++i)
                {
                    u = i * UBSpline.Step + UBSpline.LowKnot;
                    if (u >= UBSpline.HighKnot)
                    {
                        u = UBSpline.HighKnot - BSpline.Epsilon;
                    }

                    vl.Add(new CadVertex(CalcPoint(u, v)));
                }
            }
        }
Пример #11
0
        private VertexList GenerateVertexList(
            VoxelCorners <float> voxelDensities, VoxelCorners <int3> voxelCorners,
            int edgeIndex, float isolevel)
        {
            var vertexList = new VertexList();

            for (var i = 0; i < 12; i++)
            {
                if ((edgeIndex & (1 << i)) == 0)
                {
                    continue;
                }

                var edgeStartIndex = MarchingCubesTables.EdgeIndexTable[2 * i + 0];
                var edgeEndIndex   = MarchingCubesTables.EdgeIndexTable[2 * i + 1];

                var corner1 = (float3)voxelCorners[edgeStartIndex] * voxelSize;
                var corner2 = (float3)voxelCorners[edgeEndIndex] * voxelSize;

                var density1 = voxelDensities[edgeStartIndex];
                var density2 = voxelDensities[edgeEndIndex];

                vertexList[i] = VertexInterpolate(corner1, corner2, density1, density2, isolevel);
            }

            return(vertexList);
        }
Пример #12
0
 /// <summary>
 /// clears all lists.
 /// </summary>
 public void Clear()
 {
     VertexList.Clear();
     EdgeList.Clear();
     FaceList.Clear();
     EdgeCurveList.Clear();
 }
        public void GenerateVertexList_Test3()
        {
            // Arrange
            VoxelCorners <byte> densities = new VoxelCorners <byte>
            {
                Corner1 = 140,
                Corner2 = 25,
                Corner3 = 189,
                Corner4 = 89,
                Corner5 = 192,
                Corner6 = 204,
                Corner7 = 255,
                Corner8 = 229
            };

            byte isolevel  = 191;
            int  edgeIndex = 0b1111_0000_0000;

            VertexList expected = new VertexList();

            expected[8]  = new float3(-56f, -0.02439022f, 9f);
            expected[9]  = new float3(-55f, -0.07142866f, 9f);
            expected[10] = new float3(-55f, -0.9803922f, 10f);
            expected[11] = new float3(-56f, -0.272727272727f, 10f);

            // Act
            IEnumerable <float3> actual = MarchingCubesFunctions.GenerateVertexList(densities, new int3(-56, -1, 9), edgeIndex, isolevel);

            // Assert
            for (int i = 0; i < 12; i++)
            {
                var actualPosition = actual.ElementAt(i);
                Assert.AreEqual(0, math.distance(expected[i], actualPosition), 0.011f, $"Expected: {expected[i]}, Actual: {actualPosition}");
            }
        }
Пример #14
0
        /// <summary>
        /// 頂点追加.
        /// </summary>
        /// <param name="Vertex">頂点データ</param>
        public void AddVertex(Vector Vertex)
        {
            VertexList.Insert(0, Vertex);

            if (Vertex.X > Back)
            {
                Back = Vertex.X;
            }
            if (Vertex.X < Front)
            {
                Front = Vertex.X;
            }
            if (Vertex.Y > Right)
            {
                Right = Vertex.Y;
            }
            if (Vertex.Y < Left)
            {
                Left = Vertex.Y;
            }
            if (Vertex.Z > Top)
            {
                Top = Vertex.Z;
            }
            if (Vertex.Z < Bottom)
            {
                Bottom = Vertex.Z;
            }
        }
Пример #15
0
        /// <summary>
        /// Sets our global object size with an extent object
        /// </summary>
        private void updateSize()
        {
            // If there are no vertices then size should be 0.
            if (VertexList.Count == 0)
            {
                Size = new Extent
                {
                    XMax = 0,
                    XMin = 0,
                    YMax = 0,
                    YMin = 0,
                    ZMax = 0,
                    ZMin = 0
                };

                // Avoid an exception below if VertexList was empty.
                return;
            }

            Size = new Extent
            {
                XMax = VertexList.Max(v => v.Value.X),
                XMin = VertexList.Min(v => v.Value.X),
                YMax = VertexList.Max(v => v.Value.Y),
                YMin = VertexList.Min(v => v.Value.Y),
                ZMax = VertexList.Max(v => v.Value.Z),
                ZMin = VertexList.Min(v => v.Value.Z)
            };
        }
Пример #16
0
        /// <inheritdoc />
        public int RemoveVertexIf(VertexPredicate <TVertex> predicate)
        {
            if (predicate is null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            var verticesToRemove = new VertexList <TVertex>();

            verticesToRemove.AddRange(Vertices.Where(vertex => predicate(vertex)));

            // Remove out edges
            var verticesEdgesRemoved = new VertexEdgeDictionary <TVertex, TEdge>(verticesToRemove.Count);

            foreach (TVertex vertex in verticesToRemove)
            {
                verticesEdgesRemoved[vertex] = _vertexEdges[vertex];
                _vertexEdges.Remove(vertex);
            }
            EdgeCount -= verticesEdgesRemoved.Sum(pair => pair.Value.Count);
            Debug.Assert(EdgeCount >= 0);

            // Remove in edges (Run over edges and remove each edge touching vertices to remove)
            RemoveInEdges(v => verticesToRemove.Contains(v, EqualityComparer <TVertex> .Default));

            NotifyEdgesRemoved(verticesEdgesRemoved.Values.SelectMany(edges => edges));
            NotifyVerticesRemoved(verticesToRemove);

            return(verticesToRemove.Count);
        }
Пример #17
0
 private Polygon BuildGpcPolygonFromPointArray(Point[] pointArray)
 {
     Polygon polygon = new Polygon();
     VertexList contour = new VertexList(pointArray);
     polygon.AddContour(contour, false);
     return polygon;
 }
        protected override void BuildData()
        {
            VertexList.AddRange(new Vector3[]
            {
                new Vector3(.5f, -.5f, 0), new Vector3(-.5f, -.5f, 0), new Vector3(-.5f, .5f, 0), new Vector3(.5f, .5f, 0),
            });

            NormalList.AddRange(new Vector3[]
            {
                Vector3.Backward, Vector3.Backward, Vector3.Backward, Vector3.Backward,
            });

            TexCoordList.AddRange(new Vector2[]
            {
                new Vector2(1, 1), new Vector2(0, 1), new Vector2(0, 0), new Vector2(1, 0),
            });

            ColorList.AddRange(new Color[]
            {
                Color.White, Color.White, Color.White, Color.White,
            });


            IndexList.AddRange(new int[]
            {
                0, 1, 2, 2, 3, 0, // Front
            });

            CalculateTangents();
        }
Пример #19
0
        public eOperationStatus AppendEdge(int Width, int Height, int DeltaX, int DeltaY)
        {
            if (MostRecentlySelectedVertex == null)
            {
                return(eOperationStatus.NoVertexSelected);
            }

            // Add a new point
            int nextindex = FindNextIndex();

            Vertex vP = new Vertex();

            vP.Index = nextindex;
            vP.X     = MostRecentlySelectedVertex.X + DeltaX;
            vP.Y     = MostRecentlySelectedVertex.Y + DeltaY;
            VertexList.Add(vP);

            // Add an edge

            Edge oEdge = new Edge();

            oEdge.Height      = Height;
            oEdge.Width       = Width;
            oEdge.p1          = MostRecentlySelectedVertex.Index;
            oEdge.p2          = vP.Index;
            oEdge.ID          = "";
            oEdge.HoleGroupID = "";

            EdgeList.Add(oEdge);

            return(eOperationStatus.OK);
        }
Пример #20
0
        public void Setup(
            int deg,
            int ucnt, int vcnt,
            VertexList vl,
            int[] ctrlOrder,
            int uDivCnt, int vDivCnt,
            bool uedge  = true, bool vedge   = true,
            bool uclose = false, bool vclose = false)
        {
            Nurbs = new NurbsSurface(deg, ucnt, vcnt, uDivCnt, vDivCnt, uedge, vedge, uclose, vclose);

            Nurbs.CtrlPoints = vl;

            mPointList = vl;

            if (ctrlOrder == null)
            {
                Nurbs.SetupDefaultCtrlOrder();
            }
            else
            {
                Nurbs.CtrlOrder = ctrlOrder;
            }

            NurbsPointList = new VertexList(Nurbs.UOutCnt * Nurbs.VOutCnt);
        }
Пример #21
0
        public override void FlipWithPlane(Vector3d p0, Vector3d normal)
        {
            VertexList vl = PointList;

            for (int i = 0; i < vl.Count; i++)
            {
                CadVertex v = vl[i];

                Vector3d cp = CadMath.CrossPlane(v.vector, p0, normal);

                CadVertex d = v - cp;

                v = cp - d;

                vl[i] = v;
            }

            Vector3dList nl = mHeModel.NormalStore;

            for (int i = 0; i < nl.Count; i++)
            {
                Vector3d v = nl[i];

                Vector3d cp = CadMath.CrossPlane(v, Vector3d.Zero, normal);

                Vector3d d = v - cp;

                v = cp - d;

                nl[i] = v;
            }
        }
Пример #22
0
        public static CadMesh CreateSphere(Vector3d pos, double r, int slices1, int slices2)
        {
            VertexList vl = new VertexList(slices2);

            double d = Math.PI / slices2;


            for (int i = 0; i < slices2; i++)
            {
                double a = i * d;

                double x = Math.Sin(a) * r;
                double y = Math.Cos(a) * r;

                vl.Add(CadVertex.Create(x, y, 0));
            }

            vl.Add(CadVertex.Create(0, -r, 0));


            CadMesh mesh = CreateRotatingBody(
                slices1, Vector3d.Zero, Vector3d.UnitY, vl, false, false, FaceType.TRIANGLE);

            for (int i = 0; i < mesh.VertexStore.Count; i++)
            {
                mesh.VertexStore.Ref(i).vector += pos;
            }

            return(mesh);
        }
Пример #23
0
        private void addVertex(Vector3 point, Vector2 uv1, float sunLight, Color localLight)
        {
            //VertexList.Add(new VertexPositionTextureLight(point, uv1, sunLight, localLight.ToVector3()));
            //VertexList.Add(new VertexPositionNormalTexture(point, Vector3.Forward, uv1));

            VertexList.Add(new VertexPositionColorTextureNormal(point, localLight, uv1, Vector3.Forward));
        }
Пример #24
0
        // 指定された座標から最も遠いPointのIndexを求める
        public static int FindMaxDistantPointIndex(CadVertex p0, VertexList points)
        {
            int ret = -1;
            int i;

            CadVertex t;

            double maxd = 0;

            for (i = 0; i < points.Count; i++)
            {
                CadVertex fp = points[i];

                t = fp - p0;
                double d = t.Norm();

                if (d > maxd)
                {
                    maxd = d;
                    ret  = i;
                }
            }

            return(ret);
        }
Пример #25
0
        public void Clear()
        {
            VertexList.Clear();
            IndexList.Clear();

            VertexCount = 0;
        }
Пример #26
0
        public override void Undo(CadObjectDB db)
        {
            CadLayer  layer = db.GetLayer(LayerID);
            CadFigure fig   = db.GetFigure(FigureID);

            if (fig == null)
            {
                return;
            }

            int idx = PointIndex;
            int i   = 0;

            if (mPointList == null)
            {
                mPointList = new VertexList();
            }

            mPointList.Clear();

            for (; i < InsertNum; i++)
            {
                mPointList.Add(fig.GetPointAt(idx + i));
            }

            fig.RemovePointsRange(idx, InsertNum);
        }
Пример #27
0
    public static void CheckAfterEarCutoff(List <Vector3> vertices, List <PolyVertex> pvs, PolyVertex pv, Vector3 polygonNormal,
                                           VertexList ears)
    {
        // 1.) if prev was convex, do nothing.
        // 2.) if prev was reflex, re-check, and modify convex / reflex lists.
        // 3.) if convex, update its ear status.

        if (!pv.isConvex)
        {
            var prev = vertices[pv.prevIndex];
            var tip  = vertices[pv.currIndex];
            var next = vertices[pv.nextIndex];

            pv.isConvex = IsFacingSameAsPolyNormal(prev, tip, next, polygonNormal);
        }

        if (pv.isConvex)
        {
            var isEar          = IsEarTip(vertices, pvs, pv);
            var weKnowItsAnEar = ears.Contains(pv.currIndex);

            if (isEar != weKnowItsAnEar)
            {
                if (isEar)
                {
                    ears.AddIndex(pv.currIndex);
                }
                else
                {
                    ears.RemoveIndex(pv.currIndex);
                }
            }
        }
    }
Пример #28
0
        public void GetData(PmxModelData data)
        {
            var header = new PmxHeaderData()
            {
                Version = 2.0F
            };

            var boneSlot = new PmxSlotData()
            {
                SlotName = "弾ボーン",
                Type     = PmxSlotData.SLOT_TYPE_BONE,
                Indices  = Enumerable.Range(0, BoneList.Count).ToArray()
            };

            var morphSlot = new PmxSlotData()
            {
                SlotName = "弾モーフ",
                Type     = PmxSlotData.SLOT_TYPE_MORPH,
                Indices  = Enumerable.Range(0, MorphList.Count).ToArray()
            };

            data.Header        = header;
            data.VertexIndices = IndexList.ToArray();
            data.TextureFiles  = TextureList.ToArray();
            data.VertexArray   = VertexList.ToArray();
            data.MaterialArray = MaterialList.ToArray();
            data.BoneArray     = BoneList.ToArray();
            data.MorphArray    = MorphList.ToArray();
            data.SlotArray     = new PmxSlotData[] { boneSlot, morphSlot };
        }
Пример #29
0
        private Graph <Vertex> BuildLargeGraph()
        {
            VertexList <Vertex> vertices = new VertexList <Vertex>()
            {
                new Vertex("S"), new Vertex("A"), new Vertex("B"), new Vertex("D"),
                new Vertex("F"), new Vertex("H"), new Vertex("G"), new Vertex("C"),
                new Vertex("L"), new Vertex("I"), new Vertex("J"), new Vertex("K"),
                new Vertex("E")
            };

            Graph <Vertex> graph = new Graph <Vertex>(vertices);

            graph.AddEdges(vertices.Get("S"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("A"), 7), new Edge <Vertex>(vertices.Get("B"), 2), new Edge <Vertex>(vertices.Get("C"), 3) });
            graph.AddEdges(vertices.Get("A"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("S"), 7), new Edge <Vertex>(vertices.Get("B"), 3), new Edge <Vertex>(vertices.Get("D"), 4) });
            graph.AddEdges(vertices.Get("B"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("S"), 2), new Edge <Vertex>(vertices.Get("A"), 3), new Edge <Vertex>(vertices.Get("D"), 4), new Edge <Vertex>(vertices.Get("H"), 1) });
            graph.AddEdges(vertices.Get("D"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("A"), 4), new Edge <Vertex>(vertices.Get("B"), 4), new Edge <Vertex>(vertices.Get("F"), 5) });
            graph.AddEdges(vertices.Get("F"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("D"), 5), new Edge <Vertex>(vertices.Get("H"), 3) });
            graph.AddEdges(vertices.Get("H"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("B"), 1), new Edge <Vertex>(vertices.Get("F"), 3), new Edge <Vertex>(vertices.Get("G"), 2) });
            graph.AddEdges(vertices.Get("G"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("H"), 2), new Edge <Vertex>(vertices.Get("E"), 2) });
            graph.AddEdges(vertices.Get("C"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("S"), 3), new Edge <Vertex>(vertices.Get("L"), 2) });
            graph.AddEdges(vertices.Get("L"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("C"), 2), new Edge <Vertex>(vertices.Get("I"), 4), new Edge <Vertex>(vertices.Get("J"), 4) });
            graph.AddEdges(vertices.Get("I"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("L"), 4), new Edge <Vertex>(vertices.Get("J"), 6), new Edge <Vertex>(vertices.Get("K"), 4) });
            graph.AddEdges(vertices.Get("J"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("L"), 4), new Edge <Vertex>(vertices.Get("I"), 6), new Edge <Vertex>(vertices.Get("K"), 4) });
            graph.AddEdges(vertices.Get("K"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("J"), 4), new Edge <Vertex>(vertices.Get("I"), 4), new Edge <Vertex>(vertices.Get("E"), 5) });
            graph.AddEdges(vertices.Get("E"), new Edge <Vertex>[] { new Edge <Vertex>(vertices.Get("G"), 2), new Edge <Vertex>(vertices.Get("K"), 5) });
            return(graph);
        }
Пример #30
0
        //"1,1;2,2;3,3"
        public static void Main(string[] args)
        {
            //args = new string[3];
            //string ss = "0,0;0,1;1,1;1,0";
            //string ss1 = "0,0;0,1;1,1;1,0";
            //string ss2 = "0";
            //args[0] = ss;
            //args[1] = ss1;
            //args[2] = ss2;

            if (args?.Count() != 3)
            {
                return;
            }
            try
            {
                string[] ptStr1 = args[0].Split(';');
                string[] ptStr2 = args[1].Split(';');
                //0:相差  1:相交  2:异或  3:合并
                GpcOperation operation = (GpcOperation)(int.Parse(args[2]));
                //组织多边形A顶点数据
                GpcWrapper.Polygon polygonA = new GpcWrapper.Polygon();
                PointF[]           aa       = new PointF[ptStr1.Count()];
                for (int i = 0; i < ptStr1.Count(); i++)
                {
                    var subPtStr = ptStr1[i].Split(',');
                    aa[i] = new PointF(float.Parse(subPtStr[0]),
                                       float.Parse(subPtStr[1]));
                }
                VertexList vtxA = new VertexList(aa);
                polygonA.AddContour(vtxA, false);

                //组织多边形B顶点数据
                GpcWrapper.Polygon polygonB = new GpcWrapper.Polygon();
                PointF[]           bb       = new PointF[ptStr2.Count()];
                for (int i = 0; i < ptStr2.Count(); i++)
                {
                    var subPtStr = ptStr2[i].Split(',');
                    bb[i] = new PointF(float.Parse(subPtStr[0]),
                                       float.Parse(subPtStr[1]));
                }
                VertexList vtxB = new VertexList(bb);
                polygonB.AddContour(vtxB, false);
                //调用GPC库的剪辑算法
                GpcWrapper.Polygon result = polygonA.Clip(operation, polygonB);
                //组织返回结果字符串
                if (result.Contour == null || result.Contour.Count() == 0)
                {
                    Console.WriteLine("");
                    return;
                }
                string str = string.Join(";", result.Contour[0].Vertex);
                str = str.Replace("(", string.Empty).Replace(")", string.Empty);
                Console.WriteLine(str);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public void GenerateVertexList_Test1()
        {
            // Arrange
            VoxelCorners <byte> densities = new VoxelCorners <byte>
            {
                Corner1 = 255,
                Corner2 = 255,
                Corner3 = 255,
                Corner4 = 0,
                Corner5 = 255,
                Corner6 = 255,
                Corner7 = 255,
                Corner8 = 255
            };

            int  edgeIndex = 0b1000_0000_1100;
            byte isolevel  = 127;

            VertexList expected = new VertexList();

            expected[2]  = new float3(0.5f, 0f, 1f);
            expected[3]  = new float3(0f, 0f, 0.5f);
            expected[11] = new float3(0f, 0.5f, 1f);

            // Act
            IEnumerable <float3> actual = MarchingCubesFunctions.GenerateVertexList(densities, new int3(0, 0, 0), edgeIndex, isolevel);

            // Assert
            for (int i = 0; i < 12; i++)
            {
                var actualPosition = actual.ElementAt(i);
                Assert.AreEqual(0, math.distance(expected[i], actualPosition), 0.011f, $"Expected: {expected[i]}, Actual: {actualPosition}");
            }
        }
Пример #32
0
        // path should contain only polylines ( use Flatten )
        // furthermore the constructor assumes that all Subpathes of path except the first one are holes
        public Polygon(GraphicsPath path)
        {
            byte[] pathTypes = path.PathTypes;

            NofContours = 0;
            foreach (byte b in pathTypes)
            {
                if ((b & ((byte)PathPointType.CloseSubpath)) != 0)
                {
                    NofContours++;
                }
            }

            ContourIsHole = new bool[NofContours];
            Contour = new VertexList[NofContours];

            for (int i = 0; i < NofContours; i++)
            {
                ContourIsHole[i] = (i == 0);
            }

            int contourNr = 0;

            List<PointF> contour = new List<PointF>();

            PointF[] pathPoints = path.PathPoints;

            for (int i = 0; i < pathPoints.Length; i++)
            {
                contour.Add(pathPoints[i]);

                if ((pathTypes[i] & ((byte)PathPointType.CloseSubpath)) != 0)
                {
                    PointF[] pointArray = contour.ToArray();
                    VertexList vl = new VertexList(pointArray);
                    Contour[contourNr++] = vl;
                    contour.Clear();
                }
            }
        }
Пример #33
0
        void UpdateVertexBuffer()
        {
            if (m_env == null)
            {
                RemoveAndDispose(ref m_vertexBuffer);
                m_vertexList = null;
                return;
            }

            var envContents = m_env.Contents;

            if (m_vertexList != null && envContents.Count > m_vertexList.Count)
                m_vertexList = null;

            if (m_vertexList == null)
                m_vertexList = new VertexList<SceneryVertex>(envContents.Count * 2);

            IntGrid3 viewGrid = m_viewGridProvider.ViewGrid;

            m_vertexList.Clear();

            foreach (var ob in envContents.OfType<ConcreteObject>())
            {
                if (viewGrid.Contains(ob.Location) == false)
                    continue;

                var c = ob.Color;
                if (c == GameColor.None)
                    c = ob.Material.Color;

                m_vertexList.Add(new SceneryVertex(ob.Location.ToVector3(), ToColor(c), (uint)ob.SymbolID));
            }

            if (m_vertexList.Count > 0)
            {
                if (m_vertexBuffer == null || m_vertexBuffer.ElementCount < m_vertexList.Count)
                {
                    RemoveAndDispose(ref m_vertexBuffer);
                    m_vertexBuffer = ToDispose(SharpDX.Toolkit.Graphics.Buffer.Vertex.New<SceneryVertex>(this.GraphicsDevice, m_vertexList.Count));
                }

                m_vertexBuffer.SetData(m_vertexList.Data, 0, m_vertexList.Count);
            }
        }
Пример #34
0
        private void ProcessGXCommand(MaterialGroup matgroup, byte cmd, ref uint pos)
        {
            VertexList vtxlist = null;
            if (matgroup.m_Geometry.Count > 0)
                vtxlist = matgroup.m_Geometry[matgroup.m_Geometry.Count - 1];

            System.IO.StreamWriter sw = null;
            if (lolol)
                sw = new System.IO.StreamWriter(System.IO.File.Open("hurrdurr.txt", System.IO.FileMode.Append));

            // if (((cmd & 0xF0) == 0x10) && (cmd != 0x14))
            //    throw new Exception(String.Format("MATRIX COMMAND {0:X2}", cmd));

            switch (cmd)
            {
                // nop
                case 0x00: break;

                // matrix commands
                case 0x10: pos += 4; break;
                case 0x11: break;
                case 0x12: pos += 4; break;
                case 0x13: pos += 4; break;

                // matrix restore (used for animation)
                case 0x14:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        m_CurVertex.m_MatrixID = param & 0x1F;
                    }
                    break;

                // more matrix commands
                case 0x15: break;
                case 0x16: pos += 64; break;
                case 0x17: pos += 48; break;
                case 0x18: pos += 64; break;
                case 0x19: pos += 48; break;
                case 0x1A: pos += 36; break;
                case 0x1B: pos += 12; break;
                case 0x1C: pos += 12; break;

                // set color
                case 0x20:
                    {
                        uint raw = m_File.Read32(pos); pos += 4;

                        byte red = (byte)((raw << 3) & 0xF8);
                        byte green = (byte)((raw >> 2) & 0xF8);
                        byte blue = (byte)((raw >> 7) & 0xF8);

                        byte alpha = (byte)((matgroup.m_PolyAttribs >> 13) & 0xF8);
                        alpha |= (byte)(alpha >> 5);

                        m_CurVertex.m_Color = Color.FromArgb(alpha, red, green, blue);
                        if (lolol) sw.Write(String.Format("COLOR {0}\n", m_CurVertex.m_Color));
                    }
                    break;

                // normal
                case 0x21:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        short x = (short)((param << 6) & 0xFFC0);
                        short y = (short)((param >> 4) & 0xFFC0);
                        short z = (short)((param >> 14) & 0xFFC0);
                        m_CurVertex.m_Normal.X = (float)x / 512.0f;
                        m_CurVertex.m_Normal.Y = (float)y / 512.0f;
                        m_CurVertex.m_Normal.Z = (float)z / 512.0f;
                    }
                    break;

                // texcoord
                case 0x22:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        short s = (short)(param & 0xFFFF);
                        short t = (short)(param >> 16);
                        m_CurVertex.m_TexCoord.X = (float)s / 16.0f;
                        m_CurVertex.m_TexCoord.Y = (float)t / 16.0f;

                        Vector2 texsize = new Vector2((float)matgroup.m_Texture.m_Width, (float)matgroup.m_Texture.m_Height);

                        if (lolol) sw.Write(String.Format("TEXCOORD {0} (TEXSIZE {1} SCALE {2} TRANS {3})\n",
                            m_CurVertex.m_TexCoord, texsize, matgroup.m_TexCoordScale, matgroup.m_TexCoordTrans));

                        Vector2.Add(ref m_CurVertex.m_TexCoord, ref matgroup.m_TexCoordTrans, out m_CurVertex.m_TexCoord);
                        Vector2.Multiply(ref m_CurVertex.m_TexCoord, ref matgroup.m_TexCoordScale, out m_CurVertex.m_TexCoord);
                        /* if ((matgroup.m_TexParams & 0xC0000000) != 0)
                         {
                             m_CurVertex.m_TexCoord.Y += matgroup.m_Texture.m_Height;
                         }*/

                        //Vector2 texsize = new Vector2((float)matgroup.m_Texture.m_Width, (float)matgroup.m_Texture.m_Height);
                        Vector2.Divide(ref m_CurVertex.m_TexCoord, ref texsize, out m_CurVertex.m_TexCoord);

                        // s = s*matrix[0] + t*matrix[4] + matrix[8]/16 + matrix[12]/16
                        // t = s*matrix[1] + t*matrix[5] + matrix[9]/16 + matrix[13]/16

                        // s = s*sscale + 1/16*(strans*sscale)
                        // t = t*tscale + 1/16*(ttrans*tscale)
                    }
                    break;

                // define vertex
                case 0x23:
                    {
                        uint param1 = m_File.Read32(pos); pos += 4;
                        uint param2 = m_File.Read32(pos); pos += 4;

                        short x = (short)(param1 & 0xFFFF);
                        short y = (short)(param1 >> 16);
                        short z = (short)(param2 & 0xFFFF);
                        m_CurVertex.m_Position.X = ((float)x / 4096.0f) * m_ScaleFactor;
                        m_CurVertex.m_Position.Y = ((float)y / 4096.0f) * m_ScaleFactor;
                        m_CurVertex.m_Position.Z = ((float)z / 4096.0f) * m_ScaleFactor;

                        vtxlist.m_VertexList.Add(m_CurVertex);
                        if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position));
                    }
                    break;

                case 0x24:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        short x = (short)((param << 6) & 0xFFC0);
                        short y = (short)((param >> 4) & 0xFFC0);
                        short z = (short)((param >> 14) & 0xFFC0);
                        m_CurVertex.m_Position.X = ((float)x / 4096.0f) * m_ScaleFactor;
                        m_CurVertex.m_Position.Y = ((float)y / 4096.0f) * m_ScaleFactor;
                        m_CurVertex.m_Position.Z = ((float)z / 4096.0f) * m_ScaleFactor;

                        vtxlist.m_VertexList.Add(m_CurVertex);
                        if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position));
                    }
                    break;

                case 0x25:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        short x = (short)(param & 0xFFFF);
                        short y = (short)(param >> 16);
                        m_CurVertex.m_Position.X = ((float)x / 4096.0f) * m_ScaleFactor;
                        m_CurVertex.m_Position.Y = ((float)y / 4096.0f) * m_ScaleFactor;

                        vtxlist.m_VertexList.Add(m_CurVertex);
                        if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position));
                    }
                    break;

                case 0x26:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        short x = (short)(param & 0xFFFF);
                        short z = (short)(param >> 16);
                        m_CurVertex.m_Position.X = ((float)x / 4096.0f) * m_ScaleFactor;
                        m_CurVertex.m_Position.Z = ((float)z / 4096.0f) * m_ScaleFactor;

                        vtxlist.m_VertexList.Add(m_CurVertex);
                        if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position));
                    }
                    break;

                case 0x27:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        short y = (short)(param & 0xFFFF);
                        short z = (short)(param >> 16);
                        m_CurVertex.m_Position.Y = ((float)y / 4096.0f) * m_ScaleFactor;
                        m_CurVertex.m_Position.Z = ((float)z / 4096.0f) * m_ScaleFactor;

                        vtxlist.m_VertexList.Add(m_CurVertex);
                        if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position));
                    }
                    break;

                case 0x28:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        short x = (short)((param << 6) & 0xFFC0);
                        short y = (short)((param >> 4) & 0xFFC0);
                        short z = (short)((param >> 14) & 0xFFC0);
                        m_CurVertex.m_Position.X += (((float)x / 262144.0f) * m_ScaleFactor);
                        m_CurVertex.m_Position.Y += (((float)y / 262144.0f) * m_ScaleFactor);
                        m_CurVertex.m_Position.Z += (((float)z / 262144.0f) * m_ScaleFactor);

                        vtxlist.m_VertexList.Add(m_CurVertex);
                        if (lolol) sw.Write(String.Format("VERTEX {0}\n", m_CurVertex.m_Position));
                    }
                    break;

                case 0x29: pos += 4; break;
                case 0x2A: pos += 4; break;
                case 0x2B: pos += 4; break;

                // lighting commands
                case 0x30: pos += 4; break;
                case 0x31: pos += 4; break;
                case 0x32: pos += 4; break;
                case 0x33: pos += 4; break;
                case 0x34: pos += 128; break;

                // Begin vertex list
                case 0x40:
                    {
                        uint param = m_File.Read32(pos); pos += 4;

                        vtxlist = new VertexList();
                        matgroup.m_Geometry.Add(vtxlist);
                        vtxlist.m_PolyType = param & 0x3;
                        vtxlist.m_VertexList = new List<Vertex>();
                        if (lolol) sw.Write(String.Format("BEGIN {0}\n", param));
                    }
                    break;

                // End vertex list (dummy)
                case 0x41: if (lolol) sw.Write("END\n"); break;

                // misc.
                case 0x50: pos += 4; break;
                case 0x60: pos += 4; break;
                case 0x70: pos += 12; break;
                case 0x71: pos += 8; break;
                case 0x72: pos += 4; break;

                default: throw new Exception(String.Format("Unknown GX command {0:X2} in BMD file", cmd));
            }

            if (lolol)
                sw.Close();
        }
Пример #35
0
			public PMDFormat(BinaryReader bin, GameObject caller, string path)
			{
				EntryPathes(path);
				
				this.caller = caller;
				
				try {
					this.head = new Header(bin);
					this.vertex_list = new VertexList(bin);
					this.face_vertex_list = new FaceVertexList(bin);
					this.material_list = new MaterialList(bin);
					this.bone_list = new BoneList(bin); 
					this.ik_list = new IKList(bin); read_count++;
					this.skin_list = new SkinList(bin); read_count++;
					this.skin_name_list = new SkinNameList(bin);
					this.bone_name_list = new BoneNameList(bin);
					this.bone_display_list = new BoneDisplayList(bin);
					this.eg_head = new EnglishHeader(bin);
					if (this.eg_head.english_name_compatibility != 0)
					{
						this.eg_bone_name_list = new EnglishBoneNameList(bin, bone_list.bone_count);
						this.eg_skin_name_list = new EnglishSkinNameList(bin, skin_list.skin_count);
						this.eg_bone_display_list = new EnglishBoneDisplayList(bin, bone_name_list.bone_disp_name_count);
					}
					this.toon_texture_list = new ToonTextureList(bin);
					this.rigidbody_list = new RigidbodyList(bin);
					this.rigidbody_joint_list = new RigidbodyJointList(bin);
				} catch {
					Debug.Log("Don't read full format");
				}
			}
Пример #36
0
 public Shape(Vertex[] vertices)
     : this()
 {
     Vertices = new VertexList(vertices);
 }
Пример #37
0
 public void CopyShapeFrom(Shape other)
 {
     this.Vertices = other.Vertices;
     this.Location = other.Location;
     this.Rotation = other.Rotation;
     this.Scale = other.Scale;
     this.Update();
 }
Пример #38
0
        void HandleVoxel(IntVector3 p, ref Voxel vox, ref IntGrid3 viewGrid, Direction visibleChunkFaces,
			VertexList<TerrainVertex> vertexList)
        {
            // Faces that are visible due to viewgrid
            Direction sliceFaces = GetVoxelSliceDirections(p, ref viewGrid) & visibleChunkFaces;

            // Faces that are drawn (if there's something to draw)
            Direction visibleFaces = (vox.VisibleFaces | sliceFaces) & visibleChunkFaces;

            if (visibleFaces == 0)
                return;

            FaceTexture baseTexture, topTexture;

            GetTextures(p, ref vox, out baseTexture, out topTexture, sliceFaces);

            CreateCube(p, visibleFaces, ref baseTexture, ref topTexture, vertexList,
                sliceFaces);
        }
Пример #39
0
        public void AutoGenerateVertices()
        {
            PrimitiveTopology top = Topology;
            List<Vertex> verts = new List<Vertex>(Corners * (Corners - 1) + 2);
            // Figure out all the points.
            int height = Corners / 2 + 1;
            int circ = Corners;
            float[,] x = new float[height, circ];
            float[,] y = new float[height, circ];
            float[,] z = new float[height, circ];

            for (int k = 0; k < height; k++)
                for (int i = 0; i < circ; i++)
                {
                    float s = (float)Math.Sin(Math.PI * k / (height-1));
                    float yy = (float)Math.Cos(Math.PI * k / (height-1));
                    float xx = (float)(Math.Sin(Math.PI * 2 * i / (circ)) * s);
                    float zz = (float)(Math.Cos(Math.PI * 2 * i / (circ)) * s);
                    x[k, i] = xx;
                    y[k, i] = yy;
                    z[k, i] = zz;
                }
            // Draw triangles in belts
            for (int k = 1; k < height; k++)
            {
                for (int i = 0; i < circ; i++)
                {
                    // Offset each new row by -1 (aka, height-k)
                    // This ensures that when shown as a LineStrip it looks like a nice spherical mesh.
                    int m = (i + height - k) % (Corners);
                    Vector3 c0 = new Vector3(x[k - 1, m], y[k - 1, m], z[k - 1, m]);
                    Vector3 c3 = new Vector3(x[k, m], y[k, m], z[k, m]);
                    m = (i + height - k - 1) % (Corners);
                    Vector3 c1 = new Vector3(x[k - 1, m], y[k - 1, m], z[k - 1, m]);
                    Vector3 c2 = new Vector3(x[k, m], y[k, m], z[k, m]);
                    Vector3 norm = new Plane(c0, c1, c2).Normal;

                    verts.Add(new Vertex(c0, norm));
                    verts.Add(new Vertex(c1, norm));
                    verts.Add(new Vertex(c2, norm));
                    norm = new Plane(c2, c3, c0).Normal;
                    verts.Add(new Vertex(c0, norm));
                    verts.Add(new Vertex(c2, norm));
                    verts.Add(new Vertex(c3, norm));

                }
            }
            Vertices = new VertexList(verts);
            Topology = top;
            UpdateColor();
        }
Пример #40
0
        void CreateUndefinedChunk(ref IntGrid3 viewGrid, ref IntGrid3 chunkGrid, VertexList<TerrainVertex> vertexList,
			Direction visibleChunkFaces)
        {
            // Faces that are visible due to viewgrid
            Direction sliceFaces = GetGridSliceDirections(ref chunkGrid, ref viewGrid) & visibleChunkFaces;

            // Only faces revealed by viewgrid are visible
            Direction visibleFaces = sliceFaces;

            if (visibleFaces == 0)
                return;

            int sides = (int)visibleFaces;

            FaceTexture tex = Chunk.UndefinedFaceTexture;

            const int occlusion = 0;
            var offset = chunkGrid.Corner1 - this.ChunkOffset;
            var size = new IntVector3(chunkGrid.Size.Width, chunkGrid.Size.Height, chunkGrid.Size.Depth);

            // All faces are revealed by viewgrid
            byte sliceHack = (byte)1;

            if (Chunk.UseBigUnknownChunk)
            {
                /* Note: Using chunk sized quads causes t-junction problems */

                for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1)
                {
                    if ((sides & 1) == 0)
                        continue;

                    var vertices = s_cubeFaceInfo[side].Vertices;

                    IntVector3 v0 = vertices[0] * size + offset;
                    IntVector3 v1 = vertices[1] * size + offset;
                    IntVector3 v2 = vertices[2] * size + offset;
                    IntVector3 v3 = vertices[3] * size + offset;

                    var vd = new TerrainVertex(v0, v1, v2, v3, occlusion, occlusion, occlusion, occlusion, tex, sliceHack);
                    vertexList.Add(vd);
                }
            }
            else
            {
                for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1)
                {
                    if ((sides & 1) == 0)
                        continue;

                    int d0 = side / 2;
                    int d1 = (d0 + 1) % 3;
                    int d2 = (d0 + 2) % 3;

                    bool posFace = (side & 1) == 1;

                    var vertices = s_cubeFaceInfo[side].Vertices;

                    IntVector3 v0 = vertices[0] + offset;
                    IntVector3 v1 = vertices[1] + offset;
                    IntVector3 v2 = vertices[2] + offset;
                    IntVector3 v3 = vertices[3] + offset;

                    var vec1 = new IntVector3();
                    vec1[d1] = 1;

                    var vec2 = new IntVector3();
                    vec2[d2] = 1;

                    for (int v = 0; v < size[d1]; ++v)
                        for (int u = 0; u < size[d2]; ++u)
                        {
                            var off = vec1 * v + vec2 * u;
                            if (posFace)
                                off[d0] = size[d0] - 1;

                            var vd = new TerrainVertex(v0 + off, v1 + off, v2 + off, v3 + off,
                                occlusion, occlusion, occlusion, occlusion, tex, sliceHack);
                            vertexList.Add(vd);
                        }
                }
            }
        }
Пример #41
0
        void GenerateVertices(ref IntGrid3 viewGrid, Direction visibleChunkFaces,
			VertexList<TerrainVertex> terrainVertexList,
			VertexList<SceneryVertex> sceneryVertexList)
        {
            IntGrid3 chunkGrid = viewGrid.Intersect(new IntGrid3(this.ChunkOffset, Chunk.ChunkSize));

            // is the chunk inside frustum, but outside the viewgrid?
            if (chunkGrid.IsNull)
                return;

            if (m_scanned == false)
                ScanForAllEmptyOrUndefined();

            if (this.IsAllEmpty)
                return;

            if (this.IsAllUndefined)
            {
                CreateUndefinedChunk(ref viewGrid, ref chunkGrid, terrainVertexList, visibleChunkFaces);
                return;
            }

            if (m_voxelMap == null)
                FillVoxelMap();

            // Draw from up to down to avoid overdraw
            for (int z = chunkGrid.Z2; z >= chunkGrid.Z1; --z)
            {
                for (int y = chunkGrid.Y1; y <= chunkGrid.Y2; ++y)
                {
                    for (int x = chunkGrid.X1; x <= chunkGrid.X2; ++x)
                    {
                        var p = new IntVector3(x, y, z);

                        var td = m_map.GetTileData(p);

                        if (td.WaterLevel == 0)
                        {
                            if (td.IsEmpty)
                                continue;
                        }

                        var pos = p - this.ChunkOffset;

                        if (td.HasTree)
                        {
                            // Add tree as scenery vertex
                            HandleTree(sceneryVertexList, td, ref pos);
                            continue;
                        }

                        if (td.IsGreen) // XXX
                            continue;

                        var vox = m_voxelMap.Grid[pos.Z, pos.Y, pos.X];

                        HandleVoxel(p, ref vox, ref viewGrid, visibleChunkFaces, terrainVertexList);
                    }
                }
            }
        }
Пример #42
0
        void CreateCube(IntVector3 p, Direction visibleFaces,
			ref FaceTexture baseTexture, ref FaceTexture topTexture, VertexList<TerrainVertex> vertexList,
			Direction sliceFaces)
        {
            var offset = p - this.ChunkOffset;

            int sides = (int)visibleFaces;

            for (int side = 0; side < 6 && sides != 0; ++side, sides >>= 1)
            {
                if ((sides & 1) == 0)
                    continue;

                var vertices = s_cubeFaceInfo[side].Vertices;

                IntVector3 v0, v1, v2, v3;

                v0 = vertices[0] + offset;
                v1 = vertices[1] + offset;
                v2 = vertices[2] + offset;
                v3 = vertices[3] + offset;

                Direction dir = (Direction)(1 << side);

                bool isSliceFace = (sliceFaces & dir) != 0;

                int occ0, occ1, occ2, occ3;

                if (isSliceFace)
                {
                    occ0 = occ1 = occ2 = occ3 = 0;
                }
                else
                {
                    GetOcclusionsForFace(p, (DirectionOrdinal)side,
                        out occ0, out occ1, out occ2, out occ3);
                }

                var tex = side == (int)DirectionOrdinal.PositiveZ ? topTexture : baseTexture;
                byte sliceHack = isSliceFace ? (byte)1 : (byte)0;

                var vd = new TerrainVertex(v0, v1, v2, v3, occ0, occ1, occ2, occ3,
                    tex, sliceHack);
                vertexList.Add(vd);
            }
        }
Пример #43
0
        static void HandleTree(VertexList<SceneryVertex> sceneryVertexList, TileData td, ref IntVector3 pos)
        {
            SymbolID symbol;
            Color color;

            switch (td.ID)
            {
                case TileID.Tree:
                    switch (td.MaterialID)
                    {
                        case MaterialID.Fir:
                            symbol = SymbolID.ConiferousTree;
                            break;

                        case MaterialID.Pine:
                            symbol = SymbolID.ConiferousTree2;
                            break;

                        case MaterialID.Birch:
                            symbol = SymbolID.DeciduousTree;
                            break;

                        case MaterialID.Oak:
                            symbol = SymbolID.DeciduousTree2;
                            break;

                        default:
                            throw new Exception();
                    }
                    break;

                case TileID.Sapling:
                    switch (td.MaterialID)
                    {
                        case MaterialID.Fir:
                            symbol = SymbolID.ConiferousSapling;
                            break;

                        case MaterialID.Pine:
                            symbol = SymbolID.ConiferousSapling2;
                            break;

                        case MaterialID.Birch:
                            symbol = SymbolID.DeciduousSapling;
                            break;

                        case MaterialID.Oak:
                            symbol = SymbolID.DeciduousSapling2;
                            break;

                        default:
                            throw new Exception();
                    }
                    break;

                case TileID.DeadTree:
                    symbol = SymbolID.DeadTree;
                    break;

                default:
                    throw new Exception();
            }

            color = Color.ForestGreen;

            sceneryVertexList.Add(new SceneryVertex(pos.ToVector3(), Color.LightGreen, (uint)symbol));
        }
Пример #44
0
        public void UpdateVertexBuffer(GraphicsDevice device, VertexList<TerrainVertex> vertexList)
        {
            if (vertexList.Count == 0)
                return;

            if (m_vertexBuffer == null || m_vertexBuffer.ElementCount < vertexList.Count)
            {
                if (vertexList.Count > m_maxVertices)
                    m_maxVertices = vertexList.Count;

                //System.Diagnostics.Trace.TraceError("Alloc {0}: {1} verts", this.ChunkOffset, m_maxVertices);

                Utilities.Dispose(ref m_vertexBuffer);
                m_vertexBuffer = Buffer.Vertex.New<TerrainVertex>(device, m_maxVertices);
            }

            m_vertexBuffer.SetData(vertexList.Data, 0, vertexList.Count);
        }
Пример #45
0
        public void UpdateSceneryVertexBuffer(GraphicsDevice device, VertexList<SceneryVertex> vertexList)
        {
            if (vertexList.Count == 0)
                return;

            if (m_sceneryVertexBuffer == null || m_sceneryVertexBuffer.ElementCount < vertexList.Count)
            {
                Utilities.Dispose(ref m_sceneryVertexBuffer);
                m_sceneryVertexBuffer = Buffer.Vertex.New<SceneryVertex>(device, vertexList.Data.Length);
            }

            m_sceneryVertexBuffer.SetData(vertexList.Data, 0, vertexList.Count);
        }
Пример #46
0
        public void GenerateVertices(ref IntGrid3 viewGrid, IntVector3 cameraChunkPos,
			VertexList<TerrainVertex> terrainVertexList, VertexList<SceneryVertex> sceneryVertexList)
        {
            terrainVertexList.Clear();
            sceneryVertexList.Clear();

            var diff = cameraChunkPos - this.ChunkPosition;

            Direction visibleChunkFaces = 0;
            if (diff.X >= 0)
                visibleChunkFaces |= Direction.PositiveX;
            if (diff.X <= 0)
                visibleChunkFaces |= Direction.NegativeX;
            if (diff.Y >= 0)
                visibleChunkFaces |= Direction.PositiveY;
            if (diff.Y <= 0)
                visibleChunkFaces |= Direction.NegativeY;
            if (diff.Z >= 0)
                visibleChunkFaces |= Direction.PositiveZ;
            if (diff.Z <= 0)
                visibleChunkFaces |= Direction.NegativeZ;

            GenerateVertices(ref viewGrid, visibleChunkFaces, terrainVertexList, sceneryVertexList);

            this.VertexCount = terrainVertexList.Count;
            this.SceneryVertexCount = sceneryVertexList.Count;
        }