#----------------------------------------------------------------------------- # Name : tuinmeubel Maker 1.0 # Description : A tool to create tuinmeubels # Menu Item : Tools->Tafel # Context Menu: Edit Tafel # Date : 2009-7-18 # Type : Dialog Box #----------------------------------------------------------------------------- # test like this: Tafel.create_tafel(Sketchup.active_model.entities) require 'sketchup.rb' require 'parametric.rb' $stoeph= 0.45.m; # methods shared by all Meubels class Meubel def Meubel.rectangle(p0, width, height, container, close) v1 = Geom::Vector3d.new(width,0,0) v2 = Geom::Vector3d.new(0,height,0) p1 = p0; p2 = p0 + v1 p3 = p2 + v2 p4 = p0 + v2 edges = [] edges[0]=container.add_line p1, p2 edges[1]=container.add_line p2, p3 edges[2]=container.add_line p3, p4 edges[3]=container.add_line p4, p1 if( close ) f = container.add_face edges else edges end end def Meubel.add_poot(p1, thickness, height, container) poot = container.add_group outer = Meubel.rectangle(p1, thickness, thickness, poot.entities, true) # Extrude the window outer.pushpull(-height) poot end def Meubel.add_rect(p1, width, depth, height, container) rect = container.add_group outer = Meubel.rectangle(p1, width, depth, rect.entities, true) # Extrude the window outer.pushpull(-height) rect end def Meubel.add_frame(p1, width, height, thickness, frameWidth, container) # create a group for the frame frame = container.add_group v = Geom::Vector3d.new(frameWidth, frameWidth, 0) p2 = p1 + v holeWidth = width - frameWidth*2; holeHeight = height - frameWidth*2; # Create the outer frame and the hole outer = Meubel.rectangle(p1, width, height, frame.entities, true) hole = Meubel.rectangle(p2, holeWidth, holeHeight, frame.entities, true) hole.erase! # Extrude the window outer.pushpull(-thickness) frame end end #============================================================================= class Tafel < Parametric def default_parameters { } end def create_entities(data, container) height= 0.76.m; width= 1.50.m; depth= 0.90.m; poot = 0.05.m; bladh= 0.02.m; pooth= height-bladh frameh = 0.08.m; framew = width-0.02.m; framed = depth-0.02.m; Meubel.add_poot(Geom::Point3d.new(0.01.m, 0.01.m, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(0.01.m, depth-poot-0.01.m, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(width-poot-0.01.m, 0.01.m, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(width-poot-0.01.m, depth-poot-0.01.m, 0), poot, pooth, container); Meubel.add_frame(Geom::Point3d.new(0.01.m, 0.01.m, pooth), framew, framed, frameh, 0.02.m, container); Meubel.add_rect(Geom::Point3d.new(0,0,height-bladh), width, depth, bladh, container); end end #============================================================================= class Paal < Parametric def default_parameters { } end def create_entities(data,container) height= 2.000.m; width= 0.075.m; Meubel.add_poot(ORIGIN, width, height, container); end end #============================================================================= class Zandbak < Parametric def default_parameters { } end def create_entities(data,container) width= 10.cm; thick= 1.5.cm; length= 1.20.m; Meubel.add_rect(Geom::Point3d.new(0,0,0), length, thick, width, container); Meubel.add_rect(Geom::Point3d.new(0,0,width), length, thick, -width, container); Meubel.add_rect(Geom::Point3d.new(0,0,0), thick, length, width, container); Meubel.add_rect(Geom::Point3d.new(0,0,width), thick, length, -width, container); Meubel.add_rect(Geom::Point3d.new(length,length,0), -length, -thick, width, container); Meubel.add_rect(Geom::Point3d.new(length,length,width), -length, -thick, -width, container); Meubel.add_rect(Geom::Point3d.new(length,length,0), -thick, -length, width, container); Meubel.add_rect(Geom::Point3d.new(length,length,width), -thick, -length, -width, container); end end #============================================================================= class Bankje < Parametric def default_parameters { } end def create_entities(data,container) poot = 0.05.m; pooth = 0.45.m; bankw = 1.20.m; bankd = 0.55.m; leunh = 0.90.m; Meubel.add_poot(Geom::Point3d.new(0, 0, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(bankw, 0, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(0, bankd, 0), poot, leunh, container); Meubel.add_poot(Geom::Point3d.new(bankw, bankd, 0), poot, leunh, container); # zitvlak Meubel.add_rect(Geom::Point3d.new(0,0,pooth), bankw, bankd, 0.02.m, container); # bovenkant leuning Meubel.add_rect(Geom::Point3d.new(0,bankd,leunh), bankw, 0.02.m, 0.10.m, container); end end #============================================================================= class LeunStoel < Parametric def default_parameters { } end # todo, make leaning def create_entities(data,container) poot = 0.05.m; pooth = 0.45.m; bankw = 0.55.m; bankd = 0.60.m; leunh = 1.10.m; Meubel.add_poot(Geom::Point3d.new(0, 0, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(bankw, 0, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(0, bankd, 0), poot, leunh, container); Meubel.add_poot(Geom::Point3d.new(bankw, bankd, 0), poot, leunh, container); # zitvlak Meubel.add_rect(Geom::Point3d.new(0,0,pooth), bankw, bankd, 0.02.m, container); # bovenkant leuning Meubel.add_rect(Geom::Point3d.new(0,bankd,leunh), bankw, 0.02.m, 0.10.m, container); end end #============================================================================= class WitteStoel < Parametric def default_parameters { } end # todo: check params def create_entities(data,container) poot = 0.05.m; pooth = 0.45.m; bankw = 0.60.m; bankd = 0.50.m; leunh = 0.80.m; Meubel.add_poot(Geom::Point3d.new(0, 0, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(bankw, 0, 0), poot, pooth, container); Meubel.add_poot(Geom::Point3d.new(0, bankd, 0), poot, leunh, container); Meubel.add_poot(Geom::Point3d.new(bankw, bankd, 0), poot, leunh, container); # zitvlak Meubel.add_rect(Geom::Point3d.new(0,0,pooth), bankw, bankd, 0.02.m, container); # bovenkant leuning Meubel.add_rect(Geom::Point3d.new(0,bankd,leunh), bankw, 0.02.m, 0.30.m, container); end end #============================================================================= class BlauweTafel < Parametric def default_parameters { } end def create_entities(data,container) end end #============================================================================= class Plantenbak < Parametric def default_parameters { } end # todo: check params def create_entities(data,container) Meubel.add_rect(Geom::Point3d.new(0,0,0), 1.00.m, 0.50.m, 0.59.m, container); end end #============================================================================= class Tuin < Parametric def default_parameters { } end def pointonline(left, right, lofs) length= left.distance(right) Geom.linear_combination((length-lofs)/length, left, lofs/length, right); end def create_entities(data,container) dir= Geom::Vector3d.new(0,0,1); whuis= 4.705.m; weind= 4.10.m; diepte= 8.70.m; plinksgevel= Geom::Point3d.new(0,0,0); prechtsgevel= Geom::Point3d.new(whuis,0,0); plinksachter= Geom::Point3d.new((whuis-weind)/2,diepte,0); prechtsachter= Geom::Point3d.new((whuis-weind)/2+weind,diepte,0); gevel= container.add_line(plinksgevel, prechtsgevel); achter= container.add_line(plinksachter, prechtsachter); rechts= container.add_line(prechtsgevel, prechtsachter); links= container.add_line(plinksgevel, plinksachter); randgrasl= pointonline(plinksachter, plinksgevel, 1.05.m); randgrasr= pointonline(prechtsachter, prechtsgevel, 1.30.m); print "rechts: start=", rechts.start().position, " end=", rechts.end().position, "\n"; print "links: start=", links.start().position, " end=", links.end().position, "\n"; print "achter: start=", achter.start().position, " end=", achter.end().position, "\n"; print "gevel: start=", gevel.start().position, " end=", gevel.end().position, "\n"; print "grasrand: l=", randgrasl, " r=", randgrasr, "\n"; grasrand= container.add_line(randgrasl, randgrasr); perkachter= pointonline(plinksachter, plinksgevel, 1.95.m); print "perkachter: ", perkachter, "\n"; perkzandl= pointonline(plinksachter, plinksgevel, 3.43.m) plantenachter= pointonline(randgrasr, randgrasl, 0.63.m); print "plantenachter: ", plantenachter, "\n"; pstoepr= pointonline(prechtsgevel, prechtsachter, 3.06.m) print "pstoepr: ", pstoepr, "\n"; pstoepl= Geom::Point3d.new(pstoepr.x-1.53.m, pstoepr.y, pstoepr.z) print "pstoepl: ", pstoepl, "\n"; stoeprecht= container.add_line(pstoepl, pstoepr); plantenvoor= Geom::Point3d.new(pstoepr.x-0.80.m, pstoepr.y, pstoepr.z) stoepschuin= container.add_line(pstoepl, perkachter); plantenrand= container.add_line(plantenachter, plantenvoor) lvec= links.line[1]; perkzandr = Geom.intersect_line_line(stoepschuin.line, [perkzandl, Geom::Vector3d.new(lvec.y, lvec.x, lvec.z)] ) print "perkzandl: ", perkzandl, " perkzandr: ", perkzandr, "\n"; print perkzandl.class.name, " ", perkzandr.class.name, "\n"; #container.add_text("perkzandr", perkzandr, dir); #container.add_text("perkzandl", perkzandl, dir); zandrand= container.add_line(perkzandl, perkzandr); gras= container.add_face([perkachter, randgrasl, randgrasr, plantenachter, plantenvoor, pstoepl ]) gras.pushpull(-0.30.m); gras.back_material= "green"; stoep= container.add_face([plinksgevel, prechtsgevel, pstoepr, pstoepl, perkzandr, perkzandl ]); stoep.pushpull(-$stoeph); gras.back_material= "yellow"; perk= container.add_face([perkzandr, perkzandl, perkachter]); perk.pushpull(-0.60.m); perk.back_material= "DarkGray"; Paal.new.entity.transform!(Geom::Transformation.new(pointonline(randgrasl, randgrasr, 1.17.m))); Paal.new.entity.transform!(Geom::Transformation.new(pointonline(randgrasl, randgrasr, 1.17.m+1.25.m))); Paal.new.entity.transform!(Geom::Transformation.new(randgrasl)); Paal.new.entity.transform!(Geom::Transformation.new(randgrasr)); # todo: add colors to the gras, and stoep surfaces # todo: add wide boders between gras / plant / stoep # todo: measure height of gras/stoep/perk end end # todo add method to do translation + rotation together def add_furniture x= Tafel.new x.entity.transform!(Geom::Transformation.new([0.4.m,0.8.m,$stoeph])); # rotate bank 180 x= Bankje.new; x.entity.transform!(Geom::Transformation.new(ORIGIN, [0,0,1], 180.degrees)); x.entity.transform!(Geom::Transformation.new([1.8.m,0.7.m,$stoeph])); x= LeunStoel.new; x.entity.transform!(Geom::Transformation.new([0.5.m,1.3.m,$stoeph])); x= LeunStoel.new; x.entity.transform!(Geom::Transformation.new([1.13.m,1.3.m,$stoeph])); x= WitteStoel.new; x.entity.transform!(Geom::Transformation.new(ORIGIN, [0,0,1], -90.degrees)); x.entity.transform!(Geom::Transformation.new([2.0.m,1.5.m,$stoeph])); x= Zandbak.new; x.entity.transform!(Geom::Transformation.new([0.25.m,4.0.m,$stoeph])); end # add a menu with the tafel types if( not $tuinmeubels_menu_loaded ) submenu = UI.menu("Draw").add_submenu("TuinMeubels"); submenu.add_item("Tafel") { Tafel.new } submenu.add_item("Paal") { Paal.new } submenu.add_item("Zandbak") { Zandbak.new } submenu.add_item("Bankje") { Bankje.new } submenu.add_item("LeunStoel") { LeunStoel.new } submenu.add_item("Witte Stoel") { WitteStoel.new } submenu.add_item("Blauwe Tafel") { BlauweTafel.new } submenu.add_item("Blauwe Stoel") { BlauweStoel.new } submenu.add_item("Plantenbak") { Plantenbak.new } UI.menu("Draw").add_item("Tuin") { Tuin.new } UI.menu("Draw").add_item("Populate") { add_furniture(); } $tuinmeubels_menu_loaded= true end