diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GDMLAppComponent.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GDMLAppComponent.kt index 041150c0..e575e103 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GDMLAppComponent.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GDMLAppComponent.kt @@ -3,19 +3,18 @@ package hep.dataforge.vision.gdml.demo import hep.dataforge.context.Context import hep.dataforge.names.Name import hep.dataforge.vision.Vision +import hep.dataforge.vision.bootstrap.gridRow import hep.dataforge.vision.bootstrap.nameCrumbs import hep.dataforge.vision.bootstrap.threeControls import hep.dataforge.vision.gdml.toVision import hep.dataforge.vision.react.ThreeCanvasComponent import hep.dataforge.vision.react.flexColumn -import hep.dataforge.vision.react.flexRow import hep.dataforge.vision.solid.Solid import hep.dataforge.vision.solid.SolidManager import hep.dataforge.vision.solid.specifications.Canvas3DOptions import hep.dataforge.vision.solid.three.ThreeCanvas import kotlinx.browser.window import kotlinx.css.* -import kotlinx.css.properties.border import kscience.gdml.GDML import kscience.gdml.decodeFromString import org.w3c.files.FileReader @@ -69,25 +68,22 @@ val GDMLApp = functionalComponent("GDMLApp") { props -> vision = parsedVision } - flexRow { - css { - height = 100.vh - 35.px - width = 100.vw - 35.px - //flexWrap = FlexWrap.wrap - } + gridRow { flexColumn { - css { - flex(1.0, 1.0, FlexBasis.auto) + css{ + +"col-lg-9" + height = 100.vh } styledDiv { css { + +"mx-auto" +"page-header" - +"justify-content-center" } h1 { +"GDML/JSON loader demo" } } nameCrumbs(selected, "World", onSelect) //canvas + child(ThreeCanvasComponent) { attrs { this.context = props.context @@ -105,11 +101,11 @@ val GDMLApp = functionalComponent("GDMLApp") { props -> } flexColumn { css { - minWidth = 400.px - height = 100.pct - margin(left = 4.px, right = 4.px, top = 4.px) - border(1.px, BorderStyle.solid, Color.lightGray) - flex(0.0,1.0, FlexBasis.zero) + +"col-lg-3" + padding(top = 4.px) + //border(1.px, BorderStyle.solid, Color.lightGray) + height = 100.vh + overflowY = Overflow.auto } fileDrop("(drag file here)") { files -> val file = files?.get(0) diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt index 67df999f..352d645c 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GdmlJsDemoApp.kt @@ -12,10 +12,9 @@ import react.dom.render private class GDMLDemoApp : Application { override fun start(state: Map) { - - val context = Global.context("demo") {} val element = document.getElementById("app") ?: error("Element with id 'app' not found on page") + val context = Global.context("demo") {} render(element) { child(GDMLApp) { attrs { diff --git a/demo/gdml/src/jsMain/resources/index.html b/demo/gdml/src/jsMain/resources/index.html index 74e27a96..0e663f1d 100644 --- a/demo/gdml/src/jsMain/resources/index.html +++ b/demo/gdml/src/jsMain/resources/index.html @@ -8,10 +8,11 @@ - - -
+
+ + + \ No newline at end of file diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt index 8af687d9..37220400 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt @@ -8,8 +8,10 @@ import hep.dataforge.names.length import hep.dataforge.vision.Vision import hep.dataforge.vision.bootstrap.canvasControls import hep.dataforge.vision.bootstrap.card +import hep.dataforge.vision.bootstrap.gridRow import hep.dataforge.vision.react.ThreeCanvasComponent import hep.dataforge.vision.react.configEditor +import hep.dataforge.vision.react.flexColumn import hep.dataforge.vision.react.objectTree import hep.dataforge.vision.solid.specifications.Camera import hep.dataforge.vision.solid.specifications.Canvas3DOptions @@ -55,14 +57,14 @@ val MMApp = functionalComponent("Muon monitor") { props -> val root = props.model.root - div("row") { - styledDiv { + gridRow{ + flexColumn { css { +"col-lg-3" + +"order-lg-1" + +"order-2" padding(0.px) overflowY = Overflow.auto - display = Display.flex - flexDirection = FlexDirection.column height = 100.vh } //tree @@ -73,14 +75,14 @@ val MMApp = functionalComponent("Muon monitor") { props -> objectTree(root, selected, onSelect) } } - styledDiv { + flexColumn { css { +"col-lg-6" - display = Display.flex - flexDirection = FlexDirection.column + +"order-lg-2" + +"order-1" height = 100.vh } - h1("mx-auto") { + h1("mx-auto page-header") { +"Muon monitor demo" } //canvas @@ -89,22 +91,21 @@ val MMApp = functionalComponent("Muon monitor") { props -> attrs { this.context = props.context this.obj = root + this.selected = selected this.options = canvasConfig.apply { this.onSelect = onSelect } - this.selected = selected this.canvasCallback = { canvas = it } } } } - styledDiv { + flexColumn { css { +"col-lg-3" + +"order-3" padding(0.px) - display = Display.flex - flexDirection = FlexDirection.column height = 100.vh } styledDiv { diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt index 1d3ea8cd..0ca23130 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt @@ -21,10 +21,9 @@ private class MMDemoApp : Application { } override fun start(state: Map) { - - val context = Global.context("demo") {} val element = document.getElementById("app") ?: error("Element with id 'app' not found on page") + val context = Global.context("demo") {} render(element) { child(MMApp) { attrs { diff --git a/demo/muon-monitor/src/jsMain/resources/index.html b/demo/muon-monitor/src/jsMain/resources/index.html index f7d59058..4e8cf959 100644 --- a/demo/muon-monitor/src/jsMain/resources/index.html +++ b/demo/muon-monitor/src/jsMain/resources/index.html @@ -7,10 +7,11 @@ - - -
+
+ + + \ No newline at end of file diff --git a/ui/react/src/main/kotlin/hep/dataforge/vision/react/ThreeCanvasComponent.kt b/ui/react/src/main/kotlin/hep/dataforge/vision/react/ThreeCanvasComponent.kt index a0ef757f..aa78a0fb 100644 --- a/ui/react/src/main/kotlin/hep/dataforge/vision/react/ThreeCanvasComponent.kt +++ b/ui/react/src/main/kotlin/hep/dataforge/vision/react/ThreeCanvasComponent.kt @@ -6,7 +6,8 @@ import hep.dataforge.vision.solid.Solid import hep.dataforge.vision.solid.specifications.Canvas3DOptions import hep.dataforge.vision.solid.three.ThreeCanvas import hep.dataforge.vision.solid.three.ThreePlugin -import kotlinx.css.* +import kotlinx.css.Display +import kotlinx.css.display import org.w3c.dom.Element import org.w3c.dom.HTMLElement import react.* @@ -57,10 +58,7 @@ public val ThreeCanvasComponent: FunctionalComponent = functio styledDiv { css { - display = Display.inherit - width = 100.pct - height = 100.pct - flex(1.0, 1.0, FlexBasis.auto) + display = Display.contents } ref = elementRef } diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt index fafaeb6c..a0f173b9 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/ThreePlugin.kt @@ -54,6 +54,7 @@ public class ThreePlugin : AbstractPlugin(), HtmlVisionBinding { group[token] = object3D } catch (ex: Throwable) { logger.error(ex) { "Failed to render $child" } + ex.printStackTrace() } } } diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/csg.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/csg.kt index a67d5439..af99f66e 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/csg.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/csg.kt @@ -1,26 +1,17 @@ -@file:JsModule("three-csg-ts") -@file:JsNonModule -@file:Suppress( - "INTERFACE_WITH_SUPERCLASS", +@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS", - "EXTERNAL_DELEGATION", - "NESTED_CLASS_IN_EXTERNAL_INTERFACE" -) - -package hep.dataforge.vision.solid.three + "EXTERNAL_DELEGATION") +@file:JsModule("three-csg-ts") +@file:JsNonModule import info.laht.threekt.math.Matrix4 import info.laht.threekt.math.Vector3 import info.laht.threekt.objects.Mesh -/** - * Constructive Solid Geometry - */ -open external class CSG { - open var polygons: Array +external open class CSG { open fun clone(): CSG open fun toPolygons(): Array open fun union(csg: CSG): CSG @@ -33,7 +24,7 @@ open external class CSG { fun fromGeometry(geom: Any): CSG fun fromMesh(mesh: Mesh): CSG fun toMesh(csg: CSG, toMatrix: Matrix4): Mesh - fun iEval(tokens: Mesh, index: Number? = definedExternally /* null */): Unit + fun iEval(tokens: Mesh, index: Number? = definedExternally) fun eval(tokens: Mesh, doRemove: Boolean): Mesh var _tmpm3: Any var doRemove: Any @@ -44,7 +35,7 @@ open external class CSG { } } -open external class Vector(x: Number, y: Number, z: Number): Vector3 { +external open class Vector(x: Number, y: Number, z: Number) : Vector3 { open fun negated(): Vector open fun plus(a: Vector): Vector open fun minus(a: Vector): Vector @@ -61,27 +52,27 @@ external interface IVector { var z: Number } -open external class Vertex(pos: IVector, normal: IVector, uv: IVector) { +external open class Vertex(pos: IVector, normal: IVector, uv: IVector? = definedExternally) { open var pos: Vector open var normal: Vector open var uv: Vector open fun clone(): Vertex - open fun flip(): Unit + open fun flip() open fun interpolate(other: Vertex, t: Number): Vertex } -open external class Plane(normal: Vector, w: Number) { +external open class Plane(normal: Vector, w: Number) { open var normal: Vector open var w: Number open fun clone(): Plane - open fun flip(): Unit + open fun flip() open fun splitPolygon( polygon: Polygon, coplanarFront: Array, coplanarBack: Array, front: Array, - back: Array - ): Unit + back: Array, + ) companion object { fun fromPoints(a: Vector, b: Vector, c: Vector): Plane @@ -89,10 +80,10 @@ open external class Plane(normal: Vector, w: Number) { } } -open external class Polygon(vertices: Array, shared: Any? = definedExternally /* null */) { +external open class Polygon(vertices: Array, shared: Any? = definedExternally) { open var plane: Plane open var vertices: Array open var shared: Any open fun clone(): Polygon - open fun flip(): Unit + open fun flip() } \ No newline at end of file diff --git a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/three.kt b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/three.kt index c0a739e9..862960a9 100644 --- a/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/three.kt +++ b/visionforge-threejs/src/main/kotlin/hep/dataforge/vision/solid/three/three.kt @@ -1,5 +1,6 @@ package hep.dataforge.vision.solid.three +import CSG import hep.dataforge.meta.MetaItem import hep.dataforge.meta.float import hep.dataforge.meta.get @@ -22,15 +23,13 @@ public fun Geometry.toBufferGeometry(): BufferGeometry = BufferGeometry().apply internal fun Double.toRadians() = this * PI / 180 -internal val ZERO = Vector3(0,0,0) - public fun CSG.toGeometry(): Geometry { val geom = Geometry() val vertices = ArrayList() val faces = ArrayList() - for (polygon in polygons) { + for (polygon in toPolygons()) { val v0 = vertices.size val pvs = polygon.vertices @@ -39,7 +38,7 @@ public fun CSG.toGeometry(): Geometry { } for (j in 3..polygon.vertices.size) { - val fc = Face3(v0, v0 + j - 2, v0 + j - 1, ZERO) + val fc = Face3(v0, v0 + j - 2, v0 + j - 1, Vector3()) fc.vertexNormals = arrayOf( Vector3().copy(pvs[0].normal), Vector3().copy(pvs[j - 2].normal),