示例#1
0
        /*
         * Recieve an AJAX command to select an operation and generate the desired shape
         */
        public ContentResult P0830_SelectCSG(string operation)
        {
            List <CSGPolygon> PolygonList = null;
            bool BothSides = false;

            switch (operation)
            {
            case "union":
                PolygonList = CSG.Sphere().union(CSG.Cube()).toPolygons();
                break;

            case "intersection":
                PolygonList = CSG.Sphere().intersect(CSG.Cube()).toPolygons();
                break;

            case "subtraction":
                PolygonList = CSG.Sphere().subtract(CSG.Cube()).toPolygons();
                BothSides   = true;
                break;

            case "subtraction2":
                PolygonList = CSG.Cube().subtract(CSG.Sphere()).toPolygons();
                BothSides   = true;
                break;
            }

            /*
             * Create a JSON object containing the 3D shape to send to the browser
             */
            JObject JShape = new JObject();

            /*
             * The design of the JSON object is an array of shapes. In our case we only send one
             */
            JArray shapeArray = new JArray();

            JShape.Add("ShapeList", shapeArray);

            JObject oShape = AddPolygonList(CSG.fromTriangles(PolygonList), BothSides);

            shapeArray.Add(oShape);

            return(Content(JShape.ToString()));
        }