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); }
public void FilteringIntersections_Union_Test() { var csg = new CsgUnion(s1, s2); FilteringIntersectionsTest(csg, 0, 3); }
public void Union_IntersectionAllowedTest(bool leftHit, bool insideLeft, bool insideRight, bool expected) { var unionCsg = new CsgUnion(new Sphere(), new Sphere()); Check.That(unionCsg.IntersectionAllowed(leftHit, insideLeft, insideRight)).IsEqualTo(expected); }
public CsgUnionWrapper(CsgNodeWrapperRepository repo, CsgUnion node) : base(repo, node) { Object = node; }
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); }