Minor fixes

This commit is contained in:
Alexander Nozik 2023-05-30 19:37:03 +03:00
parent c4b866f5b5
commit be52551564
5 changed files with 28 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package space.kscience.visionforge.examples
import kotlinx.html.h2 import kotlinx.html.h2
import space.kscience.dataforge.meta.ValueType import space.kscience.dataforge.meta.ValueType
import space.kscience.dataforge.meta.invoke
import space.kscience.plotly.layout import space.kscience.plotly.layout
import space.kscience.plotly.models.ScatterMode import space.kscience.plotly.models.ScatterMode
import space.kscience.plotly.models.TextPosition import space.kscience.plotly.models.TextPosition
@ -12,13 +13,14 @@ import space.kscience.visionforge.markup.markdown
import space.kscience.visionforge.plotly.plotly import space.kscience.visionforge.plotly.plotly
import space.kscience.visionforge.solid.box import space.kscience.visionforge.solid.box
import space.kscience.visionforge.solid.solid import space.kscience.visionforge.solid.solid
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
import space.kscience.visionforge.solid.z import space.kscience.visionforge.solid.z
import space.kscience.visionforge.tables.columnTable import space.kscience.visionforge.tables.columnTable
import java.nio.file.Paths import kotlin.io.path.Path
fun main() = makeVisionFile( fun main() = makeVisionFile(
Paths.get("VisionForgeDemo.html"), Path("VisionForgeDemo.html"),
resourceLocation = ResourceLocation.EMBED resourceLocation = ResourceLocation.EMBED
) { ) {
markdown { markdown {
@ -32,7 +34,14 @@ fun main() = makeVisionFile(
h2 { +"3D visualization with Three-js" } h2 { +"3D visualization with Three-js" }
vision("3D") { vision("3D") {
solid { solid(
Canvas3DOptions {
axes {
size = 200.0
visible = true
}
}
) {
box(100, 100, 100, name = "aBox") { box(100, 100, 100, name = "aBox") {
z = 50.0 z = 50.0
} }

View File

@ -26,7 +26,7 @@ public annotation class VisionDSL
* A placeholder object to attach inline vision builders. * A placeholder object to attach inline vision builders.
*/ */
@VisionDSL @VisionDSL
public class VisionOutput @PublishedApi internal constructor(public val context: Context, public val name: Name) { public class VisionOutput @PublishedApi internal constructor(override val context: Context, public val name: Name): ContextAware {
public var meta: Meta = Meta.EMPTY public var meta: Meta = Meta.EMPTY
private val requirements: MutableSet<PluginFactory<*>> = HashSet() private val requirements: MutableSet<PluginFactory<*>> = HashSet()
@ -95,9 +95,10 @@ public abstract class VisionTagConsumer<R>(
if (!outputMeta.isEmpty()) { if (!outputMeta.isEmpty()) {
//Hard-code output configuration //Hard-code output configuration
script { script {
type = "text/json"
attributes["class"] = OUTPUT_META_CLASS attributes["class"] = OUTPUT_META_CLASS
unsafe { unsafe {
+manager.jsonFormat.encodeToString(MetaSerializer, outputMeta) +("\n" + manager.jsonFormat.encodeToString(MetaSerializer, outputMeta) + "\n")
} }
} }
} }

View File

@ -176,11 +176,13 @@ public class VisionClient : AbstractPlugin() {
} }
val outputMeta = element.getEmbeddedData(VisionTagConsumer.OUTPUT_META_CLASS)?.let { val outputMeta = element.getEmbeddedData(VisionTagConsumer.OUTPUT_META_CLASS)?.let {
VisionManager.defaultJson.decodeFromString(MetaSerializer, it) VisionManager.defaultJson.decodeFromString(MetaSerializer, it).also {
logger.info { "Output meta for $name: $it" }
}
} ?: Meta.EMPTY } ?: Meta.EMPTY
when { when {
// fetch data if path is provided // fetch data if the path is provided
element.attributes[OUTPUT_FETCH_ATTRIBUTE] != null -> { element.attributes[OUTPUT_FETCH_ATTRIBUTE] != null -> {
val attr = element.attributes[OUTPUT_FETCH_ATTRIBUTE]!! val attr = element.attributes[OUTPUT_FETCH_ATTRIBUTE]!!

View File

@ -85,5 +85,9 @@ public inline fun VisionOutput.solid(options: Canvas3DOptions? = null, block: So
options?.let { options?.let {
meta = options.meta meta = options.meta
} }
return SolidGroup().apply(block) return SolidGroup().apply(block).apply {
if (children.values.none { it is LightSource }) {
ambientLight()
}
}
} }

View File

@ -124,7 +124,7 @@ public class ThreePlugin : AbstractPlugin(), ElementVisionRenderer {
public fun getOrCreateCanvas( public fun getOrCreateCanvas(
element: Element, element: Element,
options: Canvas3DOptions = Canvas3DOptions(), options: Canvas3DOptions,
): ThreeCanvas = canvasCache.getOrPut(element) { ): ThreeCanvas = canvasCache.getOrPut(element) {
ThreeCanvas(this, element, options) ThreeCanvas(this, element, options)
} }
@ -142,7 +142,7 @@ public class ThreePlugin : AbstractPlugin(), ElementVisionRenderer {
internal fun renderSolid( internal fun renderSolid(
element: Element, element: Element,
vision: Solid, vision: Solid,
options: Canvas3DOptions = Canvas3DOptions(), options: Canvas3DOptions,
): ThreeCanvas = getOrCreateCanvas(element, options).apply { ): ThreeCanvas = getOrCreateCanvas(element, options).apply {
render(vision) render(vision)
} }
@ -166,7 +166,7 @@ public fun ThreePlugin.render(
element: HTMLElement, element: HTMLElement,
obj: Solid, obj: Solid,
optionsBuilder: Canvas3DOptions.() -> Unit = {}, optionsBuilder: Canvas3DOptions.() -> Unit = {},
): ThreeCanvas = renderSolid(element, obj).apply { ): ThreeCanvas = renderSolid(element, obj, Canvas3DOptions(optionsBuilder)).apply {
options.apply(optionsBuilder) options.apply(optionsBuilder)
} }