From f99a359e246197b17a3cded07e05b4b08502d4ab Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sat, 14 Aug 2021 21:31:36 +0300 Subject: [PATCH] Fix color resolution --- build.gradle.kts | 4 +-- demo/playground/build.gradle.kts | 4 +-- .../src/jvmMain/kotlin/randomSpheres.kt | 2 +- .../visionforge/solid/ColorAccessor.kt | 13 ++++---- .../kscience/visionforge/solid/SolidBase.kt | 6 ---- .../visionforge/solid/three/ThreeMaterials.kt | 30 ++++++++++--------- 6 files changed, 27 insertions(+), 32 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5c2557bd..2dc7926a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,9 @@ plugins { id("ru.mipt.npm.gradle.project") - kotlin("multiplatform") version "1.5.30-RC" apply false +// kotlin("multiplatform") version "1.5.30-RC" apply false } -val dataforgeVersion by extra("0.5.0") +val dataforgeVersion by extra("0.5.1") val fxVersion by extra("11") allprojects { diff --git a/demo/playground/build.gradle.kts b/demo/playground/build.gradle.kts index 73fd2aa7..68ea5f9a 100644 --- a/demo/playground/build.gradle.kts +++ b/demo/playground/build.gradle.kts @@ -20,7 +20,7 @@ kotlin { this.outputFileName = "js/visionforge-playground.js" } commonWebpackConfig { - sourceMaps = false + sourceMaps = true cssSupport.enabled = false } } @@ -37,7 +37,7 @@ kotlin { } afterEvaluate { - val jsBrowserDistribution by tasks.getting + val jsBrowserDistribution = tasks.getByName("jsBrowserDevelopmentExecutableDistribution") tasks.getByName("jvmProcessResources") { dependsOn(jsBrowserDistribution) diff --git a/demo/playground/src/jvmMain/kotlin/randomSpheres.kt b/demo/playground/src/jvmMain/kotlin/randomSpheres.kt index 383f3d3a..0185bdc8 100644 --- a/demo/playground/src/jvmMain/kotlin/randomSpheres.kt +++ b/demo/playground/src/jvmMain/kotlin/randomSpheres.kt @@ -17,7 +17,7 @@ fun main() { context.makeVisionFile( Paths.get("randomSpheres.html"), - resourceLocation = ResourceLocation.EMBED + resourceLocation = ResourceLocation.SYSTEM ) { h1 { +"Happy new year!" } div { diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/ColorAccessor.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/ColorAccessor.kt index f06a7c6f..57f868f2 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/ColorAccessor.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/ColorAccessor.kt @@ -2,16 +2,15 @@ package space.kscience.visionforge.solid import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.plus -import space.kscience.dataforge.values.MutableValueProvider -import space.kscience.dataforge.values.Value -import space.kscience.dataforge.values.asValue -import space.kscience.dataforge.values.string +import space.kscience.dataforge.values.* import space.kscience.visionforge.Colors import space.kscience.visionforge.VisionBuilder @VisionBuilder -public class ColorAccessor(private val provider: MutableValueProvider, private val colorKey: Name) : - MutableValueProvider { +public class ColorAccessor( + private val provider: MutableValueProvider, + private val colorKey: Name +) : MutableValueProvider { public var value: Value? get() = provider.getValue(colorKey) set(value) { @@ -26,7 +25,7 @@ public class ColorAccessor(private val provider: MutableValueProvider, private v } public var ColorAccessor?.string: String? - get() = this?.value?.string + get() = this?.value?.let { if(it == Null) null else it.string } set(value) { this?.value = value?.asValue() } diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidBase.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidBase.kt index 7ca5c45d..021079d3 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidBase.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidBase.kt @@ -5,7 +5,6 @@ import kotlinx.serialization.Serializable import space.kscience.dataforge.meta.MutableMeta import space.kscience.dataforge.meta.descriptors.MetaDescriptor import space.kscience.visionforge.VisionBase -import space.kscience.visionforge.VisionChange @Serializable @SerialName("solid") @@ -14,9 +13,4 @@ public open class SolidBase : VisionBase(), Solid { override var properties: MutableMeta? = null override val descriptor: MetaDescriptor get() = Solid.descriptor - - override fun update(change: VisionChange) { - updatePosition(change.properties) - super.update(change) - } } diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeMaterials.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeMaterials.kt index dc0ab967..522c0362 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeMaterials.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeMaterials.kt @@ -5,10 +5,7 @@ import info.laht.threekt.materials.Material import info.laht.threekt.materials.MeshBasicMaterial import info.laht.threekt.math.Color import info.laht.threekt.objects.Mesh -import space.kscience.dataforge.meta.Meta -import space.kscience.dataforge.meta.boolean -import space.kscience.dataforge.meta.double -import space.kscience.dataforge.meta.get +import space.kscience.dataforge.meta.* import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName import space.kscience.dataforge.values.* @@ -100,18 +97,23 @@ public object ThreeMaterials { /** * Compute color */ -public fun Meta.threeColor(): Color = getValue(Name.EMPTY)?.let { value -> - if (value.type == ValueType.NUMBER) { - val int = value.int - Color(int) +public fun Meta.threeColor(): Color? { + val value = getValue(Name.EMPTY) + return if (isLeaf) { + when { + value == null -> null + value === Null -> null + value.type == ValueType.NUMBER -> Color(value.int) + else -> Color(value.string) + } } else { - Color(value.string) + Color( + getValue(Colors.RED_KEY.asName())?.int ?: 0, + getValue(Colors.GREEN_KEY.asName())?.int ?: 0, + getValue(Colors.BLUE_KEY.asName())?.int ?: 0 + ) } -} ?: Color( - getValue(Colors.RED_KEY.asName())?.int ?: 0, - getValue(Colors.GREEN_KEY.asName())?.int ?: 0, - getValue(Colors.BLUE_KEY.asName())?.int ?: 0 -) +} private var Material.cached: Boolean get() = userData["cached"] == true