Skip to content

Commit

Permalink
Update the mesh and lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rm committed Nov 24, 2023
1 parent c809805 commit 33b04c6
Show file tree
Hide file tree
Showing 8 changed files with 2,119 additions and 818 deletions.
2,857 changes: 2,057 additions & 800 deletions public/billiard-table.obj.txt

Large diffs are not rendered by default.

File renamed without changes
Binary file added public/img/billiard-table-metallic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/billiard-table-roughness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 13 additions & 4 deletions src/Bodies.elm
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,12 @@ bodyToEntity roughnessTexture ballTextures table body =

CueBall ->
Scene3d.sphereWithShadow
(Material.matte (Color.rgb255 255 255 255))
(Material.texturedPbr
{ baseColor = Material.constant Color.white
, roughness = roughnessTexture
, metallic = Material.constant 0
}
)
ballSphere

Table ->
Expand All @@ -347,11 +352,15 @@ cueBall =
|> Body.withBehavior (Body.dynamic (Mass.grams 170))


cueBallEntity : Bool -> Scene3d.Entity BodyCoordinates
cueBallEntity isActive =
cueBallEntity : Bool -> Material.Texture Float -> Scene3d.Entity BodyCoordinates
cueBallEntity isActive roughnessTexture =
Scene3d.sphereWithShadow
(if isActive then
Material.matte Color.white
Material.texturedPbr
{ baseColor = Material.constant Color.white
, roughness = roughnessTexture
, metallic = Material.constant 0
}

else
Material.matte inactiveColor
Expand Down
36 changes: 29 additions & 7 deletions src/Game.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Illuminance
import Json.Decode
import Length exposing (Meters)
import List
import LuminousFlux
import Physics.Body as Body exposing (Body)
import Physics.Contact as Contact
import Physics.Coordinates exposing (WorldCoordinates)
Expand Down Expand Up @@ -808,16 +809,37 @@ view ballTextures roughnessTexture table window model =
sunlight =
Scene3d.Light.directional (Scene3d.Light.castsShadows True)
{ direction = Direction3d.xyZ (Angle.degrees 135) (Angle.degrees -60)
, intensity = Illuminance.lux 10000
, intensity = Illuminance.lux 2000
, chromaticity = Scene3d.Light.daylight
}

lamp1 =
Scene3d.Light.point Scene3d.Light.neverCastsShadows
{ position = Point3d.xyz Quantity.zero Quantity.zero (Length.meters 0.5)
, chromaticity = Scene3d.Light.fluorescent
, intensity = LuminousFlux.lumens 2000
}

lamp2 =
Scene3d.Light.point Scene3d.Light.neverCastsShadows
{ position = Point3d.xyz (Length.meters 0.8) Quantity.zero (Length.meters 0.5)
, chromaticity = Scene3d.Light.fluorescent
, intensity = LuminousFlux.lumens 2000
}

lamp3 =
Scene3d.Light.point Scene3d.Light.neverCastsShadows
{ position = Point3d.xyz (Length.meters -0.8) Quantity.zero (Length.meters 0.5)
, chromaticity = Scene3d.Light.fluorescent
, intensity = LuminousFlux.lumens 2000
}

environmentalLighting =
Scene3d.Light.soft
{ upDirection = Direction3d.positiveZ
, chromaticity = Scene3d.Light.daylight
, intensityAbove = Illuminance.lux 3000
, intensityBelow = Illuminance.lux 2000
, chromaticity = Scene3d.Light.fluorescent
, intensityAbove = Illuminance.lux 400
, intensityBelow = Illuminance.lux 300
}

camera3d =
Expand Down Expand Up @@ -846,7 +868,7 @@ view ballTextures roughnessTexture table window model =
Scene3d.nothing

cueBallEntity =
Bodies.cueBallEntity (spawn == CanPlace)
Bodies.cueBallEntity (spawn == CanPlace) roughnessTexture
|> Scene3d.placeIn (Frame3d.atPoint position)
in
cueBallEntity :: highlightAreaEntity :: entities
Expand Down Expand Up @@ -883,8 +905,8 @@ view ballTextures roughnessTexture table window model =
, antialiasing = Scene3d.multisampling
, camera = camera3d
, entities = entitiesWithUI
, lights = Scene3d.twoLights environmentalLighting sunlight
, exposure = Scene3d.exposureValue 13
, lights = Scene3d.fiveLights environmentalLighting sunlight lamp1 lamp2 lamp3
, exposure = Scene3d.exposureValue 10
, whiteBalance = Scene3d.Light.daylight
, clipDepth = Bodies.clipDepth
, background = Scene3d.backgroundColor Color.black
Expand Down
4 changes: 3 additions & 1 deletion src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ init unsafeFlags =
, Task.attempt GotRoughnessTexture (Material.load (assetsPath ++ "img/roughness.jpg"))
, Task.attempt GotTable
(Table.load
{ texture = assetsPath ++ "img/billiard-table.png"
{ colorTexture = assetsPath ++ "img/billiard-table-color.png"
, roughnessTexture = assetsPath ++ "img/billiard-table-roughness.png"
, metallicTexture = assetsPath ++ "img/billiard-table-metallic.png"
, mesh = assetsPath ++ "/billiard-table.obj.txt"
}
)
Expand Down
23 changes: 17 additions & 6 deletions src/Table.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Length
import Obj.Decode exposing (Decoder)
import Physics.Coordinates exposing (BodyCoordinates)
import Physics.Shape as Shape exposing (Shape)
import Scene3d.Material
import Scene3d.Material as Material
import Scene3d.Mesh exposing (Shadow, Textured)
import Task exposing (Task)

Expand All @@ -28,11 +28,11 @@ type alias Table =
, pockets : List Shape
, mesh : Textured BodyCoordinates
, shadow : Shadow BodyCoordinates
, material : Scene3d.Material.Textured BodyCoordinates
, material : Material.Textured BodyCoordinates
}


load : { texture : String, mesh : String } -> Task String Table
load : { colorTexture : String, roughnessTexture : String, metallicTexture : String, mesh : String } -> Task String Table
load urls =
Http.task
{ method = "get"
Expand All @@ -53,13 +53,24 @@ load urls =
}
|> Task.andThen
(\fn ->
Scene3d.Material.loadWith Scene3d.Material.nearestNeighborFiltering urls.texture
Task.map3
(\colorTexture _ metallicTexture ->
fn
(Material.texturedPbr
{ baseColor = colorTexture
, roughness = Material.constant 0.8 -- roughnessTexture
, metallic = metallicTexture
}
)
)
(Material.loadWith Material.nearestNeighborFiltering urls.colorTexture)
(Material.load urls.roughnessTexture)
(Material.load urls.metallicTexture)
|> Task.mapError (\_ -> "Failed to load texture")
|> Task.map (\texture -> fn (Scene3d.Material.texturedMatte texture))
)


tableDecoder : Decoder (Scene3d.Material.Textured BodyCoordinates -> Table)
tableDecoder : Decoder (Material.Textured BodyCoordinates -> Table)
tableDecoder =
Obj.Decode.map4
(\tableConvexes cushionsConvexes pocketsConvex visual ->
Expand Down

0 comments on commit 33b04c6

Please sign in to comment.