From 7ee40679b974b4f39b35800e0d6137b0c2bf4185 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 28 Jan 2022 14:17:37 +0300 Subject: [PATCH] Update light descriptor --- .../kotlin/ru/mipt/npm/muon/monitor/Model.kt | 7 ++- .../mipt/npm/muon/monitor/MMAppComponent.kt | 6 ++- kotlin-js-store/yarn.lock | 8 ++-- .../visionforge/solid/ColorAccessor.kt | 11 ++++- .../kscience/visionforge/solid/LightSource.kt | 46 +++++++++++++++---- visionforge-threejs/build.gradle.kts | 2 +- .../solid/three/ThreePointLightFactory.kt | 6 ++- 7 files changed, 68 insertions(+), 18 deletions(-) diff --git a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt index 2dab49a2..06501374 100644 --- a/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt +++ b/demo/muon-monitor/src/commonMain/kotlin/ru/mipt/npm/muon/monitor/Model.kt @@ -8,6 +8,12 @@ import space.kscience.visionforge.removeAll import space.kscience.visionforge.setAsRoot import space.kscience.visionforge.setProperty import space.kscience.visionforge.solid.* +import kotlin.collections.HashMap +import kotlin.collections.HashSet +import kotlin.collections.filter +import kotlin.collections.forEach +import kotlin.collections.set +import kotlin.collections.toTypedArray import kotlin.math.PI class Model(val manager: VisionManager) { @@ -39,7 +45,6 @@ class Model(val manager: VisionManager) { val root: SolidGroup = SolidGroup().apply { setAsRoot(this@Model.manager) material { - wireframe color("darkgreen") } rotationX = PI / 2 diff --git a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt index 350d25f3..f9c03756 100644 --- a/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt +++ b/demo/muon-monitor/src/jsMain/kotlin/ru/mipt/npm/muon/monitor/MMAppComponent.kt @@ -19,11 +19,13 @@ import react.useState import space.kscience.dataforge.context.Context import space.kscience.dataforge.meta.invoke import space.kscience.dataforge.names.Name +import space.kscience.visionforge.Colors import space.kscience.visionforge.react.flexColumn import space.kscience.visionforge.react.flexRow import space.kscience.visionforge.ring.ThreeCanvasWithControls import space.kscience.visionforge.ring.tab import space.kscience.visionforge.solid.ambientLight +import space.kscience.visionforge.solid.invoke import space.kscience.visionforge.solid.specifications.Canvas3DOptions import space.kscience.visionforge.solid.three.edges import styled.css @@ -55,7 +57,9 @@ val MMApp = fc("Muon monitor") { props -> val root = useMemo(props.model) { props.model.root.apply { edges() - ambientLight() + ambientLight{ + color(Colors.white) + } } } diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index df058368..bf21978a 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -8244,10 +8244,10 @@ three-csg-ts@3.1.9: resolved "https://registry.yarnpkg.com/three-csg-ts/-/three-csg-ts-3.1.9.tgz#1438de3b6747b9b55deb88d9e0acdc6e47681979" integrity sha512-Qke0+07AKDfeiRjh46sOF2iiilSMcKnfgHjuArdMB4poZs3X0FQLHGFIEBbGrv3ejrkHASW9o5pLRfFFQhk9hg== -three@0.130.1: - version "0.130.1" - resolved "https://registry.yarnpkg.com/three/-/three-0.130.1.tgz#797588b2877ace31603bbbc864eb2e3022f0b3b4" - integrity sha512-OSPPKcGvFSiGkG3jFrwwC76PBV/ZSrGxpBbg28bW8s9GU8r/y2spNGtEXHEb/CVqo0Ctf5Lx2rVaxQZB6OasaA== +three@0.137.4: + version "0.137.4" + resolved "https://registry.yarnpkg.com/three/-/three-0.137.4.tgz#ec73b6a6c40b733d56544b13d0c3cdb0bce5d0a7" + integrity sha512-kUyOZNX+dMbvaS0mGYM1BaXHkHVNQdpryWH8dBg3mn725dJcTo9/5rjyH+OJ8V0r+XbZPz7sncV+c3Gjpc9UBA== through2@^0.6.3: version "0.6.5" 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 57f868f2..0f9abc4d 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 @@ -1,15 +1,18 @@ package space.kscience.visionforge.solid +import space.kscience.dataforge.meta.Configurable import space.kscience.dataforge.names.Name +import space.kscience.dataforge.names.asName import space.kscience.dataforge.names.plus import space.kscience.dataforge.values.* import space.kscience.visionforge.Colors import space.kscience.visionforge.VisionBuilder +import kotlin.properties.ReadOnlyProperty @VisionBuilder public class ColorAccessor( private val provider: MutableValueProvider, - private val colorKey: Name + private val colorKey: Name, ) : MutableValueProvider { public var value: Value? get() = provider.getValue(colorKey) @@ -24,8 +27,12 @@ public class ColorAccessor( } } +public fun Configurable.color(): ReadOnlyProperty = ReadOnlyProperty { _, property -> + ColorAccessor(meta, property.name.asName()) +} + public var ColorAccessor?.string: String? - get() = this?.value?.let { if(it == Null) null else it.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/LightSource.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/LightSource.kt index 3b85b469..6bab2cf3 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/LightSource.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/LightSource.kt @@ -2,18 +2,48 @@ package space.kscience.visionforge.solid import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient -import space.kscience.dataforge.names.asName -import space.kscience.visionforge.VisionBuilder -import space.kscience.visionforge.VisionContainerBuilder -import space.kscience.visionforge.numberProperty -import space.kscience.visionforge.set +import space.kscience.dataforge.meta.descriptors.MetaDescriptor +import space.kscience.dataforge.meta.descriptors.node +import space.kscience.dataforge.meta.descriptors.value +import space.kscience.dataforge.values.ValueType +import space.kscience.visionforge.* @Serializable public abstract class LightSource : SolidBase() { - @Transient - public val color: ColorAccessor = ColorAccessor(meta, "color".asName()) + override val descriptor: MetaDescriptor get() = LightSource.descriptor + + public val color: ColorAccessor by color() public var intensity: Number by numberProperty(includeStyles = false) { 1.0 } + + public companion object{ + public val descriptor: MetaDescriptor by lazy { + MetaDescriptor { + value(Vision.VISIBLE_KEY, ValueType.BOOLEAN) { + inherited = false + default(true) + } + + value(LightSource::color.name, ValueType.STRING, ValueType.NUMBER) { + inherited = false + widgetType = "color" + } + + value(LightSource::intensity.name, ValueType.NUMBER) { + inherited = false + default(1.0) + } + + value(SolidMaterial.COLOR_KEY, ValueType.STRING, ValueType.NUMBER) { + inherited = false + widgetType = "color" + } + + node(Solid.POSITION_KEY) { + hide() + } + } + } + } } @Serializable diff --git a/visionforge-threejs/build.gradle.kts b/visionforge-threejs/build.gradle.kts index 5ae86f41..3aa1ef5e 100644 --- a/visionforge-threejs/build.gradle.kts +++ b/visionforge-threejs/build.gradle.kts @@ -10,6 +10,6 @@ kotlin{ dependencies { api(project(":visionforge-solid")) - implementation(npm("three", "0.130.1")) + implementation(npm("three", "0.137.4")) implementation(npm("three-csg-ts", "3.1.9")) } diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreePointLightFactory.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreePointLightFactory.kt index a7a6d758..727aa098 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreePointLightFactory.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreePointLightFactory.kt @@ -2,7 +2,9 @@ package space.kscience.visionforge.solid.three import info.laht.threekt.lights.PointLight import info.laht.threekt.math.Color +import space.kscience.dataforge.names.asName import space.kscience.visionforge.onPropertyChange +import space.kscience.visionforge.solid.LightSource import space.kscience.visionforge.solid.PointLightSource import kotlin.reflect.KClass @@ -18,7 +20,9 @@ public object ThreePointLightFactory : ThreeFactory { } obj.onPropertyChange { name -> - when { + when (name) { + LightSource::color.name.asName() -> res.color = obj.color.threeColor() ?: Color(0x404040) + LightSource::intensity.name.asName() -> res.intensity = obj.intensity.toDouble() else -> res.updateProperty(obj, name) } }