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