From b8b8606371358b87679b0cd972a4403d70bf0881 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 6 Oct 2019 22:12:17 +0300 Subject: [PATCH 1/3] Fix proxy styling --- .../vis/common/AbstractVisualObject.kt | 15 ++++---- .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 38 ++++++++++--------- .../dataforge/vis/spatial/VisualGroup3D.kt | 12 +++--- .../vis/spatial/three/ThreeProxyFactory.kt | 9 ----- .../vis/spatial/tree/jsVisualTree.kt | 2 +- 5 files changed, 36 insertions(+), 40 deletions(-) diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt index effe38d8..c4ce41ae 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -58,11 +58,12 @@ abstract class AbstractVisualObject : VisualObject { private var styleCache: Laminate? = null - protected val actualStyles: Laminate - get() = styleCache ?: run { - Laminate(style.map { it.toName() }.mapNotNull(::findStyle)) - .also { styleCache = it } - } + /** + * Collect all styles for this object in a laminate + */ + val appliedStyles: Laminate + get() = styleCache ?: Laminate(style.map { it.toName() }.mapNotNull(::findStyle)).also { styleCache = it } + /** * Helper to reset style cache @@ -74,9 +75,9 @@ abstract class AbstractVisualObject : VisualObject { override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { - properties?.get(name) ?: actualStyles[name] ?: parent?.getProperty(name, inherit) + properties?.get(name) ?: appliedStyles[name] ?: parent?.getProperty(name, inherit) } else { - properties?.get(name) ?: actualStyles[name] + properties?.get(name) ?: appliedStyles[name] } } diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index ef284f22..111490aa 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -35,9 +35,10 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua /** * Recursively search for defined template in the parent */ - val prototype: VisualObject3D - get() = (parent as? VisualGroup3D)?.getTemplate(templateName) - ?: error("Template with name $templateName not found in $parent") + val prototype: VisualObject3D get() = getPrototype() + + private fun getPrototype(): VisualObject3D = (parent as? VisualGroup3D)?.getTemplate(templateName) + ?: error("Template with name $templateName not found in $parent") override fun getStyle(name: Name): Meta? = (parent as VisualGroup?)?.getStyle(name) @@ -70,17 +71,23 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua return NameToken(PROXY_CHILD_PROPERTY_PREFIX, childName.toString()) + propertyName } + private fun prototypeFor(name: Name): VisualObject = + (prototype as? VisualGroup)?.get(name) + ?: error("Prototype with name $name not found in ${this@Proxy}") + + inner class ProxyChild(val name: Name) : AbstractVisualObject(), VisualGroup { + val prototype: VisualObject by lazy { + prototypeFor(name) + } + override val children: Map - get() = ((prototype as? MutableVisualGroup)?.get(name) as? MutableVisualGroup) - ?.children - ?.mapValues { (key, _) -> - ProxyChild( - name + key.asName() - ) - } - ?: emptyMap() + get() = (prototype as? VisualGroup)?.children?.mapValues { (key, _) -> + ProxyChild( + name + key.asName() + ) + } ?: emptyMap() override fun getStyle(name: Name): Meta? = this@Proxy.getStyle(name) @@ -88,10 +95,6 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua this@Proxy.setStyle(name, meta) } - val prototype: VisualObject - get() = (this@Proxy.prototype as? VisualGroup)?.get(name) - ?: error("Prototype with name $name not found in ${this@Proxy}") - override var properties: Config? get() = propertyCache[name] set(value) { @@ -112,15 +115,16 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? { return if (inherit) { properties?.get(name) - ?: actualStyles[name] + ?: appliedStyles[name] ?: parent?.getProperty(name, inherit) ?: prototype.getProperty(name, inherit) } else { properties?.get(name) - ?: actualStyles[name] + ?: appliedStyles[name] ?: prototype.getProperty(name, inherit) } } + } companion object { diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt index e2ccbd25..d960cfc7 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualGroup3D.kt @@ -20,7 +20,7 @@ import hep.dataforge.names.NameToken import hep.dataforge.names.asName import hep.dataforge.names.isEmpty import hep.dataforge.vis.common.AbstractVisualGroup -import hep.dataforge.vis.common.MutableVisualGroup +import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.common.VisualObject import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -103,15 +103,15 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D { /** * A fix for serialization bug that writes all proper parents inside the tree after deserialization */ -fun MutableVisualGroup.attachChildren() { +fun VisualGroup.attachChildren() { this.children.values.forEach { it.parent = this - (it as? MutableVisualGroup)?.attachChildren() + (it as? VisualGroup)?.attachChildren() } if (this is VisualGroup3D) { - templates?.apply { - parent = this@attachChildren - attachChildren() + templates?.also { + it.parent = this + it.attachChildren() } } } diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt index 91effe00..05bdd9e1 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeProxyFactory.kt @@ -1,25 +1,16 @@ package hep.dataforge.vis.spatial.three import hep.dataforge.names.toName -import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.spatial.Proxy import hep.dataforge.vis.spatial.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX import hep.dataforge.vis.spatial.VisualObject3D -import hep.dataforge.vis.spatial.material -import hep.dataforge.vis.spatial.visible import info.laht.threekt.core.Object3D -import info.laht.threekt.objects.Mesh class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { private val cache = HashMap() override val type = Proxy::class - private fun Mesh.updateProperties(obj: VisualObject?) { - material = obj?.material.jsMaterial() - visible = obj?.visible ?: true - } - override fun invoke(obj: Proxy): Object3D { val template = obj.prototype val cachedObject = cache.getOrPut(template) { diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt index 2d86b7f4..84bd067d 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/tree/jsVisualTree.kt @@ -32,7 +32,7 @@ internal fun createInspireTree(block: Config.() -> Unit = {}): InspireTree { return InspireTree(config) } -fun VisualGroup.toTree(onFocus: (VisualObject?, String?) -> Unit = { obj, name -> }): InspireTree { +fun VisualGroup.toTree(onFocus: (VisualObject?, String?) -> Unit = { _, _ -> }): InspireTree { val map = HashMap() From 28625ebe58a6853dc20cfe719461826e99a6b47e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 6 Oct 2019 22:30:12 +0300 Subject: [PATCH 2/3] Fixed style merging problem --- .../dataforge/vis/common/AbstractVisualObject.kt | 6 +++--- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt index c4ce41ae..01e2c770 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/AbstractVisualObject.kt @@ -56,13 +56,13 @@ abstract class AbstractVisualObject : VisualObject { config[name] = value } - private var styleCache: Laminate? = null + private var styleCache: Meta? = null /** * Collect all styles for this object in a laminate */ - val appliedStyles: Laminate - get() = styleCache ?: Laminate(style.map { it.toName() }.mapNotNull(::findStyle)).also { styleCache = it } + protected val appliedStyles: Meta + get() = styleCache ?: Laminate(style.map { it.toName() }.mapNotNull(::findStyle)).merge().also { styleCache = it } /** diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index 49f8a382..d3417530 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -4,7 +4,10 @@ import hep.dataforge.context.Global import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.hmr.ApplicationBase import hep.dataforge.vis.hmr.startApplication -import hep.dataforge.vis.spatial.* +import hep.dataforge.vis.spatial.Visual3DPlugin +import hep.dataforge.vis.spatial.VisualGroup3D +import hep.dataforge.vis.spatial.VisualObject3D +import hep.dataforge.vis.spatial.attachChildren import hep.dataforge.vis.spatial.gdml.GDMLTransformer import hep.dataforge.vis.spatial.gdml.LUnit import hep.dataforge.vis.spatial.gdml.toVisual @@ -137,15 +140,15 @@ private class GDMLDemoApp : ApplicationBase() { } solidConfiguration = { parent, solid -> - if (!parent.physVolumes.isEmpty()) { - opacity = 0.3 - } - if (solid.name.startsWith("Coil") + if (parent.physVolumes.isNotEmpty() + || solid.name.startsWith("Coil") || solid.name.startsWith("Yoke") || solid.name.startsWith("Magnet") || solid.name.startsWith("Pole") ) { - opacity = 0.3 + useStyle("opaque") { + VisualObject3D.OPACITY_KEY to 0.3 + } } } } From 47c1a30c8948d0f6165c513ec1bbd4c69abf0fb2 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 7 Oct 2019 14:52:58 +0300 Subject: [PATCH 3/3] Fixed colors and sizes for demo --- build.gradle.kts | 3 +- .../kotlin/hep/dataforge/vis/common/Colors.kt | 14 ++++- .../vis/spatial/gdml/GDMLTransformer.kt | 2 +- .../vis/spatial/gdml/demo/GDMLDemoApp.kt | 3 +- .../vis/spatial/gdml/TestConvertor.kt | 3 + dataforge-vis-spatial/build.gradle.kts | 3 +- .../hep/dataforge/vis/spatial/Material3D.kt | 56 +++++++++++++++++++ .../kotlin/hep/dataforge/vis/spatial/Proxy.kt | 4 +- .../dataforge/vis/spatial/VisualObject3D.kt | 45 +-------------- .../hep/dataforge/vis/spatial/ConvexTest.kt | 1 + .../dataforge/vis/spatial/three/Materials.kt | 3 + .../vis/spatial/three/ThreeFactory.kt | 7 ++- .../vis/spatial/three/ThreeOutput.kt | 12 ++-- .../vis/spatial/tree/propertyEditor.kt | 4 +- spatial-js-demo/build.gradle.kts | 9 --- .../vis/spatial/demo/ThreeDemoGrid.kt | 3 +- 16 files changed, 98 insertions(+), 74 deletions(-) create mode 100644 dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Material3D.kt diff --git a/build.gradle.kts b/build.gradle.kts index 0dae2b76..48899168 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ val dataforgeVersion by extra("0.1.3") -plugins{ +plugins { val kotlinVersion = "1.3.50" val toolsVersion = "0.2.0" @@ -16,6 +16,7 @@ plugins{ allprojects { repositories { maven("https://dl.bintray.com/pdvrieze/maven") + maven("http://maven.jzy3d.org/releases") } group = "hep.dataforge" diff --git a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt index a908cc53..1f42d87c 100644 --- a/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt +++ b/dataforge-vis-common/src/commonMain/kotlin/hep/dataforge/vis/common/Colors.kt @@ -178,7 +178,19 @@ object Colors { const val yellowgreen = 0x9ACD32 fun rgbToString(rgb: Int): String { - val string = rgb.toString(16) + val string = rgb.toString(16).padStart(6, '0') return "#" + string.substring(max(0, string.length - 6)) } + + fun rgbToString(red: UByte, green: UByte, blue: UByte): String { + fun colorToString(color: UByte): String{ + return color.toString(16).padStart(2,'0') + } + return buildString { + append("#") + append(colorToString(red)) + append(colorToString(green)) + append(colorToString(blue)) + } + } } \ No newline at end of file diff --git a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt index b6d7f108..381e32f1 100644 --- a/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt +++ b/dataforge-vis-spatial-gdml/src/commonMain/kotlin/hep/dataforge/vis/spatial/gdml/GDMLTransformer.kt @@ -8,10 +8,10 @@ import hep.dataforge.names.toName import hep.dataforge.vis.common.Colors import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.common.applyStyle +import hep.dataforge.vis.spatial.Material3D.Companion.COLOR_KEY import hep.dataforge.vis.spatial.RotationOrder import hep.dataforge.vis.spatial.VisualGroup3D import hep.dataforge.vis.spatial.VisualObject3D -import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY import hep.dataforge.vis.spatial.rotationOrder import scientifik.gdml.* import kotlin.collections.set diff --git a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt index d3417530..63a255c0 100644 --- a/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt +++ b/dataforge-vis-spatial-gdml/src/jsMain/kotlin/hep/dataforge/vis/spatial/gdml/demo/GDMLDemoApp.kt @@ -4,6 +4,7 @@ import hep.dataforge.context.Global import hep.dataforge.vis.common.VisualGroup import hep.dataforge.vis.hmr.ApplicationBase import hep.dataforge.vis.hmr.startApplication +import hep.dataforge.vis.spatial.Material3D.Companion.OPACITY_KEY import hep.dataforge.vis.spatial.Visual3DPlugin import hep.dataforge.vis.spatial.VisualGroup3D import hep.dataforge.vis.spatial.VisualObject3D @@ -147,7 +148,7 @@ private class GDMLDemoApp : ApplicationBase() { || solid.name.startsWith("Pole") ) { useStyle("opaque") { - VisualObject3D.OPACITY_KEY to 0.3 + OPACITY_KEY to 0.3 } } } diff --git a/dataforge-vis-spatial-gdml/src/jvmTest/kotlin/hep/dataforge/vis/spatial/gdml/TestConvertor.kt b/dataforge-vis-spatial-gdml/src/jvmTest/kotlin/hep/dataforge/vis/spatial/gdml/TestConvertor.kt index 3644139c..f9cad99c 100644 --- a/dataforge-vis-spatial-gdml/src/jvmTest/kotlin/hep/dataforge/vis/spatial/gdml/TestConvertor.kt +++ b/dataforge-vis-spatial-gdml/src/jvmTest/kotlin/hep/dataforge/vis/spatial/gdml/TestConvertor.kt @@ -5,10 +5,12 @@ import org.junit.Test import scientifik.gdml.GDML import java.io.File import java.net.URL +import kotlin.test.Ignore class TestConvertor { @Test + @Ignore fun testBMNGeometry() { val url = URL("https://drive.google.com/open?id=1w5e7fILMN83JGgB8WANJUYm8OW2s0WVO") val file = File("D:\\Work\\Projects\\gdml.kt\\gdml-source\\BM@N.gdml") @@ -24,6 +26,7 @@ class TestConvertor { } @Test + @Ignore fun testCubes() { val file = File("D:\\Work\\Projects\\gdml.kt\\gdml-source\\cubes.gdml ") val stream = if (file.exists()) { diff --git a/dataforge-vis-spatial/build.gradle.kts b/dataforge-vis-spatial/build.gradle.kts index cfef3268..ab4f5ce7 100644 --- a/dataforge-vis-spatial/build.gradle.kts +++ b/dataforge-vis-spatial/build.gradle.kts @@ -22,7 +22,7 @@ kotlin { jvmMain { dependencies { implementation(project(":dataforge-vis-fx")) - implementation("org.fxyz3d:fxyz3d:0.4.0") + implementation("org.fxyz3d:fxyz3d:0.5.2") } } jsMain { @@ -30,7 +30,6 @@ kotlin { implementation(npm("three", "0.106.2")) implementation(npm("@hi-level/three-csg", "1.0.6")) implementation(npm("style-loader")) - implementation(npm("element-resize-event")) implementation(npm("inspire-tree","6.0.1")) implementation(npm("inspire-tree-dom","4.0.6")) implementation(npm("jsoneditor")) diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Material3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Material3D.kt new file mode 100644 index 00000000..aea1ed4c --- /dev/null +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Material3D.kt @@ -0,0 +1,56 @@ +package hep.dataforge.vis.spatial + +import hep.dataforge.meta.* +import hep.dataforge.names.asName +import hep.dataforge.names.plus +import hep.dataforge.vis.common.Colors +import hep.dataforge.vis.common.VisualObject +import hep.dataforge.vis.spatial.Material3D.Companion.COLOR_KEY +import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_KEY +import hep.dataforge.vis.spatial.Material3D.Companion.OPACITY_KEY + +class Material3D(override val config: Config) : Specific { + + val color by string() + + val opacity by float(1f) + + companion object : Specification { + override fun wrap(config: Config): Material3D = Material3D(config) + + val MATERIAL_KEY = "material".asName() + val COLOR_KEY = MATERIAL_KEY + "color" + val OPACITY_KEY = MATERIAL_KEY + "opacity" + + } +} + +fun VisualObject.color(rgb: String) { + setProperty(COLOR_KEY, rgb) +} + +fun VisualObject.color(rgb: Int) = color(Colors.rgbToString(rgb)) + +fun VisualObject.color(r: UByte, g: UByte, b: UByte) = color( Colors.rgbToString(r,g,b)) + +var VisualObject.color: String? + get() = getProperty(COLOR_KEY).string + set(value) { + if (value != null) { + color(value) + } + } + +var VisualObject.material: Material3D? + get() = getProperty(MATERIAL_KEY).node?.let { Material3D.wrap(it) } + set(value) = setProperty(MATERIAL_KEY, value?.config) + +fun VisualObject.material(builder: Material3D.() -> Unit) { + material = Material3D.build(builder) +} + +var VisualObject.opacity: Double? + get() = getProperty(OPACITY_KEY).double + set(value) { + setProperty(OPACITY_KEY, value) + } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt index 111490aa..c01ddd1c 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Proxy.kt @@ -35,9 +35,7 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua /** * Recursively search for defined template in the parent */ - val prototype: VisualObject3D get() = getPrototype() - - private fun getPrototype(): VisualObject3D = (parent as? VisualGroup3D)?.getTemplate(templateName) + val prototype: VisualObject3D get() = (parent as? VisualGroup3D)?.getTemplate(templateName) ?: error("Template with name $templateName not found in $parent") override fun getStyle(name: Name): Meta? = (parent as VisualGroup?)?.getStyle(name) diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt index 9a18af53..cd9b22b3 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/VisualObject3D.kt @@ -7,13 +7,9 @@ import hep.dataforge.meta.* import hep.dataforge.names.asName import hep.dataforge.names.plus import hep.dataforge.output.Output -import hep.dataforge.vis.common.Colors.rgbToString import hep.dataforge.vis.common.VisualObject -import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY -import hep.dataforge.vis.spatial.VisualObject3D.Companion.MATERIAL_KEY -import hep.dataforge.vis.spatial.VisualObject3D.Companion.OPACITY_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.SELECTED_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY import kotlinx.serialization.UseSerializers @@ -36,7 +32,7 @@ interface VisualObject3D : VisualObject { } companion object { - val MATERIAL_KEY = "material".asName() + val VISIBLE_KEY = "visible".asName() val SELECTED_KEY = "selected".asName() val DETAIL_KEY = "detail".asName() @@ -44,9 +40,6 @@ interface VisualObject3D : VisualObject { val GEOMETRY_KEY = "geometey".asName() - val COLOR_KEY = MATERIAL_KEY + "color" - val OPACITY_KEY = MATERIAL_KEY + "opacity" - val x = "x".asName() val y = "y".asName() val z = "z".asName() @@ -111,16 +104,6 @@ var VisualObject3D.detail: Int? get() = getProperty(DETAIL_KEY, false).int set(value) = setProperty(DETAIL_KEY, value) -var VisualObject.material: Meta? - get() = getProperty(MATERIAL_KEY).node - set(value) = setProperty(MATERIAL_KEY, value) - -var VisualObject.opacity: Double? - get() = getProperty(OPACITY_KEY).double - set(value) { - setProperty(OPACITY_KEY, value) - } - var VisualObject.visible: Boolean? get() = getProperty(VISIBLE_KEY).boolean set(value) = setProperty(VISIBLE_KEY, value) @@ -129,32 +112,6 @@ var VisualObject.selected: Boolean? get() = getProperty(SELECTED_KEY).boolean set(value) = setProperty(SELECTED_KEY, value) -fun VisualObject.color(rgb: Int) { - setProperty(COLOR_KEY, rgbToString(rgb)) -} - -fun VisualObject.color(rgb: String) { - setProperty(COLOR_KEY, rgb) -} - -var VisualObject.color: String? - get() = getProperty(COLOR_KEY).string - set(value) { - if (value != null) { - color(value) - } - } - -fun VisualObject3D.material(builder: MetaBuilder.() -> Unit) { - material = buildMeta(builder) -} - -fun VisualObject3D.color(r: Int, g: Int, b: Int) = material { - "red" to r - "green" to g - "blue" to b -} - private fun VisualObject3D.position(): Point3D = position ?: Point3D(0.0, 0.0, 0.0).also { position = it } diff --git a/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/ConvexTest.kt b/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/ConvexTest.kt index 6d1c5152..beba580c 100644 --- a/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/ConvexTest.kt +++ b/dataforge-vis-spatial/src/commonTest/kotlin/hep/dataforge/vis/spatial/ConvexTest.kt @@ -8,6 +8,7 @@ import kotlin.test.Test import kotlin.test.assertEquals class ConvexTest { + @Suppress("UNUSED_VARIABLE") @Test fun testConvexBuilder() { val group = VisualGroup3D().apply { diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/Materials.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/Materials.kt index 523fd1ec..e6c72174 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/Materials.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/Materials.kt @@ -3,6 +3,7 @@ package hep.dataforge.vis.spatial.three import hep.dataforge.meta.* import hep.dataforge.values.ValueType import hep.dataforge.vis.common.Colors +import hep.dataforge.vis.spatial.Material3D import info.laht.threekt.materials.Material import info.laht.threekt.materials.MeshBasicMaterial import info.laht.threekt.materials.MeshPhongMaterial @@ -61,3 +62,5 @@ fun Meta?.jsMaterial(): Material { } } +fun Material3D?.jsMaterial(): Material = this?.config.jsMaterial() + diff --git a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt index e0b4e11a..c190f048 100644 --- a/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt +++ b/dataforge-vis-spatial/src/jsMain/kotlin/hep/dataforge/vis/spatial/three/ThreeFactory.kt @@ -9,6 +9,7 @@ import hep.dataforge.names.startsWith import hep.dataforge.provider.Type import hep.dataforge.vis.common.VisualObject import hep.dataforge.vis.spatial.* +import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_KEY import hep.dataforge.vis.spatial.VisualObject3D.Companion.GEOMETRY_KEY import hep.dataforge.vis.spatial.three.ThreeFactory.Companion.TYPE import info.laht.threekt.core.BufferGeometry @@ -101,9 +102,9 @@ abstract class MeshThreeFactory(override val type: KClass buildMesh(obj: T, geometryBuilder: (T) -> BufferGeometry): Mesh { //TODO add caching for geometries using templates @@ -129,7 +130,7 @@ abstract class MeshThreeFactory(override val type: KClass { @@ -53,13 +51,15 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output(VisualObject::class, name.toName(), meta = meta) + val output = get(VisualObject::class, name.toName(), meta = meta) output.render(action = block) } \ No newline at end of file