예제 #1
0
파일: CSG.cs 프로젝트: valera6285/olde
        public CSG Clone()
        {
            CSG csg = new CSG();

            csg.polygons = this.polygons.Clone <Polygon>(); // TODO should clone?
            return(csg);
        }
예제 #2
0
파일: CSG.cs 프로젝트: valera6285/olde
        public static CSG FromPolygons(Polygon[] polygons)
        {
            CSG csg = new CSG();

            csg.polygons = polygons;
            return(csg);
        }
예제 #3
0
파일: CSG.cs 프로젝트: valera6285/olde
            public CSG Generate(Vector3 start, Vector3 end, float radius, int slices)
            {
                this.start  = start;
                this.end    = end;
                this.radius = radius;

                ray   = end - start;
                axisZ = ray.normalized;
                bool isY = (Mathf.Abs(axisZ.y) > 0.5f);

                axisX = Vector3.Cross(new Vector3((isY ? 1 : 0), (isY ? 0 : 1), 0), axisZ).normalized;
                axisY = Vector3.Cross(axisX, axisZ).normalized;
                Vertex startVertex = new Vertex(start, axisZ * -1, Vector2.zero);
                Vertex endVertex   = new Vertex(end, axisZ.normalized, Vector2.zero);

                List <Polygon> polygons = new List <Polygon>();

                for (int i = 0; i < slices; i++)
                {
                    float t0 = (float)i / slices;
                    float t1 = (float)(i + 1) / slices;

                    polygons.Add(new Polygon(new Vertex[] { startVertex, Point(0, t0, -1), Point(0, t1, -1) }));
                    polygons.Add(new Polygon(new Vertex[] { Point(0, t1, 0), Point(0, t0, 0), Point(1, t0, 0), Point(1, t1, 0) }));
                    polygons.Add(new Polygon(new Vertex[] { endVertex, Point(1, t1, 1), Point(1, t0, 1) }));
                }
                return(CSG.FromPolygons(polygons.ToArray()));
            }
예제 #4
0
파일: CSG.cs 프로젝트: valera6285/olde
            public CSG Generate(Vector3 center, float radius, int slices, int stacks)
            {
                this.center = center;
                this.radius = radius;
                for (float i = 0; i < slices; i++)
                {
                    for (float j = 0; j < stacks; j++)
                    {
                        vertices = new List <Vertex>();
                        Vertex(i / slices, j / stacks);
                        if (j > 0)
                        {
                            Vertex((i + 1) / slices, j / stacks);
                        }
                        if (j < stacks - 1)
                        {
                            Vertex((i + 1) / slices, (j + 1) / stacks);
                        }
                        Vertex(i / slices, (j + 1) / stacks);

                        for (int vi = 0; vi < vertices.Count; vi++)
                        {
                            //Debug.Log(vertices[vi].Position + " " + vertices[vi].Normal);
                        }

                        polygons.Add(new Polygon(vertices.ToArray()));
                    }
                }

                return(CSG.FromPolygons(polygons.ToArray()));
            }
예제 #5
0
파일: CSG.cs 프로젝트: valera6285/olde
            public CSG Generate(Vector3 center, Vector3 radius, Quaternion rotation)
            {
                Polygon[] polygons = new Polygon[6];

                polygons[0] = new Polygon(new Vertex[] {
                    new Vertex(new Vector3(-1, -1, -1).Multiply(radius), new Vector3(-1, 0, 0), new Vector2(radius.z * 2, 0)),
                    new Vertex(new Vector3(-1, -1, 1).Multiply(radius), new Vector3(-1, 0, 0), new Vector2(0, 0)),
                    new Vertex(new Vector3(-1, 1, 1).Multiply(radius), new Vector3(-1, 0, 0), new Vector2(0, radius.y * 2)),
                    new Vertex(new Vector3(-1, 1, -1).Multiply(radius), new Vector3(-1, 0, 0), new Vector2(radius.z * 2, radius.y * 2)),
                });

                polygons[1] = new Polygon(new Vertex[] {
                    new Vertex(new Vector3(1, -1, -1).Multiply(radius), new Vector3(1, 0, 0), new Vector2(radius.y * 2, 0)),
                    new Vertex(new Vector3(1, 1, -1).Multiply(radius), new Vector3(1, 0, 0), new Vector2(0, 0)),
                    new Vertex(new Vector3(1, 1, 1).Multiply(radius), new Vector3(1, 0, 0), new Vector2(0, radius.z * 2)),
                    new Vertex(new Vector3(1, -1, 1).Multiply(radius), new Vector3(1, 0, 0), new Vector2(radius.y * 2, radius.z * 2)),
                });

                polygons[2] = new Polygon(new Vertex[] {
                    new Vertex(new Vector3(-1, -1, -1).Multiply(radius), new Vector3(0, -1, 0), new Vector2(radius.x * 2, 0)),
                    new Vertex(new Vector3(1, -1, -1).Multiply(radius), new Vector3(0, -1, 0), new Vector2(0, 0)),
                    new Vertex(new Vector3(1, -1, 1).Multiply(radius), new Vector3(0, -1, 0), new Vector2(0, radius.z * 2)),
                    new Vertex(new Vector3(-1, -1, 1).Multiply(radius), new Vector3(0, -1, 0), new Vector2(radius.x * 2, radius.z * 2)),
                });

                polygons[3] = new Polygon(new Vertex[] {
                    new Vertex(new Vector3(-1, 1, -1).Multiply(radius), new Vector3(0, 1, 0), new Vector2(radius.z * 2, 0)),
                    new Vertex(new Vector3(-1, 1, 1).Multiply(radius), new Vector3(0, 1, 0), new Vector2(0, 0)),
                    new Vertex(new Vector3(1, 1, 1).Multiply(radius), new Vector3(0, 1, 0), new Vector2(0, radius.x * 2)),
                    new Vertex(new Vector3(1, 1, -1).Multiply(radius), new Vector3(0, 1, 0), new Vector2(radius.z * 2, radius.x * 2)),
                });

                polygons[4] = new Polygon(new Vertex[] {
                    new Vertex(new Vector3(-1, -1, -1).Multiply(radius), new Vector3(0, 0, -1), new Vector2(radius.y * 2, 0)),
                    new Vertex(new Vector3(-1, 1, -1).Multiply(radius), new Vector3(0, 0, -1), new Vector2(0, 0)),
                    new Vertex(new Vector3(1, 1, -1).Multiply(radius), new Vector3(0, 0, -1), new Vector2(0, radius.x * 2)),
                    new Vertex(new Vector3(1, -1, -1).Multiply(radius), new Vector3(0, 0, -1), new Vector2(radius.y * 2, radius.x * 2)),
                });

                polygons[5] = new Polygon(new Vertex[] {
                    new Vertex(new Vector3(-1, -1, 1).Multiply(radius), new Vector3(0, 0, 1), new Vector2(radius.x * 2, 0)),
                    new Vertex(new Vector3(1, -1, 1).Multiply(radius), new Vector3(0, 0, 1), new Vector2(0, 0)),
                    new Vertex(new Vector3(1, 1, 1).Multiply(radius), new Vector3(0, 0, 1), new Vector2(0, radius.y * 2)),
                    new Vertex(new Vector3(-1, 1, 1).Multiply(radius), new Vector3(0, 0, 1), new Vector2(radius.x * 2, radius.y * 2)),
                });

                for (int i = 0; i < polygons.Length; i++)
                {
                    for (int j = 0; j < polygons[i].Vertices.Length; j++)
                    {
                        polygons[i].Vertices[j].Position = rotation * polygons[i].Vertices[j].Position + center;
                        polygons[i].Vertices[j].Normal   = rotation * polygons[i].Vertices[j].Normal;
                    }
                }

                return(CSG.FromPolygons(polygons));
            }
예제 #6
0
파일: CSG.cs 프로젝트: valera6285/olde
        public CSG Inverse()
        {
            CSG csg = this.Clone();

            for (int i = 0; i < csg.polygons.Length; i++)
            {
                csg.polygons[i].Flip();
            }
            return(csg);
        }
예제 #7
0
파일: CSG.cs 프로젝트: Avatarchik/olde
        public CSG Intersect(CSG csg)
        {
            Node a = new Node(this.Clone().polygons);
            Node b = new Node(csg.Clone().polygons);

            a.Invert();
            b.ClipTo(a);
            b.Invert();
            a.ClipTo(b);
            b.ClipTo(a);
            a.Build(b.AllPolygons.ToList());
            a.Invert();
            return CSG.FromPolygons(a.AllPolygons);
        }
예제 #8
0
파일: CSG.cs 프로젝트: valera6285/olde
        public CSG Intersect(CSG csg)
        {
            Node a = new Node(this.Clone().polygons);
            Node b = new Node(csg.Clone().polygons);

            a.Invert();
            b.ClipTo(a);
            b.Invert();
            a.ClipTo(b);
            b.ClipTo(a);
            a.Build(b.AllPolygons.ToList());
            a.Invert();
            return(CSG.FromPolygons(a.AllPolygons));
        }
예제 #9
0
파일: CSG.cs 프로젝트: Avatarchik/olde
 public CSG Clone()
 {
     CSG csg = new CSG();
     csg.polygons = this.polygons.Clone<Polygon>(); // TODO should clone?
     return csg;
 }
예제 #10
0
파일: CSG.cs 프로젝트: Avatarchik/olde
 public static CSG FromPolygons(Polygon[] polygons)
 {
     CSG csg = new CSG();
     csg.polygons = polygons;
     return csg;
 }