Exemple #1
0
 public static RealtimeCSG.Plane[] TransformCopy(RealtimeCSG.Plane[] planes, Matrix by)
 {
     var r = new RealtimeCSG.Plane[planes.Length];
     for (int i = 0; i < planes.Length; ++i)
         r[i] = TransformCopy(planes[i], by);
     return r;
 }
Exemple #2
0
        public static RealtimeCSG.Plane[] BevelCopy(RealtimeCSG.Plane[] planes, float bevelSize)
        {
            var r = new List<RealtimeCSG.Plane>();
            r.AddRange(planes);

            for (int a = 0; a < planes.Length; ++a)
                for (int b = a + 1; b < planes.Length; ++b)
                {
                    var va = new Vector3(planes[a].A, planes[a].B, planes[a].C);
                    var vb = new Vector3(planes[b].A, planes[b].B, planes[b].C);

                    var nv = va + vb;
                    nv.Normalize();
                    if (!IsValid(nv)) continue;

                    va.Normalize();
                    vb.Normalize();
                    float DotProduct = Vector3.Dot(va, vb);
                    DotProduct = MathHelper.Clamp(DotProduct, -1.0f, 1.0f);

                    var angle = (float)System.Math.Acos(DotProduct);
                    var cos = (float)System.Math.Cos(angle / 2.0f);
                    var nd = planes[a].D / cos;
                    nd -= bevelSize;

                    if (nd < 0) continue;
                    r.Add(new RealtimeCSG.Plane(nv.X, nv.Y, nv.Z, nd));
                }

            return r.ToArray();
        }
Exemple #3
0
 public static RealtimeCSG.Plane TransformCopy(RealtimeCSG.Plane plane, Matrix by)
 {
     var lv = new Vector4(plane.A, plane.B, plane.C, plane.D);
     lv = Vector4.Transform(lv, by);
     var lv3 = new Vector3(lv.X, lv.Y, lv.Z);
     lv.W *= lv3.Length();
     lv3.Normalize();
     lv.X = lv3.X;
     lv.Y = lv3.Y;
     lv.Z = lv3.Z;
     return new RealtimeCSG.Plane(lv.X, lv.Y, lv.Z, lv.W);
 }
Exemple #4
0
        public static Mesh ConvertToMesh(RealtimeCSG.CSGMesh csg)
        {
            var result = new Mesh();
            result.verticies = new VertexPositionNormalTexture[csg.Vertices.Count];
            for (int i = 0; i < csg.Vertices.Count; ++i)
                result.verticies[i].Position = new Vector3(csg.Vertices[i].X, csg.Vertices[i].Y, csg.Vertices[i].Z);

            var indicies = new List<short>();
            foreach (var polygon in csg.Polygons)
            {
                if (polygon.Visible && polygon.FirstIndex >= 0)
                {
                    var indexList = new List<short>();
                    var start = csg.Edges[polygon.FirstIndex];
                    indexList.Add(start.VertexIndex);
                    var current = csg.Edges[start.NextIndex];
                    while (current != start)
                    {
                        indexList.Add(current.VertexIndex);
                        current = csg.Edges[current.NextIndex];
                    }

                    for (var index = 0; index < indexList.Count - 2; ++index)
                    {

                        indicies.Add(indexList[0]);

                        if (polygon.Category == RealtimeCSG.PolygonCategory.Aligned)
                        {
                            indicies.Add(indexList[index + 2]);
                            indicies.Add(indexList[index + 1]);
                        }
                        else
                        {
                            indicies.Add(indexList[index + 1]);
                            indicies.Add(indexList[index + 2]);
                        }
                    }
                }
            }

            result.indicies = indicies.ToArray();

            return result;
        }
Exemple #5
0
        private void drawCsg(RenderContext context, RealtimeCSG.CSGNode node)
        {
            if (node.NodeType == RealtimeCSG.CSGNodeType.Brush)
            {
                if (node.cachedRenderMesh == null)
                    node.cachedRenderMesh = Geo.Gen.FacetCopy(Geo.Csg.ConvertToMesh(node.cachedMesh));
                if (node.TextureProjection != null)
                    node.TextureProjection.Project(node.cachedRenderMesh, node.WorldTransformation);

                if (node.Texture == null) context.Texture = context.White;
                else context.Texture = node.Texture;
                context.Color = node.Color;
                context.ApplyChanges();
                context.Draw(node.cachedRenderMesh);
            }
            if (node.NodeType != RealtimeCSG.CSGNodeType.Brush)
            {
                drawCsg(context, node.Left);
                drawCsg(context, node.Right);
            }
        }
Exemple #6
0
 public CsgMeshNode(RealtimeCSG.CSGNode csgRoot, Common.Euler Orientation = null)
 {
     this.csgRoot = csgRoot;
     this.Orientation = Orientation;
     if (this.Orientation == null) this.Orientation = new Common.Euler();
 }
 public PlanarProjection(RealtimeCSG.Plane plane, Vector3 upHint, float Scale)
 {
     this.plane = plane;
     this.upHint = upHint;
     this.Scale = Scale;
 }