62 lines
1.7 KiB
Kotlin
Raw Normal View History

2020-03-23 22:19:52 +03:00
import hep.dataforge.context.Global
import hep.dataforge.js.Application
import hep.dataforge.js.startApplication
import hep.dataforge.vision.bootstrap.visionPropertyEditor
2020-11-09 19:51:57 +03:00
import hep.dataforge.vision.react.ThreeCanvasComponent
2020-08-09 14:41:24 +03:00
import hep.dataforge.vision.react.objectTree
import hep.dataforge.vision.solid.*
import hep.dataforge.vision.solid.specifications.Canvas3DOptions
2020-08-08 09:40:07 +03:00
import hep.dataforge.vision.solid.three.ThreePlugin
import kotlinx.browser.document
2020-03-23 22:19:52 +03:00
import org.w3c.dom.HTMLElement
import react.RBuilder
import react.child
2020-03-23 22:19:52 +03:00
import react.dom.div
import react.dom.render
public fun RBuilder.threeCanvas(object3D: Solid, options: Canvas3DOptions.() -> Unit = {}) {
child(ThreeCanvasComponent) {
attrs {
this.obj = object3D
this.options = Canvas3DOptions.invoke(options)
}
}
}
2020-03-23 22:19:52 +03:00
private class PlayGroundApp : Application {
private val three = Global.plugins.fetch(ThreePlugin)
override fun start(state: Map<String, Any>) {
val element =
document.getElementById("app") as? HTMLElement ?: error("Element with id 'canvas' not found on page")
2020-08-08 09:40:07 +03:00
val obj = SolidGroup().apply {
2020-03-23 22:37:02 +03:00
box(100, 100, 100, name = "A")
group("B") {
2020-03-23 22:19:52 +03:00
position = Point3D(120, 0, 0)
2020-03-23 22:37:02 +03:00
box(100, 100, 100, name = "C")
2020-03-23 22:19:52 +03:00
}
}
render(element) {
div("row") {
div("col-3") {
objectTree(obj)
}
div("col-6") {
threeCanvas(obj)
}
div("col-3") {
visionPropertyEditor(obj)
2020-03-23 22:19:52 +03:00
}
}
}
}
}
fun main() {
startApplication(::PlayGroundApp)
}