Skip to content

Instantly share code, notes, and snippets.

@acamilo
Last active June 24, 2017 02:04
Show Gist options
  • Save acamilo/deccd373e0dff4e716f508a73b5924e2 to your computer and use it in GitHub Desktop.
Save acamilo/deccd373e0dff4e716f508a73b5924e2 to your computer and use it in GitHub Desktop.
@groovy.transform.InheritConstructors
class Bell {
double belltop = 50;
double bellbottom = 100;
double height = 150;
double topheight = 10;
double bellthickness = 10;
int facets = 16;
CSG model;
def toCSG(){
CSG cylinder = new Cylinder( belltop, // Radius at the top
bellbottom, // Radius at the bottom
height, // Height
(int)facets //resolution
).toCSG();
CSG innervoid = new Cylinder( belltop-bellthickness, // Radius at the top
bellbottom-bellthickness, // Radius at the bottom
height, // Height
(int)facets //resolution
).toCSG();
CSG top = new Cylinder( belltop, // Radius at the top
belltop, // Radius at the bottom
topheight, // Height
(int)facets //resolution
).toCSG();
model = cylinder.difference(innervoid).rotx(180).union(top).movez(-topheight);
return model;
}
}
@groovy.transform.InheritConstructors
class Tank {
int facets = 16;
double length = 600;
double diameter = 150;
double cyllen = length-diameter;
def toCSG(){
CSG sphere = new Sphere(diameter,facets,8).toCSG().rotx(90);
CSG body = new Cylinder( diameter, // Radius at the top
diameter, // Radius at the bottom
cyllen, // Height
(int)facets //resolution
).toCSG();
body = body.union([sphere,sphere.movez(cyllen)]);
body = body.movez(-cyllen/2)
body = body.rotz(22.5);
CSG strut = new Cylinder( 20, // Radius at the top
20, // Radius at the bottom
100, // Height
(int)facets, //resolution
).toCSG().roty(90).movex(-diameter+30);
body = body.union([strut.movez(length*0.40),strut.movez(-length*0.40)]);
return body;
}
}
@groovy.transform.InheritConstructors
class Reactor {
double diameter =100;
double middle = 300;
double height = 400;
double endHeight = height * 0.2;
double tankheight = height * 0.6;
int facets = 16;
def toCSG(){
CSG cap = new Cylinder( middle, // Radius at the top
diameter, // Radius at the bottom
endHeight, // Height
(int)facets //resolution
).toCSG();
CSG body = new Cylinder( middle, // Radius at the top
middle, // Radius at the bottom
tankheight, // Height
(int)facets //resolution
).toCSG();
CSG tank = body.union([cap.movez(tankheight),cap.rotx(180) ]).movez(endHeight);
return tank;
}
}
@groovy.transform.InheritConstructors
class Ship {
Bell rocket;
Reactor reactor;
Tank tank;
int facet = 24;
Ship(){
rocket = new Bell();
reactor = new Reactor();
tank = new Tank();
rocket.facets = facet;
reactor.facets = facet*2;
tank.facets = facet;
}
def toCSG(){
CSG pipe = new Cylinder( 20, // Radius at the top
20, // Radius at the bottom
50, // Height
(int)facet //resolution
).toCSG();
CSG b = rocket.toCSG().union(pipe).rotx(-10).rotz(90).movez(0).movex(120+10);
CSG engines = b.union([b.rotz(90),b.rotz(180),b.rotz(270)])
CSG r = reactor.toCSG();
CSG ship = r.union(engines).movez(-400);
CSG centershaft = new Cylinder( 20, // Radius at the top
20, // Radius at the bottom
800, // Height
(int)facet //resolution
).toCSG();
ship = ship.union(centershaft);
CSG tankelem = tank.toCSG();
tankelem = tankelem.movex(230).movez(400);
ship = ship.union([tankelem,tankelem.rotz(90),tankelem.rotz(180),tankelem.rotz(270)]);
return ship;
}
}
CSG ship = new Ship().toCSG();
return ship;
//return new Tank().toCSG();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment