From 900d5f4d942d2ab421c64e14da4f0df390f52fec Mon Sep 17 00:00:00 2001 From: Andrey Kuzmin Date: Fri, 8 Dec 2023 10:51:04 +0100 Subject: [PATCH] Move files around --- public/{assets => font}/Teko-Medium.woff | Bin public/{assets => font}/Teko-Medium.woff2 | Bin public/{assets => font}/teko-license.txt | 0 public/img/{ => balls}/roughness.jpg | Bin .../color.png} | Bin .../metallic.png} | Bin .../roughness.png} | Bin src/Main.elm | 16 +- src/Table.elm | 160 ++++++++++-------- 9 files changed, 93 insertions(+), 83 deletions(-) rename public/{assets => font}/Teko-Medium.woff (100%) rename public/{assets => font}/Teko-Medium.woff2 (100%) rename public/{assets => font}/teko-license.txt (100%) rename public/img/{ => balls}/roughness.jpg (100%) rename public/img/{billiard-table-color.png => table/color.png} (100%) rename public/img/{billiard-table-metallic.png => table/metallic.png} (100%) rename public/img/{billiard-table-roughness.png => table/roughness.png} (100%) diff --git a/public/assets/Teko-Medium.woff b/public/font/Teko-Medium.woff similarity index 100% rename from public/assets/Teko-Medium.woff rename to public/font/Teko-Medium.woff diff --git a/public/assets/Teko-Medium.woff2 b/public/font/Teko-Medium.woff2 similarity index 100% rename from public/assets/Teko-Medium.woff2 rename to public/font/Teko-Medium.woff2 diff --git a/public/assets/teko-license.txt b/public/font/teko-license.txt similarity index 100% rename from public/assets/teko-license.txt rename to public/font/teko-license.txt diff --git a/public/img/roughness.jpg b/public/img/balls/roughness.jpg similarity index 100% rename from public/img/roughness.jpg rename to public/img/balls/roughness.jpg diff --git a/public/img/billiard-table-color.png b/public/img/table/color.png similarity index 100% rename from public/img/billiard-table-color.png rename to public/img/table/color.png diff --git a/public/img/billiard-table-metallic.png b/public/img/table/metallic.png similarity index 100% rename from public/img/billiard-table-metallic.png rename to public/img/table/metallic.png diff --git a/public/img/billiard-table-roughness.png b/public/img/table/roughness.png similarity index 100% rename from public/img/billiard-table-roughness.png rename to public/img/table/roughness.png diff --git a/src/Main.elm b/src/Main.elm index d323f36..877150c 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -29,7 +29,7 @@ type Model type Msg = WindowResized (Rectangle2d Pixels ScreenCoordinates) | GotBallTexture Int (Result WebGL.Texture.Error (Material.Texture Color)) - | GotRoughnessTexture (Result WebGL.Texture.Error (Material.Texture Float)) + | GotBallRoughnessTexture (Result WebGL.Texture.Error (Material.Texture Float)) | GotTable (Result String Table) | RunningMsg Game.Msg | StartNewGameButtonClicked @@ -130,12 +130,12 @@ init unsafeFlags = ) (List.range 1 15) ) - , Task.attempt GotRoughnessTexture (Material.load (assetsPath ++ "img/roughness.jpg")) + , Task.attempt GotBallRoughnessTexture (Material.load (assetsPath ++ "img/balls/roughness.jpg")) , Task.attempt GotTable (Table.load - { colorTexture = assetsPath ++ "img/billiard-table-color.png" - , roughnessTexture = assetsPath ++ "img/billiard-table-roughness.png" - , metallicTexture = assetsPath ++ "img/billiard-table-metallic.png" + { colorTexture = assetsPath ++ "img/table/color.png" + , roughnessTexture = assetsPath ++ "img/table/roughness.png" + , metallicTexture = assetsPath ++ "img/table/metallic.png" , mesh = assetsPath ++ "/billiard-table.obj.txt" } ) @@ -249,8 +249,8 @@ fontStyle path = """ @font-face { font-family: 'Teko'; - src: url('""" ++ path ++ """assets/Teko-Medium.woff2') format('woff2'), - url('""" ++ path ++ """assets/Teko-Medium.woff') format('woff'); + src: url('""" ++ path ++ """font/Teko-Medium.woff2') format('woff2'), + url('""" ++ path ++ """font/Teko-Medium.woff') format('woff'); font-weight: 500; font-style: normal; font-display: block; @@ -282,7 +282,7 @@ update msg model = Err _ -> Failed "Failed to load ball texture" - ( GotRoughnessTexture maybeTexture, Loading loadingModel ) -> + ( GotBallRoughnessTexture maybeTexture, Loading loadingModel ) -> case maybeTexture of Ok texture -> loadComplete diff --git a/src/Table.elm b/src/Table.elm index e04f811..a6b4020 100644 --- a/src/Table.elm +++ b/src/Table.elm @@ -48,6 +48,91 @@ type alias Table = } +length : Length +length = + Length.meters 2.26 + + +width : Length +width = + Length.meters 1.24 + + +{-| Anywhere on the table. This where the cue ball should be placed after it goes in a pocket +or after the failure to hit the object ball. +-} +areaBallInHand : Rectangle3d Meters WorldCoordinates +areaBallInHand = + let + xOffset = + Quantity.half length |> Quantity.minus Ball.radius + + yOffset = + Quantity.half width |> Quantity.minus Ball.radius + in + Rectangle3d.on SketchPlane3d.xy + (Rectangle2d.from + (Point2d.xy (Quantity.negate xOffset) (Quantity.negate yOffset)) + (Point2d.xy xOffset yOffset) + ) + |> Rectangle3d.translateIn Direction3d.z (Length.millimeters 1) + + +{-| The foot spot is the place where you “spot the ball”, it is also +the place where the top object ball is placed when racking a game +-} +footSpot : Point2d Meters WorldCoordinates +footSpot = + Point2d.xy + (Quantity.half (Quantity.half length)) + Quantity.zero + + +{-| The area where you break from, and where you must place the cue ball after a scratch. +-} +areaBehindTheHeadString : Rectangle3d Meters WorldCoordinates +areaBehindTheHeadString = + let + yOffset = + Quantity.half width |> Quantity.minus Ball.radius + + xMin = + Quantity.half length |> Quantity.minus Ball.radius |> Quantity.negate + + xMax = + Quantity.half (Quantity.half length) |> Quantity.negate + in + Rectangle3d.on SketchPlane3d.xy + (Rectangle2d.from + (Point2d.xy xMin (Quantity.negate yOffset)) + (Point2d.xy xMax yOffset) + ) + |> Rectangle3d.translateIn Direction3d.z (Length.millimeters 1) + + +{-| Highlight the area behind the head string when the ball should be placed there +-} +areaBehindTheHeadStringEntity : Entity WorldCoordinates +areaBehindTheHeadStringEntity = + case Rectangle3d.vertices areaBehindTheHeadString of + [ v1, v2, v3, v4 ] -> + Scene3d.quad + (Material.nonmetal + { baseColor = Color.rgb255 131 146 34 + , roughness = 1 + } + ) + v1 + v2 + v3 + v4 + + _ -> + Scene3d.nothing + + +{-| Load the visual entity and the collider bodies for the table from the obj file and texture files +-} load : { colorTexture : String, roughnessTexture : String, metallicTexture : String, mesh : String } -> Task String Table load urls = Http.task @@ -146,78 +231,3 @@ startsWith prefix decoder = |> List.map (\name -> Obj.Decode.object name decoder) |> Obj.Decode.combine ) - - -areaBallInHand : Rectangle3d Meters WorldCoordinates -areaBallInHand = - let - xOffset = - Quantity.half length |> Quantity.minus Ball.radius - - yOffset = - Quantity.half width |> Quantity.minus Ball.radius - in - Rectangle3d.on SketchPlane3d.xy - (Rectangle2d.from - (Point2d.xy (Quantity.negate xOffset) (Quantity.negate yOffset)) - (Point2d.xy xOffset yOffset) - ) - |> Rectangle3d.translateIn Direction3d.z (Length.millimeters 1) - - -length : Length -length = - Length.meters 2.26 - - -width : Length -width = - Length.meters 1.24 - - -footSpot : Point2d Meters WorldCoordinates -footSpot = - Point2d.xy - (Quantity.half (Quantity.half length)) - Quantity.zero - - -areaBehindTheHeadString : Rectangle3d Meters WorldCoordinates -areaBehindTheHeadString = - let - yOffset = - Quantity.half width |> Quantity.minus Ball.radius - - xMin = - Quantity.half length |> Quantity.minus Ball.radius |> Quantity.negate - - xMax = - Quantity.half (Quantity.half length) |> Quantity.negate - in - Rectangle3d.on SketchPlane3d.xy - (Rectangle2d.from - (Point2d.xy xMin (Quantity.negate yOffset)) - (Point2d.xy xMax yOffset) - ) - |> Rectangle3d.translateIn Direction3d.z (Length.millimeters 1) - - -{-| Highlight the area where the ball should be placed --} -areaBehindTheHeadStringEntity : Entity WorldCoordinates -areaBehindTheHeadStringEntity = - case Rectangle3d.vertices areaBehindTheHeadString of - [ v1, v2, v3, v4 ] -> - Scene3d.quad - (Material.nonmetal - { baseColor = Color.rgb255 131 146 34 - , roughness = 1 - } - ) - v1 - v2 - v3 - v4 - - _ -> - Scene3d.nothing