forked from kscience/visionforge
Fix proxy display
This commit is contained in:
parent
a5a03f1c02
commit
a564e078e5
@ -17,7 +17,7 @@ import kotlin.random.Random
|
||||
|
||||
class GDMLTransformer(val root: GDML) {
|
||||
private val materialCache = HashMap<GDMLMaterial, Meta>()
|
||||
private val random = Random(111)
|
||||
private val random = Random(222)
|
||||
|
||||
enum class Action {
|
||||
ACCEPT,
|
||||
|
@ -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)
|
||||
}
|
@ -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,
|
||||
|
@ -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<String>
|
||||
get() = super.styles + prototype.styles
|
||||
set(value) {
|
||||
setProperty(VisualObject.STYLE_KEY, value)
|
||||
updateStyles(value)
|
||||
}
|
||||
|
||||
override val children: Map<NameToken, VisualObject>
|
||||
get() = (prototype as? VisualGroup)?.children?.mapValues { (key, _) ->
|
||||
ProxyChild(
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user