Last active
August 29, 2015 13:58
-
-
Save ToJans/9933767 to your computer and use it in GitHub Desktop.
Here's some of the code causing the headache
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
// coords are a list of Vector3D | |
// polygons are a sequence of triangles | |
// triangles are a list of 3 vertices | |
// vertices are a Vector3D | |
let triangle a b c = [a;b;c] | |
let coordsToPolygon coords = | |
let fst = Seq.head coords | |
let triangleF = function | |
| [|a;b|] -> triangle fst a b |> Some | |
| _ -> None | |
coords | |
|> Seq.skip 1 | |
|> Seq.windowed 2 | |
|> Seq.choose triangleF | |
let coordsToPolygons c = Seq.map coordsToPolygon c | |
let polygonsToTriangles p = Seq.collect (fun(x) -> x) p | |
let trianglesToVertices t = Seq.collect (fun(x) -> x) t | |
let verticesTo3dDecimals v = Seq.collect (fun(x:Vector3D) -> x.toDecimalList) v | |
let verticesTo2dDecimals v = Seq.collect (fun(x:Vector3D) -> x.toDecimalList |> Seq.take 2 ) v | |
let cube (size: Scale) = | |
let corner = Vector3D.unit*size | |
let flt = corner * Scale.front * Scale.left * Scale.top | |
let frt = corner * Scale.front * Scale.right * Scale.top | |
let frb = corner * Scale.front * Scale.right * Scale.bottom | |
let flb = corner * Scale.front * Scale.left * Scale.bottom | |
let blt = corner * Scale.back * Scale.left * Scale.top | |
let brt = corner * Scale.back * Scale.right * Scale.top | |
let brb = corner * Scale.back * Scale.right * Scale.bottom | |
let blb = corner * Scale.back * Scale.left * Scale.bottom | |
let front = [flt;frt;frb;flb] | |
let back = [brt;blt;blb;brb] | |
let left = [blt;flt;flb;blb] | |
let right = [frt;brt;brb;frb] | |
let top = [blt;brt;frt;flt] | |
let bottom = [brb;blb;flb;frb] | |
[front;back;left;right;top;bottom] | |
|> coordsToPolygons | |
|> polygonsToTriangles | |
|> trianglesToVertices | |
|> verticesTo3dDecimals | |
let cubeNormals = | |
[Vector3D.front;Vector3D.back;Vector3D.left;Vector3D.right;Vector3D.top;Vector3D.bottom] | |
|> Seq.map (fun (x) -> [x;x;x;x]) | |
|> coordsToPolygons | |
|> polygonsToTriangles | |
|> trianglesToVertices | |
|> verticesTo3dDecimals | |
let cubeUV u v = | |
let tl = Vector3D.fromDecimal 0M 0M 0M | |
let tr = Vector3D.fromDecimal u 0M 0M | |
let br = Vector3D.fromDecimal u v 0M | |
let bl = Vector3D.fromDecimal 0M v 0M | |
(fun (_) -> coordsToPolygon [tl;tr;br;bl]) | |
|> Seq.init 6 | |
|> polygonsToTriangles | |
|> trianglesToVertices | |
|> verticesTo2dDecimals |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment