forked from kscience/visionforge
Merge dev into doc
This commit is contained in:
commit
6ff8002485
@ -1,6 +1,6 @@
|
|||||||
val dataforgeVersion by extra("0.1.3")
|
val dataforgeVersion by extra("0.1.3")
|
||||||
|
|
||||||
plugins{
|
plugins {
|
||||||
val kotlinVersion = "1.3.50"
|
val kotlinVersion = "1.3.50"
|
||||||
val toolsVersion = "0.2.0"
|
val toolsVersion = "0.2.0"
|
||||||
|
|
||||||
@ -16,6 +16,7 @@ plugins{
|
|||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://dl.bintray.com/pdvrieze/maven")
|
maven("https://dl.bintray.com/pdvrieze/maven")
|
||||||
|
maven("http://maven.jzy3d.org/releases")
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "hep.dataforge"
|
group = "hep.dataforge"
|
||||||
|
@ -56,13 +56,14 @@ abstract class AbstractVisualObject : VisualObject {
|
|||||||
config[name] = value
|
config[name] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
private var styleCache: Laminate? = null
|
private var styleCache: Meta? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect all styles for this object in a laminate
|
||||||
|
*/
|
||||||
|
protected val appliedStyles: Meta
|
||||||
|
get() = styleCache ?: Laminate(style.map { it.toName() }.mapNotNull(::findStyle)).merge().also { styleCache = it }
|
||||||
|
|
||||||
protected val actualStyles: Laminate
|
|
||||||
get() = styleCache ?: run {
|
|
||||||
Laminate(style.map { it.toName() }.mapNotNull(::findStyle))
|
|
||||||
.also { styleCache = it }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to reset style cache
|
* Helper to reset style cache
|
||||||
@ -74,9 +75,9 @@ abstract class AbstractVisualObject : VisualObject {
|
|||||||
|
|
||||||
override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? {
|
override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? {
|
||||||
return if (inherit) {
|
return if (inherit) {
|
||||||
properties?.get(name) ?: actualStyles[name] ?: parent?.getProperty(name, inherit)
|
properties?.get(name) ?: appliedStyles[name] ?: parent?.getProperty(name, inherit)
|
||||||
} else {
|
} else {
|
||||||
properties?.get(name) ?: actualStyles[name]
|
properties?.get(name) ?: appliedStyles[name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +178,19 @@ object Colors {
|
|||||||
const val yellowgreen = 0x9ACD32
|
const val yellowgreen = 0x9ACD32
|
||||||
|
|
||||||
fun rgbToString(rgb: Int): String {
|
fun rgbToString(rgb: Int): String {
|
||||||
val string = rgb.toString(16)
|
val string = rgb.toString(16).padStart(6, '0')
|
||||||
return "#" + string.substring(max(0, string.length - 6))
|
return "#" + string.substring(max(0, string.length - 6))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun rgbToString(red: UByte, green: UByte, blue: UByte): String {
|
||||||
|
fun colorToString(color: UByte): String{
|
||||||
|
return color.toString(16).padStart(2,'0')
|
||||||
|
}
|
||||||
|
return buildString {
|
||||||
|
append("#")
|
||||||
|
append(colorToString(red))
|
||||||
|
append(colorToString(green))
|
||||||
|
append(colorToString(blue))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,10 +8,10 @@ import hep.dataforge.names.toName
|
|||||||
import hep.dataforge.vis.common.Colors
|
import hep.dataforge.vis.common.Colors
|
||||||
import hep.dataforge.vis.common.VisualObject
|
import hep.dataforge.vis.common.VisualObject
|
||||||
import hep.dataforge.vis.common.applyStyle
|
import hep.dataforge.vis.common.applyStyle
|
||||||
|
import hep.dataforge.vis.spatial.Material3D.Companion.COLOR_KEY
|
||||||
import hep.dataforge.vis.spatial.RotationOrder
|
import hep.dataforge.vis.spatial.RotationOrder
|
||||||
import hep.dataforge.vis.spatial.VisualGroup3D
|
import hep.dataforge.vis.spatial.VisualGroup3D
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D
|
import hep.dataforge.vis.spatial.VisualObject3D
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY
|
|
||||||
import hep.dataforge.vis.spatial.rotationOrder
|
import hep.dataforge.vis.spatial.rotationOrder
|
||||||
import scientifik.gdml.*
|
import scientifik.gdml.*
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
@ -4,7 +4,11 @@ import hep.dataforge.context.Global
|
|||||||
import hep.dataforge.vis.common.VisualGroup
|
import hep.dataforge.vis.common.VisualGroup
|
||||||
import hep.dataforge.vis.hmr.ApplicationBase
|
import hep.dataforge.vis.hmr.ApplicationBase
|
||||||
import hep.dataforge.vis.hmr.startApplication
|
import hep.dataforge.vis.hmr.startApplication
|
||||||
import hep.dataforge.vis.spatial.*
|
import hep.dataforge.vis.spatial.Material3D.Companion.OPACITY_KEY
|
||||||
|
import hep.dataforge.vis.spatial.Visual3DPlugin
|
||||||
|
import hep.dataforge.vis.spatial.VisualGroup3D
|
||||||
|
import hep.dataforge.vis.spatial.VisualObject3D
|
||||||
|
import hep.dataforge.vis.spatial.attachChildren
|
||||||
import hep.dataforge.vis.spatial.gdml.GDMLTransformer
|
import hep.dataforge.vis.spatial.gdml.GDMLTransformer
|
||||||
import hep.dataforge.vis.spatial.gdml.LUnit
|
import hep.dataforge.vis.spatial.gdml.LUnit
|
||||||
import hep.dataforge.vis.spatial.gdml.toVisual
|
import hep.dataforge.vis.spatial.gdml.toVisual
|
||||||
@ -137,15 +141,15 @@ private class GDMLDemoApp : ApplicationBase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
solidConfiguration = { parent, solid ->
|
solidConfiguration = { parent, solid ->
|
||||||
if (!parent.physVolumes.isEmpty()) {
|
if (parent.physVolumes.isNotEmpty()
|
||||||
opacity = 0.3
|
|| solid.name.startsWith("Coil")
|
||||||
}
|
|
||||||
if (solid.name.startsWith("Coil")
|
|
||||||
|| solid.name.startsWith("Yoke")
|
|| solid.name.startsWith("Yoke")
|
||||||
|| solid.name.startsWith("Magnet")
|
|| solid.name.startsWith("Magnet")
|
||||||
|| solid.name.startsWith("Pole")
|
|| solid.name.startsWith("Pole")
|
||||||
) {
|
) {
|
||||||
opacity = 0.3
|
useStyle("opaque") {
|
||||||
|
OPACITY_KEY to 0.3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,12 @@ import org.junit.Test
|
|||||||
import scientifik.gdml.GDML
|
import scientifik.gdml.GDML
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
import kotlin.test.Ignore
|
||||||
|
|
||||||
class TestConvertor {
|
class TestConvertor {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
fun testBMNGeometry() {
|
fun testBMNGeometry() {
|
||||||
val url = URL("https://drive.google.com/open?id=1w5e7fILMN83JGgB8WANJUYm8OW2s0WVO")
|
val url = URL("https://drive.google.com/open?id=1w5e7fILMN83JGgB8WANJUYm8OW2s0WVO")
|
||||||
val file = File("D:\\Work\\Projects\\gdml.kt\\gdml-source\\BM@N.gdml")
|
val file = File("D:\\Work\\Projects\\gdml.kt\\gdml-source\\BM@N.gdml")
|
||||||
@ -24,6 +26,7 @@ class TestConvertor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
fun testCubes() {
|
fun testCubes() {
|
||||||
val file = File("D:\\Work\\Projects\\gdml.kt\\gdml-source\\cubes.gdml ")
|
val file = File("D:\\Work\\Projects\\gdml.kt\\gdml-source\\cubes.gdml ")
|
||||||
val stream = if (file.exists()) {
|
val stream = if (file.exists()) {
|
||||||
|
@ -22,7 +22,7 @@ kotlin {
|
|||||||
jvmMain {
|
jvmMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":dataforge-vis-fx"))
|
implementation(project(":dataforge-vis-fx"))
|
||||||
implementation("org.fxyz3d:fxyz3d:0.4.0")
|
implementation("org.fxyz3d:fxyz3d:0.5.2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsMain {
|
jsMain {
|
||||||
@ -30,7 +30,6 @@ kotlin {
|
|||||||
implementation(npm("three", "0.106.2"))
|
implementation(npm("three", "0.106.2"))
|
||||||
implementation(npm("@hi-level/three-csg", "1.0.6"))
|
implementation(npm("@hi-level/three-csg", "1.0.6"))
|
||||||
implementation(npm("style-loader"))
|
implementation(npm("style-loader"))
|
||||||
implementation(npm("element-resize-event"))
|
|
||||||
implementation(npm("inspire-tree","6.0.1"))
|
implementation(npm("inspire-tree","6.0.1"))
|
||||||
implementation(npm("inspire-tree-dom","4.0.6"))
|
implementation(npm("inspire-tree-dom","4.0.6"))
|
||||||
implementation(npm("jsoneditor"))
|
implementation(npm("jsoneditor"))
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
package hep.dataforge.vis.spatial
|
||||||
|
|
||||||
|
import hep.dataforge.meta.*
|
||||||
|
import hep.dataforge.names.asName
|
||||||
|
import hep.dataforge.names.plus
|
||||||
|
import hep.dataforge.vis.common.Colors
|
||||||
|
import hep.dataforge.vis.common.VisualObject
|
||||||
|
import hep.dataforge.vis.spatial.Material3D.Companion.COLOR_KEY
|
||||||
|
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_KEY
|
||||||
|
import hep.dataforge.vis.spatial.Material3D.Companion.OPACITY_KEY
|
||||||
|
|
||||||
|
class Material3D(override val config: Config) : Specific {
|
||||||
|
|
||||||
|
val color by string()
|
||||||
|
|
||||||
|
val opacity by float(1f)
|
||||||
|
|
||||||
|
companion object : Specification<Material3D> {
|
||||||
|
override fun wrap(config: Config): Material3D = Material3D(config)
|
||||||
|
|
||||||
|
val MATERIAL_KEY = "material".asName()
|
||||||
|
val COLOR_KEY = MATERIAL_KEY + "color"
|
||||||
|
val OPACITY_KEY = MATERIAL_KEY + "opacity"
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun VisualObject.color(rgb: String) {
|
||||||
|
setProperty(COLOR_KEY, rgb)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun VisualObject.color(rgb: Int) = color(Colors.rgbToString(rgb))
|
||||||
|
|
||||||
|
fun VisualObject.color(r: UByte, g: UByte, b: UByte) = color( Colors.rgbToString(r,g,b))
|
||||||
|
|
||||||
|
var VisualObject.color: String?
|
||||||
|
get() = getProperty(COLOR_KEY).string
|
||||||
|
set(value) {
|
||||||
|
if (value != null) {
|
||||||
|
color(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var VisualObject.material: Material3D?
|
||||||
|
get() = getProperty(MATERIAL_KEY).node?.let { Material3D.wrap(it) }
|
||||||
|
set(value) = setProperty(MATERIAL_KEY, value?.config)
|
||||||
|
|
||||||
|
fun VisualObject.material(builder: Material3D.() -> Unit) {
|
||||||
|
material = Material3D.build(builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
var VisualObject.opacity: Double?
|
||||||
|
get() = getProperty(OPACITY_KEY).double
|
||||||
|
set(value) {
|
||||||
|
setProperty(OPACITY_KEY, value)
|
||||||
|
}
|
@ -35,9 +35,8 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
|
|||||||
/**
|
/**
|
||||||
* Recursively search for defined template in the parent
|
* Recursively search for defined template in the parent
|
||||||
*/
|
*/
|
||||||
val prototype: VisualObject3D
|
val prototype: VisualObject3D get() = (parent as? VisualGroup3D)?.getTemplate(templateName)
|
||||||
get() = (parent as? VisualGroup3D)?.getTemplate(templateName)
|
?: error("Template with name $templateName not found in $parent")
|
||||||
?: error("Template with name $templateName not found in $parent")
|
|
||||||
|
|
||||||
override fun getStyle(name: Name): Meta? = (parent as VisualGroup?)?.getStyle(name)
|
override fun getStyle(name: Name): Meta? = (parent as VisualGroup?)?.getStyle(name)
|
||||||
|
|
||||||
@ -70,17 +69,23 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
|
|||||||
return NameToken(PROXY_CHILD_PROPERTY_PREFIX, childName.toString()) + propertyName
|
return NameToken(PROXY_CHILD_PROPERTY_PREFIX, childName.toString()) + propertyName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun prototypeFor(name: Name): VisualObject =
|
||||||
|
(prototype as? VisualGroup)?.get(name)
|
||||||
|
?: error("Prototype with name $name not found in ${this@Proxy}")
|
||||||
|
|
||||||
|
|
||||||
inner class ProxyChild(val name: Name) : AbstractVisualObject(), VisualGroup {
|
inner class ProxyChild(val name: Name) : AbstractVisualObject(), VisualGroup {
|
||||||
|
|
||||||
|
val prototype: VisualObject by lazy {
|
||||||
|
prototypeFor(name)
|
||||||
|
}
|
||||||
|
|
||||||
override val children: Map<NameToken, VisualObject>
|
override val children: Map<NameToken, VisualObject>
|
||||||
get() = ((prototype as? MutableVisualGroup)?.get(name) as? MutableVisualGroup)
|
get() = (prototype as? VisualGroup)?.children?.mapValues { (key, _) ->
|
||||||
?.children
|
ProxyChild(
|
||||||
?.mapValues { (key, _) ->
|
name + key.asName()
|
||||||
ProxyChild(
|
)
|
||||||
name + key.asName()
|
} ?: emptyMap()
|
||||||
)
|
|
||||||
}
|
|
||||||
?: emptyMap()
|
|
||||||
|
|
||||||
override fun getStyle(name: Name): Meta? = this@Proxy.getStyle(name)
|
override fun getStyle(name: Name): Meta? = this@Proxy.getStyle(name)
|
||||||
|
|
||||||
@ -88,10 +93,6 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
|
|||||||
this@Proxy.setStyle(name, meta)
|
this@Proxy.setStyle(name, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
val prototype: VisualObject
|
|
||||||
get() = (this@Proxy.prototype as? VisualGroup)?.get(name)
|
|
||||||
?: error("Prototype with name $name not found in ${this@Proxy}")
|
|
||||||
|
|
||||||
override var properties: Config?
|
override var properties: Config?
|
||||||
get() = propertyCache[name]
|
get() = propertyCache[name]
|
||||||
set(value) {
|
set(value) {
|
||||||
@ -112,15 +113,16 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
|
|||||||
override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? {
|
override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? {
|
||||||
return if (inherit) {
|
return if (inherit) {
|
||||||
properties?.get(name)
|
properties?.get(name)
|
||||||
?: actualStyles[name]
|
?: appliedStyles[name]
|
||||||
?: parent?.getProperty(name, inherit)
|
?: parent?.getProperty(name, inherit)
|
||||||
?: prototype.getProperty(name, inherit)
|
?: prototype.getProperty(name, inherit)
|
||||||
} else {
|
} else {
|
||||||
properties?.get(name)
|
properties?.get(name)
|
||||||
?: actualStyles[name]
|
?: appliedStyles[name]
|
||||||
?: prototype.getProperty(name, inherit)
|
?: prototype.getProperty(name, inherit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -20,7 +20,7 @@ import hep.dataforge.names.NameToken
|
|||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
import hep.dataforge.names.isEmpty
|
import hep.dataforge.names.isEmpty
|
||||||
import hep.dataforge.vis.common.AbstractVisualGroup
|
import hep.dataforge.vis.common.AbstractVisualGroup
|
||||||
import hep.dataforge.vis.common.MutableVisualGroup
|
import hep.dataforge.vis.common.VisualGroup
|
||||||
import hep.dataforge.vis.common.VisualObject
|
import hep.dataforge.vis.common.VisualObject
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -103,15 +103,15 @@ class VisualGroup3D : AbstractVisualGroup(), VisualObject3D {
|
|||||||
/**
|
/**
|
||||||
* A fix for serialization bug that writes all proper parents inside the tree after deserialization
|
* A fix for serialization bug that writes all proper parents inside the tree after deserialization
|
||||||
*/
|
*/
|
||||||
fun MutableVisualGroup.attachChildren() {
|
fun VisualGroup.attachChildren() {
|
||||||
this.children.values.forEach {
|
this.children.values.forEach {
|
||||||
it.parent = this
|
it.parent = this
|
||||||
(it as? MutableVisualGroup)?.attachChildren()
|
(it as? VisualGroup)?.attachChildren()
|
||||||
}
|
}
|
||||||
if (this is VisualGroup3D) {
|
if (this is VisualGroup3D) {
|
||||||
templates?.apply {
|
templates?.also {
|
||||||
parent = this@attachChildren
|
it.parent = this
|
||||||
attachChildren()
|
it.attachChildren()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,9 @@ import hep.dataforge.meta.*
|
|||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
import hep.dataforge.names.plus
|
import hep.dataforge.names.plus
|
||||||
import hep.dataforge.output.Output
|
import hep.dataforge.output.Output
|
||||||
import hep.dataforge.vis.common.Colors.rgbToString
|
|
||||||
import hep.dataforge.vis.common.VisualObject
|
import hep.dataforge.vis.common.VisualObject
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY
|
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY
|
import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY
|
import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.MATERIAL_KEY
|
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.OPACITY_KEY
|
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.SELECTED_KEY
|
import hep.dataforge.vis.spatial.VisualObject3D.Companion.SELECTED_KEY
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
|
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
|
||||||
import kotlinx.serialization.UseSerializers
|
import kotlinx.serialization.UseSerializers
|
||||||
@ -36,7 +32,7 @@ interface VisualObject3D : VisualObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val MATERIAL_KEY = "material".asName()
|
|
||||||
val VISIBLE_KEY = "visible".asName()
|
val VISIBLE_KEY = "visible".asName()
|
||||||
val SELECTED_KEY = "selected".asName()
|
val SELECTED_KEY = "selected".asName()
|
||||||
val DETAIL_KEY = "detail".asName()
|
val DETAIL_KEY = "detail".asName()
|
||||||
@ -44,9 +40,6 @@ interface VisualObject3D : VisualObject {
|
|||||||
|
|
||||||
val GEOMETRY_KEY = "geometey".asName()
|
val GEOMETRY_KEY = "geometey".asName()
|
||||||
|
|
||||||
val COLOR_KEY = MATERIAL_KEY + "color"
|
|
||||||
val OPACITY_KEY = MATERIAL_KEY + "opacity"
|
|
||||||
|
|
||||||
val x = "x".asName()
|
val x = "x".asName()
|
||||||
val y = "y".asName()
|
val y = "y".asName()
|
||||||
val z = "z".asName()
|
val z = "z".asName()
|
||||||
@ -111,16 +104,6 @@ var VisualObject3D.detail: Int?
|
|||||||
get() = getProperty(DETAIL_KEY, false).int
|
get() = getProperty(DETAIL_KEY, false).int
|
||||||
set(value) = setProperty(DETAIL_KEY, value)
|
set(value) = setProperty(DETAIL_KEY, value)
|
||||||
|
|
||||||
var VisualObject.material: Meta?
|
|
||||||
get() = getProperty(MATERIAL_KEY).node
|
|
||||||
set(value) = setProperty(MATERIAL_KEY, value)
|
|
||||||
|
|
||||||
var VisualObject.opacity: Double?
|
|
||||||
get() = getProperty(OPACITY_KEY).double
|
|
||||||
set(value) {
|
|
||||||
setProperty(OPACITY_KEY, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
var VisualObject.visible: Boolean?
|
var VisualObject.visible: Boolean?
|
||||||
get() = getProperty(VISIBLE_KEY).boolean
|
get() = getProperty(VISIBLE_KEY).boolean
|
||||||
set(value) = setProperty(VISIBLE_KEY, value)
|
set(value) = setProperty(VISIBLE_KEY, value)
|
||||||
@ -129,32 +112,6 @@ var VisualObject.selected: Boolean?
|
|||||||
get() = getProperty(SELECTED_KEY).boolean
|
get() = getProperty(SELECTED_KEY).boolean
|
||||||
set(value) = setProperty(SELECTED_KEY, value)
|
set(value) = setProperty(SELECTED_KEY, value)
|
||||||
|
|
||||||
fun VisualObject.color(rgb: Int) {
|
|
||||||
setProperty(COLOR_KEY, rgbToString(rgb))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun VisualObject.color(rgb: String) {
|
|
||||||
setProperty(COLOR_KEY, rgb)
|
|
||||||
}
|
|
||||||
|
|
||||||
var VisualObject.color: String?
|
|
||||||
get() = getProperty(COLOR_KEY).string
|
|
||||||
set(value) {
|
|
||||||
if (value != null) {
|
|
||||||
color(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun VisualObject3D.material(builder: MetaBuilder.() -> Unit) {
|
|
||||||
material = buildMeta(builder)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun VisualObject3D.color(r: Int, g: Int, b: Int) = material {
|
|
||||||
"red" to r
|
|
||||||
"green" to g
|
|
||||||
"blue" to b
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun VisualObject3D.position(): Point3D =
|
private fun VisualObject3D.position(): Point3D =
|
||||||
position ?: Point3D(0.0, 0.0, 0.0).also { position = it }
|
position ?: Point3D(0.0, 0.0, 0.0).also { position = it }
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import kotlin.test.Test
|
|||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class ConvexTest {
|
class ConvexTest {
|
||||||
|
@Suppress("UNUSED_VARIABLE")
|
||||||
@Test
|
@Test
|
||||||
fun testConvexBuilder() {
|
fun testConvexBuilder() {
|
||||||
val group = VisualGroup3D().apply {
|
val group = VisualGroup3D().apply {
|
||||||
|
@ -3,6 +3,7 @@ package hep.dataforge.vis.spatial.three
|
|||||||
import hep.dataforge.meta.*
|
import hep.dataforge.meta.*
|
||||||
import hep.dataforge.values.ValueType
|
import hep.dataforge.values.ValueType
|
||||||
import hep.dataforge.vis.common.Colors
|
import hep.dataforge.vis.common.Colors
|
||||||
|
import hep.dataforge.vis.spatial.Material3D
|
||||||
import info.laht.threekt.materials.Material
|
import info.laht.threekt.materials.Material
|
||||||
import info.laht.threekt.materials.MeshBasicMaterial
|
import info.laht.threekt.materials.MeshBasicMaterial
|
||||||
import info.laht.threekt.materials.MeshPhongMaterial
|
import info.laht.threekt.materials.MeshPhongMaterial
|
||||||
@ -61,3 +62,5 @@ fun Meta?.jsMaterial(): Material {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Material3D?.jsMaterial(): Material = this?.config.jsMaterial()
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import hep.dataforge.names.startsWith
|
|||||||
import hep.dataforge.provider.Type
|
import hep.dataforge.provider.Type
|
||||||
import hep.dataforge.vis.common.VisualObject
|
import hep.dataforge.vis.common.VisualObject
|
||||||
import hep.dataforge.vis.spatial.*
|
import hep.dataforge.vis.spatial.*
|
||||||
|
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_KEY
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.GEOMETRY_KEY
|
import hep.dataforge.vis.spatial.VisualObject3D.Companion.GEOMETRY_KEY
|
||||||
import hep.dataforge.vis.spatial.three.ThreeFactory.Companion.TYPE
|
import hep.dataforge.vis.spatial.three.ThreeFactory.Companion.TYPE
|
||||||
import info.laht.threekt.core.BufferGeometry
|
import info.laht.threekt.core.BufferGeometry
|
||||||
@ -101,9 +102,9 @@ abstract class MeshThreeFactory<T : VisualObject3D>(override val type: KClass<ou
|
|||||||
val WIREFRAME_KEY = "wireframe".asName()
|
val WIREFRAME_KEY = "wireframe".asName()
|
||||||
val ENABLED_KEY = "enabled".asName()
|
val ENABLED_KEY = "enabled".asName()
|
||||||
val EDGES_ENABLED_KEY = EDGES_KEY + ENABLED_KEY
|
val EDGES_ENABLED_KEY = EDGES_KEY + ENABLED_KEY
|
||||||
val EDGES_MATERIAL_KEY = EDGES_KEY + VisualObject3D.MATERIAL_KEY
|
val EDGES_MATERIAL_KEY = EDGES_KEY + MATERIAL_KEY
|
||||||
val WIREFRAME_ENABLED_KEY = WIREFRAME_KEY + ENABLED_KEY
|
val WIREFRAME_ENABLED_KEY = WIREFRAME_KEY + ENABLED_KEY
|
||||||
val WIREFRAME_MATERIAL_KEY = WIREFRAME_KEY + VisualObject3D.MATERIAL_KEY
|
val WIREFRAME_MATERIAL_KEY = WIREFRAME_KEY + MATERIAL_KEY
|
||||||
|
|
||||||
fun <T : VisualObject3D> buildMesh(obj: T, geometryBuilder: (T) -> BufferGeometry): Mesh {
|
fun <T : VisualObject3D> buildMesh(obj: T, geometryBuilder: (T) -> BufferGeometry): Mesh {
|
||||||
//TODO add caching for geometries using templates
|
//TODO add caching for geometries using templates
|
||||||
@ -129,7 +130,7 @@ abstract class MeshThreeFactory<T : VisualObject3D>(override val type: KClass<ou
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Object3D.updateProperty(source: VisualObject, propertyName: Name) {
|
fun Object3D.updateProperty(source: VisualObject, propertyName: Name) {
|
||||||
if (this is Mesh && propertyName.startsWith(VisualObject3D.MATERIAL_KEY)) {
|
if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) {
|
||||||
//updated material
|
//updated material
|
||||||
material = source.material.jsMaterial()
|
material = source.material.jsMaterial()
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -4,7 +4,6 @@ import hep.dataforge.context.Context
|
|||||||
import hep.dataforge.meta.*
|
import hep.dataforge.meta.*
|
||||||
import hep.dataforge.output.Output
|
import hep.dataforge.output.Output
|
||||||
import hep.dataforge.vis.common.Colors
|
import hep.dataforge.vis.common.Colors
|
||||||
import hep.dataforge.vis.hmr.require
|
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D
|
import hep.dataforge.vis.spatial.VisualObject3D
|
||||||
import info.laht.threekt.WebGLRenderer
|
import info.laht.threekt.WebGLRenderer
|
||||||
import info.laht.threekt.helpers.AxesHelper
|
import info.laht.threekt.helpers.AxesHelper
|
||||||
@ -13,8 +12,7 @@ import info.laht.threekt.scenes.Scene
|
|||||||
import org.w3c.dom.HTMLElement
|
import org.w3c.dom.HTMLElement
|
||||||
import kotlin.browser.window
|
import kotlin.browser.window
|
||||||
import kotlin.dom.clear
|
import kotlin.dom.clear
|
||||||
|
import kotlin.math.max
|
||||||
private val elementResizeEvent = require("element-resize-event")
|
|
||||||
|
|
||||||
class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<VisualObject3D> {
|
class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<VisualObject3D> {
|
||||||
|
|
||||||
@ -53,13 +51,15 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<V
|
|||||||
|
|
||||||
element.appendChild(renderer.domElement)
|
element.appendChild(renderer.domElement)
|
||||||
|
|
||||||
elementResizeEvent(element) {
|
val minSize by meta.number(0).int
|
||||||
|
|
||||||
|
renderer.setSize(max(minSize, element.offsetWidth), max(minSize, element.offsetWidth))
|
||||||
|
|
||||||
|
element.onresize = {
|
||||||
renderer.setSize(element.offsetWidth, element.offsetWidth)
|
renderer.setSize(element.offsetWidth, element.offsetWidth)
|
||||||
camera.updateProjectionMatrix()
|
camera.updateProjectionMatrix()
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.setSize(element.offsetWidth, element.offsetWidth)
|
|
||||||
|
|
||||||
animate()
|
animate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,25 +1,16 @@
|
|||||||
package hep.dataforge.vis.spatial.three
|
package hep.dataforge.vis.spatial.three
|
||||||
|
|
||||||
import hep.dataforge.names.toName
|
import hep.dataforge.names.toName
|
||||||
import hep.dataforge.vis.common.VisualObject
|
|
||||||
import hep.dataforge.vis.spatial.Proxy
|
import hep.dataforge.vis.spatial.Proxy
|
||||||
import hep.dataforge.vis.spatial.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX
|
import hep.dataforge.vis.spatial.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D
|
import hep.dataforge.vis.spatial.VisualObject3D
|
||||||
import hep.dataforge.vis.spatial.material
|
|
||||||
import hep.dataforge.vis.spatial.visible
|
|
||||||
import info.laht.threekt.core.Object3D
|
import info.laht.threekt.core.Object3D
|
||||||
import info.laht.threekt.objects.Mesh
|
|
||||||
|
|
||||||
class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory<Proxy> {
|
class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory<Proxy> {
|
||||||
private val cache = HashMap<VisualObject3D, Object3D>()
|
private val cache = HashMap<VisualObject3D, Object3D>()
|
||||||
|
|
||||||
override val type = Proxy::class
|
override val type = Proxy::class
|
||||||
|
|
||||||
private fun Mesh.updateProperties(obj: VisualObject?) {
|
|
||||||
material = obj?.material.jsMaterial()
|
|
||||||
visible = obj?.visible ?: true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun invoke(obj: Proxy): Object3D {
|
override fun invoke(obj: Proxy): Object3D {
|
||||||
val template = obj.prototype
|
val template = obj.prototype
|
||||||
val cachedObject = cache.getOrPut(template) {
|
val cachedObject = cache.getOrPut(template) {
|
||||||
|
@ -32,7 +32,7 @@ internal fun createInspireTree(block: Config.() -> Unit = {}): InspireTree {
|
|||||||
return InspireTree(config)
|
return InspireTree(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun VisualGroup.toTree(onFocus: (VisualObject?, String?) -> Unit = { obj, name -> }): InspireTree {
|
fun VisualGroup.toTree(onFocus: (VisualObject?, String?) -> Unit = { _, _ -> }): InspireTree {
|
||||||
|
|
||||||
val map = HashMap<String, VisualObject>()
|
val map = HashMap<String, VisualObject>()
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@ import hep.dataforge.meta.DynamicMeta
|
|||||||
import hep.dataforge.meta.builder
|
import hep.dataforge.meta.builder
|
||||||
import hep.dataforge.meta.update
|
import hep.dataforge.meta.update
|
||||||
import hep.dataforge.vis.common.VisualObject
|
import hep.dataforge.vis.common.VisualObject
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY
|
import hep.dataforge.vis.spatial.Material3D.Companion.COLOR_KEY
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.OPACITY_KEY
|
import hep.dataforge.vis.spatial.Material3D.Companion.OPACITY_KEY
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
|
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
|
||||||
import hep.dataforge.vis.spatial.color
|
import hep.dataforge.vis.spatial.color
|
||||||
import hep.dataforge.vis.spatial.opacity
|
import hep.dataforge.vis.spatial.opacity
|
||||||
|
@ -7,12 +7,3 @@ dependencies {
|
|||||||
api(project(":dataforge-vis-spatial"))
|
api(project(":dataforge-vis-spatial"))
|
||||||
testCompile(kotlin("test-js"))
|
testCompile(kotlin("test-js"))
|
||||||
}
|
}
|
||||||
|
|
||||||
//kotlin{
|
|
||||||
// sourceSets["main"].dependencies{
|
|
||||||
// implementation(npm("three","0.106.2"))
|
|
||||||
// implementation(npm("@hi-level/three-csg"))
|
|
||||||
// implementation(npm("style-loader"))
|
|
||||||
// implementation(npm("element-resize-event"))
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
@ -52,6 +52,7 @@ class ThreeDemoGrid(meta: Meta) : AbstractPlugin(meta), OutputManager {
|
|||||||
return outputs.getOrPut(name) {
|
return outputs.getOrPut(name) {
|
||||||
if (type != VisualObject::class) error("Supports only DisplayObject")
|
if (type != VisualObject::class) error("Supports only DisplayObject")
|
||||||
val output = three.output(meta = meta) {
|
val output = three.output(meta = meta) {
|
||||||
|
"minSize" to 500
|
||||||
"axis" to {
|
"axis" to {
|
||||||
"size" to 500
|
"size" to 500
|
||||||
}
|
}
|
||||||
@ -86,6 +87,6 @@ fun ThreeDemoGrid.demo(name: String, title: String = name, block: VisualGroup3D.
|
|||||||
val meta = buildMeta {
|
val meta = buildMeta {
|
||||||
"title" to title
|
"title" to title
|
||||||
}
|
}
|
||||||
val output = get<VisualObject>(VisualObject::class, name.toName(), meta = meta)
|
val output = get(VisualObject::class, name.toName(), meta = meta)
|
||||||
output.render(action = block)
|
output.render(action = block)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user