From 9805c249ad5bfc7a875109dee5849d4b4a223aa7 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 5 Aug 2020 22:39:56 +0300 Subject: [PATCH] Class name refactoring --- .../vision/spatial/gdml/GDMLVisualTest.kt | 2 +- .../spatial/gdml/demo/GDMLAppComponent.kt | 8 +-- .../vision/spatial/gdml/demo/GDMLDemoApp.kt | 4 +- .../vision/spatial/gdml/demo/GDMLDemoApp.kt | 8 +-- .../vision/spatial/gdml/demo/readFile.kt | 10 +-- .../vision/spatial/gdml/demo/saveToJson.kt | 4 +- .../ru/mipt/npm/muon/monitor/MMDemoApp.kt | 4 +- .../mipt/npm/muon/monitor/server/MMServer.kt | 4 +- .../vision/spatial/demo/VariableBox.kt | 16 ++--- .../hep/dataforge/vision/AbstractVision.kt | 2 +- ...VisionlGroup.kt => AbstractVisionGroup.kt} | 8 +-- .../hep/dataforge/vision/SimpleVisionGroup.kt | 2 +- .../hep/dataforge/vision/VisionManager.kt | 23 +++---- .../vision/spatial/gdml/GDMLTransformer.kt | 6 +- .../gdml/{visualGDML.kt => GdmlVision.kt} | 12 ++-- .../vision/spatial/gdml/TestConvertor.kt | 6 +- .../hep/dataforge/vision/spatial/Box.kt | 11 ++-- .../hep/dataforge/vision/spatial/Composite.kt | 8 +-- .../dataforge/vision/spatial/ConeSegment.kt | 4 +- .../hep/dataforge/vision/spatial/Convex.kt | 4 +- .../hep/dataforge/vision/spatial/Extruded.kt | 4 +- .../vision/spatial/GeometryBuilder.kt | 4 +- .../hep/dataforge/vision/spatial/Label3D.kt | 4 +- .../dataforge/vision/spatial/Material3D.kt | 14 ++-- .../hep/dataforge/vision/spatial/PolyLine.kt | 4 +- .../hep/dataforge/vision/spatial/Proxy.kt | 10 +-- .../{Visual3D.kt => SpatialVisionManager.kt} | 28 ++++---- .../hep/dataforge/vision/spatial/Sphere.kt | 4 +- .../hep/dataforge/vision/spatial/Tube.kt | 4 +- .../{VisualObject3D.kt => Vision3D.kt} | 64 +++++++++---------- .../dataforge/vision/spatial/VisionGroup3D.kt | 10 +-- .../hep/dataforge/vision/spatial/geometry.kt | 10 +-- .../dataforge/vision/spatial/serialization.kt | 4 +- .../spatial/transform/RemoveSingleChild.kt | 2 +- .../dataforge/vision/spatial/ConvexTest.kt | 2 +- .../hep/dataforge/vision/spatial/GroupTest.kt | 4 +- .../vision/spatial/three/MeshThreeFactory.kt | 10 +-- .../vision/spatial/three/ThreeCanvas.kt | 10 +-- .../spatial/three/ThreeCanvasComponent.kt | 6 +- .../vision/spatial/three/ThreeFactory.kt | 10 +-- .../vision/spatial/three/ThreePlugin.kt | 24 +++---- .../vision/spatial/three/ThreeProxyFactory.kt | 4 +- .../{ThreeVisualObject.kt => ThreeVision.kt} | 10 +-- .../vision/spatial/three/outputConfig.kt | 6 +- .../dataforge/vision/spatial/three/three.kt | 2 +- .../dataforge/vision/spatial/fx/FX3DPlugin.kt | 32 +++++----- .../dataforge/vision/spatial/fx/FXCanvas3D.kt | 10 +-- .../vision/spatial/generateSchema.kt | 4 +- 48 files changed, 225 insertions(+), 221 deletions(-) rename visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/{AbstractVisionlGroup.kt => AbstractVisionGroup.kt} (94%) rename visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/{visualGDML.kt => GdmlVision.kt} (97%) rename visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/{Visual3D.kt => SpatialVisionManager.kt} (71%) rename visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/{VisualObject3D.kt => Vision3D.kt} (72%) rename visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/{ThreeVisualObject.kt => ThreeVision.kt} (71%) diff --git a/demo/gdml/src/commonTest/kotlin/hep/dataforge/vision/spatial/gdml/GDMLVisualTest.kt b/demo/gdml/src/commonTest/kotlin/hep/dataforge/vision/spatial/gdml/GDMLVisualTest.kt index 7c0c97ad..228206ed 100644 --- a/demo/gdml/src/commonTest/kotlin/hep/dataforge/vision/spatial/gdml/GDMLVisualTest.kt +++ b/demo/gdml/src/commonTest/kotlin/hep/dataforge/vision/spatial/gdml/GDMLVisualTest.kt @@ -13,7 +13,7 @@ class GDMLVisualTest { @Test fun testPrototypeProperty() { val gdml = cubes() - val visual = gdml.toVisual() + val visual = gdml.toVision() visual["composite000.segment0".toName()]?.setItem(Material3D.MATERIAL_COLOR_KEY, "red".asValue()) assertEquals("red", visual["composite000.segment0".toName()]?.getItem(Material3D.MATERIAL_COLOR_KEY).string) } diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLAppComponent.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLAppComponent.kt index 9bedb697..791afc70 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLAppComponent.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLAppComponent.kt @@ -10,9 +10,9 @@ import hep.dataforge.vision.react.component import hep.dataforge.vision.react.configEditor import hep.dataforge.vision.react.flexColumn import hep.dataforge.vision.react.state +import hep.dataforge.vision.spatial.Vision3D import hep.dataforge.vision.spatial.VisionGroup3D -import hep.dataforge.vision.spatial.VisualObject3D -import hep.dataforge.vision.spatial.gdml.toVisual +import hep.dataforge.vision.spatial.gdml.toVision import hep.dataforge.vision.spatial.specifications.Camera import hep.dataforge.vision.spatial.specifications.Canvas3DOptions import hep.dataforge.vision.spatial.three.ThreeCanvas @@ -60,7 +60,7 @@ val GDMLApp = component { props -> visual = when { name.endsWith(".gdml") || name.endsWith(".xml") -> { val gdml = GDML.parse(data) - gdml.toVisual(gdmlConfiguration) + gdml.toVision(gdmlConfiguration) } name.endsWith(".json") -> VisionGroup3D.parseJson(data) else -> { @@ -107,7 +107,7 @@ val GDMLApp = component { props -> gridColumn(6, maxSize= GridMaxSize.XL, classes = "order-1 order-xl-2") { //canvas - (visual as? VisualObject3D)?.let { visual3D -> + (visual as? Vision3D)?.let { visual3D -> child(ThreeCanvasComponent::class) { attrs { this.context = props.context diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLDemoApp.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLDemoApp.kt index d5d73df0..4a68d2b1 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLDemoApp.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLDemoApp.kt @@ -6,7 +6,7 @@ import hep.dataforge.js.startApplication import hep.dataforge.vision.spatial.Material3D.Companion.MATERIAL_OPACITY_KEY import hep.dataforge.vision.spatial.gdml.GDMLTransformer import hep.dataforge.vision.spatial.gdml.LUnit -import hep.dataforge.vision.spatial.gdml.toVisual +import hep.dataforge.vision.spatial.gdml.toVision import kotlinx.css.* import react.child import react.dom.render @@ -60,7 +60,7 @@ private class GDMLDemoApp : Application { child(GDMLApp) { attrs { this.context = context - this.rootObject = cubes().toVisual(gdmlConfiguration) + this.rootObject = cubes().toVision(gdmlConfiguration) } } } diff --git a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLDemoApp.kt b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLDemoApp.kt index e21c55f0..b937cccf 100644 --- a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLDemoApp.kt +++ b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/GDMLDemoApp.kt @@ -4,10 +4,10 @@ import hep.dataforge.context.Global import hep.dataforge.vision.editor.VisualObjectEditorFragment import hep.dataforge.vision.editor.VisualObjectTreeFragment import hep.dataforge.vision.spatial.Material3D -import hep.dataforge.vision.spatial.Visual3D +import hep.dataforge.vision.spatial.SpatialVisionManager import hep.dataforge.vision.spatial.fx.FX3DPlugin import hep.dataforge.vision.spatial.fx.FXCanvas3D -import hep.dataforge.vision.spatial.gdml.toVisual +import hep.dataforge.vision.spatial.gdml.toVision import javafx.geometry.Orientation import javafx.scene.Parent import javafx.stage.FileChooser @@ -39,7 +39,7 @@ class GDMLView : View() { runAsync { val file = chooseFile("Select a GDML/json file", filters = fileNameFilter).firstOrNull() ?: return@runAsync null - Visual3D.readFile(file) + SpatialVisionManager.readFile(file) } ui { if (it != null) { canvas.render(it) @@ -58,7 +58,7 @@ class GDMLView : View() { init { runAsync { - cubes().toVisual() + cubes().toVision() } ui { canvas.render(it) } diff --git a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/readFile.kt b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/readFile.kt index 226f8fb4..dd521aea 100644 --- a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/readFile.kt +++ b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/readFile.kt @@ -3,19 +3,19 @@ package hep.dataforge.vision.spatial.gdml.demo import hep.dataforge.meta.setItem import hep.dataforge.values.asValue import hep.dataforge.vision.spatial.Material3D +import hep.dataforge.vision.spatial.SpatialVisionManager import hep.dataforge.vision.spatial.VisionGroup3D -import hep.dataforge.vision.spatial.Visual3D import hep.dataforge.vision.spatial.gdml.LUnit import hep.dataforge.vision.spatial.gdml.readFile -import hep.dataforge.vision.spatial.gdml.toVisual +import hep.dataforge.vision.spatial.gdml.toVision import scientifik.gdml.GDML import java.io.File import java.util.zip.GZIPInputStream import java.util.zip.ZipInputStream -fun Visual3D.Companion.readFile(file: File): VisionGroup3D = when { +fun SpatialVisionManager.Companion.readFile(file: File): VisionGroup3D = when { file.extension == "gdml" || file.extension == "xml" -> { - GDML.readFile(file.toPath()).toVisual { + GDML.readFile(file.toPath()).toVision { lUnit = LUnit.CM solidConfiguration = { parent, solid -> @@ -48,4 +48,4 @@ fun Visual3D.Companion.readFile(file: File): VisionGroup3D = when { else -> error("Unknown extension ${file.extension}") } -fun Visual3D.Companion.readFile(fileName: String): VisionGroup3D = readFile(File(fileName)) \ No newline at end of file +fun SpatialVisionManager.Companion.readFile(fileName: String): VisionGroup3D = readFile(File(fileName)) \ No newline at end of file diff --git a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/saveToJson.kt b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/saveToJson.kt index 5c83ed37..2cb29af4 100644 --- a/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/saveToJson.kt +++ b/demo/gdml/src/jvmMain/kotlin/hep/dataforge/vision/spatial/gdml/demo/saveToJson.kt @@ -2,7 +2,7 @@ package hep.dataforge.vision.spatial.gdml.demo import hep.dataforge.vision.spatial.gdml.LUnit import hep.dataforge.vision.spatial.gdml.readFile -import hep.dataforge.vision.spatial.gdml.toVisual +import hep.dataforge.vision.spatial.gdml.toVision import hep.dataforge.vision.spatial.stringify import scientifik.gdml.GDML import java.io.File @@ -17,7 +17,7 @@ fun main(args: Array) { val gdml = GDML.readFile(Paths.get(inputFileName)) //GDML.readFile(Paths.get("D:\\Work\\Projects\\visionforge\\visionforge-spatial-gdml\\src\\jvmTest\\resources\\gdml\\simple1.gdml")) - val visual = gdml.toVisual { + val visual = gdml.toVision { lUnit = LUnit.CM } diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt index b500fee8..90ecaa31 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMDemoApp.kt @@ -3,7 +3,7 @@ package ru.mipt.npm.muon.monitor import hep.dataforge.context.Global import hep.dataforge.js.Application import hep.dataforge.js.startApplication -import hep.dataforge.vision.spatial.Visual3D +import hep.dataforge.vision.spatial.SpatialVisionManager import io.ktor.client.HttpClient import io.ktor.client.features.json.JsonFeature import io.ktor.client.features.json.serializer.KotlinxSerializer @@ -19,7 +19,7 @@ private class MMDemoApp : Application { private val connection = HttpClient { install(JsonFeature) { - serializer = KotlinxSerializer(Json(context = Visual3D.serialModule)) + serializer = KotlinxSerializer(Json(context = SpatialVisionManager.serialModule)) } } diff --git a/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/server/MMServer.kt b/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/server/MMServer.kt index 97320bac..10f24f13 100644 --- a/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/server/MMServer.kt +++ b/demo/muon-monitor/src/jvmMain/kotlin/ru/mipt/npm/muon/monitor/server/MMServer.kt @@ -1,7 +1,7 @@ package ru.mipt.npm.muon.monitor.server -import hep.dataforge.vision.spatial.Visual3D +import hep.dataforge.vision.spatial.SpatialVisionManager import io.ktor.application.Application import io.ktor.application.call import io.ktor.application.install @@ -36,7 +36,7 @@ fun Application.module() { install(DefaultHeaders) install(CallLogging) install(ContentNegotiation) { - json(module = Visual3D.serialModule) + json(module = SpatialVisionManager.serialModule) } install(Routing) { get("/event") { diff --git a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/VariableBox.kt b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/VariableBox.kt index d22f7a0e..8855d173 100644 --- a/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/VariableBox.kt +++ b/demo/spatial-showcase/src/jsMain/kotlin/hep/dataforge/vision/spatial/demo/VariableBox.kt @@ -11,7 +11,7 @@ import hep.dataforge.values.asValue import hep.dataforge.vision.getProperty import hep.dataforge.vision.set import hep.dataforge.vision.spatial.* -import hep.dataforge.vision.spatial.VisualObject3D.Companion.GEOMETRY_KEY +import hep.dataforge.vision.spatial.Vision3D.Companion.GEOMETRY_KEY import hep.dataforge.vision.spatial.demo.VariableBoxThreeFactory.Z_SIZE_KEY import hep.dataforge.vision.spatial.three.* import hep.dataforge.vision.spatial.three.ThreeMaterials.getMaterial @@ -23,13 +23,13 @@ import kotlinx.serialization.UseSerializers import kotlin.math.max import kotlin.reflect.KClass -internal var VisualObject3D.variableZSize: Number +internal var Vision3D.variableZSize: Number get() = getProperty(Z_SIZE_KEY, false).number ?: 0f set(value) { setItem(Z_SIZE_KEY, value.asValue()) } -internal var VisualObject3D.value: Int +internal var Vision3D.value: Int get() = getProperty("value", false).int ?: 0 set(value) { setItem("value", value.asValue()) @@ -48,21 +48,21 @@ fun VisionGroup3D.varBox( ySize: Number, zSize: Number, name: String = "", - action: VisualObject3D.() -> Unit = {} -) = CustomThreeVisualObject(VariableBoxThreeFactory).apply { + action: Vision3D.() -> Unit = {} +) = CustomThreeVision(VariableBoxThreeFactory).apply { scaleX = xSize scaleY = ySize scaleZ = zSize }.apply(action).also { set(name, it) } -private object VariableBoxThreeFactory : ThreeFactory { +private object VariableBoxThreeFactory : ThreeFactory { val X_SIZE_KEY = GEOMETRY_KEY + "xSize" val Y_SIZE_KEY = GEOMETRY_KEY + "ySize" val Z_SIZE_KEY = GEOMETRY_KEY + "zSize" - override val type: KClass get() = VisualObject3D::class + override val type: KClass get() = Vision3D::class - override fun invoke(obj: VisualObject3D): Object3D { + override fun invoke(obj: Vision3D): Object3D { val xSize = obj.getProperty(X_SIZE_KEY, false).number?.toDouble() ?: 1.0 val ySize = obj.getProperty(Y_SIZE_KEY, false).number?.toDouble() ?: 1.0 val zSize = obj.getProperty(Z_SIZE_KEY, false).number?.toDouble() ?: 1.0 diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt index 11f8b652..0365e84d 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVision.kt @@ -14,7 +14,7 @@ internal data class PropertyListener( val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit ) -abstract class AbstractVisualObject : Vision { +abstract class AbstractVision : Vision { @Transient override var parent: VisionGroup? = null diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionlGroup.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionGroup.kt similarity index 94% rename from visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionlGroup.kt rename to visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionGroup.kt index 6a1ecf51..a8016397 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionlGroup.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/AbstractVisionGroup.kt @@ -11,7 +11,7 @@ import kotlinx.serialization.Transient /** * Abstract implementation of mutable group of [Vision] */ -abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup { +abstract class AbstractVisionGroup : AbstractVision(), MutableVisionGroup { //protected abstract val _children: MutableMap @@ -86,7 +86,7 @@ abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup { protected open fun addStatic(child: Vision) = set(NameToken("@static(${child.hashCode()})").asName(), child) - protected abstract fun createGroup(): AbstractVision + protected abstract fun createGroup(): AbstractVisionGroup /** * Set this node as parent for given node @@ -102,7 +102,7 @@ abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup { /** * Recursively create a child group */ - private fun createGroups(name: Name): AbstractVision { + private fun createGroups(name: Name): AbstractVisionGroup { return when { name.isEmpty() -> error("Should be unreachable") name.length == 1 -> { @@ -112,7 +112,7 @@ abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup { attach(child) setChild(token, child) } - is AbstractVision -> current + is AbstractVisionGroup -> current else -> error("Can't create group with name $name because it exists and not a group") } } diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt index 2b87dbf4..8dc7e716 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/SimpleVisionGroup.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable @Serializable @SerialName("group") -class SimpleVisionGroup : AbstractVision() { +class SimpleVisionGroup : AbstractVisionGroup() { override var styleSheet: StyleSheet? = null diff --git a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt index a8887d31..5be76805 100644 --- a/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt +++ b/visionforge-core/src/commonMain/kotlin/hep/dataforge/vision/VisionManager.kt @@ -4,13 +4,8 @@ import hep.dataforge.context.* import hep.dataforge.meta.Meta import kotlin.reflect.KClass -interface VisualFactory { +interface VisionFactory : Factory { val type: KClass - operator fun invoke( - context: Context, - parent: Vision?, - meta: Meta - ): T } class VisionManager(meta: Meta) : AbstractPlugin(meta) { @@ -19,12 +14,18 @@ class VisionManager(meta: Meta) : AbstractPlugin(meta) { /** * Create a list of factories on first call and cache it */ - val visualFactories by lazy { - context.content>(VISUAL_FACTORY_TYPE).mapKeys { it.value.type } + private val factories by lazy { + context.content>(VISION_FACTORY_TYPE).mapKeys { it.value.type } } - inline fun buildVisual(parent: Vision?, meta: Meta): T? { - return visualFactories[T::class]?.invoke(context, parent, meta) as T? + @Suppress("UNCHECKED_CAST") + fun resolveVisionFactory(type: KClass): VisionFactory? = + factories[type] as VisionFactory + + inline fun buildVision(parent: VisionGroup?, meta: Meta): T? { + return resolveVisionFactory(T::class)?.invoke(meta, context)?.apply { + this.parent = parent + } } companion object : PluginFactory { @@ -33,6 +34,6 @@ class VisionManager(meta: Meta) : AbstractPlugin(meta) { override fun invoke(meta: Meta, context: Context): VisionManager = VisionManager(meta) - const val VISUAL_FACTORY_TYPE = "vision.factory" + const val VISION_FACTORY_TYPE = "vision.factory" } } \ No newline at end of file diff --git a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GDMLTransformer.kt b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GDMLTransformer.kt index 0eb1750a..90aaafd6 100644 --- a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GDMLTransformer.kt +++ b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GDMLTransformer.kt @@ -33,7 +33,7 @@ class GDMLTransformer(val root: GDML) { var volumeAction: (GDMLGroup) -> Action = { Action.CACHE } - var solidConfiguration: VisualObject3D.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ -> + var solidConfiguration: Vision3D.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ -> lUnit = LUnit.CM if (parent.physVolumes.isNotEmpty()) { useStyle("opaque") { @@ -42,14 +42,14 @@ class GDMLTransformer(val root: GDML) { } } - fun VisualObject3D.useStyle(name: String, builder: MetaBuilder.() -> Unit) { + fun Vision3D.useStyle(name: String, builder: MetaBuilder.() -> Unit) { styleCache.getOrPut(name.toName()) { Meta(builder) } useStyle(name) } - internal fun configureSolid(obj: VisualObject3D, parent: GDMLVolume, solid: GDMLSolid) { + internal fun configureSolid(obj: Vision3D, parent: GDMLVolume, solid: GDMLSolid) { val material = parent.materialref.resolve(root) ?: GDMLElement(parent.materialref.ref) val styleName = "material[${material.name}]" diff --git a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDML.kt b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GdmlVision.kt similarity index 97% rename from visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDML.kt rename to visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GdmlVision.kt index 85adb06b..a6ebcf31 100644 --- a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/visualGDML.kt +++ b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/spatial/gdml/GdmlVision.kt @@ -14,12 +14,12 @@ import kotlin.math.cos import kotlin.math.sin -private fun VisualObject3D.withPosition( +private fun Vision3D.withPosition( lUnit: LUnit, newPos: GDMLPosition? = null, newRotation: GDMLRotation? = null, newScale: GDMLScale? = null -): VisualObject3D = apply { +): Vision3D = apply { newPos?.let { val point = Point3D(it.x(lUnit), it.y(lUnit), it.z(lUnit)) if (position != null || point != ZERO) { @@ -52,8 +52,8 @@ private fun VisionGroup3D.addSolid( context: GDMLTransformer, solid: GDMLSolid, name: String = "", - block: VisualObject3D.() -> Unit = {} -): VisualObject3D { + block: Vision3D.() -> Unit = {} +): Vision3D { //context.solidAdded(solid) val lScale = solid.lscale(context.lUnit) val aScale = solid.ascale() @@ -253,7 +253,7 @@ private fun volume( } } -fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisionGroup3D { +fun GDML.toVision(block: GDMLTransformer.() -> Unit = {}): VisionGroup3D { val context = GDMLTransformer(this).apply(block) return context.finalize(volume(context, world)) } @@ -262,7 +262,7 @@ fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisionGroup3D { * Append gdml node to the group */ fun VisionGroup3D.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) { - val visual = gdml.toVisual(transformer) + val visual = gdml.toVision(transformer) //println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual)) set(key, visual) } \ No newline at end of file diff --git a/visionforge-gdml/src/jvmTest/kotlin/hep/dataforge/vision/spatial/gdml/TestConvertor.kt b/visionforge-gdml/src/jvmTest/kotlin/hep/dataforge/vision/spatial/gdml/TestConvertor.kt index 60d885f7..51d5182d 100644 --- a/visionforge-gdml/src/jvmTest/kotlin/hep/dataforge/vision/spatial/gdml/TestConvertor.kt +++ b/visionforge-gdml/src/jvmTest/kotlin/hep/dataforge/vision/spatial/gdml/TestConvertor.kt @@ -13,7 +13,7 @@ class TestConvertor { val xmlReader = StAXReader(stream, "UTF-8") val xml = GDML.format.parse(GDML.serializer(), xmlReader) - val visual = xml.toVisual() + val visual = xml.toVision() println(visual.stringify()) } @@ -23,7 +23,7 @@ class TestConvertor { val xmlReader = StAXReader(stream, "UTF-8") val xml = GDML.format.parse(GDML.serializer(), xmlReader) - val visual = xml.toVisual() + val visual = xml.toVision() // println(visual) } @@ -33,7 +33,7 @@ class TestConvertor { val xmlReader = StAXReader(stream, "UTF-8") val xml = GDML.format.parse(GDML.serializer(), xmlReader) - val visual = xml.toVisual() + val visual = xml.toVision() println(visual.stringify()) } } \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Box.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Box.kt index 0bac53c1..2a9568cc 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Box.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Box.kt @@ -6,7 +6,10 @@ import hep.dataforge.meta.Config import hep.dataforge.meta.Meta import hep.dataforge.meta.float import hep.dataforge.meta.get -import hep.dataforge.vision.* +import hep.dataforge.vision.AbstractVision +import hep.dataforge.vision.MutableVisionGroup +import hep.dataforge.vision.VisionFactory +import hep.dataforge.vision.set import hep.dataforge.vision.spatial.Box.Companion.TYPE_NAME import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -19,7 +22,7 @@ class Box( val xSize: Float, val ySize: Float, val zSize: Float -) : AbstractVisualObject(), VisualObject3D, Shape { +) : AbstractVision(), Vision3D, Shape { override var position: Point3D? = null override var rotation: Point3D? = null @@ -48,13 +51,13 @@ class Box( geometryBuilder.face4(node8, node5, node6, node7) } - companion object : VisualFactory { + companion object : VisionFactory { const val TYPE_NAME = "3d.box" override val type: KClass get() = Box::class - override fun invoke(context: Context, parent: Vision?, meta: Meta): Box = Box( + override fun invoke(meta: Meta, context: Context): Box = Box( meta["xSize"].float!!, meta["ySize"].float!!, meta["zSize"].float!! diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Composite.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Composite.kt index b822263d..d0739f82 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Composite.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Composite.kt @@ -20,9 +20,9 @@ enum class CompositeType { @SerialName("3d.composite") class Composite( val compositeType: CompositeType, - val first: VisualObject3D, - val second: VisualObject3D -) : AbstractVisualObject(), VisualObject3D, VisionGroup { + val first: Vision3D, + val second: Vision3D +) : AbstractVision(), Vision3D, VisionGroup { init { first.parent = this @@ -48,7 +48,7 @@ inline fun MutableVisionGroup.composite( builder: VisionGroup3D.() -> Unit ): Composite { val group = VisionGroup3D().apply(builder) - val children = group.children.values.filterIsInstance() + val children = group.children.values.filterIsInstance() if (children.size != 2) error("Composite requires exactly two children") return Composite(type, children[0], children[1]).also { it.config.update(group.config) diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/ConeSegment.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/ConeSegment.kt index 0bf79daa..5f8e9c56 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/ConeSegment.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/ConeSegment.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVisualObject +import hep.dataforge.vision.AbstractVision import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName @@ -23,7 +23,7 @@ class ConeSegment( var upperRadius: Float, var startAngle: Float = 0f, var angle: Float = PI2 -) : AbstractVisualObject(), VisualObject3D, Shape { +) : AbstractVision(), Vision3D, Shape { override var ownProperties: Config? = null diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Convex.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Convex.kt index 2623ace7..d7f63829 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Convex.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Convex.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVisualObject +import hep.dataforge.vision.AbstractVision import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName @@ -12,7 +12,7 @@ import kotlinx.serialization.UseSerializers @Serializable @SerialName("3d.convex") -class Convex(val points: List) : AbstractVisualObject(), VisualObject3D { +class Convex(val points: List) : AbstractVision(), Vision3D { override var ownProperties: Config? = null diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Extruded.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Extruded.kt index a0fc132c..cda80e06 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Extruded.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Extruded.kt @@ -2,7 +2,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVisualObject +import hep.dataforge.vision.AbstractVision import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName @@ -43,7 +43,7 @@ data class Layer(var x: Float, var y: Float, var z: Float, var scale: Float) class Extruded( var shape: List = ArrayList(), var layers: MutableList = ArrayList() -) : AbstractVisualObject(), VisualObject3D, Shape { +) : AbstractVision(), Vision3D, Shape { override var ownProperties: Config? = null diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/GeometryBuilder.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/GeometryBuilder.kt index ec6b39a0..b6bad6db 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/GeometryBuilder.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/GeometryBuilder.kt @@ -31,9 +31,9 @@ fun GeometryBuilder<*>.face4( } /** - * [Shape] is a [VisualObject3D] that can represent its own geometry as a set of polygons. + * [Shape] is a [Vision3D] that can represent its own geometry as a set of polygons. */ -interface Shape : VisualObject3D { +interface Shape : Vision3D { fun toGeometry(geometryBuilder: GeometryBuilder) } diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Label3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Label3D.kt index e3345900..40ecdf37 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Label3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Label3D.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVisualObject +import hep.dataforge.vision.AbstractVision import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName @@ -12,7 +12,7 @@ import kotlinx.serialization.UseSerializers @Serializable @SerialName("3d.label") -class Label3D(var text: String, var fontSize: Double, var fontFamily: String) : AbstractVisualObject(), VisualObject3D { +class Label3D(var text: String, var fontSize: Double, var fontFamily: String) : AbstractVision(), Vision3D { override var ownProperties: Config? = null override var position: Point3D? = null diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Material3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Material3D.kt index 2de4369d..626c2848 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Material3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Material3D.kt @@ -77,18 +77,18 @@ class Material3D : Scheme() { /** * Set color as web-color */ -fun VisualObject3D.color(webColor: String) { +fun Vision3D.color(webColor: String) { setItem(MATERIAL_COLOR_KEY, webColor.asValue()) } /** * Set color as integer */ -fun VisualObject3D.color(rgb: Int) { +fun Vision3D.color(rgb: Int) { setItem(MATERIAL_COLOR_KEY, rgb.asValue()) } -fun VisualObject3D.color(r: UByte, g: UByte, b: UByte) = setItem( +fun Vision3D.color(r: UByte, g: UByte, b: UByte) = setItem( MATERIAL_COLOR_KEY, Colors.rgbToMeta(r, g, b) ) @@ -96,16 +96,16 @@ fun VisualObject3D.color(r: UByte, g: UByte, b: UByte) = setItem( /** * Web colors representation of the color in `#rrggbb` format or HTML name */ -var VisualObject3D.color: String? +var Vision3D.color: String? get() = getItem(MATERIAL_COLOR_KEY)?.let { Colors.fromMeta(it) } set(value) { setItem(MATERIAL_COLOR_KEY, value?.asValue()) } -val VisualObject3D.material: Material3D? +val Vision3D.material: Material3D? get() = getItem(MATERIAL_KEY).node?.let { Material3D.wrap(it) } -fun VisualObject3D.material(builder: Material3D.() -> Unit) { +fun Vision3D.material(builder: Material3D.() -> Unit) { val node = config[MATERIAL_KEY].node if (node != null) { Material3D.update(node, builder) @@ -114,7 +114,7 @@ fun VisualObject3D.material(builder: Material3D.() -> Unit) { } } -var VisualObject3D.opacity: Double? +var Vision3D.opacity: Double? get() = getItem(MATERIAL_OPACITY_KEY).double set(value) { setItem(MATERIAL_OPACITY_KEY, value?.asValue()) diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/PolyLine.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/PolyLine.kt index 0d1b5caa..96cbd6c4 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/PolyLine.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/PolyLine.kt @@ -6,7 +6,7 @@ import hep.dataforge.meta.Config import hep.dataforge.meta.number import hep.dataforge.names.asName import hep.dataforge.names.plus -import hep.dataforge.vision.AbstractVisualObject +import hep.dataforge.vision.AbstractVision import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName @@ -15,7 +15,7 @@ import kotlinx.serialization.UseSerializers @Serializable @SerialName("3d.line") -class PolyLine(var points: List) : AbstractVisualObject(), VisualObject3D { +class PolyLine(var points: List) : AbstractVision(), Vision3D { override var ownProperties: Config? = null override var position: Point3D? = null diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Proxy.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Proxy.kt index 80cdf6fa..c721df11 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Proxy.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Proxy.kt @@ -16,13 +16,13 @@ import kotlinx.serialization.UseSerializers import kotlin.collections.set /** - * A proxy [VisualObject3D] to reuse a template object + * A proxy [Vision3D] to reuse a template object */ @Serializable @SerialName("3d.proxy") class Proxy private constructor( val templateName: Name -) : AbstractVisualObject(), VisionGroup, VisualObject3D { +) : AbstractVision(), VisionGroup, Vision3D { constructor(parent: VisionGroup3D, templateName: Name) : this(templateName) { this.parent = parent @@ -37,7 +37,7 @@ class Proxy private constructor( /** * Recursively search for defined template in the parent */ - val prototype: VisualObject3D + val prototype: Vision3D get() = (parent as? VisionGroup3D)?.getPrototype(templateName) ?: error("Prototype with name $templateName not found in $parent") @@ -94,7 +94,7 @@ class Proxy private constructor( override val descriptor: NodeDescriptor? get() = prototype.descriptor - inner class ProxyChild(val name: Name) : AbstractVisualObject(), + inner class ProxyChild(val name: Name) : AbstractVision(), VisionGroup { val prototype: Vision get() = prototypeFor(name) @@ -179,7 +179,7 @@ fun VisionGroup3D.ref( */ fun VisionGroup3D.proxy( name: String, - obj: VisualObject3D, + obj: Vision3D, templateName: Name = name.toName() ): Proxy { val existing = getPrototype(templateName) diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Visual3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/SpatialVisionManager.kt similarity index 71% rename from visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Visual3D.kt rename to visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/SpatialVisionManager.kt index 94af42a5..99155dcd 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Visual3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/SpatialVisionManager.kt @@ -17,29 +17,29 @@ import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.contextual import kotlin.reflect.KClass -class Visual3D(meta: Meta) : AbstractPlugin(meta) { +class SpatialVisionManager(meta: Meta) : AbstractPlugin(meta) { - val visual by require(VisionManager) + val visionManager by require(VisionManager) override val tag: PluginTag get() = Companion.tag - override fun provideTop(target: String): Map = if (target == VisionManager.VISUAL_FACTORY_TYPE) { + override fun provideTop(target: String): Map = if (target == VisionManager.VISION_FACTORY_TYPE) { mapOf(Box.TYPE_NAME.toName() to Box) } else { super.provideTop(target) } - companion object : PluginFactory { + companion object : PluginFactory { override val tag: PluginTag = PluginTag(name = "visual.spatial", group = PluginTag.DATAFORGE_GROUP) - override val type: KClass = Visual3D::class - override fun invoke(meta: Meta, context: Context): Visual3D = Visual3D(meta) + override val type: KClass = SpatialVisionManager::class + override fun invoke(meta: Meta, context: Context): SpatialVisionManager = SpatialVisionManager(meta) val serialModule = SerializersModule { contextual(Point3DSerializer) contextual(Point2DSerializer) - polymorphic(Vision::class, VisualObject3D::class) { + polymorphic(Vision::class, Vision3D::class) { subclass(SimpleVisionGroup.serializer()) subclass(VisionGroup3D.serializer()) subclass(Proxy.serializer()) @@ -67,15 +67,15 @@ class Visual3D(meta: Meta) : AbstractPlugin(meta) { } } -internal fun VisualObject3D.update(meta: Meta) { +internal fun Vision3D.update(meta: Meta) { fun Meta.toVector(default: Float = 0f) = Point3D( - this[VisualObject3D.X_KEY].float ?: default, - this[VisualObject3D.Y_KEY].float ?: default, - this[VisualObject3D.Z_KEY].float ?: default + this[Vision3D.X_KEY].float ?: default, + this[Vision3D.Y_KEY].float ?: default, + this[Vision3D.Z_KEY].float ?: default ) - meta[VisualObject3D.POSITION_KEY].node?.toVector()?.let { position = it } - meta[VisualObject3D.ROTATION].node?.toVector()?.let { rotation = it } - meta[VisualObject3D.SCALE_KEY].node?.toVector(1f)?.let { scale = it } + meta[Vision3D.POSITION_KEY].node?.toVector()?.let { position = it } + meta[Vision3D.ROTATION].node?.toVector()?.let { rotation = it } + meta[Vision3D.SCALE_KEY].node?.toVector(1f)?.let { scale = it } meta["properties"].node?.let { configure(it) } } \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Sphere.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Sphere.kt index 24f2b5a1..b225fad9 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Sphere.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Sphere.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVisualObject +import hep.dataforge.vision.AbstractVision import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName @@ -21,7 +21,7 @@ class Sphere( var phi: Float = PI2, var thetaStart: Float = 0f, var theta: Float = PI.toFloat() -) : AbstractVisualObject(), VisualObject3D, Shape { +) : AbstractVision(), Vision3D, Shape { override var ownProperties: Config? = null diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Tube.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Tube.kt index ae2480eb..bc98f217 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Tube.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Tube.kt @@ -3,7 +3,7 @@ package hep.dataforge.vision.spatial import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVisualObject +import hep.dataforge.vision.AbstractVision import hep.dataforge.vision.MutableVisionGroup import hep.dataforge.vision.set import kotlinx.serialization.SerialName @@ -24,7 +24,7 @@ class Tube( var innerRadius: Float = 0f, var startAngle: Float = 0f, var angle: Float = PI2 -) : AbstractVisualObject(), VisualObject3D, Shape { +) : AbstractVision(), Vision3D, Shape { override var position: Point3D? = null override var rotation: Point3D? = null diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualObject3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Vision3D.kt similarity index 72% rename from visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualObject3D.kt rename to visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Vision3D.kt index 8ab6616e..238741ec 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisualObject3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/Vision3D.kt @@ -11,16 +11,16 @@ import hep.dataforge.values.ValueType import hep.dataforge.values.asValue import hep.dataforge.vision.Vision import hep.dataforge.vision.enum -import hep.dataforge.vision.spatial.VisualObject3D.Companion.DETAIL_KEY -import hep.dataforge.vision.spatial.VisualObject3D.Companion.IGNORE_KEY -import hep.dataforge.vision.spatial.VisualObject3D.Companion.LAYER_KEY -import hep.dataforge.vision.spatial.VisualObject3D.Companion.VISIBLE_KEY +import hep.dataforge.vision.spatial.Vision3D.Companion.DETAIL_KEY +import hep.dataforge.vision.spatial.Vision3D.Companion.IGNORE_KEY +import hep.dataforge.vision.spatial.Vision3D.Companion.LAYER_KEY +import hep.dataforge.vision.spatial.Vision3D.Companion.VISIBLE_KEY import kotlinx.serialization.UseSerializers /** * Interface for 3-dimensional [Vision] */ -interface VisualObject3D : Vision { +interface Vision3D : Vision { var position: Point3D? var rotation: Point3D? var scale: Point3D? @@ -86,13 +86,13 @@ interface VisualObject3D : Vision { /** * Count number of layers to the top object. Return 1 if this is top layer */ -var VisualObject3D.layer: Int +var Vision3D.layer: Int get() = getItem(LAYER_KEY).int ?: 0 set(value) { setItem(LAYER_KEY, value.asValue()) } -fun Renderer.render(meta: Meta = Meta.EMPTY, action: VisionGroup3D.() -> Unit) = +fun Renderer.render(meta: Meta = Meta.EMPTY, action: VisionGroup3D.() -> Unit) = render(VisionGroup3D().apply(action), meta) // Common properties @@ -109,15 +109,15 @@ enum class RotationOrder { /** * Rotation order */ -var VisualObject3D.rotationOrder: RotationOrder - get() = getItem(VisualObject3D.ROTATION_ORDER_KEY).enum() ?: RotationOrder.XYZ - set(value) = setItem(VisualObject3D.ROTATION_ORDER_KEY, value.name.asValue()) +var Vision3D.rotationOrder: RotationOrder + get() = getItem(Vision3D.ROTATION_ORDER_KEY).enum() ?: RotationOrder.XYZ + set(value) = setItem(Vision3D.ROTATION_ORDER_KEY, value.name.asValue()) /** * Preferred number of polygons for displaying the object. If not defined, uses shape or renderer default. Not inherited */ -var VisualObject3D.detail: Int? +var Vision3D.detail: Int? get() = getProperty(DETAIL_KEY, false).int set(value) = setItem(DETAIL_KEY, value?.asValue()) @@ -137,74 +137,74 @@ var Vision.ignore: Boolean? // get() = getProperty(SELECTED_KEY).boolean // set(value) = setProperty(SELECTED_KEY, value) -private fun VisualObject3D.position(): Point3D = +private fun Vision3D.position(): Point3D = position ?: Point3D(0.0, 0.0, 0.0).also { position = it } -var VisualObject3D.x: Number +var Vision3D.x: Number get() = position?.x ?: 0f set(value) { position().x = value.toDouble() - propertyInvalidated(VisualObject3D.X_POSITION_KEY) + propertyInvalidated(Vision3D.X_POSITION_KEY) } -var VisualObject3D.y: Number +var Vision3D.y: Number get() = position?.y ?: 0f set(value) { position().y = value.toDouble() - propertyInvalidated(VisualObject3D.Y_POSITION_KEY) + propertyInvalidated(Vision3D.Y_POSITION_KEY) } -var VisualObject3D.z: Number +var Vision3D.z: Number get() = position?.z ?: 0f set(value) { position().z = value.toDouble() - propertyInvalidated(VisualObject3D.Z_POSITION_KEY) + propertyInvalidated(Vision3D.Z_POSITION_KEY) } -private fun VisualObject3D.rotation(): Point3D = +private fun Vision3D.rotation(): Point3D = rotation ?: Point3D(0.0, 0.0, 0.0).also { rotation = it } -var VisualObject3D.rotationX: Number +var Vision3D.rotationX: Number get() = rotation?.x ?: 0f set(value) { rotation().x = value.toDouble() - propertyInvalidated(VisualObject3D.X_ROTATION_KEY) + propertyInvalidated(Vision3D.X_ROTATION_KEY) } -var VisualObject3D.rotationY: Number +var Vision3D.rotationY: Number get() = rotation?.y ?: 0f set(value) { rotation().y = value.toDouble() - propertyInvalidated(VisualObject3D.Y_ROTATION_KEY) + propertyInvalidated(Vision3D.Y_ROTATION_KEY) } -var VisualObject3D.rotationZ: Number +var Vision3D.rotationZ: Number get() = rotation?.z ?: 0f set(value) { rotation().z = value.toDouble() - propertyInvalidated(VisualObject3D.Z_ROTATION_KEY) + propertyInvalidated(Vision3D.Z_ROTATION_KEY) } -private fun VisualObject3D.scale(): Point3D = +private fun Vision3D.scale(): Point3D = scale ?: Point3D(1.0, 1.0, 1.0).also { scale = it } -var VisualObject3D.scaleX: Number +var Vision3D.scaleX: Number get() = scale?.x ?: 1f set(value) { scale().x = value.toDouble() - propertyInvalidated(VisualObject3D.X_SCALE_KEY) + propertyInvalidated(Vision3D.X_SCALE_KEY) } -var VisualObject3D.scaleY: Number +var Vision3D.scaleY: Number get() = scale?.y ?: 1f set(value) { scale().y = value.toDouble() - propertyInvalidated(VisualObject3D.Y_SCALE_KEY) + propertyInvalidated(Vision3D.Y_SCALE_KEY) } -var VisualObject3D.scaleZ: Number +var Vision3D.scaleZ: Number get() = scale?.z ?: 1f set(value) { scale().z = value.toDouble() - propertyInvalidated(VisualObject3D.Z_SCALE_KEY) + propertyInvalidated(Vision3D.Z_SCALE_KEY) } \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisionGroup3D.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisionGroup3D.kt index 06165aae..05b32417 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisionGroup3D.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/VisionGroup3D.kt @@ -24,7 +24,7 @@ interface PrototypeHolder { */ @Serializable @SerialName("group.3d") -class VisionGroup3D : AbstractVision(), VisualObject3D, PrototypeHolder { +class VisionGroup3D : AbstractVisionGroup(), Vision3D, PrototypeHolder { override var styleSheet: StyleSheet? = null @@ -82,15 +82,15 @@ class VisionGroup3D : AbstractVision(), VisualObject3D, PrototypeHolder { // val PROTOTYPES_KEY = NameToken("@prototypes") fun parseJson(json: String): VisionGroup3D = - Visual3D.json.parse(serializer(), json).also { it.attachChildren() } + SpatialVisionManager.json.parse(serializer(), json).also { it.attachChildren() } } } /** * Ger a prototype redirecting the request to the parent if prototype is not found */ -tailrec fun PrototypeHolder.getPrototype(name: Name): VisualObject3D? = - prototypes?.get(name) as? VisualObject3D ?: (parent as? PrototypeHolder)?.getPrototype(name) +tailrec fun PrototypeHolder.getPrototype(name: Name): Vision3D? = + prototypes?.get(name) as? Vision3D ?: (parent as? PrototypeHolder)?.getPrototype(name) /** * Define a group with given [name], attach it to this parent and return it. @@ -102,7 +102,7 @@ fun MutableVisionGroup.group(name: String = "", action: VisionGroup3D.() -> Unit internal class Prototypes( override var children: MutableMap = LinkedHashMap() -) : AbstractVision(), MutableVisionGroup, PrototypeHolder { +) : AbstractVisionGroup(), MutableVisionGroup, PrototypeHolder { override var styleSheet: StyleSheet? get() = null diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/geometry.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/geometry.kt index 6eaa23f1..4c522a0b 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/geometry.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/geometry.kt @@ -21,8 +21,8 @@ operator fun Point2D.component1() = x operator fun Point2D.component2() = y fun Point2D.toMeta() = Meta { - VisualObject3D.X_KEY put x - VisualObject3D.Y_KEY put y + Vision3D.X_KEY put x + Vision3D.Y_KEY put y } fun Meta.point2D() = Point2D(this["x"].number ?: 0, this["y"].number ?: 0) @@ -42,7 +42,7 @@ operator fun Point3D.component3() = z fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0) fun Point3D.toMeta() = Meta { - VisualObject3D.X_KEY put x - VisualObject3D.Y_KEY put y - VisualObject3D.Z_KEY put z + Vision3D.X_KEY put x + Vision3D.Y_KEY put y + Vision3D.Z_KEY put z } \ No newline at end of file diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/serialization.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/serialization.kt index 2a273e66..9cb11972 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/serialization.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/serialization.kt @@ -118,9 +118,9 @@ internal object PrototypesSerializer : KSerializer { } } -fun Vision.stringify(): String = Visual3D.json.stringify(Vision.serializer(), this) +fun Vision.stringify(): String = SpatialVisionManager.json.stringify(Vision.serializer(), this) -fun Vision.Companion.parseJson(str: String) = Visual3D.json.parse(Vision.serializer(), str).also { +fun Vision.Companion.parseJson(str: String) = SpatialVisionManager.json.parse(Vision.serializer(), str).also { if(it is VisionGroup){ it.attachChildren() } diff --git a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/RemoveSingleChild.kt b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/RemoveSingleChild.kt index cd81d460..78b556e3 100644 --- a/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/RemoveSingleChild.kt +++ b/visionforge-spatial/src/commonMain/kotlin/hep/dataforge/vision/spatial/transform/RemoveSingleChild.kt @@ -14,7 +14,7 @@ internal fun mergeChild(parent: VisionGroup, child: Vision): Vision { //parent.properties?.let { config.update(it) } - if (this is VisualObject3D && parent is VisualObject3D) { + if (this is Vision3D && parent is Vision3D) { position = (position ?: World.ZERO) + (parent.position ?: World.ZERO) rotation = (parent.rotation ?: World.ZERO) + (parent.rotation ?: World.ZERO) scale = when { diff --git a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/ConvexTest.kt b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/ConvexTest.kt index c1252ca2..e30d39df 100644 --- a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/ConvexTest.kt +++ b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/ConvexTest.kt @@ -26,7 +26,7 @@ class ConvexTest { val convex = group.children.values.first() as Convex - val json = Visual3D.json.toJson(Convex.serializer(), convex) + val json = SpatialVisionManager.json.toJson(Convex.serializer(), convex) val meta = json.toMetaItem().node!! val points = meta.getIndexed("points").values.map { (it as MetaItem.NodeItem<*>).node.point3D() } diff --git a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/GroupTest.kt b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/GroupTest.kt index d313eefa..9992e633 100644 --- a/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/GroupTest.kt +++ b/visionforge-spatial/src/commonTest/kotlin/hep/dataforge/vision/spatial/GroupTest.kt @@ -45,7 +45,7 @@ class GroupTest { } assertEquals(3, group.children.count()) - assertEquals(300.0, (group["intersect"] as VisualObject3D).y.toDouble()) - assertEquals(-300.0, (group["subtract"] as VisualObject3D).y.toDouble()) + assertEquals(300.0, (group["intersect"] as Vision3D).y.toDouble()) + assertEquals(-300.0, (group["subtract"] as Vision3D).y.toDouble()) } } \ No newline at end of file diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/MeshThreeFactory.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/MeshThreeFactory.kt index b2d9c592..06127ff0 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/MeshThreeFactory.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/MeshThreeFactory.kt @@ -6,7 +6,7 @@ import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.names.startsWith import hep.dataforge.vision.spatial.Material3D -import hep.dataforge.vision.spatial.VisualObject3D +import hep.dataforge.vision.spatial.Vision3D import hep.dataforge.vision.spatial.layer import hep.dataforge.vision.spatial.three.ThreeMaterials.getMaterial import info.laht.threekt.core.BufferGeometry @@ -19,7 +19,7 @@ import kotlin.reflect.KClass /** * Basic geometry-based factory */ -abstract class MeshThreeFactory( +abstract class MeshThreeFactory( override val type: KClass ) : ThreeFactory { /** @@ -52,7 +52,7 @@ abstract class MeshThreeFactory( //add listener to object properties obj.onPropertyChange(this) { name, _, _ -> when { - name.startsWith(VisualObject3D.GEOMETRY_KEY) -> { + name.startsWith(Vision3D.GEOMETRY_KEY) -> { val oldGeometry = mesh.geometry as BufferGeometry val newGeometry = buildGeometry(obj) oldGeometry.attributes = newGeometry.attributes @@ -79,7 +79,7 @@ abstract class MeshThreeFactory( } } -fun Mesh.applyEdges(obj: VisualObject3D) { +fun Mesh.applyEdges(obj: Vision3D) { children.find { it.name == "@edges" }?.let { remove(it) (it as LineSegments).dispose() @@ -99,7 +99,7 @@ fun Mesh.applyEdges(obj: VisualObject3D) { } } -fun Mesh.applyWireFrame(obj: VisualObject3D) { +fun Mesh.applyWireFrame(obj: Vision3D) { children.find { it.name == "@wireframe" }?.let { remove(it) (it as LineSegments).dispose() diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeCanvas.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeCanvas.kt index c4d5cd06..85f83ce5 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeCanvas.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeCanvas.kt @@ -9,7 +9,7 @@ import hep.dataforge.names.plus import hep.dataforge.names.toName import hep.dataforge.output.Renderer import hep.dataforge.vision.Colors -import hep.dataforge.vision.spatial.VisualObject3D +import hep.dataforge.vision.spatial.Vision3D import hep.dataforge.vision.spatial.specifications.Camera import hep.dataforge.vision.spatial.specifications.Canvas3DOptions import hep.dataforge.vision.spatial.specifications.Controls @@ -41,11 +41,11 @@ import kotlin.math.sin /** * */ -class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val options: Canvas3DOptions) : Renderer { +class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val options: Canvas3DOptions) : Renderer { override val context: Context get() = three.context - var content: VisualObject3D? = null + var content: Vision3D? = null private set private var root: Object3D? = null @@ -172,7 +172,7 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val options: Can } } - override fun render(obj: VisualObject3D, meta: Meta) { + override fun render(obj: Vision3D, meta: Meta) { //clear old root clear() @@ -244,5 +244,5 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val options: Can fun ThreePlugin.output(element: HTMLElement, spec: Canvas3DOptions = Canvas3DOptions.empty()): ThreeCanvas = ThreeCanvas(element, this, spec) -fun ThreePlugin.render(element: HTMLElement, obj: VisualObject3D, spec: Canvas3DOptions = Canvas3DOptions.empty()): Unit = +fun ThreePlugin.render(element: HTMLElement, obj: Vision3D, spec: Canvas3DOptions = Canvas3DOptions.empty()): Unit = output(element, spec).render(obj) \ No newline at end of file diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeCanvasComponent.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeCanvasComponent.kt index d48ae96f..886578d3 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeCanvasComponent.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeCanvasComponent.kt @@ -2,7 +2,7 @@ package hep.dataforge.vision.spatial.three import hep.dataforge.context.Context import hep.dataforge.names.Name -import hep.dataforge.vision.spatial.VisualObject3D +import hep.dataforge.vision.spatial.Vision3D import hep.dataforge.vision.spatial.specifications.Canvas3DOptions import org.w3c.dom.Element import org.w3c.dom.HTMLElement @@ -15,7 +15,7 @@ import react.dom.findDOMNode interface ThreeCanvasProps : RProps { var context: Context - var obj: VisualObject3D + var obj: Vision3D var options: Canvas3DOptions? var selected: Name? var clickCallback: (Name?) -> Unit @@ -61,7 +61,7 @@ class ThreeCanvasComponent : RComponent() { } } -fun RBuilder.threeCanvas(object3D: VisualObject3D, options: Canvas3DOptions.() -> Unit = {}) { +fun RBuilder.threeCanvas(object3D: Vision3D, options: Canvas3DOptions.() -> Unit = {}) { child(ThreeCanvasComponent::class) { attrs { this.obj = object3D diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeFactory.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeFactory.kt index 4a7c5600..9dd3f519 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeFactory.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeFactory.kt @@ -33,7 +33,7 @@ interface ThreeFactory { */ fun Object3D.updatePosition(obj: Vision) { visible = obj.visible ?: true - if(obj is VisualObject3D) { + if(obj is Vision3D) { position.set(obj.x, obj.y, obj.z) setRotationFromEuler(obj.euler) scale.set(obj.scaleX, obj.scaleY, obj.scaleZ) @@ -60,13 +60,13 @@ fun Object3D.updateProperty(source: Vision, propertyName: Name) { if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) { this.material = getMaterial(source) } else if ( - propertyName.startsWith(VisualObject3D.POSITION_KEY) - || propertyName.startsWith(VisualObject3D.ROTATION) - || propertyName.startsWith(VisualObject3D.SCALE_KEY) + propertyName.startsWith(Vision3D.POSITION_KEY) + || propertyName.startsWith(Vision3D.ROTATION) + || propertyName.startsWith(Vision3D.SCALE_KEY) ) { //update position of mesh using this object updatePosition(source) - } else if (propertyName == VisualObject3D.VISIBLE_KEY) { + } else if (propertyName == Vision3D.VISIBLE_KEY) { visible = source.visible ?: true } } diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreePlugin.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreePlugin.kt index e81e5b3a..b8a1d943 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreePlugin.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreePlugin.kt @@ -13,7 +13,7 @@ import info.laht.threekt.objects.Group as ThreeGroup class ThreePlugin : AbstractPlugin() { override val tag: PluginTag get() = Companion.tag - private val objectFactories = HashMap, ThreeFactory<*>>() + private val objectFactories = HashMap, ThreeFactory<*>>() private val compositeFactory = ThreeCompositeFactory(this) private val proxyFactory = ThreeProxyFactory(this) @@ -28,20 +28,20 @@ class ThreePlugin : AbstractPlugin() { } @Suppress("UNCHECKED_CAST") - private fun findObjectFactory(type: KClass): ThreeFactory? { + private fun findObjectFactory(type: KClass): ThreeFactory? { return (objectFactories[type] ?: context.content>(ThreeFactory.TYPE).values.find { it.type == type }) - as ThreeFactory? + as ThreeFactory? } - fun buildObject3D(obj: VisualObject3D): Object3D { + fun buildObject3D(obj: Vision3D): Object3D { return when (obj) { - is ThreeVisualObject -> obj.toObject3D() + is ThreeVision -> obj.toObject3D() is Proxy -> proxyFactory(obj) is VisionGroup3D -> { val group = ThreeGroup() obj.children.forEach { (token, child) -> - if (child is VisualObject3D && child.ignore != true) { + if (child is Vision3D && child.ignore != true) { try { val object3D = buildObject3D(child) group[token] = object3D @@ -57,13 +57,13 @@ class ThreePlugin : AbstractPlugin() { obj.onPropertyChange(this) { name, _, _ -> if ( - name.startsWith(VisualObject3D.POSITION_KEY) || - name.startsWith(VisualObject3D.ROTATION) || - name.startsWith(VisualObject3D.SCALE_KEY) + name.startsWith(Vision3D.POSITION_KEY) || + name.startsWith(Vision3D.ROTATION) || + name.startsWith(Vision3D.SCALE_KEY) ) { //update position of mesh using this object updatePosition(obj) - } else if (name == VisualObject3D.VISIBLE_KEY) { + } else if (name == Vision3D.VISIBLE_KEY) { visible = obj.visible ?: true } } @@ -83,7 +83,7 @@ class ThreePlugin : AbstractPlugin() { } //adding new object - if (child != null && child is VisualObject3D) { + if (child != null && child is Vision3D) { try { val object3D = buildObject3D(child) set(name, object3D) @@ -97,7 +97,7 @@ class ThreePlugin : AbstractPlugin() { is Composite -> compositeFactory(obj) else -> { //find specialized factory for this type if it is present - val factory: ThreeFactory? = findObjectFactory(obj::class) + val factory: ThreeFactory? = findObjectFactory(obj::class) when { factory != null -> factory(obj) obj is Shape -> ThreeShapeFactory(obj) diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeProxyFactory.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeProxyFactory.kt index 32723f2f..9dbc69fa 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeProxyFactory.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeProxyFactory.kt @@ -3,11 +3,11 @@ package hep.dataforge.vision.spatial.three import hep.dataforge.names.toName import hep.dataforge.vision.spatial.Proxy import hep.dataforge.vision.spatial.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX -import hep.dataforge.vision.spatial.VisualObject3D +import hep.dataforge.vision.spatial.Vision3D import info.laht.threekt.core.Object3D class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { - private val cache = HashMap() + private val cache = HashMap() override val type = Proxy::class diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeVisualObject.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeVision.kt similarity index 71% rename from visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeVisualObject.kt rename to visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeVision.kt index e0e6afbf..f17adef3 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeVisualObject.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/ThreeVision.kt @@ -3,10 +3,10 @@ package hep.dataforge.vision.spatial.three import hep.dataforge.meta.Config -import hep.dataforge.vision.AbstractVisualObject +import hep.dataforge.vision.AbstractVision import hep.dataforge.vision.spatial.Point3D import hep.dataforge.vision.spatial.Point3DSerializer -import hep.dataforge.vision.spatial.VisualObject3D +import hep.dataforge.vision.spatial.Vision3D import info.laht.threekt.core.Object3D import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers @@ -14,13 +14,13 @@ import kotlinx.serialization.UseSerializers /** * A custom visual object that has its own Three.js renderer */ -interface ThreeVisualObject : VisualObject3D { +interface ThreeVision : Vision3D { fun toObject3D(): Object3D } @Serializable -class CustomThreeVisualObject(val threeFactory: ThreeFactory) : AbstractVisualObject(), - ThreeVisualObject { +class CustomThreeVision(val threeFactory: ThreeFactory) : AbstractVision(), + ThreeVision { override var position: Point3D? = null override var rotation: Point3D? = null override var scale: Point3D? = null diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/outputConfig.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/outputConfig.kt index d4ea812b..74f3a8f3 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/outputConfig.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/outputConfig.kt @@ -3,8 +3,8 @@ package hep.dataforge.vision.spatial.three import hep.dataforge.js.requireJS import hep.dataforge.vision.bootstrap.accordion import hep.dataforge.vision.bootstrap.entry +import hep.dataforge.vision.spatial.SpatialVisionManager import hep.dataforge.vision.spatial.VisionGroup3D -import hep.dataforge.vision.spatial.Visual3D import kotlinx.html.* import kotlinx.html.dom.append import kotlinx.html.js.onChangeFunction @@ -53,7 +53,7 @@ fun RBuilder.canvasControls(canvas: ThreeCanvas) = accordion("controls") { attrs { onClickFunction = { val json = (canvas.content as? VisionGroup3D)?.let { group -> - Visual3D.json.stringify( + SpatialVisionManager.json.stringify( VisionGroup3D.serializer(), group ) @@ -117,7 +117,7 @@ fun Element.displayCanvasControls(canvas: ThreeCanvas, block: TagConsumer - Visual3D.json.stringify( + SpatialVisionManager.json.stringify( VisionGroup3D.serializer(), group ) diff --git a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/three.kt b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/three.kt index 52d8fe2e..096bc12a 100644 --- a/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/three.kt +++ b/visionforge-spatial/src/jsMain/kotlin/hep/dataforge/vision/spatial/three/three.kt @@ -17,7 +17,7 @@ import info.laht.threekt.objects.Mesh import info.laht.threekt.textures.Texture import kotlin.math.PI -val VisualObject3D.euler get() = Euler(rotationX, rotationY, rotationZ, rotationOrder.name) +val Vision3D.euler get() = Euler(rotationX, rotationY, rotationZ, rotationOrder.name) val MetaItem<*>.vector get() = Vector3(node["x"].float ?: 0f, node["y"].float ?: 0f, node["z"].float ?: 0f) diff --git a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FX3DPlugin.kt b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FX3DPlugin.kt index b9d5f663..a300156c 100644 --- a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FX3DPlugin.kt +++ b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FX3DPlugin.kt @@ -26,7 +26,7 @@ import kotlin.reflect.KClass class FX3DPlugin : AbstractPlugin() { override val tag: PluginTag get() = Companion.tag - private val objectFactories = HashMap, FX3DFactory<*>>() + private val objectFactories = HashMap, FX3DFactory<*>>() private val compositeFactory = FXCompositeFactory(this) private val proxyFactory = FXProxyFactory(this) @@ -37,18 +37,18 @@ class FX3DPlugin : AbstractPlugin() { @Suppress("UNCHECKED_CAST") - private fun findObjectFactory(type: KClass): FX3DFactory? { + private fun findObjectFactory(type: KClass): FX3DFactory? { return (objectFactories[type] ?: context.content>(TYPE).values.find { it.type == type }) - as FX3DFactory? + as FX3DFactory? } - fun buildNode(obj: VisualObject3D): Node { + fun buildNode(obj: Vision3D): Node { val binding = VisualObjectFXBinding(obj) return when (obj) { is Proxy -> proxyFactory(obj, binding) is VisionGroup3D -> { Group(obj.children.mapNotNull { (token, obj) -> - (obj as? VisualObject3D)?.let { + (obj as? Vision3D)?.let { buildNode(it).apply { properties["name"] = token.toString() } @@ -77,7 +77,7 @@ class FX3DPlugin : AbstractPlugin() { } else -> { //find specialized factory for this type if it is present - val factory: FX3DFactory? = findObjectFactory(obj::class) + val factory: FX3DFactory? = findObjectFactory(obj::class) when { factory != null -> factory(obj, binding) obj is Shape -> FXShapeFactory(obj, binding) @@ -85,23 +85,23 @@ class FX3DPlugin : AbstractPlugin() { } } }.apply { - translateXProperty().bind(binding[VisualObject3D.X_POSITION_KEY].float(obj.x.toFloat())) - translateYProperty().bind(binding[VisualObject3D.Y_POSITION_KEY].float(obj.y.toFloat())) - translateZProperty().bind(binding[VisualObject3D.Z_POSITION_KEY].float(obj.z.toFloat())) - scaleXProperty().bind(binding[VisualObject3D.X_SCALE_KEY].float(obj.scaleX.toFloat())) - scaleYProperty().bind(binding[VisualObject3D.Y_SCALE_KEY].float(obj.scaleY.toFloat())) - scaleZProperty().bind(binding[VisualObject3D.Z_SCALE_KEY].float(obj.scaleZ.toFloat())) + translateXProperty().bind(binding[Vision3D.X_POSITION_KEY].float(obj.x.toFloat())) + translateYProperty().bind(binding[Vision3D.Y_POSITION_KEY].float(obj.y.toFloat())) + translateZProperty().bind(binding[Vision3D.Z_POSITION_KEY].float(obj.z.toFloat())) + scaleXProperty().bind(binding[Vision3D.X_SCALE_KEY].float(obj.scaleX.toFloat())) + scaleYProperty().bind(binding[Vision3D.Y_SCALE_KEY].float(obj.scaleY.toFloat())) + scaleZProperty().bind(binding[Vision3D.Z_SCALE_KEY].float(obj.scaleZ.toFloat())) val rotateX = Rotate(0.0, Rotate.X_AXIS).apply { - angleProperty().bind(binding[VisualObject3D.X_ROTATION_KEY].float(obj.rotationX.toFloat()).multiply(180.0 / PI)) + angleProperty().bind(binding[Vision3D.X_ROTATION_KEY].float(obj.rotationX.toFloat()).multiply(180.0 / PI)) } val rotateY = Rotate(0.0, Rotate.Y_AXIS).apply { - angleProperty().bind(binding[VisualObject3D.Y_ROTATION_KEY].float(obj.rotationY.toFloat()).multiply(180.0 / PI)) + angleProperty().bind(binding[Vision3D.Y_ROTATION_KEY].float(obj.rotationY.toFloat()).multiply(180.0 / PI)) } val rotateZ = Rotate(0.0, Rotate.Z_AXIS).apply { - angleProperty().bind(binding[VisualObject3D.Z_ROTATION_KEY].float(obj.rotationZ.toFloat()).multiply(180.0 / PI)) + angleProperty().bind(binding[Vision3D.Z_ROTATION_KEY].float(obj.rotationZ.toFloat()).multiply(180.0 / PI)) } when (obj.rotationOrder) { @@ -140,7 +140,7 @@ class FX3DPlugin : AbstractPlugin() { * Builder and updater for three.js object */ @Type(TYPE) -interface FX3DFactory { +interface FX3DFactory { val type: KClass diff --git a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FXCanvas3D.kt b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FXCanvas3D.kt index 18354607..69bb828a 100644 --- a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FXCanvas3D.kt +++ b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/fx/FXCanvas3D.kt @@ -4,7 +4,7 @@ import hep.dataforge.context.Context import hep.dataforge.context.ContextAware import hep.dataforge.meta.Meta import hep.dataforge.output.Renderer -import hep.dataforge.vision.spatial.VisualObject3D +import hep.dataforge.vision.spatial.Vision3D import hep.dataforge.vision.spatial.specifications.Canvas3DOptions import javafx.application.Platform import javafx.beans.property.ObjectProperty @@ -15,7 +15,7 @@ import org.fxyz3d.scene.Axes import tornadofx.* class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas3DOptions = Canvas3DOptions.empty()) : - Fragment(), Renderer, ContextAware { + Fragment(), Renderer, ContextAware { override val context: Context get() = plugin.context @@ -58,8 +58,8 @@ class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas3DOptions = Canvas3DOpt world.add(it.centerMarker) } - val rootObjectProperty: ObjectProperty = SimpleObjectProperty() - var rootObject: VisualObject3D? by rootObjectProperty + val rootObjectProperty: ObjectProperty = SimpleObjectProperty() + var rootObject: Vision3D? by rootObjectProperty private val rootNodeProperty = rootObjectProperty.objectBinding { it?.let { plugin.buildNode(it) } @@ -80,7 +80,7 @@ class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas3DOptions = Canvas3DOpt } } - override fun render(obj: VisualObject3D, meta: Meta) { + override fun render(obj: Vision3D, meta: Meta) { rootObject = obj } } \ No newline at end of file diff --git a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/generateSchema.kt b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/generateSchema.kt index 6a6addae..f1ae19d1 100644 --- a/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/generateSchema.kt +++ b/visionforge-spatial/src/jvmMain/kotlin/hep/dataforge/vision/spatial/generateSchema.kt @@ -142,11 +142,11 @@ private fun jsonSchema(descriptor: SerialDescriptor, context: SerialModule): Jso } fun main() { - val context = Visual3D.serialModule + val context = SpatialVisionManager.serialModule val definitions = json { "children" to json { "anyOf" to jsonArray { - context.enumerate(VisualObject3D::class).forEach { + context.enumerate(Vision3D::class).forEach { if (it.serialName == "hep.dataforge.vis.spatial.VisualGroup3D") { +json { "\$ref" to "#/$definitionNode/${it.serialName}"