Ejemplo n.º 1
0
        // Create a new vertex between this vertex and `other` by linearly
        // interpolating all properties using a parameter of `t`. Subclasses should
        // override this to interpolate additional properties.
        public static csgjs_vertex interpolate(csgjs_vertex  a,  csgjs_vertex b, float t)
        {
	        csgjs_vertex ret = new csgjs_vertex();
            ret.pos = csgjs_vector.lerp(a.pos, b.pos, t);
            ret.normal = csgjs_vector.lerp(a.normal, b.normal, t);
            ret.uv = csgjs_vector.lerp(a.uv, b.uv, t);
	        return ret;
        }
Ejemplo n.º 2
0
 public csgjs_vertex clone() 
 {
     csgjs_vertex c = new csgjs_vertex();
     c.pos = pos.clone();
     c.normal = normal.clone();
     c.uv = uv.clone();
     return c;
 }
Ejemplo n.º 3
0
        // Create a new vertex between this vertex and `other` by linearly
        // interpolating all properties using a parameter of `t`. Subclasses should
        // override this to interpolate additional properties.
        public static csgjs_vertex interpolate(csgjs_vertex a, csgjs_vertex b, float t)
        {
            csgjs_vertex ret = new csgjs_vertex();

            ret.pos    = csgjs_vector.lerp(a.pos, b.pos, t);
            ret.normal = csgjs_vector.lerp(a.normal, b.normal, t);
            ret.uv     = csgjs_vector.lerp(a.uv, b.uv, t);
            return(ret);
        }
Ejemplo n.º 4
0
        public csgjs_vertex clone()
        {
            csgjs_vertex c = new csgjs_vertex();

            c.pos    = pos.clone();
            c.normal = normal.clone();
            c.uv     = uv.clone();
            return(c);
        }
Ejemplo n.º 5
0
        public static List <csgjs_polygon> csgjs_modelToPolygons(csgjs_model model)
        {
            List <csgjs_polygon> list = new List <csgjs_polygon>();

            for (int i = 0; i < model.indices.Count; i += 3)
            {
                List <csgjs_vertex> triangle = new List <csgjs_vertex>();
                for (int j = 0; j < 3; j++)
                {
                    csgjs_vertex v = model.vertices[model.indices[i + j]];
                    triangle.Add(v);            //.push_back(v);
                }
                //list.push_back(csgjs_polygon(triangle));
                list.Add(new csgjs_polygon(triangle));
            }
            return(list);
        }
Ejemplo n.º 6
0
        // Split `polygon` by this plane if needed, then put the polygon or polygon
        // fragments in the appropriate lists. Coplanar polygons go into either
        // `coplanarFront` or `coplanarBack` depending on their orientation with
        // respect to this plane. Polygons in front or in back of this plane go into
        // either `front` or `back`.
        public void splitPolygon(csgjs_polygon polygon, List <csgjs_polygon> coplanarFront, List <csgjs_polygon> coplanarBack, ref List <csgjs_polygon> front, ref List <csgjs_polygon> back)
        {
            // Classify each point as well as the entire polygon into one of the above
            // four classes.
            int        polygonType = 0;
            List <int> types       = new List <int>();

            for (int i = 0; i < polygon.vertices.Count; i++)
            {
                float t    = csgjs_vector.dot(normal, polygon.vertices[i].pos) - w;
                int   type = (t < -CSG.csgjs_EPSILON) ? BACK : ((t > CSG.csgjs_EPSILON) ? FRONT : COPLANAR);
                polygonType |= type;
                types.Add(type);
            }

            // Put the polygon in the correct list, splitting it when necessary.
            switch (polygonType)
            {
            case COPLANAR:
            {
                if (csgjs_vector.dot(normal, polygon.plane.normal) > 0)
                {
                    coplanarFront.Add(polygon);
                }
                else
                {
                    coplanarBack.Add(polygon);
                }
                break;
            }

            case FRONT:
            {
                front.Add(polygon);
                break;
            }

            case BACK:
            {
                back.Add(polygon);
                break;
            }

            case SPANNING:
            {
                List <csgjs_vertex> f = new List <csgjs_vertex>();
                List <csgjs_vertex> b = new List <csgjs_vertex>();
                for (int i = 0; i < polygon.vertices.Count; i++)
                {
                    int          j = (i + 1) % polygon.vertices.Count;
                    int          ti = types[i], tj = types[j];
                    csgjs_vertex vi = polygon.vertices[i], vj = polygon.vertices[j];
                    if (ti != BACK)
                    {
                        f.Add(vi);
                    }
                    if (ti != FRONT)
                    {
                        b.Add(vi);
                    }
                    if ((ti | tj) == SPANNING)
                    {
                        float        t = (w - csgjs_vector.dot(normal, vi.pos)) / csgjs_vector.dot(normal, vj.pos - vi.pos);
                        csgjs_vertex v = csgjs_vertex.interpolate(vi, vj, t);
                        f.Add(v);
                        b.Add(v);
                    }
                }
                if (f.Count >= 3)
                {
                    front.Add(new csgjs_polygon(f));
                }

                if (b.Count >= 3)
                {
                    back.Add(new csgjs_polygon(b));
                }
                break;
            }
            }
        }
Ejemplo n.º 7
0
 // Invert all orientation-specific data (e.g. vertex normal). Called when the
 // orientation of a polygon is flipped.
 public static csgjs_vertex flip(csgjs_vertex v)
 {
     v.normal = csgjs_vector.negate(v.normal);
     return(v);
 }
Ejemplo n.º 8
0
        // Invert all orientation-specific data (e.g. vertex normal). Called when the
        // orientation of a polygon is flipped.
        public static csgjs_vertex flip(csgjs_vertex v) 
        {
            v.normal = csgjs_vector.negate(v.normal); 
	        return v; 
        }