示例#1
0
        private void Ring()
        {
            var    csgRing       = new CsgDifference().Rotate(rx: Pi / 2);
            var    outerRing     = new Cylinder(-0.01, 0.01, true);
            double ringThickness = 0.05;
            var    innerRing     = new Cylinder(-0.011, 0.011, true).Scale(sx: 1 - ringThickness, sz: 1 - ringThickness);

            csgRing.Init(outerRing, innerRing);

            double   delta   = 0.005;
            ColorMap ringMap = new ColorMap(
                (0, White / 8),
                (0.3 - delta, White / 8),
                (0.3, Cyan / 4),
                (0.3 + delta, White / 8),
                (0.5 - delta, White / 8),
                (0.5, Blue / 2),
                (0.5 + delta, White / 8),
                (1, Blue / 2)
                );
            double perlinScale = 15;
            var    ringPattern = new PerlinPattern(ringMap, 8)
                                 .Translate(tx: 1 / perlinScale, tz: 1 / perlinScale)
                                 .Scale(sx: perlinScale, sz: 10 * perlinScale, sy: perlinScale);

            csgRing.Material = new Material(ringPattern, ambient: 1, diffuse: 2, reflective: 1);

            Add(csgRing);
        }
示例#2
0
        public override void InitWorld()
        {
            DefaultFloor();
            Light(0, 4, 0);
            Light(5, 15, -5, Color.White);

            var cube            = new Cube();
            var sphere          = new Sphere().Scale(1.4);
            var csgIntersection = new CsgIntersection(sphere, cube);

            var cyl1 = new Cylinder(-4, 4)
            {
                Material = new Material(Red)
            }.Scale(sx: 0.75, sz: 0.75);
            var cyl2 = new Cylinder(-4, 4)
            {
                Material = new Material(Green)
            }.Scale(sx: 0.75, sz: 0.75).Rotate(rx: Pi / 2);
            var cyl3 = new Cylinder(-4, 4)
            {
                Material = new Material(Blue)
            }.Scale(sx: 0.75, sz: 0.75).Rotate(rz: Pi / 2);
            var csgUnion = new CsgUnion(cyl1, new CsgUnion(cyl2, cyl3));

            var csgDifference = new CsgDifference(csgIntersection, csgUnion);

            csgDifference.Translate(ty: 1).Rotate(ry: Pi / 4);
            Add(csgDifference);
        }
示例#3
0
        public void CsgDifferenceTest()
        {
            var csgDifference = new CsgDifference(sphere).Add(box);

            Check.That(csgDifference.Type).IsEqualTo("difference");
            var povCode = csgDifference.ToPovCode();

            Check.That(povCode).IsEqualTo("difference {\n sphere {\n < 0, 0, 0>, 1\n}\n object {\n MyBox\n}\n}");
        }
示例#4
0
        public override void InitWorld()
        {
            DefaultFloor().Translate(ty: -1.5);
            Light(-1, 5, -5, Color.White / 2);
            Light(-5, 5, -1, Color.White / 4);
            Light(5, 5, -1, Color.White / 6);

            var sponge2 = new MengerSponge(4);
            var cube    = new Cube().Scale(sx: 2, sz: 2).Translate(ty: 1);
            var diff    = new CsgDifference(sponge2, cube);

            Add(diff);
        }
示例#5
0
        public DroidBody(Pigment mainPigment, Pigment decoPigmentMajor, Pigment decoPigmentMinor)
        {
            // Main Body
            Add(new Sphere()
            {
                Radius = rBody
            });

            // Sides
            var ring = new CsgDifference(
                new Cylinder {
                BasePoint = _Zero, CapPoint = rBody * _Z, Radius = rOutterSide
            }
                )
                       .Add(new Cylinder {
                BasePoint = _Zero, CapPoint = (rBody + 0.1) * _Z, Radius = rInnerSide
            })
            ;

            Local(nameof(ring), ring);
            var bidule = new Prism {
                Height1 = 0, Height2 = rBody
            }.Add(-0.1, 0).Add(-0.05, 0.2).Add(0.05, 0.2).Add(0.1, 0).TranslateZ(-rInnerSide).RotateX(90);

            Local(nameof(bidule), bidule);
            var side = new CsgUnion().Add(
                ring,
                bidule.Obj().RotateZ(0 * 90),
                bidule.Obj().RotateZ(1 * 90),
                bidule.Obj().RotateZ(2 * 90),
                bidule.Obj().RotateZ(3 * 90)
                )
            ;

            Local(nameof(side), side);
            var sides = new CsgUnion().Add(
                side.Obj().RotateY(0 * 90),
                side.Obj().RotateY(1 * 90),
                side.Obj().RotateY(2 * 90),
                side.Obj().RotateY(3 * 90),
                side.Obj().RotateY(3 * 90),
                side.Obj().RotateX(90),
                side.Obj().RotateX(-90))
            ;

            Add(new CsgIntersection().Add(new Sphere {
                Radius = rBody * 1.0001
            }).Add(sides).AddModifiers(decoPigmentMajor));
            this.TranslateY(rBody);
            AddModifiers(mainPigment);
        }
示例#6
0
        private IShape MakeSponge(int m)
        {
            var thing1 = MakeCubes(-1.5, -1.5, 1.5, 1.5, 0, m);
            var thing2 = MakeCubes(-1.5, -1.5, 1.5, 1.5, 0, m);
            var thing3 = MakeCubes(-1.5, -1.5, 1.5, 1.5, 0, m);
            var c1     = thing1;
            var c2     = thing2.Rotate(rx: Pi / 2);
            var c3     = thing3.Rotate(ry: Pi / 2);
            var u1     = new CsgUnion(c1, c2);
            var u2     = new CsgUnion(u1, c3);
            var cube   = new Cube().Scale(1.5);
            var sponge = new CsgDifference(cube, u2);

            return(sponge);
        }
示例#7
0
        public void DivideTest()
        {
            var sphere1 = new Sphere().Translate(-1.5);
            var sphere2 = new Sphere().Translate(1.5);
            var left    = new Group().Add(sphere1, sphere2);
            var sphere3 = new Sphere().Translate(tz: -1.5);
            var sphere4 = new Sphere().Translate(tz:  1.5);
            var right   = new Group().Add(sphere3, sphere4);
            var diff    = new CsgDifference(left, right);

            diff.Divide(1);
            Check.That(((Group)left[0])[0]).IsSameReferenceAs(sphere1);
            Check.That(((Group)left[1])[0]).IsSameReferenceAs(sphere2);
            Check.That(((Group)right[0])[0]).IsSameReferenceAs(sphere3);
            Check.That(((Group)right[1])[0]).IsSameReferenceAs(sphere4);
        }
示例#8
0
        public void CsgDemoTest()
        {
            scene.Name = "TestCsg";

            var cylinderX = scene.Declare("cylinderX", new Cylinder()
            {
                BasePoint = _V(-2, 0, 0), CapPoint = _V(2, 0, 0), Radius = 0.5
            });
            var cylinderY = scene.Declare("cylinderY", new Cylinder()
            {
                BasePoint = _V(0, -2, 0), CapPoint = _V(0, 2, 0), Radius = 0.5
            });
            var cylinderZ = scene.Declare("cylinderZ", new Cylinder()
            {
                BasePoint = _V(0, 0, -2), CapPoint = _V(0, 0, 2), Radius = 0.5
            });

            var csgUnion = new CsgUnion()
                           .Add(cylinderX)
                           .Add(cylinderY)
                           .Add(cylinderZ)
                           .AddModifiers(new Pigment(_Red));

            scene.Add(csgUnion);

            var csgIntersection = new CsgIntersection()
                                  .Add(cylinderX)
                                  .Add(cylinderY)
                                  .Add(cylinderZ)
                                  .AddModifiers(new Pigment(_Green))
                                  .Translate(0, 0, 3);

            scene.Add(csgIntersection);

            var csgDifference = new CsgDifference(cylinderX)
                                .Add(cylinderY)
                                .Add(cylinderZ)
                                .AddModifiers(new Pigment(_Blue))
                                .Translate(3, 0, -3);

            scene.Add(csgDifference);
            var path = engine.Render(scene, options, false);
        }
示例#9
0
        public override void InitWorld()
        {
            DefaultFloor();
            Light(1, 1, -1);

            var poly3 = new Prism(BuildPolygon(3)).Scale(0.2, 0.25, 0.2).Translate(tx: -0.75, tz: 0);
            var poly4 = new Prism(BuildPolygon(4)).Scale(0.2, 0.25, 0.2).Translate(tx: -0, tz: 0.75);
            var poly5 = new Prism(BuildPolygon(5)).Scale(0.2, 0.25, 0.2).Translate(tx: 0.75, tz: 0.5);
            var poly6 = new CsgDifference(new Prism(BuildPolygon(6)), new Cylinder().Scale(0.5));

            poly6.Scale(0.2, 0.25, 0.2).Translate(tx: 0.5, tz: -0.5);

            poly3.Material = new Material(new SolidPattern(Color._Green + Color._Red));
            poly4.Material = new Material(new SolidPattern(Color._Green + Color._Blue));
            poly5.Material = new Material(new SolidPattern(Color._Green));
            poly6.Material = new Material(new SolidPattern(Color._Red));

            Add(poly3, poly4, poly5, poly6);

            IEnumerable <Point2D> points = new[]
            {
                new Point2D(-3, 5),
                new Point2D(3, 5),
                new Point2D(3, 3),
                new Point2D(-1, 3),
                new Point2D(-1, 1),
                new Point2D(1, 1),

                new Point2D(1, -1),
                new Point2D(-1, -1),
                new Point2D(-1, -3),
                new Point2D(3, -3),
                new Point2D(3, -5),
                new Point2D(-3, -5)
            }.Reverse();

            var letterE = new Prism(points);

            letterE.Material = new Material(new SolidPattern(Color._Blue));
            Add(letterE.Scale(0.1).Rotate(ry: Math.PI / 4));
        }
示例#10
0
        public void FilteringIntersections_Difference_Test()
        {
            var csg = new CsgDifference(s1, s2);

            FilteringIntersectionsTest(csg, 0, 1);
        }
示例#11
0
        public void DifferenceAllowedTest(bool leftHit, bool insideLeft, bool insideRight, bool expected)
        {
            var diffCsg = new CsgDifference(new Sphere(), new Sphere());

            Check.That(diffCsg.IntersectionAllowed(leftHit, insideLeft, insideRight)).IsEqualTo(expected);
        }
示例#12
0
        public DroidHead(Pigment mainPigment, Pigment decoPigmentMajor, Pigment decoPigmentMinor)
        {
            double yBottomSkull = 2 * rSkull - hSkull;
            double rBottomSkull = Math.Sqrt(Math.Pow(rSkull, 2) - Math.Pow(hSkull - rSkull, 2));

            #region SkullNeck
            var skull = new CsgDifference(
                new Sphere()
            {
                Center = _V(0, rSkull, 0), Radius = rSkull
            })
                        .Add(new Box()
            {
                Corner1 = _V(-1), Corner2 = _V(1, yBottomSkull, 1)
            });
            Local(nameof(skull), skull);

            var neck = new CsgDifference(
                new Cone()
            {
                BaseRadius = rBottomSkull,
                BasePoint  = _V(0, yBottomSkull, 0),
                CapPoint   = _V(0, yBottomSkull - 0.5, 0)
            })
                       .Add(new Box()
            {
                Corner1 = _V(-1, yBottomSkull - hNeck, -1), Corner2 = _V(1, -1, 1)
            })
            ;
            Local(nameof(neck), neck);
            #endregion
            #region Deco
            var smallDecoBox = new Box()
            {
                Corner1 = _V(-1, 0, -1), Corner2 = _V(1, 1, 1)
            };
            Local(nameof(smallDecoBox), smallDecoBox);

            var topRing    = smallDecoBox.Obj().ScaleY(hTopRing).TranslateY(yTopRing);
            var bottomRing = smallDecoBox.Obj().ScaleY(hBottomRing);

            var middleRing = new CsgDifference(
                smallDecoBox.Obj()
                .ScaleY(hBottomRing)
                .TranslateY(yMiddleRing))
                             .Add(new Cylinder {
                BasePoint = yBigEye * _Y, CapPoint = yBigEye * _Y + 2 * _Z, Radius = rBigEye * 1.2
            })
            ;

            var minorDecoElements = new CsgUnion()
                                    .Add(topRing)
                                    .Add(bottomRing)
                                    .TranslateY(yBottomSkull)
            ;

            var minorDeco = new CsgIntersection()
                            .Add(new Sphere()
            {
                Center = rSkull * _Y, Radius = rSkull * 1.0005
            })
                            .Add(minorDecoElements)
                            .AddModifiers(decoPigmentMinor);
            ;

            var miscDeco = new CsgUnion();
            for (int i = 0; i < 10; i++)
            {
                miscDeco.Add(
                    smallDecoBox.Obj().Scale(1, hTopRing, 0.02).RotateY(30 * i + 15),
                    smallDecoBox.Obj().Scale(1, hTopRing, 0.05).RotateY(30 * i));
            }

            miscDeco.TranslateY(hBottomRing);

            var majorDecoElements = new CsgUnion().Add(
                middleRing,
                miscDeco)
                                    .TranslateY(yBottomSkull)
            ;
            var majorDeco = new CsgIntersection()
                            .Add(new Sphere()
            {
                Center = rSkull * _Y, Radius = rSkull * 1.0005
            })
                            .Add(majorDecoElements)
                            .AddModifiers(decoPigmentMajor);
            ;
            #endregion

            double zBigEye = Math.Sqrt(Math.Pow(rSkull, 2) - Math.Pow(yBigEye, 2));
            var    bigEye  = new Sphere {
                Center = _V(0, yBigEye + yBottomSkull, zBigEye), Radius = rBigEye
            }
            .AddModifiers(new Pigment(_Black));
            double zSmallEye = Math.Sqrt(Math.Pow(rSkull, 2) - Math.Pow(ySmallEye, 2));
            var    smallEye  = new Sphere {
                Center = _V(0, ySmallEye + yBottomSkull, zSmallEye), Radius = rSmallEye
            }
            .RotateY(aSmallEye)
            .AddModifiers(new Pigment(_Black));

            Add(bigEye, smallEye, majorDeco, minorDeco, skull, neck);
            AddModifiers(mainPigment);
            this.TranslateY(-yBottomSkull + hNeck);
        }