Last active
August 29, 2015 13:58
-
-
Save ToJans/10380240 to your computer and use it in GitHub Desktop.
Still optimizing my 3D construction DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let frame width height = | |
let context = Builder.zero | |
let horizontalBeam = a_beam.with_a_width_of ( width ) | |
let verticalBeam = a_beam.with_a_height_of ( height - horizontalBeam.height * 2M ) | |
let topBeam = context.add a horizontalBeam anchoring its TopLeftFront on the TopLeftFront context.boundingBox | |
let leftBeam = context.add a verticalBeam anchoring its TopLeftFront on the BottomLeftFront topBeam.boundingBox | |
let rightBeam = context.add a verticalBeam anchoring its TopRightFront on the BottomRightFront topBeam.boundingBox | |
let bottomBeam = context.add a horizontalBeam anchoring its BottomLeftFront on the BottomLeftFront leftBeam.boundingBox | |
context | |
let wall width height = | |
let maxWidth = 1600M | |
let count = width/maxWidth |> System.Math.Ceiling |> int | |
let realWidth = width / decimal(count) | |
frame realWidth height |> repeat count |> append_from_left_to_right_aligning_with_front | |
let getWalls vec = | |
let frontWall = wall vec.x vec.y | |
let sideWall = wall vec.z vec.y | |
let leftWall = Builder.rotateY_CCW_90degrees sideWall | |
let rightWall = Builder.rotateY_CW_90degrees sideWall | |
let movedLeftWall = Builder.move the TopRightFront leftWall on the TopLeftBack frontWall.boundingBox | |
let movedRightWall = Builder.move the TopLeftFront rightWall on the TopRightBack frontWall.boundingBox | |
(movedLeftWall + frontWall + movedRightWall) | |
|> Builder.center | |
|> Builder.materialize ShinyStuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let frame(width, height, depth, beamThickness) = | |
let horizontalGeometry = CubeGeometry({x=width; y=beamThickness; z=depth}) | |
let topBeam = { | |
geometry = horizontalGeometry | |
position = {mm0 with y = (height-beamThickness)/2M} | |
rotation = degrees0 | |
material = ShinyStuff | |
castShadow = true | |
receiveShadow = false | |
} | |
let bottomBeam = {topBeam with position = {mm0 with y = -(height-beamThickness)/2M} } | |
let verticalGeometry = CubeGeometry({x=beamThickness; y = height; z = depth}) | |
let leftBeam = { | |
geometry = verticalGeometry | |
position = {mm0 with x = (width-beamThickness)/2M} | |
rotation = degrees0 | |
material = ShinyStuff | |
castShadow = true | |
receiveShadow = false | |
} | |
let rightBeam = { leftBeam with position = {mm0 with x = -(width-beamThickness)/2M}} | |
let glassGeometry = PlaneGeometry({x= width - beamThickness*2M; y = height - beamThickness*2M }) | |
let glassPane = { | |
geometry = glassGeometry | |
position = mm0 | |
rotation = degrees0 | |
material = Glass | |
castShadow = false | |
receiveShadow = false | |
} | |
{ objects = [];meshes = [leftBeam;rightBeam;topBeam;bottomBeam]; position = mm0; rotation = degrees0} | |
let wall(x,y) = | |
let maxWidth = 1400M<mm> | |
let depth = 100M<mm> | |
let beamThickness = 50M<mm> | |
let count = x/maxWidth |> System.Math.Ceiling |> int | |
let realWidth = x / decimal(count) | |
let intToFrame i = | |
let pos = realWidth*(decimal(i)-0.5M) - x/2M | |
{ frame(realWidth,y,depth,beamThickness) with position = {mm0 with x = pos} } | |
let items= [1..count] |> List.map(fun (i)-> intToFrame(i)) | |
{ objects = items;meshes = [];position = mm0;rotation = degrees0} | |
let getWalls(x,y,z) = | |
let xWall = wall(x,y) | |
let frontWall = moveObjZ(xWall, 0.5M*z) | |
let backWall = moveObjZ(xWall, -0.5M*z) | |
let zWall = wall(z,y) | |
let leftWall = rotObjY(moveObjX(zWall, -0.5M*x), 90M<degrees>) | |
let rightWall = rotObjY(moveObjX(zWall, 0.5M*x), 90M<degrees>) | |
{objects = [frontWall;leftWall;rightWall];meshes = [];position = mm0;rotation = degrees0 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment