Default properties for JS

This commit is contained in:
Alexander Nozik 2019-12-25 12:01:42 +03:00
parent 193fed524e
commit c2e396328f
5 changed files with 67 additions and 18 deletions

View File

@ -26,7 +26,7 @@ interface VisualObject : Configurable {
/**
* All properties including styles and prototypes if present, but without inheritance
*/
fun allProperties(): Meta
fun allProperties(): Laminate
/**
* Set property for this object

View File

@ -32,16 +32,20 @@ class Material3D(override val config: Config) : Specific {
val MATERIAL_WIREFRAME_KEY = MATERIAL_KEY + WIREFRAME_KEY
val descriptor = NodeDescriptor {
value(VisualObject3D.VISIBLE_KEY) {
type(ValueType.BOOLEAN)
default(true)
}
node(MATERIAL_KEY) {
value(COLOR_KEY) {
type(ValueType.STRING, ValueType.NUMBER)
default("#ffffff")
}
value(OPACITY_KEY){
value(OPACITY_KEY) {
type(ValueType.NUMBER)
default(1.0)
}
value(WIREFRAME_KEY){
value(WIREFRAME_KEY) {
type(ValueType.BOOLEAN)
default(false)
}

View File

@ -23,6 +23,9 @@ class ThreeCanvas(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Renderer
override val context: Context get() = three.context
var data: VisualObject3D? = null
private set
val axes = AxesHelper(meta["axes.size"].int ?: 50).apply { visible = false }
val scene: Scene = Scene().apply {
@ -90,6 +93,7 @@ class ThreeCanvas(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Renderer
}
override fun render(obj: VisualObject3D, meta: Meta) {
data = obj
scene.add(three.buildObject3D(obj))
}
}

View File

@ -2,16 +2,49 @@ package hep.dataforge.vis.spatial.three
import hep.dataforge.vis.js.editor.card
import kotlinx.html.InputType
import kotlinx.html.button
import kotlinx.html.dom.append
import kotlinx.html.js.div
import kotlinx.html.js.input
import kotlinx.html.js.label
import kotlinx.html.js.*
import org.w3c.dom.Element
import kotlin.dom.clear
//private fun download(filename: String, text: String) {
// var element = document.createElement("a");
// element.setAttribute("href", "data:text/json;charset=utf-8," + encodeURIComponent(text));
// element.setAttribute("download", filename);
//
// element.style.display = 'none';
// document.body.appendChild(element);
//
// element.click();
//
// document.body.removeChild(element);
//}
fun Element.threeOutputConfig(canvas: ThreeCanvas) {
clear()
append {
card("Settings"){
div("row"){
div("col-1") {
label { +"Axes" }
input(type = InputType.checkBox).apply {
checked = canvas.axes.visible
onChangeFunction = {
canvas.axes.visible = checked
}
}
}
div("col-1") {
button {
+"Export"
onClickFunction = {
}
}
}
}
}
card("Layers"){
div("row") {
(0..11).forEach { layer ->
@ -21,7 +54,7 @@ fun Element.threeOutputConfig(canvas: ThreeCanvas) {
if (layer == 0) {
checked = true
}
onchange = {
onChangeFunction = {
if (checked) {
canvas.camera.layers.enable(layer)
} else {

View File

@ -4,20 +4,24 @@ import hep.dataforge.context.Global
import hep.dataforge.js.Application
import hep.dataforge.js.objectTree
import hep.dataforge.js.startApplication
import hep.dataforge.meta.Meta
import hep.dataforge.meta.builder
import hep.dataforge.meta.buildMeta
import hep.dataforge.meta.withBottom
import hep.dataforge.names.NameToken
import hep.dataforge.vis.spatial.*
import hep.dataforge.vis.js.editor.propertyEditor
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_COLOR_KEY
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_OPACITY_KEY
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_WIREFRAME_KEY
import hep.dataforge.vis.spatial.Visual3DPlugin
import hep.dataforge.vis.spatial.VisualGroup3D
import hep.dataforge.vis.spatial.VisualObject3D
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
import hep.dataforge.vis.js.editor.propertyEditor
import hep.dataforge.vis.spatial.three.threeOutputConfig
import hep.dataforge.vis.spatial.gdml.GDMLTransformer
import hep.dataforge.vis.spatial.gdml.LUnit
import hep.dataforge.vis.spatial.gdml.toVisual
import hep.dataforge.vis.spatial.three.ThreePlugin
import hep.dataforge.vis.spatial.three.output
import hep.dataforge.vis.spatial.three.threeOutputConfig
import hep.dataforge.vis.spatial.visible
import kotlinx.html.dom.append
import kotlinx.html.js.p
import org.w3c.dom.DragEvent
@ -156,15 +160,19 @@ private class GDMLDemoApp : Application {
configElement.threeOutputConfig(output)
//tree.visualObjectTree(visual, editor::propertyEditor)
treeElement.objectTree(NameToken("World"), visual) {
editorElement.propertyEditor(it) {item->
val config: Meta = item.prototype.config
config.builder().apply {
VISIBLE_KEY to (item.visible ?: true)
editorElement.propertyEditor(it) { item ->
//val descriptorMeta = Material3D.descriptor
val properties = item.allProperties()
val bottom = buildMeta {
VISIBLE_KEY put (item.visible ?: true)
if (item is VisualObject3D) {
MATERIAL_COLOR_KEY to (item.color ?: "#ffffff")
MATERIAL_OPACITY_KEY to (item.opacity ?: 1.0)
MATERIAL_COLOR_KEY put "#ffffff"
MATERIAL_OPACITY_KEY put 1.0
MATERIAL_WIREFRAME_KEY put false
}
}
properties.withBottom(bottom)
}
}