diff --git a/build.gradle.kts b/build.gradle.kts index 48899168..0822fa2f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,7 @@ val dataforgeVersion by extra("0.1.3") plugins { val kotlinVersion = "1.3.50" - val toolsVersion = "0.2.0" + val toolsVersion = "0.2.1" kotlin("jvm") version kotlinVersion apply false id("kotlin-dce-js") version kotlinVersion apply false diff --git a/dataforge-vis-common/build.gradle.kts b/dataforge-vis-common/build.gradle.kts index 678a9e72..9306c687 100644 --- a/dataforge-vis-common/build.gradle.kts +++ b/dataforge-vis-common/build.gradle.kts @@ -1,5 +1,8 @@ +import org.openjfx.gradle.JavaFXOptions + plugins { id("scientifik.mpp") + id("org.openjfx.javafxplugin") } scientifik{ @@ -9,13 +12,23 @@ scientifik{ val dataforgeVersion: String by rootProject.extra kotlin { + jvm{ + withJava() + } + sourceSets { - val commonMain by getting { + commonMain{ dependencies { api("hep.dataforge:dataforge-output:$dataforgeVersion") } } - val jsMain by getting { + jvmMain{ + dependencies { + api("no.tornado:tornadofx:1.7.19") + api("no.tornado:tornadofx-controlsfx:0.1") + } + } + jsMain{ dependencies { api("hep.dataforge:dataforge-output-html:$dataforgeVersion") api(npm("text-encoding")) @@ -24,4 +37,8 @@ kotlin { } } } -} \ No newline at end of file +} + +configure { + modules("javafx.controls") +} diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/FXPlugin.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/FXPlugin.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/FXPlugin.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/FXPlugin.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/demo/MetaEditorDemo.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/demo/MetaEditorDemo.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/demo/MetaEditorDemo.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/demo/MetaEditorDemo.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/meta/ConfigEditor.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/meta/ConfigEditor.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/meta/ConfigEditor.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/meta/ConfigEditor.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/meta/FXMeta.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/meta/FXMeta.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/meta/FXMeta.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/meta/FXMeta.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/meta/MetaViewer.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/meta/MetaViewer.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/meta/MetaViewer.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/meta/MetaViewer.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ColorValueChooser.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ColorValueChooser.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ColorValueChooser.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ColorValueChooser.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ComboBoxValueChooser.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ComboBoxValueChooser.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ComboBoxValueChooser.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ComboBoxValueChooser.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/TextValueChooser.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/TextValueChooser.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/TextValueChooser.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/TextValueChooser.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ValueCallback.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ValueCallback.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ValueCallback.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ValueCallback.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ValueChooser.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ValueChooser.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ValueChooser.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ValueChooser.kt diff --git a/dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ValueChooserBase.kt b/dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ValueChooserBase.kt similarity index 100% rename from dataforge-vis-fx/src/main/kotlin/hep/dataforge/vis/fx/values/ValueChooserBase.kt rename to dataforge-vis-common/src/jvmMain/kotlin/hep/dataforge/vis/fx/values/ValueChooserBase.kt diff --git a/dataforge-vis-fx/src/main/resources/img/df.png b/dataforge-vis-common/src/jvmMain/resources/img/df.png similarity index 100% rename from dataforge-vis-fx/src/main/resources/img/df.png rename to dataforge-vis-common/src/jvmMain/resources/img/df.png diff --git a/dataforge-vis-fx/build.gradle.kts b/dataforge-vis-fx/build.gradle.kts deleted file mode 100644 index 6408a4ab..00000000 --- a/dataforge-vis-fx/build.gradle.kts +++ /dev/null @@ -1,23 +0,0 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.openjfx.gradle.JavaFXOptions - -plugins { - id("scientifik.jvm") - id("org.openjfx.javafxplugin") -} - -dependencies { - api(project(":dataforge-vis-common")) - api("no.tornado:tornadofx:1.7.19") - api("no.tornado:tornadofx-controlsfx:0.1") -} - -configure { - modules("javafx.controls") -} - -tasks.withType { - kotlinOptions{ - jvmTarget = "1.8" - } -} \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/build.gradle.kts b/dataforge-vis-spatial-gdml/build.gradle.kts index af7f99ad..d02c8258 100644 --- a/dataforge-vis-spatial-gdml/build.gradle.kts +++ b/dataforge-vis-spatial-gdml/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack + plugins { id("scientifik.mpp") } @@ -21,4 +23,10 @@ kotlin { } } } +} + +tasks{ + val jsBrowserWebpack by getting(KotlinWebpack::class) { + sourceMaps = false + } } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/MeshThreeFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/MeshThreeFactory.kt index 2b0c5d21..19745507 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/MeshThreeFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/MeshThreeFactory.kt @@ -19,8 +19,8 @@ import kotlin.reflect.KClass /** * Basic geometry-based factory */ -abstract class MeshThreeFactory( - override val type: KClass +abstract class MeshThreeFactory( + override val type: KClass ) : ThreeFactory { /** * Build a geometry for an object diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt index 94e71f5e..23339ac7 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt @@ -16,9 +16,9 @@ import kotlin.reflect.KClass * Builder and updater for three.js object */ @Type(TYPE) -interface ThreeFactory { +interface ThreeFactory { - val type: KClass + val type: KClass operator fun invoke(obj: T): Object3D @@ -30,7 +30,7 @@ interface ThreeFactory { /** * Update position, rotation and visibility */ -internal fun Object3D.updatePosition(obj: VisualObject3D) { +fun Object3D.updatePosition(obj: VisualObject3D) { visible = obj.visible ?: true position.set(obj.x, obj.y, obj.z) setRotationFromEuler(obj.euler) @@ -50,6 +50,9 @@ operator fun ThreeFactory.invoke(obj: Any): Object3D { } } +/** + * Update non-position non-geometry property + */ fun Object3D.updateProperty(source: VisualObject, propertyName: Name) { if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) { //updated material diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeGeometryBuilder.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeGeometryBuilder.kt index a7a6b606..c45d6caa 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeGeometryBuilder.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeGeometryBuilder.kt @@ -10,6 +10,9 @@ import info.laht.threekt.core.Face3 import info.laht.threekt.core.Geometry import info.laht.threekt.math.Vector3 +/** + * An implementation of geometry builder for Three.js [BufferGeometry] + */ class ThreeGeometryBuilder : GeometryBuilder { private val vertices = ArrayList() diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeLineFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeLineFactory.kt index cb109e8b..f3a46e1b 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeLineFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeLineFactory.kt @@ -9,7 +9,7 @@ import info.laht.threekt.objects.LineSegments import kotlin.reflect.KClass object ThreeLineFactory : ThreeFactory { - override val type: KClass get() = PolyLine::class + override val type: KClass get() = PolyLine::class override fun invoke(obj: PolyLine): Object3D { val geometry = Geometry().apply { diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt index 0952f78e..1dd74ca3 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeOutput.kt @@ -5,11 +5,16 @@ import hep.dataforge.meta.* import hep.dataforge.output.Output import hep.dataforge.vis.common.Colors import hep.dataforge.vis.spatial.VisualObject3D +import hep.dataforge.vis.spatial.World import info.laht.threekt.WebGLRenderer +import info.laht.threekt.cameras.PerspectiveCamera +import info.laht.threekt.external.controls.OrbitControls +import info.laht.threekt.external.controls.TrackballControls import info.laht.threekt.helpers.AxesHelper import info.laht.threekt.lights.AmbientLight import info.laht.threekt.scenes.Scene import org.w3c.dom.HTMLElement +import org.w3c.dom.Node import kotlin.browser.window import kotlin.dom.clear import kotlin.math.max @@ -28,7 +33,28 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output TrackballControls(camera, element) + else -> OrbitControls(camera, element) + } + } fun attach(element: HTMLElement) { element.clear() @@ -40,7 +66,7 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output, ThreeFactory<*>>() + private val objectFactories = HashMap, ThreeFactory<*>>() private val compositeFactory = ThreeCompositeFactory(this) private val proxyFactory = ThreeProxyFactory(this) @@ -36,7 +32,7 @@ class ThreePlugin : AbstractPlugin() { objectFactories[PolyLine::class] = ThreeLineFactory } - private fun findObjectFactory(type: KClass): ThreeFactory<*>? { + private fun findObjectFactory(type: KClass): ThreeFactory<*>? { return objectFactories[type] ?: context.content>(ThreeFactory.TYPE).values.find { it.type == type } } @@ -89,27 +85,6 @@ class ThreePlugin : AbstractPlugin() { } } - fun buildCamera(meta: Meta) = PerspectiveCamera( - meta["fov"].int ?: 75, - meta["aspect"].double ?: 1.0, - meta["nearClip"].double ?: World.CAMERA_NEAR_CLIP, - meta["farClip"].double ?: World.CAMERA_FAR_CLIP - ).apply { - position.setZ(World.CAMERA_INITIAL_DISTANCE) - rotation.set( - World.CAMERA_INITIAL_X_ANGLE, - World.CAMERA_INITIAL_Y_ANGLE, - World.CAMERA_INITIAL_Z_ANGLE - ) - } - - fun addControls(camera: Camera, element: Node, meta: Meta) { - when (meta["type"].string) { - "trackball" -> TrackballControls(camera, element) - else -> OrbitControls(camera, element) - } - } - companion object : PluginFactory { override val tag = PluginTag("visual.three", PluginTag.DATAFORGE_GROUP) override val type = ThreePlugin::class