https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hiring-french
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
k

Kebbin

11/27/2021, 2:08 AM
How would you choose to create 3D shapes in a Compose Canvas? Is there a 3D objects or shapes library? Would you draw 12 individual lines for a cube? Would drawing a series of tilted rectangles work better? What about a sphere? I will try some ideas and see what happens! Thanks! 🤓 📦
k

Kirill Grouchnikov

11/27/2021, 3:37 AM
For experimenting or for something a bit more complex with lots of shapes, textures, lighting etc?
r

romainguy

11/27/2021, 4:29 AM
For anything more complicated than a cube I would just use an actual 3D renderer
You could probably fake a sphere with a circle + gradients but it will never look quite right
k

Kebbin

11/27/2021, 5:50 AM
Thanks! Prob plenty of basic shapes. I'm creating a virtual representation of a model train layout, so thinking a good handful of basic building / structure shapes. No real need for fancy lighting and shadows (yet). Plenty of dreams of creating endless randomly lightly populated worlds for my kids to explore, in both visual and conceptual form. Might spark their interest to create a target programming exercise, rather than be overwhelmed with the immensity of general possibilities! :kids:
The idea of the gradient circles and triangles would work for trees prob.
I should be able to place Image components to represent sides of buildings/trees?
So which 3D renderer would you use? Like Filament, or something from Skia?
k

Kirill Grouchnikov

11/27/2021, 6:08 AM
Really depends on what you envision. You can draw simple shapes yourself with canvas APIs. That would work for something like wireframes. If you do want to get into occlusion (not drawing the back side of a cube, or having a sphere placed in front of the cube "hiding" some part of that cube), you'd probably do want to go to an existing library and have it render things onto the native Skia surface.
k

Kebbin

11/27/2021, 6:15 AM
Yes, that sounds better. I will try the Canvas APIs for the experience, but I should look into a decent library. What would you suggest?
d

darkmoon_uk

11/27/2021, 6:48 AM
Hey @Kebbin since you're in 🇦🇺 I can direct you to this. Just a little App I made for a community art project, but it uses Filament to show 3D models.
Not sure what it proves beyond 'someone has used Filament in an Android App' (not even Desktop) but I thought I'd mention it. TBH Filament looks great and powerful, it was also a touch intimidating beyond the simple 'orbit a model' use case I had here.
For more involved use cases you'd have to touch some native library stuff and be prepared to wrangle your assets in its proprietary format.
Once you get past that though, it's a scene-graph with good performance and amazing quality.
k

Kebbin

11/27/2021, 6:52 AM
Cool! Thanks mate. I think it was you who told me about Filament. Yes, it does look intimidating, but the results are spectacular!
1
Ok, I'll pop by in here and read your responses properly in a minute.
👍 1
@Igor Demin @darkmoon_uk I really should have gone to bed, but had to try this!! 😵
😁 1
👍 3
m

Michael Paus

11/27/2021, 1:47 PM
I’d point you to https://libgdx.com/ but I don’t know how to best integrate it into compose.
k

Kebbin

11/27/2021, 1:47 PM
Thanks! I'll have a look at that.
KorGE was another one prob similar to that.
OK, goodnight all! And thanks again.
r

romainguy

11/27/2021, 6:18 PM
@Kebbin if you have questions about Filament, don't hesitate to ask. I'm one of the authors.
@darkmoon_uk Filament doesn't have a dedicated format. We provide one for convenience but that's all. We actually recommend using glTF instead since it's compatible with so many tools nowadays.
k

Kebbin

11/27/2021, 10:22 PM
Ok well done! Thanks Romain! Top product. So where do I start if I want to use it to create a basic 3D scene, like for my railway layout? Will the objects inside it still be clickable/interactive as Compose objects? Thanks!
r

romainguy

11/28/2021, 3:47 AM
There's an API to pick objects in Filament. Given a x/y coordinates it can tell you which entity you touched. I have a simple example of compose integration on https://github.com/romainguy/sample-materials-shop
👀 1
It's based on compose alpha so you'll need to adjust a couple of things but it shows how to load glTF scenes un filament
k

Kebbin

11/28/2021, 4:24 AM
OK! Thanks very much! I will have a look.
Ah yes. I did see that one! OK, I will look into it.
Hmm. Yes, not a massive amount of boilerplate code at all, but will take a while to get my head around it. Relatively succinct, but I guess I'd be hoping for that to be bundled in a more concise library, which obviously could be done within the app. I would have just the one main scene, with interactive objects. I prob should be focussing on the MVVM side of my program first! I just thought I'd explore the 3D side first to get a feel for the possibilities. I'll look more into the Filament product docs now, and see if I can find a simple way to create a basic scene. I guess I'd need to create some 3D models too, which shouldn't be an issue, as that is part of a past life of mine!
Looks like a photographer's dream with all the capabilities!
So I guess I'd need to try the Android sample code as the closest thing to Compose Desktop?
r

romainguy

11/28/2021, 5:59 AM
Yes indeed. With Compose you'll have to use a SurfaceView inside an AndroidView, otherwise the samples will be the same
k

Kebbin

11/28/2021, 6:09 AM
OK, so to start off, I'll need to add Filament implementations to my Gradle file?
Sorry, got roped in to playing a quick few games of cards with the kids after putting washing out!
I also found a post of yours on Reddit explaining SurfaceView, and had links to your wake-me-up sample! I like that one. It seems straightforward, so will have a look at them, plus the https://github.com/google/filament#rendering-with-filament section. Until then, I'll get the basics of my program going, and explore Filament with you later! Thanks so much for your time and info!
m

Michael Paus

11/28/2021, 11:02 AM
In a previous answer I mentioned libgdx which uses lwjgl as its default rendering engine and it seems there is already some kind of experimental/official JetBrains Compose support for it here: lwjgl-integration. Until now I didn’t know that. I’ll have to have a look at that myself too.
:thank-you: 1
c

Colton Idle

11/28/2021, 6:16 PM
@Kebbin did you create that cube in filament? @romainguy would you take a PR to update your compose/filament sample to latest stable? 😄
k

Kebbin

11/29/2021, 6:27 AM
No, I created that cube in Desktop Compose/Kotlin. The only issue is that the system thinks the parts are all still oblique in the display, so individual pointer interaction is near impossible. I had another crack last night at combining rotation with proportional X - Y scaling of the actual underlying Composable to get a similar effect while maintaining clickability, but as soon as perspective is introduced, the screen coordinates will be out the window, so a lot of maths to compensate! I think for basic isometric-style it will work well, but really my time will be better spent learning a 3D renderer! 🤓📖
The suggestion given by members of the libgdx Discord was that it wouldn't be ideal for use in Kotlin/Compose Desktop, but I'll have a look at these links you've just posted. I'm sure we can use it for something!