diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt index d59d1a3f..bb60b8b6 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt @@ -17,7 +17,7 @@ import kotlin.random.Random class GDMLTransformer(val root: GDML) { private val materialCache = HashMap() - private val random = Random(111) + private val random = Random(222) enum class Action { ACCEPT, diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt index 9134989b..6c9f9baf 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/visualGDML.kt @@ -5,6 +5,8 @@ import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.vis.common.get import hep.dataforge.vis.spatial.* +import hep.dataforge.vis.spatial.GeometryConstants.one +import hep.dataforge.vis.spatial.GeometryConstants.zero import scientifik.gdml.* import kotlin.math.cos import kotlin.math.sin @@ -12,25 +14,28 @@ import kotlin.math.sin private fun VisualObject3D.withPosition( lUnit: LUnit, - pos: GDMLPosition? = null, - rotation: GDMLRotation? = null, - scale: GDMLScale? = null + newPos: GDMLPosition? = null, + newRotation: GDMLRotation? = null, + newScale: GDMLScale? = null ): VisualObject3D = apply { - pos?.let { - this@withPosition.x = pos.x(lUnit) - this@withPosition.y = pos.y(lUnit) - this@withPosition.z = pos.z(lUnit) + newPos?.let { + val point = Point3D(it.x(lUnit), it.y(lUnit), it.z(lUnit)) + if (position != null || point != zero) { + position = point + } } - rotation?.let { - this@withPosition.rotationX = rotation.x() - this@withPosition.rotationY = rotation.y() - this@withPosition.rotationZ = rotation.z() + newRotation?.let { + val point = Point3D(it.x(), it.y(), it.z()) + if (rotation != null || point != zero) { + rotation = point + } //this@withPosition.rotationOrder = RotationOrder.ZXY } - scale?.let { - this@withPosition.scaleX = scale.x.toFloat() - this@withPosition.scaleY = scale.y.toFloat() - this@withPosition.scaleZ = scale.z.toFloat() + newScale?.let { + val point = Point3D(it.x, it.y, it.z) + if (scale != null || point != one) { + scale = point + } } //TODO convert units if needed } @@ -251,6 +256,6 @@ fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisualGroup3D { */ fun VisualGroup3D.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) { val visual = gdml.toVisual(transformer) - println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(),visual)) + println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual)) set(key, visual) } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt index 550430f3..fd6358a2 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Box.kt @@ -10,11 +10,13 @@ import hep.dataforge.meta.get import hep.dataforge.vis.common.AbstractVisualObject import hep.dataforge.vis.common.VisualFactory import hep.dataforge.vis.common.VisualObject +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers import kotlin.reflect.KClass @Serializable +@SerialName("3d.box") class Box( val xSize: Float, val ySize: Float, diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index 95da3d1a..c74e2236 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -12,6 +12,7 @@ import hep.dataforge.names.NameToken import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.vis.common.* +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import kotlinx.serialization.UseSerializers @@ -23,6 +24,7 @@ import kotlin.collections.set * A proxy [VisualObject3D] to reuse a template object */ @Serializable +@SerialName("3d.proxy") class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, VisualObject3D { override var position: Point3D? = null @@ -90,6 +92,13 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua override val styleSheet: StyleSheet get() = this@Proxy.styleSheet + override var styles: List + get() = super.styles + prototype.styles + set(value) { + setProperty(VisualObject.STYLE_KEY, value) + updateStyles(value) + } + override val children: Map get() = (prototype as? VisualGroup)?.children?.mapValues { (key, _) -> ProxyChild( diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index 4bacdd79..51e06062 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -25,6 +25,7 @@ import kotlinx.serialization.UseSerializers import kotlin.collections.set @Serializable +@SerialName("group.3d") class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { /** * A container for templates visible inside this group diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt index e9fab6ab..cd739046 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/geometry.kt @@ -50,10 +50,13 @@ operator fun Point3D.component3() = z fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0) -val zero = Point3D(0, 0, 0) - fun Point3D.toMeta() = buildMeta { VisualObject3D.x put x VisualObject3D.y put y VisualObject3D.z put z +} + +object GeometryConstants{ + val zero = Point3D(0.0, 0.0, 0.0) + val one = Point3D(1.0, 1.0, 1.0) } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/three.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/three.kt index 34e67764..a203d1f5 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/three.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/three.kt @@ -5,6 +5,7 @@ import hep.dataforge.meta.float import hep.dataforge.meta.get import hep.dataforge.meta.node import hep.dataforge.vis.spatial.* +import hep.dataforge.vis.spatial.GeometryConstants.zero import info.laht.threekt.core.* import info.laht.threekt.external.controls.OrbitControls import info.laht.threekt.materials.Material diff --git a/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/geometryJVM.kt b/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/geometryJVM.kt index affc7f8c..46707c0c 100644 --- a/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/geometryJVM.kt +++ b/dataforge-vis-spatial/src/jvmMain/kotlin/hep/dataforge/vis/spatial/geometryJVM.kt @@ -1,8 +1,7 @@ package hep.dataforge.vis.spatial -actual class Point2D actual constructor(x: Number, y: Number) { - actual var x = x.toDouble() - actual var y = y.toDouble() +actual data class Point2D(actual var x: Double, actual var y: Double){ + actual constructor(x: Number, y: Number): this(x.toDouble(),y.toDouble()) } actual class Point3D(val point: org.fxyz3d.geometry.Point3D) { @@ -29,4 +28,16 @@ actual class Point3D(val point: org.fxyz3d.geometry.Point3D) { inline set(value) { point.z = value.toFloat() } + + override fun equals(other: Any?): Boolean { + return this.point == (other as? hep.dataforge.vis.spatial.Point3D)?.point + } + + override fun hashCode(): Int { + return point.hashCode() + } + + override fun toString(): String { + return point.toString() + } } \ No newline at end of file diff --git a/spatial-demo/src/jvmMain/kotlin/hep/dataforge/vis/spatial/demo/FXDemoApp.kt b/spatial-demo/src/jvmMain/kotlin/hep/dataforge/vis/spatial/demo/FXDemoApp.kt index 1808c43f..3fbaff04 100644 --- a/spatial-demo/src/jvmMain/kotlin/hep/dataforge/vis/spatial/demo/FXDemoApp.kt +++ b/spatial-demo/src/jvmMain/kotlin/hep/dataforge/vis/spatial/demo/FXDemoApp.kt @@ -17,7 +17,7 @@ class FXDemoApp : App(FXDemoGrid::class) { stage.width = 400.0 stage.height = 400.0 - view.showcase() + //view.showcase() view.demo("gdml", "gdml") { gdml(Paths.get("D:\\Work\\Projects\\gdml.kt\\gdml-source\\cubes.gdml")) { lUnit = LUnit.CM