From 8652b03fa5bdf102e99a524f2beaccd22fa86382 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 11 May 2021 11:33:12 +0300 Subject: [PATCH] Fix a bug with composite children. Composite is no longer a group. --- .../playground/src/jvmMain/kotlin/gdmCurve.kt | 10 ++++++++-- .../ThreeWithControls.kt | 2 +- .../space/kscience/visionforge/VisionBase.kt | 4 +--- .../visionforge/gdml/GdmlTransformerEnv.kt | 6 +++--- .../kscience/visionforge/solid/Composite.kt | 19 +++++++++---------- .../kscience/visionforge/solid/SolidBase.kt | 12 +++++------- .../kscience/visionforge/solid/SolidGroup.kt | 9 +++------ .../kscience/visionforge/solid/Solids.kt | 1 + .../solid/specifications/Canvas3DOptions.kt | 11 +++++++++++ .../visionforge/solid/three/ThreeCanvas.kt | 9 ++++++++- 10 files changed, 50 insertions(+), 33 deletions(-) diff --git a/demo/playground/src/jvmMain/kotlin/gdmCurve.kt b/demo/playground/src/jvmMain/kotlin/gdmCurve.kt index 3f7ff281..cbdac68a 100644 --- a/demo/playground/src/jvmMain/kotlin/gdmCurve.kt +++ b/demo/playground/src/jvmMain/kotlin/gdmCurve.kt @@ -5,6 +5,8 @@ import space.kscience.gdml.* import space.kscience.visionforge.gdml.toVision import space.kscience.visionforge.html.ResourceLocation import space.kscience.visionforge.solid.Solids +import space.kscience.visionforge.solid.color +import space.kscience.visionforge.solid.invoke import space.kscience.visionforge.visible import java.nio.file.Path @@ -229,8 +231,12 @@ fun main() { if(solid.name == "world"){ visible = false } - //make all solids semi-transparent - transparent() + if(solid.name.startsWith("gas")){ + color("green") + } else { + //make all solids semi-transparent + transparent() + } } } } diff --git a/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeWithControls.kt b/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeWithControls.kt index 9b415e84..6d7aaa0b 100644 --- a/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeWithControls.kt +++ b/ui/ring/src/main/kotlin/space.kscience.visionforge.ring/ThreeWithControls.kt @@ -16,7 +16,7 @@ import space.kscience.visionforge.solid.three.ThreePlugin import kotlin.reflect.KClass public class ThreeWithControls : AbstractPlugin(), ElementVisionRenderer { - public val three by require(ThreePlugin) + public val three: ThreePlugin by require(ThreePlugin) override val tag: PluginTag get() = Companion.tag diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionBase.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionBase.kt index 651de863..26ec2523 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionBase.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionBase.kt @@ -32,12 +32,10 @@ internal data class PropertyListener( @SerialName("vision") public open class VisionBase( internal var properties: Config? = null, + @Transient override var parent: VisionGroup? = null, @Transient public val coroutineScope: CoroutineScope = GlobalScope, ) : Vision { - @Transient - override var parent: VisionGroup? = null - @Synchronized protected fun getOrCreateConfig(): Config { if (properties == null) { diff --git a/visionforge-gdml/src/commonMain/kotlin/space/kscience/visionforge/gdml/GdmlTransformerEnv.kt b/visionforge-gdml/src/commonMain/kotlin/space/kscience/visionforge/gdml/GdmlTransformerEnv.kt index 0d4b6d29..ef41a214 100644 --- a/visionforge-gdml/src/commonMain/kotlin/space/kscience/visionforge/gdml/GdmlTransformerEnv.kt +++ b/visionforge-gdml/src/commonMain/kotlin/space/kscience/visionforge/gdml/GdmlTransformerEnv.kt @@ -160,20 +160,20 @@ private class GdmlTransformerEnv(val settings: GdmlTransformer) { ): T = apply { newPos?.let { val point = Point3D(it.x(settings.lUnit), it.y(settings.lUnit), it.z(settings.lUnit)) - if (position != null || point != Point3D.ZERO) { + if (point != Point3D.ZERO) { position = point } } newRotation?.let { val point = Point3D(it.x(settings.aUnit), it.y(settings.aUnit), it.z(settings.aUnit)) - if (rotation != null || point != Point3D.ZERO) { + if (point != Point3D.ZERO) { rotation = point } //this@withPosition.rotationOrder = RotationOrder.ZXY } newScale?.let { val point = Point3D(it.x, it.y, it.z) - if (scale != null || point != Point3D.ONE) { + if (point != Point3D.ONE) { scale = point } } diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Composite.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Composite.kt index f7325d2b..1b9ecd0f 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Composite.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Composite.kt @@ -3,7 +3,6 @@ package space.kscience.visionforge.solid import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import space.kscience.dataforge.meta.update -import space.kscience.dataforge.names.NameToken import space.kscience.visionforge.* public enum class CompositeType { @@ -18,15 +17,15 @@ public class Composite( public val compositeType: CompositeType, public val first: Solid, public val second: Solid, -) : SolidBase(), Solid, VisionGroup { - - init { - first.parent = this - second.parent = this - } - - override val children: Map - get() = mapOf(NameToken("first") to first, NameToken("second") to second) +) : SolidBase(), Solid { +// +// init { +// first.parent = this +// second.parent = this +// } +// +// override val children: Map +// get() = mapOf(NameToken("first") to first, NameToken("second") to second) } @VisionBuilder diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidBase.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidBase.kt index 77e66a53..e69f729c 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidBase.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidBase.kt @@ -12,15 +12,13 @@ import space.kscience.visionforge.VisionChange @Serializable @SerialName("solid") -public open class SolidBase : VisionBase(), Solid { +public open class SolidBase( + override var position: Point3D? = null, + override var rotation: Point3D? = null, + override var scale: Point3D? = null, +) : VisionBase(), Solid { override val descriptor: NodeDescriptor get() = Solid.descriptor - override var position: Point3D? = null - - override var rotation: Point3D? = null - - override var scale: Point3D? = null - override fun update(change: VisionChange) { updatePosition(change.properties) super.update(change) diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt index c9c987a2..20ca8afc 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt @@ -29,6 +29,9 @@ public interface PrototypeHolder { @SerialName("group.solid") public class SolidGroup( @Serializable(PrototypeSerializer::class) internal var prototypes: MutableVisionGroup? = null, + override var position: Point3D? = null, + override var rotation: Point3D? = null, + override var scale: Point3D? = null, ) : VisionGroupBase(), Solid, PrototypeHolder { init { @@ -53,12 +56,6 @@ public class SolidGroup( }).run(builder) } - override var position: Point3D? = null - - override var rotation: Point3D? = null - - override var scale: Point3D? = null - // /** // * TODO add special static group to hold statics without propagation // */ diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solids.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solids.kt index f65bd7d2..1a83d2cb 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solids.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solids.kt @@ -54,6 +54,7 @@ public class Solids(meta: Meta) : VisionPlugin(meta) { } internal val jsonForSolids: Json = Json(VisionManager.defaultJson) { + encodeDefaults = false serializersModule = serializersModuleForSolids } diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Canvas3DOptions.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Canvas3DOptions.kt index aa7cb258..4a7686b4 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Canvas3DOptions.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/specifications/Canvas3DOptions.kt @@ -9,6 +9,15 @@ import space.kscience.visionforge.scheme import space.kscience.visionforge.value import space.kscience.visionforge.widgetType +public class ClippingPlane: Scheme(){ + public var x: Double by double(0.0) + public var y: Double by double(0.0) + public var z: Double by double(0.0) + + public companion object: SchemeSpec(::ClippingPlane) +} + + public class Canvas3DOptions : Scheme() { public var axes: Axes by spec(Axes) public var light: Light by spec(Light) @@ -25,6 +34,8 @@ public class Canvas3DOptions : Scheme() { public var layers: List by numberList(0) + //public var clippingPlanes: List by list + public var onSelect: ((Name?) -> Unit)? = null diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeCanvas.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeCanvas.kt index e9c7a61a..306bdbaf 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeCanvas.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeCanvas.kt @@ -11,6 +11,7 @@ import info.laht.threekt.geometries.EdgesGeometry import info.laht.threekt.helpers.AxesHelper import info.laht.threekt.lights.AmbientLight import info.laht.threekt.materials.LineBasicMaterial +import info.laht.threekt.math.Box3 import info.laht.threekt.math.Vector2 import info.laht.threekt.objects.LineSegments import info.laht.threekt.objects.Mesh @@ -43,7 +44,13 @@ public class ThreeCanvas( public val three: ThreePlugin, public val options: Canvas3DOptions, ) { + + private var boundingBox: Box3? = null private var root: Object3D? = null + set(value) { + field = value + if (value != null) boundingBox = Box3().setFromObject(value) + } private val raycaster = Raycaster() private val mousePosition: Vector2 = Vector2() @@ -84,7 +91,7 @@ public class ThreeCanvas( (0..31).forEach { if (it in selectedLayers) { this@apply.layers.enable(it) - } else{ + } else { this@apply.layers.disable(it) } }