From c1627b450413893e10820925f3f084ca536e0cfd Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 15 Jul 2021 18:56:29 +0300 Subject: [PATCH] Minor FX fixes --- .../kscience/visionforge/solid/FX3DPlugin.kt | 19 +++++++++-------- .../visionforge/solid/FXCompositeFactory.kt | 2 +- .../visionforge/solid/FXConvexFactory.kt | 2 +- .../visionforge/solid/FXShapeFactory.kt | 2 +- .../visionforge/solid/OrbitControls.kt | 21 ++++++++++++++++--- .../solid/specifications/Camera.kt | 5 +++-- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FX3DPlugin.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FX3DPlugin.kt index 6bd56fcf..aac30150 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FX3DPlugin.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FX3DPlugin.kt @@ -65,6 +65,7 @@ class FX3DPlugin : AbstractPlugin() { } is SolidLabel -> Text(obj.text).apply { font = Font.font(obj.fontFamily, obj.fontSize) + x = -layoutBounds.width / 2 y = layoutBounds.height / 2 } @@ -129,10 +130,10 @@ class FX3DPlugin : AbstractPlugin() { } } - companion object : PluginFactory { - override val tag = PluginTag("vision.fx3D", PluginTag.DATAFORGE_GROUP) - override val type = FX3DPlugin::class - override fun invoke(meta: Meta, context: Context) = FX3DPlugin() + public companion object : PluginFactory { + override val tag: PluginTag = PluginTag("vision.fx3D", PluginTag.DATAFORGE_GROUP) + override val type: KClass = FX3DPlugin::class + override fun invoke(meta: Meta, context: Context): FX3DPlugin = FX3DPlugin() } } @@ -140,14 +141,14 @@ class FX3DPlugin : AbstractPlugin() { * Builder and updater for three.js object */ @Type(TYPE) -interface FX3DFactory { +public interface FX3DFactory { - val type: KClass + public val type: KClass - operator fun invoke(obj: T, binding: VisualObjectFXBinding): Node + public operator fun invoke(obj: T, binding: VisualObjectFXBinding): Node - companion object { - const val TYPE = "fx3DFactory" + public companion object { + public const val TYPE = "fx3DFactory" } } diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXCompositeFactory.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXCompositeFactory.kt index 663a927b..1cdcf914 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXCompositeFactory.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXCompositeFactory.kt @@ -38,7 +38,7 @@ private fun MeshView.toCSG(): CSG { return CSG.fromPolygons(polygons) } -class FXCompositeFactory(val plugin: FX3DPlugin) : FX3DFactory { +public class FXCompositeFactory(public val plugin: FX3DPlugin) : FX3DFactory { override val type: KClass get() = Composite::class diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXConvexFactory.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXConvexFactory.kt index 7538d6c6..7bc44207 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXConvexFactory.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXConvexFactory.kt @@ -7,7 +7,7 @@ import javafx.scene.Node import kotlin.reflect.KClass -object FXConvexFactory : FX3DFactory { +public object FXConvexFactory : FX3DFactory { override val type: KClass get() = Convex::class override fun invoke(obj: Convex, binding: VisualObjectFXBinding): Node { diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXShapeFactory.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXShapeFactory.kt index ad88aac0..116075ce 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXShapeFactory.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/FXShapeFactory.kt @@ -8,7 +8,7 @@ import org.fxyz3d.geometry.Face3 import space.kscience.dataforge.meta.Meta import kotlin.reflect.KClass -object FXShapeFactory : FX3DFactory { +public object FXShapeFactory : FX3DFactory { override val type: KClass get() = GeometrySolid::class override fun invoke(obj: GeometrySolid, binding: VisualObjectFXBinding): MeshView { diff --git a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/OrbitControls.kt b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/OrbitControls.kt index 5f15fe37..2fe573e0 100644 --- a/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/OrbitControls.kt +++ b/visionforge-fx/src/main/kotlin/space/kscience/visionforge/solid/OrbitControls.kt @@ -21,10 +21,25 @@ import space.kscience.visionforge.solid.specifications.Camera as CameraSpec public class OrbitControls internal constructor(camera: Camera, canvas: SubScene, spec: CameraSpec) { - public val azimuthProperty: SimpleDoubleProperty = SimpleDoubleProperty(spec.azimuth) + /** + * Azimuth angle in radians + */ + public val azimuthProperty: SimpleDoubleProperty = SimpleDoubleProperty().apply { + spec.useProperty(CameraSpec::azimuth){ + set(spec.azimuth) + } + } public var azimuth: Double by azimuthProperty - public val zenithProperty: SimpleDoubleProperty = SimpleDoubleProperty(PI / 2 - spec.latitude) + /** + * Zenith angle in radians + */ + public val zenithProperty: SimpleDoubleProperty = SimpleDoubleProperty().apply { + spec.useProperty(CameraSpec::latitude){ + set(PI / 2 - spec.latitude) + } + } + public var zenith: Double by zenithProperty @@ -123,7 +138,7 @@ public class OrbitControls internal constructor(camera: Camera, canvas: SubScene if (me.isPrimaryButtonDown) { azimuth = (azimuth - mouseDeltaX * MOUSE_SPEED * modifier * ROTATION_SPEED) - zenith = (zenith - mouseDeltaY * MOUSE_SPEED * modifier * ROTATION_SPEED).coerceIn(-PI, PI) + zenith = (zenith - mouseDeltaY * MOUSE_SPEED * modifier * ROTATION_SPEED).coerceIn(-PI/2, PI/2) } else if (me.isSecondaryButtonDown) { x += MOUSE_SPEED * modifier * TRACK_SPEED * (mouseDeltaX * cos(azimuth) - mouseDeltaY * sin(azimuth)) z += MOUSE_SPEED * modifier * TRACK_SPEED * ( mouseDeltaX * sin(azimuth) + mouseDeltaY * cos(azimuth)) diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Camera.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Camera.kt index b6209b54..905fa234 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Camera.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Camera.kt @@ -18,7 +18,6 @@ public class Camera : Scheme() { public var distance: Double by double(INITIAL_DISTANCE) public var azimuth: Double by double(INITIAL_AZIMUTH) public var latitude: Double by double(INITIAL_LATITUDE) - public val zenith: Double get() = PI / 2 - latitude public companion object : SchemeSpec(::Camera) { public const val INITIAL_DISTANCE: Double = 300.0 @@ -51,4 +50,6 @@ public class Camera : Scheme() { } } } -} \ No newline at end of file +} + +public val Camera.zenith: Double get() = PI / 2 - latitude \ No newline at end of file