From 67afa4e45b5008cdfe4416c35d561d1ae9e8fd7c Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 15 Aug 2022 09:47:56 +0300 Subject: [PATCH] Fix light --- demo/playground/src/jvmMain/kotlin/gdmlCubes.kt | 11 +++++++++-- .../src/main/kotlin/ru/mipt/npm/sat/satServer.kt | 7 ++++++- .../kotlin/space/kscience/visionforge/VisionChange.kt | 11 ++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt b/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt index d5d483bc..fc134408 100644 --- a/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt +++ b/demo/playground/src/jvmMain/kotlin/gdmlCubes.kt @@ -1,13 +1,20 @@ package space.kscience.visionforge.examples import space.kscience.gdml.GdmlShowCase +import space.kscience.visionforge.Colors import space.kscience.visionforge.gdml.toVision import space.kscience.visionforge.html.ResourceLocation import space.kscience.visionforge.solid.Solids +import space.kscience.visionforge.solid.ambientLight +import space.kscience.visionforge.solid.set -fun main() = makeVisionFile(resourceLocation = ResourceLocation.SYSTEM){ +fun main() = makeVisionFile(resourceLocation = ResourceLocation.SYSTEM) { vision("canvas") { requirePlugin(Solids) - GdmlShowCase.cubes().toVision() + GdmlShowCase.cubes().toVision().also { + it.ambientLight { + color.set(Colors.white) + } + } } } \ No newline at end of file diff --git a/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/satServer.kt b/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/satServer.kt index 41ac4d2f..e7326982 100644 --- a/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/satServer.kt +++ b/demo/sat-demo/src/main/kotlin/ru/mipt/npm/sat/satServer.kt @@ -8,6 +8,7 @@ import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.fetch import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.names.Name +import space.kscience.visionforge.Colors import space.kscience.visionforge.html.Page import space.kscience.visionforge.html.plus import space.kscience.visionforge.server.close @@ -28,7 +29,11 @@ fun main() { val solids = satContext.fetch(Solids) //Create a geometry - val sat = solids.visionOfSatellite(ySegments = 3) + val sat = solids.visionOfSatellite(ySegments = 3).apply { + ambientLight { + color.set(Colors.white) + } + } val server = satContext.visionManager.serve { page(header = Page.threeJsHeader + Page.styleSheetHeader("css/styles.css")) { diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionChange.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionChange.kt index 1edcdf70..0001dd44 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionChange.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/VisionChange.kt @@ -9,6 +9,7 @@ import kotlinx.serialization.Serializable import space.kscience.dataforge.meta.* import space.kscience.dataforge.meta.descriptors.MetaDescriptor import space.kscience.dataforge.names.Name +import space.kscience.dataforge.names.isEmpty import space.kscience.dataforge.names.plus import kotlin.jvm.Synchronized import kotlin.time.Duration @@ -17,7 +18,7 @@ import kotlin.time.Duration * Create a deep copy of given Vision without external connections. */ private fun Vision.deepCopy(manager: VisionManager): Vision { - if(this is NullVision) return NullVision + if (this is NullVision) return NullVision //Assuming that unrooted visions are already isolated //TODO replace by efficient deep copy @@ -49,7 +50,7 @@ public object NullVision : Vision { public class VisionChangeBuilder(private val manager: VisionManager) : MutableVisionContainer { private var vision: Vision? = null - private val propertyChange = MutableMeta() + private var propertyChange = MutableMeta() private val children: HashMap = HashMap() public fun isEmpty(): Boolean = propertyChange.isEmpty() && propertyChange.isEmpty() && children.isEmpty() @@ -61,7 +62,11 @@ public class VisionChangeBuilder(private val manager: VisionManager) : MutableVi public fun propertyChanged(visionName: Name, propertyName: Name, item: Meta?) { if (visionName == Name.EMPTY) { //Write property removal as [Null] - propertyChange[propertyName] = (item ?: Meta(Null)) + if (propertyName.isEmpty()) { + propertyChange = item?.toMutableMeta() ?: MutableMeta() + } else { + propertyChange[propertyName] = (item ?: Meta(Null)) + } } else { getOrPutChild(visionName).propertyChanged(Name.EMPTY, propertyName, item) }