Example #1
0
        private static CsgObject CutUpASphereHybrid()
        {
            Sphere     mainSphere   = new Sphere(GimmeABoundedDouble(_smallest, _largest));
            Difference d            = new Difference(mainSphere);
            int        howManyBumps = _rand.Next(5) + 2;

            for (int i = 0; i < howManyBumps; i++)
            {
                Vector3   direction = GimmeADirection();
                double    radius    = GimmeABoundedDouble(0.25, 0.75) * mainSphere.Radius;
                Sphere    bump      = new Sphere(radius);
                Translate t         = new Translate(bump, mainSphere.GetCenter() + direction * mainSphere.Radius);
                d.AddToSubtractList(t);

                double doOpposite  = GimmeABoundedDouble(0, 1);
                double doOneAxis   = GimmeABoundedDouble(0, 1);
                double doOtherAxis = GimmeABoundedDouble(0, 1);

                Vector3 orthogonalOne = CrossProduct(direction, new Vector3(direction.z, direction.x, direction.y));
                Vector3 orthogonalTwo = CrossProduct(direction, orthogonalOne);

                if (doOneAxis >= 0.66)
                {
                    double    diff   = GimmeABoundedDouble(0, 1);
                    Sphere    oneOne = new Sphere(radius);
                    Sphere    oneTwo = new Sphere(radius);
                    Translate tOne   = new Translate(oneOne, mainSphere.GetCenter() + orthogonalOne * mainSphere.Radius);
                    Translate tTwo   = new Translate(oneOne, mainSphere.GetCenter() - orthogonalOne * mainSphere.Radius);
                    d.AddToSubtractList(tOne);
                    d.AddToSubtractList(tTwo);
                }
                if (doOtherAxis >= 0.66)
                {
                    double    diff   = GimmeABoundedDouble(0, 1);
                    Sphere    oneOne = new Sphere(radius);
                    Sphere    oneTwo = new Sphere(radius);
                    Translate tOne   = new Translate(oneOne, mainSphere.GetCenter() + orthogonalTwo * mainSphere.Radius);
                    Translate tTwo   = new Translate(oneOne, mainSphere.GetCenter() - orthogonalTwo * mainSphere.Radius);
                    d.AddToSubtractList(tOne);
                    d.AddToSubtractList(tTwo);
                }
            }
            return(d);
        }
Example #2
0
        private static CsgObject CutUpASphereRegular()
        {
            Sphere s = new Sphere(GimmeABoundedDouble(100, 200));

            List <Vector3> compassPoints = GimmeSphereCompassPoints(s);

            Difference d = new Difference(s);

            foreach (var point in compassPoints)
            {
                Sphere    cutItOut = new Sphere(GimmeABoundedDouble(40, 90));
                Translate t        = new Translate(cutItOut, point);
                d.AddToSubtractList(t);
            }

            return(d);
        }
Example #3
0
        private static CsgObject CutUpASphereRandom()
        {
            Sphere     mainSphere   = new Sphere(GimmeABoundedDouble(_smallest, _largest));
            Difference d            = new Difference(mainSphere);
            int        howManyBumps = _rand.Next(20);

            //size range is 0.25-0.75 of main sphere's radius
            //double howMuchToUse = GimmeABoundedDouble(0.1, 1);
            for (int i = 0; i < howManyBumps; i++)
            {
                Vector3   direction = GimmeADirection();
                double    radius    = GimmeABoundedDouble(0.25, 0.65) * mainSphere.Radius;
                Sphere    bump      = new Sphere(radius);
                Translate t         = new Translate(bump, mainSphere.GetCenter() + direction * mainSphere.Radius);
                d.AddToSubtractList(t);
            }
            return(d);
        }
Example #4
0
        private static CsgObject HollowSphereWithHoles(double radius, double thickness)
        {
            Sphere     outer = new Sphere(radius);
            Sphere     inner = new Sphere(radius - thickness);
            Difference d     = new Difference(outer, inner);

            int howManyHoles = _rand.Next(10, 30);

            for (int i = 0; i < howManyHoles; i++)
            {
                Vector3 where = GimmeADirection();
                double    holeRadius = radius * 0.2 + _rand.NextDouble() * radius * 0.25;
                Sphere    holeSphere = new Sphere(holeRadius);
                Translate t          = new Translate(holeSphere, where * radius);
                //Difference holeDiff = new Difference(d, t);
                //d = holeDiff;
                d.AddToSubtractList(t);
            }

            return(d);
        }
Example #5
0
        //private static CsgObject AtomDiagram()
        //{

        //}

        private static CsgObject SingleComposition()
        {
            //TODO: make some bounds on how crazy or tame this goes with relative sizes...IE does the main thing
            //get more or less emphasis?
            CsgObject returnMe = null;
            Union     u        = new Union();

            CsgObject box = new Box(new Vector3(150, 150, 150));

            int whichOne                 = _rand.Next(2);
            List <CsgObject> unions      = new List <CsgObject>();
            List <CsgObject> differences = new List <CsgObject>();

            //TODO: Order prolly matters here? Maybe? So right now we're gonna build lists, do unions, then
            //do differences. Maybe later we should do it in whatever order they happen in, or at least
            //consider it...

            //foreach (Vector3 corner in )
            //{
            //int which = _rand.Next(2);
            //switch (which)
            //{
            //	case 0:
            //		solid = new Box(new Vector3(150, 150, 150));
            //		break;
            //	case 1:
            //		solid = new Sphere(150);
            //		break;
            //	default:
            //		solid = new Box(new Vector3(150, 150, 150));
            //		break;
            //}
            //}

            u.Add(box as CsgObject);

            double averageSize = (box.XSize + box.YSize + box.ZSize) / 3.0;

            List <Vector3> boxVertexes = new List <Vector3>();

            Vector3 boxCenter = box.GetCenter();
            double  halfX     = box.XSize / 2;
            double  halfY     = box.YSize / 2;
            double  halfZ     = box.ZSize / 2;

            for (int i = 0; i < 2; i++)
            {
                double x = -1 * halfX + i * box.XSize;
                for (int j = 0; j < 2; j++)
                {
                    double y = -1 * halfY + j * box.YSize;
                    for (int k = 0; k < 2; k++)
                    {
                        double  z         = -1 * halfZ + k * box.ZSize;
                        Vector3 newVertex = new Vector3(x, y, z);
                        boxVertexes.Add(newVertex);
                    }
                }
            }

            foreach (Vector3 attachPoint in boxVertexes)
            {
                CsgObject joinThis = null;
                double    doWhat   = _rand.NextDouble();
                if (doWhat < 0.33)
                {
                    joinThis = GimmeAPrimitive(GimmeABoundedDouble(averageSize * 0.25, averageSize * 0.75), attachPoint);
                    differences.Add(joinThis);
                }
                else if (doWhat < 0.85)
                {
                    joinThis = GimmeAPrimitive(GimmeABoundedDouble(averageSize * 0.25, averageSize * 0.75), attachPoint);
                    unions.Add(joinThis);
                }
                else
                {
                    joinThis = null;
                }
            }

            foreach (var thing in unions)
            {
                u.Add(thing);
                returnMe = u;
            }
            if (differences.Count > 0)
            {
                Difference d = new Difference(returnMe, differences[0]);
                for (int i = 1; i < differences.Count; i++)
                {
                    d.AddToSubtractList(differences[i]);
                }
                returnMe = d;
            }



            return(returnMe);
        }
Example #6
0
        private static void DoABunchOneMethod(int howMany, Func <CsgObject> method)
        {
            for (int i = 0; i < howMany; i++)
            {
                //Console.Out.WriteLine(i);
                try
                {
                    CsgObject theThing    = null;
                    double    moreThanOne = _rand.NextDouble();
                    if (moreThanOne >= 0)
                    {
                        Union            u = new Union();
                        int              howManyMethods = _rand.Next(5);
                        List <CsgObject> unions         = new List <CsgObject>();
                        List <CsgObject> differences    = new List <CsgObject>();
                        for (int j = 0; j < howManyMethods; j++)
                        {
                            double addOrRemove = _rand.NextDouble();
                            if (addOrRemove <= 0.75 || j == 0)
                            {
                                var addMe = method();
                                unions.Add(addMe);
                            }
                            else
                            {
                                var diffMe = method();
                                differences.Add(diffMe);
                            }
                        }
                        foreach (var thing in unions)
                        {
                            u.Add(thing);
                        }
                        theThing = u;
                        if (differences.Count > 0)
                        {
                            Difference d = new Difference(theThing, differences[0]);
                            for (int j = 1; j < differences.Count; j++)
                            {
                                d.AddToSubtractList(differences[j]);
                            }
                            theThing = d;
                        }
                    }
                    else
                    {
                        theThing = method();
                    }

                    DateTime now = DateTime.Now;
                    if (theThing == null)
                    {
                        theThing = method();
                    }
                    //Console.Out.WriteLine("Writing file {0}", i);
                    //OpenSCadOutput.Save(theThing, string.Format("{0}.scad", now.ToString("yyMMddHHmmssff")));
                    MoveAndScaleAndWriteToFile(theThing, string.Format("{0}.scad", now.ToString("yyMMddHHmmssff")));
                }
                catch (Exception e)
                {
                    //DON'T CARE!!! HAHAHA
                    Console.Out.WriteLine("EXCEPTION: {0}", e.Message);
                }
            }
        }
Example #7
0
        private static void DoABunchSpheresOnly(int howMany)
        {
            for (int i = 0; i < howMany; i++)
            {
                //Console.Out.WriteLine(i);
                try
                {
                    CsgObject theThing    = null;
                    double    moreThanOne = _rand.NextDouble();
                    if (moreThanOne >= 0)
                    {
                        Union            u = new Union();
                        int              howManyMethods = _rand.Next(5);
                        List <CsgObject> unions         = new List <CsgObject>();
                        List <CsgObject> differences    = new List <CsgObject>();
                        for (int j = 0; j < howManyMethods; j++)
                        {
                            double addOrRemove = _rand.NextDouble();
                            if (addOrRemove <= 0.75 || j == 0)
                            {
                                var addMe = GimmeACompositionSpheresOnly();
                                unions.Add(addMe);
                            }
                            else
                            {
                                var diffMe = GimmeACompositionSpheresOnly();
                                differences.Add(diffMe);
                            }
                        }
                        foreach (var thing in unions)
                        {
                            u.Add(thing);
                        }
                        theThing = u;
                        if (differences.Count > 0)
                        {
                            Difference d = new Difference(theThing, differences[0]);
                            for (int j = 1; j < differences.Count; j++)
                            {
                                d.AddToSubtractList(differences[j]);
                            }
                            theThing = d;
                        }
                    }
                    else
                    {
                        theThing = GimmeACompositionSpheresOnly();
                    }

                    DateTime now = DateTime.Now;
                    if (theThing == null)
                    {
                        theThing = GimmeACompositionSpheresOnly();
                    }

                    var symmetry = _rand.NextDouble();
                    if (symmetry >= _symmetryLikelihood)
                    {
                        theThing = MakeThisSymmetric(theThing);
                    }

                    //Console.Out.WriteLine("Writing file {0}", i);
                    MoveAndScaleAndWriteToFile(theThing, string.Format("{0}.scad", "image-" + i));
                }
                catch (Exception e)
                {
                    //DON'T CARE!!! HAHAHA
                    Console.Out.WriteLine("EXCEPTION: {0}", e.Message);
                }
            }
        }