Update light descriptor
This commit is contained in:
parent
f828f86e29
commit
7ee40679b9
@ -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
|
||||
|
@ -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<MMAppProps>("Muon monitor") { props ->
|
||||
val root = useMemo(props.model) {
|
||||
props.model.root.apply {
|
||||
edges()
|
||||
ambientLight()
|
||||
ambientLight{
|
||||
color(Colors.white)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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<Configurable, ColorAccessor> = 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()
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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"))
|
||||
}
|
||||
|
@ -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<PointLightSource> {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user