Class name refactoring
This commit is contained in:
parent
3217a53dd6
commit
9805c249ad
@ -13,7 +13,7 @@ class GDMLVisualTest {
|
|||||||
@Test
|
@Test
|
||||||
fun testPrototypeProperty() {
|
fun testPrototypeProperty() {
|
||||||
val gdml = cubes()
|
val gdml = cubes()
|
||||||
val visual = gdml.toVisual()
|
val visual = gdml.toVision()
|
||||||
visual["composite000.segment0".toName()]?.setItem(Material3D.MATERIAL_COLOR_KEY, "red".asValue())
|
visual["composite000.segment0".toName()]?.setItem(Material3D.MATERIAL_COLOR_KEY, "red".asValue())
|
||||||
assertEquals("red", visual["composite000.segment0".toName()]?.getItem(Material3D.MATERIAL_COLOR_KEY).string)
|
assertEquals("red", visual["composite000.segment0".toName()]?.getItem(Material3D.MATERIAL_COLOR_KEY).string)
|
||||||
}
|
}
|
||||||
|
@ -10,9 +10,9 @@ import hep.dataforge.vision.react.component
|
|||||||
import hep.dataforge.vision.react.configEditor
|
import hep.dataforge.vision.react.configEditor
|
||||||
import hep.dataforge.vision.react.flexColumn
|
import hep.dataforge.vision.react.flexColumn
|
||||||
import hep.dataforge.vision.react.state
|
import hep.dataforge.vision.react.state
|
||||||
|
import hep.dataforge.vision.spatial.Vision3D
|
||||||
import hep.dataforge.vision.spatial.VisionGroup3D
|
import hep.dataforge.vision.spatial.VisionGroup3D
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D
|
import hep.dataforge.vision.spatial.gdml.toVision
|
||||||
import hep.dataforge.vision.spatial.gdml.toVisual
|
|
||||||
import hep.dataforge.vision.spatial.specifications.Camera
|
import hep.dataforge.vision.spatial.specifications.Camera
|
||||||
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
|
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
|
||||||
import hep.dataforge.vision.spatial.three.ThreeCanvas
|
import hep.dataforge.vision.spatial.three.ThreeCanvas
|
||||||
@ -60,7 +60,7 @@ val GDMLApp = component<GDMLAppProps> { props ->
|
|||||||
visual = when {
|
visual = when {
|
||||||
name.endsWith(".gdml") || name.endsWith(".xml") -> {
|
name.endsWith(".gdml") || name.endsWith(".xml") -> {
|
||||||
val gdml = GDML.parse(data)
|
val gdml = GDML.parse(data)
|
||||||
gdml.toVisual(gdmlConfiguration)
|
gdml.toVision(gdmlConfiguration)
|
||||||
}
|
}
|
||||||
name.endsWith(".json") -> VisionGroup3D.parseJson(data)
|
name.endsWith(".json") -> VisionGroup3D.parseJson(data)
|
||||||
else -> {
|
else -> {
|
||||||
@ -107,7 +107,7 @@ val GDMLApp = component<GDMLAppProps> { props ->
|
|||||||
|
|
||||||
gridColumn(6, maxSize= GridMaxSize.XL, classes = "order-1 order-xl-2") {
|
gridColumn(6, maxSize= GridMaxSize.XL, classes = "order-1 order-xl-2") {
|
||||||
//canvas
|
//canvas
|
||||||
(visual as? VisualObject3D)?.let { visual3D ->
|
(visual as? Vision3D)?.let { visual3D ->
|
||||||
child(ThreeCanvasComponent::class) {
|
child(ThreeCanvasComponent::class) {
|
||||||
attrs {
|
attrs {
|
||||||
this.context = props.context
|
this.context = props.context
|
||||||
|
@ -6,7 +6,7 @@ import hep.dataforge.js.startApplication
|
|||||||
import hep.dataforge.vision.spatial.Material3D.Companion.MATERIAL_OPACITY_KEY
|
import hep.dataforge.vision.spatial.Material3D.Companion.MATERIAL_OPACITY_KEY
|
||||||
import hep.dataforge.vision.spatial.gdml.GDMLTransformer
|
import hep.dataforge.vision.spatial.gdml.GDMLTransformer
|
||||||
import hep.dataforge.vision.spatial.gdml.LUnit
|
import hep.dataforge.vision.spatial.gdml.LUnit
|
||||||
import hep.dataforge.vision.spatial.gdml.toVisual
|
import hep.dataforge.vision.spatial.gdml.toVision
|
||||||
import kotlinx.css.*
|
import kotlinx.css.*
|
||||||
import react.child
|
import react.child
|
||||||
import react.dom.render
|
import react.dom.render
|
||||||
@ -60,7 +60,7 @@ private class GDMLDemoApp : Application {
|
|||||||
child(GDMLApp) {
|
child(GDMLApp) {
|
||||||
attrs {
|
attrs {
|
||||||
this.context = context
|
this.context = context
|
||||||
this.rootObject = cubes().toVisual(gdmlConfiguration)
|
this.rootObject = cubes().toVision(gdmlConfiguration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,10 @@ import hep.dataforge.context.Global
|
|||||||
import hep.dataforge.vision.editor.VisualObjectEditorFragment
|
import hep.dataforge.vision.editor.VisualObjectEditorFragment
|
||||||
import hep.dataforge.vision.editor.VisualObjectTreeFragment
|
import hep.dataforge.vision.editor.VisualObjectTreeFragment
|
||||||
import hep.dataforge.vision.spatial.Material3D
|
import hep.dataforge.vision.spatial.Material3D
|
||||||
import hep.dataforge.vision.spatial.Visual3D
|
import hep.dataforge.vision.spatial.SpatialVisionManager
|
||||||
import hep.dataforge.vision.spatial.fx.FX3DPlugin
|
import hep.dataforge.vision.spatial.fx.FX3DPlugin
|
||||||
import hep.dataforge.vision.spatial.fx.FXCanvas3D
|
import hep.dataforge.vision.spatial.fx.FXCanvas3D
|
||||||
import hep.dataforge.vision.spatial.gdml.toVisual
|
import hep.dataforge.vision.spatial.gdml.toVision
|
||||||
import javafx.geometry.Orientation
|
import javafx.geometry.Orientation
|
||||||
import javafx.scene.Parent
|
import javafx.scene.Parent
|
||||||
import javafx.stage.FileChooser
|
import javafx.stage.FileChooser
|
||||||
@ -39,7 +39,7 @@ class GDMLView : View() {
|
|||||||
runAsync {
|
runAsync {
|
||||||
val file = chooseFile("Select a GDML/json file", filters = fileNameFilter).firstOrNull()
|
val file = chooseFile("Select a GDML/json file", filters = fileNameFilter).firstOrNull()
|
||||||
?: return@runAsync null
|
?: return@runAsync null
|
||||||
Visual3D.readFile(file)
|
SpatialVisionManager.readFile(file)
|
||||||
} ui {
|
} ui {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
canvas.render(it)
|
canvas.render(it)
|
||||||
@ -58,7 +58,7 @@ class GDMLView : View() {
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
runAsync {
|
runAsync {
|
||||||
cubes().toVisual()
|
cubes().toVision()
|
||||||
} ui {
|
} ui {
|
||||||
canvas.render(it)
|
canvas.render(it)
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,19 @@ package hep.dataforge.vision.spatial.gdml.demo
|
|||||||
import hep.dataforge.meta.setItem
|
import hep.dataforge.meta.setItem
|
||||||
import hep.dataforge.values.asValue
|
import hep.dataforge.values.asValue
|
||||||
import hep.dataforge.vision.spatial.Material3D
|
import hep.dataforge.vision.spatial.Material3D
|
||||||
|
import hep.dataforge.vision.spatial.SpatialVisionManager
|
||||||
import hep.dataforge.vision.spatial.VisionGroup3D
|
import hep.dataforge.vision.spatial.VisionGroup3D
|
||||||
import hep.dataforge.vision.spatial.Visual3D
|
|
||||||
import hep.dataforge.vision.spatial.gdml.LUnit
|
import hep.dataforge.vision.spatial.gdml.LUnit
|
||||||
import hep.dataforge.vision.spatial.gdml.readFile
|
import hep.dataforge.vision.spatial.gdml.readFile
|
||||||
import hep.dataforge.vision.spatial.gdml.toVisual
|
import hep.dataforge.vision.spatial.gdml.toVision
|
||||||
import scientifik.gdml.GDML
|
import scientifik.gdml.GDML
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
|
|
||||||
fun Visual3D.Companion.readFile(file: File): VisionGroup3D = when {
|
fun SpatialVisionManager.Companion.readFile(file: File): VisionGroup3D = when {
|
||||||
file.extension == "gdml" || file.extension == "xml" -> {
|
file.extension == "gdml" || file.extension == "xml" -> {
|
||||||
GDML.readFile(file.toPath()).toVisual {
|
GDML.readFile(file.toPath()).toVision {
|
||||||
lUnit = LUnit.CM
|
lUnit = LUnit.CM
|
||||||
|
|
||||||
solidConfiguration = { parent, solid ->
|
solidConfiguration = { parent, solid ->
|
||||||
@ -48,4 +48,4 @@ fun Visual3D.Companion.readFile(file: File): VisionGroup3D = when {
|
|||||||
else -> error("Unknown extension ${file.extension}")
|
else -> error("Unknown extension ${file.extension}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Visual3D.Companion.readFile(fileName: String): VisionGroup3D = readFile(File(fileName))
|
fun SpatialVisionManager.Companion.readFile(fileName: String): VisionGroup3D = readFile(File(fileName))
|
@ -2,7 +2,7 @@ package hep.dataforge.vision.spatial.gdml.demo
|
|||||||
|
|
||||||
import hep.dataforge.vision.spatial.gdml.LUnit
|
import hep.dataforge.vision.spatial.gdml.LUnit
|
||||||
import hep.dataforge.vision.spatial.gdml.readFile
|
import hep.dataforge.vision.spatial.gdml.readFile
|
||||||
import hep.dataforge.vision.spatial.gdml.toVisual
|
import hep.dataforge.vision.spatial.gdml.toVision
|
||||||
import hep.dataforge.vision.spatial.stringify
|
import hep.dataforge.vision.spatial.stringify
|
||||||
import scientifik.gdml.GDML
|
import scientifik.gdml.GDML
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -17,7 +17,7 @@ fun main(args: Array<String>) {
|
|||||||
val gdml = GDML.readFile(Paths.get(inputFileName))
|
val gdml = GDML.readFile(Paths.get(inputFileName))
|
||||||
//GDML.readFile(Paths.get("D:\\Work\\Projects\\visionforge\\visionforge-spatial-gdml\\src\\jvmTest\\resources\\gdml\\simple1.gdml"))
|
//GDML.readFile(Paths.get("D:\\Work\\Projects\\visionforge\\visionforge-spatial-gdml\\src\\jvmTest\\resources\\gdml\\simple1.gdml"))
|
||||||
|
|
||||||
val visual = gdml.toVisual {
|
val visual = gdml.toVision {
|
||||||
lUnit = LUnit.CM
|
lUnit = LUnit.CM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package ru.mipt.npm.muon.monitor
|
|||||||
import hep.dataforge.context.Global
|
import hep.dataforge.context.Global
|
||||||
import hep.dataforge.js.Application
|
import hep.dataforge.js.Application
|
||||||
import hep.dataforge.js.startApplication
|
import hep.dataforge.js.startApplication
|
||||||
import hep.dataforge.vision.spatial.Visual3D
|
import hep.dataforge.vision.spatial.SpatialVisionManager
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.features.json.JsonFeature
|
import io.ktor.client.features.json.JsonFeature
|
||||||
import io.ktor.client.features.json.serializer.KotlinxSerializer
|
import io.ktor.client.features.json.serializer.KotlinxSerializer
|
||||||
@ -19,7 +19,7 @@ private class MMDemoApp : Application {
|
|||||||
|
|
||||||
private val connection = HttpClient {
|
private val connection = HttpClient {
|
||||||
install(JsonFeature) {
|
install(JsonFeature) {
|
||||||
serializer = KotlinxSerializer(Json(context = Visual3D.serialModule))
|
serializer = KotlinxSerializer(Json(context = SpatialVisionManager.serialModule))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ru.mipt.npm.muon.monitor.server
|
package ru.mipt.npm.muon.monitor.server
|
||||||
|
|
||||||
|
|
||||||
import hep.dataforge.vision.spatial.Visual3D
|
import hep.dataforge.vision.spatial.SpatialVisionManager
|
||||||
import io.ktor.application.Application
|
import io.ktor.application.Application
|
||||||
import io.ktor.application.call
|
import io.ktor.application.call
|
||||||
import io.ktor.application.install
|
import io.ktor.application.install
|
||||||
@ -36,7 +36,7 @@ fun Application.module() {
|
|||||||
install(DefaultHeaders)
|
install(DefaultHeaders)
|
||||||
install(CallLogging)
|
install(CallLogging)
|
||||||
install(ContentNegotiation) {
|
install(ContentNegotiation) {
|
||||||
json(module = Visual3D.serialModule)
|
json(module = SpatialVisionManager.serialModule)
|
||||||
}
|
}
|
||||||
install(Routing) {
|
install(Routing) {
|
||||||
get("/event") {
|
get("/event") {
|
||||||
|
@ -11,7 +11,7 @@ import hep.dataforge.values.asValue
|
|||||||
import hep.dataforge.vision.getProperty
|
import hep.dataforge.vision.getProperty
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import hep.dataforge.vision.spatial.*
|
import hep.dataforge.vision.spatial.*
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D.Companion.GEOMETRY_KEY
|
import hep.dataforge.vision.spatial.Vision3D.Companion.GEOMETRY_KEY
|
||||||
import hep.dataforge.vision.spatial.demo.VariableBoxThreeFactory.Z_SIZE_KEY
|
import hep.dataforge.vision.spatial.demo.VariableBoxThreeFactory.Z_SIZE_KEY
|
||||||
import hep.dataforge.vision.spatial.three.*
|
import hep.dataforge.vision.spatial.three.*
|
||||||
import hep.dataforge.vision.spatial.three.ThreeMaterials.getMaterial
|
import hep.dataforge.vision.spatial.three.ThreeMaterials.getMaterial
|
||||||
@ -23,13 +23,13 @@ import kotlinx.serialization.UseSerializers
|
|||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
internal var VisualObject3D.variableZSize: Number
|
internal var Vision3D.variableZSize: Number
|
||||||
get() = getProperty(Z_SIZE_KEY, false).number ?: 0f
|
get() = getProperty(Z_SIZE_KEY, false).number ?: 0f
|
||||||
set(value) {
|
set(value) {
|
||||||
setItem(Z_SIZE_KEY, value.asValue())
|
setItem(Z_SIZE_KEY, value.asValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var VisualObject3D.value: Int
|
internal var Vision3D.value: Int
|
||||||
get() = getProperty("value", false).int ?: 0
|
get() = getProperty("value", false).int ?: 0
|
||||||
set(value) {
|
set(value) {
|
||||||
setItem("value", value.asValue())
|
setItem("value", value.asValue())
|
||||||
@ -48,21 +48,21 @@ fun VisionGroup3D.varBox(
|
|||||||
ySize: Number,
|
ySize: Number,
|
||||||
zSize: Number,
|
zSize: Number,
|
||||||
name: String = "",
|
name: String = "",
|
||||||
action: VisualObject3D.() -> Unit = {}
|
action: Vision3D.() -> Unit = {}
|
||||||
) = CustomThreeVisualObject(VariableBoxThreeFactory).apply {
|
) = CustomThreeVision(VariableBoxThreeFactory).apply {
|
||||||
scaleX = xSize
|
scaleX = xSize
|
||||||
scaleY = ySize
|
scaleY = ySize
|
||||||
scaleZ = zSize
|
scaleZ = zSize
|
||||||
}.apply(action).also { set(name, it) }
|
}.apply(action).also { set(name, it) }
|
||||||
|
|
||||||
private object VariableBoxThreeFactory : ThreeFactory<VisualObject3D> {
|
private object VariableBoxThreeFactory : ThreeFactory<Vision3D> {
|
||||||
val X_SIZE_KEY = GEOMETRY_KEY + "xSize"
|
val X_SIZE_KEY = GEOMETRY_KEY + "xSize"
|
||||||
val Y_SIZE_KEY = GEOMETRY_KEY + "ySize"
|
val Y_SIZE_KEY = GEOMETRY_KEY + "ySize"
|
||||||
val Z_SIZE_KEY = GEOMETRY_KEY + "zSize"
|
val Z_SIZE_KEY = GEOMETRY_KEY + "zSize"
|
||||||
|
|
||||||
override val type: KClass<in VisualObject3D> get() = VisualObject3D::class
|
override val type: KClass<in Vision3D> get() = Vision3D::class
|
||||||
|
|
||||||
override fun invoke(obj: VisualObject3D): Object3D {
|
override fun invoke(obj: Vision3D): Object3D {
|
||||||
val xSize = obj.getProperty(X_SIZE_KEY, false).number?.toDouble() ?: 1.0
|
val xSize = obj.getProperty(X_SIZE_KEY, false).number?.toDouble() ?: 1.0
|
||||||
val ySize = obj.getProperty(Y_SIZE_KEY, false).number?.toDouble() ?: 1.0
|
val ySize = obj.getProperty(Y_SIZE_KEY, false).number?.toDouble() ?: 1.0
|
||||||
val zSize = obj.getProperty(Z_SIZE_KEY, false).number?.toDouble() ?: 1.0
|
val zSize = obj.getProperty(Z_SIZE_KEY, false).number?.toDouble() ?: 1.0
|
||||||
|
@ -14,7 +14,7 @@ internal data class PropertyListener(
|
|||||||
val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit
|
val action: (name: Name, oldItem: MetaItem<*>?, newItem: MetaItem<*>?) -> Unit
|
||||||
)
|
)
|
||||||
|
|
||||||
abstract class AbstractVisualObject : Vision {
|
abstract class AbstractVision : Vision {
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
override var parent: VisionGroup? = null
|
override var parent: VisionGroup? = null
|
||||||
|
@ -11,7 +11,7 @@ import kotlinx.serialization.Transient
|
|||||||
/**
|
/**
|
||||||
* Abstract implementation of mutable group of [Vision]
|
* Abstract implementation of mutable group of [Vision]
|
||||||
*/
|
*/
|
||||||
abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup {
|
abstract class AbstractVisionGroup : AbstractVision(), MutableVisionGroup {
|
||||||
|
|
||||||
//protected abstract val _children: MutableMap<NameToken, T>
|
//protected abstract val _children: MutableMap<NameToken, T>
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup {
|
|||||||
protected open fun addStatic(child: Vision) =
|
protected open fun addStatic(child: Vision) =
|
||||||
set(NameToken("@static(${child.hashCode()})").asName(), child)
|
set(NameToken("@static(${child.hashCode()})").asName(), child)
|
||||||
|
|
||||||
protected abstract fun createGroup(): AbstractVision
|
protected abstract fun createGroup(): AbstractVisionGroup
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set this node as parent for given node
|
* Set this node as parent for given node
|
||||||
@ -102,7 +102,7 @@ abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup {
|
|||||||
/**
|
/**
|
||||||
* Recursively create a child group
|
* Recursively create a child group
|
||||||
*/
|
*/
|
||||||
private fun createGroups(name: Name): AbstractVision {
|
private fun createGroups(name: Name): AbstractVisionGroup {
|
||||||
return when {
|
return when {
|
||||||
name.isEmpty() -> error("Should be unreachable")
|
name.isEmpty() -> error("Should be unreachable")
|
||||||
name.length == 1 -> {
|
name.length == 1 -> {
|
||||||
@ -112,7 +112,7 @@ abstract class AbstractVision : AbstractVisualObject(), MutableVisionGroup {
|
|||||||
attach(child)
|
attach(child)
|
||||||
setChild(token, child)
|
setChild(token, child)
|
||||||
}
|
}
|
||||||
is AbstractVision -> current
|
is AbstractVisionGroup -> current
|
||||||
else -> error("Can't create group with name $name because it exists and not a group")
|
else -> error("Can't create group with name $name because it exists and not a group")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,7 +8,7 @@ import kotlinx.serialization.Serializable
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("group")
|
@SerialName("group")
|
||||||
class SimpleVisionGroup : AbstractVision() {
|
class SimpleVisionGroup : AbstractVisionGroup() {
|
||||||
|
|
||||||
override var styleSheet: StyleSheet? = null
|
override var styleSheet: StyleSheet? = null
|
||||||
|
|
||||||
|
@ -4,13 +4,8 @@ import hep.dataforge.context.*
|
|||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
interface VisualFactory<T : Vision> {
|
interface VisionFactory<T : Vision> : Factory<T> {
|
||||||
val type: KClass<T>
|
val type: KClass<T>
|
||||||
operator fun invoke(
|
|
||||||
context: Context,
|
|
||||||
parent: Vision?,
|
|
||||||
meta: Meta
|
|
||||||
): T
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class VisionManager(meta: Meta) : AbstractPlugin(meta) {
|
class VisionManager(meta: Meta) : AbstractPlugin(meta) {
|
||||||
@ -19,12 +14,18 @@ class VisionManager(meta: Meta) : AbstractPlugin(meta) {
|
|||||||
/**
|
/**
|
||||||
* Create a list of factories on first call and cache it
|
* Create a list of factories on first call and cache it
|
||||||
*/
|
*/
|
||||||
val visualFactories by lazy {
|
private val factories by lazy {
|
||||||
context.content<VisualFactory<*>>(VISUAL_FACTORY_TYPE).mapKeys { it.value.type }
|
context.content<VisionFactory<*>>(VISION_FACTORY_TYPE).mapKeys { it.value.type }
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified T : Vision> buildVisual(parent: Vision?, meta: Meta): T? {
|
@Suppress("UNCHECKED_CAST")
|
||||||
return visualFactories[T::class]?.invoke(context, parent, meta) as T?
|
fun <T : Vision> resolveVisionFactory(type: KClass<out T>): VisionFactory<T>? =
|
||||||
|
factories[type] as VisionFactory<T>
|
||||||
|
|
||||||
|
inline fun <reified T : Vision> buildVision(parent: VisionGroup?, meta: Meta): T? {
|
||||||
|
return resolveVisionFactory(T::class)?.invoke(meta, context)?.apply {
|
||||||
|
this.parent = parent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : PluginFactory<VisionManager> {
|
companion object : PluginFactory<VisionManager> {
|
||||||
@ -33,6 +34,6 @@ class VisionManager(meta: Meta) : AbstractPlugin(meta) {
|
|||||||
|
|
||||||
override fun invoke(meta: Meta, context: Context): VisionManager = VisionManager(meta)
|
override fun invoke(meta: Meta, context: Context): VisionManager = VisionManager(meta)
|
||||||
|
|
||||||
const val VISUAL_FACTORY_TYPE = "vision.factory"
|
const val VISION_FACTORY_TYPE = "vision.factory"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ class GDMLTransformer(val root: GDML) {
|
|||||||
var volumeAction: (GDMLGroup) -> Action = { Action.CACHE }
|
var volumeAction: (GDMLGroup) -> Action = { Action.CACHE }
|
||||||
|
|
||||||
|
|
||||||
var solidConfiguration: VisualObject3D.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ ->
|
var solidConfiguration: Vision3D.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ ->
|
||||||
lUnit = LUnit.CM
|
lUnit = LUnit.CM
|
||||||
if (parent.physVolumes.isNotEmpty()) {
|
if (parent.physVolumes.isNotEmpty()) {
|
||||||
useStyle("opaque") {
|
useStyle("opaque") {
|
||||||
@ -42,14 +42,14 @@ class GDMLTransformer(val root: GDML) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun VisualObject3D.useStyle(name: String, builder: MetaBuilder.() -> Unit) {
|
fun Vision3D.useStyle(name: String, builder: MetaBuilder.() -> Unit) {
|
||||||
styleCache.getOrPut(name.toName()) {
|
styleCache.getOrPut(name.toName()) {
|
||||||
Meta(builder)
|
Meta(builder)
|
||||||
}
|
}
|
||||||
useStyle(name)
|
useStyle(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun configureSolid(obj: VisualObject3D, parent: GDMLVolume, solid: GDMLSolid) {
|
internal fun configureSolid(obj: Vision3D, parent: GDMLVolume, solid: GDMLSolid) {
|
||||||
val material = parent.materialref.resolve(root) ?: GDMLElement(parent.materialref.ref)
|
val material = parent.materialref.resolve(root) ?: GDMLElement(parent.materialref.ref)
|
||||||
|
|
||||||
val styleName = "material[${material.name}]"
|
val styleName = "material[${material.name}]"
|
||||||
|
@ -14,12 +14,12 @@ import kotlin.math.cos
|
|||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
|
|
||||||
private fun VisualObject3D.withPosition(
|
private fun Vision3D.withPosition(
|
||||||
lUnit: LUnit,
|
lUnit: LUnit,
|
||||||
newPos: GDMLPosition? = null,
|
newPos: GDMLPosition? = null,
|
||||||
newRotation: GDMLRotation? = null,
|
newRotation: GDMLRotation? = null,
|
||||||
newScale: GDMLScale? = null
|
newScale: GDMLScale? = null
|
||||||
): VisualObject3D = apply {
|
): Vision3D = apply {
|
||||||
newPos?.let {
|
newPos?.let {
|
||||||
val point = Point3D(it.x(lUnit), it.y(lUnit), it.z(lUnit))
|
val point = Point3D(it.x(lUnit), it.y(lUnit), it.z(lUnit))
|
||||||
if (position != null || point != ZERO) {
|
if (position != null || point != ZERO) {
|
||||||
@ -52,8 +52,8 @@ private fun VisionGroup3D.addSolid(
|
|||||||
context: GDMLTransformer,
|
context: GDMLTransformer,
|
||||||
solid: GDMLSolid,
|
solid: GDMLSolid,
|
||||||
name: String = "",
|
name: String = "",
|
||||||
block: VisualObject3D.() -> Unit = {}
|
block: Vision3D.() -> Unit = {}
|
||||||
): VisualObject3D {
|
): Vision3D {
|
||||||
//context.solidAdded(solid)
|
//context.solidAdded(solid)
|
||||||
val lScale = solid.lscale(context.lUnit)
|
val lScale = solid.lscale(context.lUnit)
|
||||||
val aScale = solid.ascale()
|
val aScale = solid.ascale()
|
||||||
@ -253,7 +253,7 @@ private fun volume(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisionGroup3D {
|
fun GDML.toVision(block: GDMLTransformer.() -> Unit = {}): VisionGroup3D {
|
||||||
val context = GDMLTransformer(this).apply(block)
|
val context = GDMLTransformer(this).apply(block)
|
||||||
return context.finalize(volume(context, world))
|
return context.finalize(volume(context, world))
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ fun GDML.toVisual(block: GDMLTransformer.() -> Unit = {}): VisionGroup3D {
|
|||||||
* Append gdml node to the group
|
* Append gdml node to the group
|
||||||
*/
|
*/
|
||||||
fun VisionGroup3D.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) {
|
fun VisionGroup3D.gdml(gdml: GDML, key: String = "", transformer: GDMLTransformer.() -> Unit = {}) {
|
||||||
val visual = gdml.toVisual(transformer)
|
val visual = gdml.toVision(transformer)
|
||||||
//println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual))
|
//println(Visual3DPlugin.json.stringify(VisualGroup3D.serializer(), visual))
|
||||||
set(key, visual)
|
set(key, visual)
|
||||||
}
|
}
|
@ -13,7 +13,7 @@ class TestConvertor {
|
|||||||
|
|
||||||
val xmlReader = StAXReader(stream, "UTF-8")
|
val xmlReader = StAXReader(stream, "UTF-8")
|
||||||
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
|
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
|
||||||
val visual = xml.toVisual()
|
val visual = xml.toVision()
|
||||||
println(visual.stringify())
|
println(visual.stringify())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ class TestConvertor {
|
|||||||
|
|
||||||
val xmlReader = StAXReader(stream, "UTF-8")
|
val xmlReader = StAXReader(stream, "UTF-8")
|
||||||
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
|
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
|
||||||
val visual = xml.toVisual()
|
val visual = xml.toVision()
|
||||||
// println(visual)
|
// println(visual)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ class TestConvertor {
|
|||||||
|
|
||||||
val xmlReader = StAXReader(stream, "UTF-8")
|
val xmlReader = StAXReader(stream, "UTF-8")
|
||||||
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
|
val xml = GDML.format.parse(GDML.serializer(), xmlReader)
|
||||||
val visual = xml.toVisual()
|
val visual = xml.toVision()
|
||||||
println(visual.stringify())
|
println(visual.stringify())
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,10 @@ import hep.dataforge.meta.Config
|
|||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import hep.dataforge.meta.float
|
import hep.dataforge.meta.float
|
||||||
import hep.dataforge.meta.get
|
import hep.dataforge.meta.get
|
||||||
import hep.dataforge.vision.*
|
import hep.dataforge.vision.AbstractVision
|
||||||
|
import hep.dataforge.vision.MutableVisionGroup
|
||||||
|
import hep.dataforge.vision.VisionFactory
|
||||||
|
import hep.dataforge.vision.set
|
||||||
import hep.dataforge.vision.spatial.Box.Companion.TYPE_NAME
|
import hep.dataforge.vision.spatial.Box.Companion.TYPE_NAME
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
@ -19,7 +22,7 @@ class Box(
|
|||||||
val xSize: Float,
|
val xSize: Float,
|
||||||
val ySize: Float,
|
val ySize: Float,
|
||||||
val zSize: Float
|
val zSize: Float
|
||||||
) : AbstractVisualObject(), VisualObject3D, Shape {
|
) : AbstractVision(), Vision3D, Shape {
|
||||||
|
|
||||||
override var position: Point3D? = null
|
override var position: Point3D? = null
|
||||||
override var rotation: Point3D? = null
|
override var rotation: Point3D? = null
|
||||||
@ -48,13 +51,13 @@ class Box(
|
|||||||
geometryBuilder.face4(node8, node5, node6, node7)
|
geometryBuilder.face4(node8, node5, node6, node7)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object : VisualFactory<Box> {
|
companion object : VisionFactory<Box> {
|
||||||
|
|
||||||
const val TYPE_NAME = "3d.box"
|
const val TYPE_NAME = "3d.box"
|
||||||
|
|
||||||
override val type: KClass<Box> get() = Box::class
|
override val type: KClass<Box> get() = Box::class
|
||||||
|
|
||||||
override fun invoke(context: Context, parent: Vision?, meta: Meta): Box = Box(
|
override fun invoke(meta: Meta, context: Context): Box = Box(
|
||||||
meta["xSize"].float!!,
|
meta["xSize"].float!!,
|
||||||
meta["ySize"].float!!,
|
meta["ySize"].float!!,
|
||||||
meta["zSize"].float!!
|
meta["zSize"].float!!
|
||||||
|
@ -20,9 +20,9 @@ enum class CompositeType {
|
|||||||
@SerialName("3d.composite")
|
@SerialName("3d.composite")
|
||||||
class Composite(
|
class Composite(
|
||||||
val compositeType: CompositeType,
|
val compositeType: CompositeType,
|
||||||
val first: VisualObject3D,
|
val first: Vision3D,
|
||||||
val second: VisualObject3D
|
val second: Vision3D
|
||||||
) : AbstractVisualObject(), VisualObject3D, VisionGroup {
|
) : AbstractVision(), Vision3D, VisionGroup {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
first.parent = this
|
first.parent = this
|
||||||
@ -48,7 +48,7 @@ inline fun MutableVisionGroup.composite(
|
|||||||
builder: VisionGroup3D.() -> Unit
|
builder: VisionGroup3D.() -> Unit
|
||||||
): Composite {
|
): Composite {
|
||||||
val group = VisionGroup3D().apply(builder)
|
val group = VisionGroup3D().apply(builder)
|
||||||
val children = group.children.values.filterIsInstance<VisualObject3D>()
|
val children = group.children.values.filterIsInstance<Vision3D>()
|
||||||
if (children.size != 2) error("Composite requires exactly two children")
|
if (children.size != 2) error("Composite requires exactly two children")
|
||||||
return Composite(type, children[0], children[1]).also {
|
return Composite(type, children[0], children[1]).also {
|
||||||
it.config.update(group.config)
|
it.config.update(group.config)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
package hep.dataforge.vision.spatial
|
package hep.dataforge.vision.spatial
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
import hep.dataforge.vision.AbstractVisualObject
|
import hep.dataforge.vision.AbstractVision
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
import hep.dataforge.vision.MutableVisionGroup
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -23,7 +23,7 @@ class ConeSegment(
|
|||||||
var upperRadius: Float,
|
var upperRadius: Float,
|
||||||
var startAngle: Float = 0f,
|
var startAngle: Float = 0f,
|
||||||
var angle: Float = PI2
|
var angle: Float = PI2
|
||||||
) : AbstractVisualObject(), VisualObject3D, Shape {
|
) : AbstractVision(), Vision3D, Shape {
|
||||||
|
|
||||||
override var ownProperties: Config? = null
|
override var ownProperties: Config? = null
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
package hep.dataforge.vision.spatial
|
package hep.dataforge.vision.spatial
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
import hep.dataforge.vision.AbstractVisualObject
|
import hep.dataforge.vision.AbstractVision
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
import hep.dataforge.vision.MutableVisionGroup
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -12,7 +12,7 @@ import kotlinx.serialization.UseSerializers
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("3d.convex")
|
@SerialName("3d.convex")
|
||||||
class Convex(val points: List<Point3D>) : AbstractVisualObject(), VisualObject3D {
|
class Convex(val points: List<Point3D>) : AbstractVision(), Vision3D {
|
||||||
|
|
||||||
override var ownProperties: Config? = null
|
override var ownProperties: Config? = null
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
package hep.dataforge.vision.spatial
|
package hep.dataforge.vision.spatial
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
import hep.dataforge.vision.AbstractVisualObject
|
import hep.dataforge.vision.AbstractVision
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
import hep.dataforge.vision.MutableVisionGroup
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -43,7 +43,7 @@ data class Layer(var x: Float, var y: Float, var z: Float, var scale: Float)
|
|||||||
class Extruded(
|
class Extruded(
|
||||||
var shape: List<Point2D> = ArrayList(),
|
var shape: List<Point2D> = ArrayList(),
|
||||||
var layers: MutableList<Layer> = ArrayList()
|
var layers: MutableList<Layer> = ArrayList()
|
||||||
) : AbstractVisualObject(), VisualObject3D, Shape {
|
) : AbstractVision(), Vision3D, Shape {
|
||||||
|
|
||||||
override var ownProperties: Config? = null
|
override var ownProperties: Config? = null
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ fun GeometryBuilder<*>.face4(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [Shape] is a [VisualObject3D] that can represent its own geometry as a set of polygons.
|
* [Shape] is a [Vision3D] that can represent its own geometry as a set of polygons.
|
||||||
*/
|
*/
|
||||||
interface Shape : VisualObject3D {
|
interface Shape : Vision3D {
|
||||||
fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>)
|
fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
package hep.dataforge.vision.spatial
|
package hep.dataforge.vision.spatial
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
import hep.dataforge.vision.AbstractVisualObject
|
import hep.dataforge.vision.AbstractVision
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
import hep.dataforge.vision.MutableVisionGroup
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -12,7 +12,7 @@ import kotlinx.serialization.UseSerializers
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("3d.label")
|
@SerialName("3d.label")
|
||||||
class Label3D(var text: String, var fontSize: Double, var fontFamily: String) : AbstractVisualObject(), VisualObject3D {
|
class Label3D(var text: String, var fontSize: Double, var fontFamily: String) : AbstractVision(), Vision3D {
|
||||||
override var ownProperties: Config? = null
|
override var ownProperties: Config? = null
|
||||||
|
|
||||||
override var position: Point3D? = null
|
override var position: Point3D? = null
|
||||||
|
@ -77,18 +77,18 @@ class Material3D : Scheme() {
|
|||||||
/**
|
/**
|
||||||
* Set color as web-color
|
* Set color as web-color
|
||||||
*/
|
*/
|
||||||
fun VisualObject3D.color(webColor: String) {
|
fun Vision3D.color(webColor: String) {
|
||||||
setItem(MATERIAL_COLOR_KEY, webColor.asValue())
|
setItem(MATERIAL_COLOR_KEY, webColor.asValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set color as integer
|
* Set color as integer
|
||||||
*/
|
*/
|
||||||
fun VisualObject3D.color(rgb: Int) {
|
fun Vision3D.color(rgb: Int) {
|
||||||
setItem(MATERIAL_COLOR_KEY, rgb.asValue())
|
setItem(MATERIAL_COLOR_KEY, rgb.asValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun VisualObject3D.color(r: UByte, g: UByte, b: UByte) = setItem(
|
fun Vision3D.color(r: UByte, g: UByte, b: UByte) = setItem(
|
||||||
MATERIAL_COLOR_KEY,
|
MATERIAL_COLOR_KEY,
|
||||||
Colors.rgbToMeta(r, g, b)
|
Colors.rgbToMeta(r, g, b)
|
||||||
)
|
)
|
||||||
@ -96,16 +96,16 @@ fun VisualObject3D.color(r: UByte, g: UByte, b: UByte) = setItem(
|
|||||||
/**
|
/**
|
||||||
* Web colors representation of the color in `#rrggbb` format or HTML name
|
* Web colors representation of the color in `#rrggbb` format or HTML name
|
||||||
*/
|
*/
|
||||||
var VisualObject3D.color: String?
|
var Vision3D.color: String?
|
||||||
get() = getItem(MATERIAL_COLOR_KEY)?.let { Colors.fromMeta(it) }
|
get() = getItem(MATERIAL_COLOR_KEY)?.let { Colors.fromMeta(it) }
|
||||||
set(value) {
|
set(value) {
|
||||||
setItem(MATERIAL_COLOR_KEY, value?.asValue())
|
setItem(MATERIAL_COLOR_KEY, value?.asValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
val VisualObject3D.material: Material3D?
|
val Vision3D.material: Material3D?
|
||||||
get() = getItem(MATERIAL_KEY).node?.let { Material3D.wrap(it) }
|
get() = getItem(MATERIAL_KEY).node?.let { Material3D.wrap(it) }
|
||||||
|
|
||||||
fun VisualObject3D.material(builder: Material3D.() -> Unit) {
|
fun Vision3D.material(builder: Material3D.() -> Unit) {
|
||||||
val node = config[MATERIAL_KEY].node
|
val node = config[MATERIAL_KEY].node
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
Material3D.update(node, builder)
|
Material3D.update(node, builder)
|
||||||
@ -114,7 +114,7 @@ fun VisualObject3D.material(builder: Material3D.() -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var VisualObject3D.opacity: Double?
|
var Vision3D.opacity: Double?
|
||||||
get() = getItem(MATERIAL_OPACITY_KEY).double
|
get() = getItem(MATERIAL_OPACITY_KEY).double
|
||||||
set(value) {
|
set(value) {
|
||||||
setItem(MATERIAL_OPACITY_KEY, value?.asValue())
|
setItem(MATERIAL_OPACITY_KEY, value?.asValue())
|
||||||
|
@ -6,7 +6,7 @@ import hep.dataforge.meta.Config
|
|||||||
import hep.dataforge.meta.number
|
import hep.dataforge.meta.number
|
||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
import hep.dataforge.names.plus
|
import hep.dataforge.names.plus
|
||||||
import hep.dataforge.vision.AbstractVisualObject
|
import hep.dataforge.vision.AbstractVision
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
import hep.dataforge.vision.MutableVisionGroup
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -15,7 +15,7 @@ import kotlinx.serialization.UseSerializers
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("3d.line")
|
@SerialName("3d.line")
|
||||||
class PolyLine(var points: List<Point3D>) : AbstractVisualObject(), VisualObject3D {
|
class PolyLine(var points: List<Point3D>) : AbstractVision(), Vision3D {
|
||||||
override var ownProperties: Config? = null
|
override var ownProperties: Config? = null
|
||||||
|
|
||||||
override var position: Point3D? = null
|
override var position: Point3D? = null
|
||||||
|
@ -16,13 +16,13 @@ import kotlinx.serialization.UseSerializers
|
|||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A proxy [VisualObject3D] to reuse a template object
|
* A proxy [Vision3D] to reuse a template object
|
||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("3d.proxy")
|
@SerialName("3d.proxy")
|
||||||
class Proxy private constructor(
|
class Proxy private constructor(
|
||||||
val templateName: Name
|
val templateName: Name
|
||||||
) : AbstractVisualObject(), VisionGroup, VisualObject3D {
|
) : AbstractVision(), VisionGroup, Vision3D {
|
||||||
|
|
||||||
constructor(parent: VisionGroup3D, templateName: Name) : this(templateName) {
|
constructor(parent: VisionGroup3D, templateName: Name) : this(templateName) {
|
||||||
this.parent = parent
|
this.parent = parent
|
||||||
@ -37,7 +37,7 @@ class Proxy private constructor(
|
|||||||
/**
|
/**
|
||||||
* Recursively search for defined template in the parent
|
* Recursively search for defined template in the parent
|
||||||
*/
|
*/
|
||||||
val prototype: VisualObject3D
|
val prototype: Vision3D
|
||||||
get() = (parent as? VisionGroup3D)?.getPrototype(templateName)
|
get() = (parent as? VisionGroup3D)?.getPrototype(templateName)
|
||||||
?: error("Prototype with name $templateName not found in $parent")
|
?: error("Prototype with name $templateName not found in $parent")
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ class Proxy private constructor(
|
|||||||
override val descriptor: NodeDescriptor?
|
override val descriptor: NodeDescriptor?
|
||||||
get() = prototype.descriptor
|
get() = prototype.descriptor
|
||||||
|
|
||||||
inner class ProxyChild(val name: Name) : AbstractVisualObject(),
|
inner class ProxyChild(val name: Name) : AbstractVision(),
|
||||||
VisionGroup {
|
VisionGroup {
|
||||||
|
|
||||||
val prototype: Vision get() = prototypeFor(name)
|
val prototype: Vision get() = prototypeFor(name)
|
||||||
@ -179,7 +179,7 @@ fun VisionGroup3D.ref(
|
|||||||
*/
|
*/
|
||||||
fun VisionGroup3D.proxy(
|
fun VisionGroup3D.proxy(
|
||||||
name: String,
|
name: String,
|
||||||
obj: VisualObject3D,
|
obj: Vision3D,
|
||||||
templateName: Name = name.toName()
|
templateName: Name = name.toName()
|
||||||
): Proxy {
|
): Proxy {
|
||||||
val existing = getPrototype(templateName)
|
val existing = getPrototype(templateName)
|
||||||
|
@ -17,29 +17,29 @@ import kotlinx.serialization.modules.SerializersModule
|
|||||||
import kotlinx.serialization.modules.contextual
|
import kotlinx.serialization.modules.contextual
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
class Visual3D(meta: Meta) : AbstractPlugin(meta) {
|
class SpatialVisionManager(meta: Meta) : AbstractPlugin(meta) {
|
||||||
|
|
||||||
val visual by require(VisionManager)
|
val visionManager by require(VisionManager)
|
||||||
|
|
||||||
override val tag: PluginTag get() = Companion.tag
|
override val tag: PluginTag get() = Companion.tag
|
||||||
|
|
||||||
override fun provideTop(target: String): Map<Name, Any> = if (target == VisionManager.VISUAL_FACTORY_TYPE) {
|
override fun provideTop(target: String): Map<Name, Any> = if (target == VisionManager.VISION_FACTORY_TYPE) {
|
||||||
mapOf(Box.TYPE_NAME.toName() to Box)
|
mapOf(Box.TYPE_NAME.toName() to Box)
|
||||||
} else {
|
} else {
|
||||||
super.provideTop(target)
|
super.provideTop(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
companion object : PluginFactory<Visual3D> {
|
companion object : PluginFactory<SpatialVisionManager> {
|
||||||
override val tag: PluginTag = PluginTag(name = "visual.spatial", group = PluginTag.DATAFORGE_GROUP)
|
override val tag: PluginTag = PluginTag(name = "visual.spatial", group = PluginTag.DATAFORGE_GROUP)
|
||||||
override val type: KClass<out Visual3D> = Visual3D::class
|
override val type: KClass<out SpatialVisionManager> = SpatialVisionManager::class
|
||||||
override fun invoke(meta: Meta, context: Context): Visual3D = Visual3D(meta)
|
override fun invoke(meta: Meta, context: Context): SpatialVisionManager = SpatialVisionManager(meta)
|
||||||
|
|
||||||
val serialModule = SerializersModule {
|
val serialModule = SerializersModule {
|
||||||
contextual(Point3DSerializer)
|
contextual(Point3DSerializer)
|
||||||
contextual(Point2DSerializer)
|
contextual(Point2DSerializer)
|
||||||
|
|
||||||
polymorphic(Vision::class, VisualObject3D::class) {
|
polymorphic(Vision::class, Vision3D::class) {
|
||||||
subclass(SimpleVisionGroup.serializer())
|
subclass(SimpleVisionGroup.serializer())
|
||||||
subclass(VisionGroup3D.serializer())
|
subclass(VisionGroup3D.serializer())
|
||||||
subclass(Proxy.serializer())
|
subclass(Proxy.serializer())
|
||||||
@ -67,15 +67,15 @@ class Visual3D(meta: Meta) : AbstractPlugin(meta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun VisualObject3D.update(meta: Meta) {
|
internal fun Vision3D.update(meta: Meta) {
|
||||||
fun Meta.toVector(default: Float = 0f) = Point3D(
|
fun Meta.toVector(default: Float = 0f) = Point3D(
|
||||||
this[VisualObject3D.X_KEY].float ?: default,
|
this[Vision3D.X_KEY].float ?: default,
|
||||||
this[VisualObject3D.Y_KEY].float ?: default,
|
this[Vision3D.Y_KEY].float ?: default,
|
||||||
this[VisualObject3D.Z_KEY].float ?: default
|
this[Vision3D.Z_KEY].float ?: default
|
||||||
)
|
)
|
||||||
|
|
||||||
meta[VisualObject3D.POSITION_KEY].node?.toVector()?.let { position = it }
|
meta[Vision3D.POSITION_KEY].node?.toVector()?.let { position = it }
|
||||||
meta[VisualObject3D.ROTATION].node?.toVector()?.let { rotation = it }
|
meta[Vision3D.ROTATION].node?.toVector()?.let { rotation = it }
|
||||||
meta[VisualObject3D.SCALE_KEY].node?.toVector(1f)?.let { scale = it }
|
meta[Vision3D.SCALE_KEY].node?.toVector(1f)?.let { scale = it }
|
||||||
meta["properties"].node?.let { configure(it) }
|
meta["properties"].node?.let { configure(it) }
|
||||||
}
|
}
|
@ -3,7 +3,7 @@
|
|||||||
package hep.dataforge.vision.spatial
|
package hep.dataforge.vision.spatial
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
import hep.dataforge.vision.AbstractVisualObject
|
import hep.dataforge.vision.AbstractVision
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
import hep.dataforge.vision.MutableVisionGroup
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -21,7 +21,7 @@ class Sphere(
|
|||||||
var phi: Float = PI2,
|
var phi: Float = PI2,
|
||||||
var thetaStart: Float = 0f,
|
var thetaStart: Float = 0f,
|
||||||
var theta: Float = PI.toFloat()
|
var theta: Float = PI.toFloat()
|
||||||
) : AbstractVisualObject(), VisualObject3D, Shape {
|
) : AbstractVision(), Vision3D, Shape {
|
||||||
|
|
||||||
override var ownProperties: Config? = null
|
override var ownProperties: Config? = null
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
package hep.dataforge.vision.spatial
|
package hep.dataforge.vision.spatial
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
import hep.dataforge.vision.AbstractVisualObject
|
import hep.dataforge.vision.AbstractVision
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
import hep.dataforge.vision.MutableVisionGroup
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -24,7 +24,7 @@ class Tube(
|
|||||||
var innerRadius: Float = 0f,
|
var innerRadius: Float = 0f,
|
||||||
var startAngle: Float = 0f,
|
var startAngle: Float = 0f,
|
||||||
var angle: Float = PI2
|
var angle: Float = PI2
|
||||||
) : AbstractVisualObject(), VisualObject3D, Shape {
|
) : AbstractVision(), Vision3D, Shape {
|
||||||
|
|
||||||
override var position: Point3D? = null
|
override var position: Point3D? = null
|
||||||
override var rotation: Point3D? = null
|
override var rotation: Point3D? = null
|
||||||
|
@ -11,16 +11,16 @@ import hep.dataforge.values.ValueType
|
|||||||
import hep.dataforge.values.asValue
|
import hep.dataforge.values.asValue
|
||||||
import hep.dataforge.vision.Vision
|
import hep.dataforge.vision.Vision
|
||||||
import hep.dataforge.vision.enum
|
import hep.dataforge.vision.enum
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D.Companion.DETAIL_KEY
|
import hep.dataforge.vision.spatial.Vision3D.Companion.DETAIL_KEY
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D.Companion.IGNORE_KEY
|
import hep.dataforge.vision.spatial.Vision3D.Companion.IGNORE_KEY
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D.Companion.LAYER_KEY
|
import hep.dataforge.vision.spatial.Vision3D.Companion.LAYER_KEY
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D.Companion.VISIBLE_KEY
|
import hep.dataforge.vision.spatial.Vision3D.Companion.VISIBLE_KEY
|
||||||
import kotlinx.serialization.UseSerializers
|
import kotlinx.serialization.UseSerializers
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for 3-dimensional [Vision]
|
* Interface for 3-dimensional [Vision]
|
||||||
*/
|
*/
|
||||||
interface VisualObject3D : Vision {
|
interface Vision3D : Vision {
|
||||||
var position: Point3D?
|
var position: Point3D?
|
||||||
var rotation: Point3D?
|
var rotation: Point3D?
|
||||||
var scale: Point3D?
|
var scale: Point3D?
|
||||||
@ -86,13 +86,13 @@ interface VisualObject3D : Vision {
|
|||||||
/**
|
/**
|
||||||
* Count number of layers to the top object. Return 1 if this is top layer
|
* Count number of layers to the top object. Return 1 if this is top layer
|
||||||
*/
|
*/
|
||||||
var VisualObject3D.layer: Int
|
var Vision3D.layer: Int
|
||||||
get() = getItem(LAYER_KEY).int ?: 0
|
get() = getItem(LAYER_KEY).int ?: 0
|
||||||
set(value) {
|
set(value) {
|
||||||
setItem(LAYER_KEY, value.asValue())
|
setItem(LAYER_KEY, value.asValue())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Renderer<VisualObject3D>.render(meta: Meta = Meta.EMPTY, action: VisionGroup3D.() -> Unit) =
|
fun Renderer<Vision3D>.render(meta: Meta = Meta.EMPTY, action: VisionGroup3D.() -> Unit) =
|
||||||
render(VisionGroup3D().apply(action), meta)
|
render(VisionGroup3D().apply(action), meta)
|
||||||
|
|
||||||
// Common properties
|
// Common properties
|
||||||
@ -109,15 +109,15 @@ enum class RotationOrder {
|
|||||||
/**
|
/**
|
||||||
* Rotation order
|
* Rotation order
|
||||||
*/
|
*/
|
||||||
var VisualObject3D.rotationOrder: RotationOrder
|
var Vision3D.rotationOrder: RotationOrder
|
||||||
get() = getItem(VisualObject3D.ROTATION_ORDER_KEY).enum<RotationOrder>() ?: RotationOrder.XYZ
|
get() = getItem(Vision3D.ROTATION_ORDER_KEY).enum<RotationOrder>() ?: RotationOrder.XYZ
|
||||||
set(value) = setItem(VisualObject3D.ROTATION_ORDER_KEY, value.name.asValue())
|
set(value) = setItem(Vision3D.ROTATION_ORDER_KEY, value.name.asValue())
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preferred number of polygons for displaying the object. If not defined, uses shape or renderer default. Not inherited
|
* Preferred number of polygons for displaying the object. If not defined, uses shape or renderer default. Not inherited
|
||||||
*/
|
*/
|
||||||
var VisualObject3D.detail: Int?
|
var Vision3D.detail: Int?
|
||||||
get() = getProperty(DETAIL_KEY, false).int
|
get() = getProperty(DETAIL_KEY, false).int
|
||||||
set(value) = setItem(DETAIL_KEY, value?.asValue())
|
set(value) = setItem(DETAIL_KEY, value?.asValue())
|
||||||
|
|
||||||
@ -137,74 +137,74 @@ var Vision.ignore: Boolean?
|
|||||||
// get() = getProperty(SELECTED_KEY).boolean
|
// get() = getProperty(SELECTED_KEY).boolean
|
||||||
// set(value) = setProperty(SELECTED_KEY, value)
|
// set(value) = setProperty(SELECTED_KEY, value)
|
||||||
|
|
||||||
private fun VisualObject3D.position(): Point3D =
|
private fun Vision3D.position(): Point3D =
|
||||||
position ?: Point3D(0.0, 0.0, 0.0).also { position = it }
|
position ?: Point3D(0.0, 0.0, 0.0).also { position = it }
|
||||||
|
|
||||||
var VisualObject3D.x: Number
|
var Vision3D.x: Number
|
||||||
get() = position?.x ?: 0f
|
get() = position?.x ?: 0f
|
||||||
set(value) {
|
set(value) {
|
||||||
position().x = value.toDouble()
|
position().x = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.X_POSITION_KEY)
|
propertyInvalidated(Vision3D.X_POSITION_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
var VisualObject3D.y: Number
|
var Vision3D.y: Number
|
||||||
get() = position?.y ?: 0f
|
get() = position?.y ?: 0f
|
||||||
set(value) {
|
set(value) {
|
||||||
position().y = value.toDouble()
|
position().y = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.Y_POSITION_KEY)
|
propertyInvalidated(Vision3D.Y_POSITION_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
var VisualObject3D.z: Number
|
var Vision3D.z: Number
|
||||||
get() = position?.z ?: 0f
|
get() = position?.z ?: 0f
|
||||||
set(value) {
|
set(value) {
|
||||||
position().z = value.toDouble()
|
position().z = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.Z_POSITION_KEY)
|
propertyInvalidated(Vision3D.Z_POSITION_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun VisualObject3D.rotation(): Point3D =
|
private fun Vision3D.rotation(): Point3D =
|
||||||
rotation ?: Point3D(0.0, 0.0, 0.0).also { rotation = it }
|
rotation ?: Point3D(0.0, 0.0, 0.0).also { rotation = it }
|
||||||
|
|
||||||
var VisualObject3D.rotationX: Number
|
var Vision3D.rotationX: Number
|
||||||
get() = rotation?.x ?: 0f
|
get() = rotation?.x ?: 0f
|
||||||
set(value) {
|
set(value) {
|
||||||
rotation().x = value.toDouble()
|
rotation().x = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.X_ROTATION_KEY)
|
propertyInvalidated(Vision3D.X_ROTATION_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
var VisualObject3D.rotationY: Number
|
var Vision3D.rotationY: Number
|
||||||
get() = rotation?.y ?: 0f
|
get() = rotation?.y ?: 0f
|
||||||
set(value) {
|
set(value) {
|
||||||
rotation().y = value.toDouble()
|
rotation().y = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.Y_ROTATION_KEY)
|
propertyInvalidated(Vision3D.Y_ROTATION_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
var VisualObject3D.rotationZ: Number
|
var Vision3D.rotationZ: Number
|
||||||
get() = rotation?.z ?: 0f
|
get() = rotation?.z ?: 0f
|
||||||
set(value) {
|
set(value) {
|
||||||
rotation().z = value.toDouble()
|
rotation().z = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.Z_ROTATION_KEY)
|
propertyInvalidated(Vision3D.Z_ROTATION_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun VisualObject3D.scale(): Point3D =
|
private fun Vision3D.scale(): Point3D =
|
||||||
scale ?: Point3D(1.0, 1.0, 1.0).also { scale = it }
|
scale ?: Point3D(1.0, 1.0, 1.0).also { scale = it }
|
||||||
|
|
||||||
var VisualObject3D.scaleX: Number
|
var Vision3D.scaleX: Number
|
||||||
get() = scale?.x ?: 1f
|
get() = scale?.x ?: 1f
|
||||||
set(value) {
|
set(value) {
|
||||||
scale().x = value.toDouble()
|
scale().x = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.X_SCALE_KEY)
|
propertyInvalidated(Vision3D.X_SCALE_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
var VisualObject3D.scaleY: Number
|
var Vision3D.scaleY: Number
|
||||||
get() = scale?.y ?: 1f
|
get() = scale?.y ?: 1f
|
||||||
set(value) {
|
set(value) {
|
||||||
scale().y = value.toDouble()
|
scale().y = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.Y_SCALE_KEY)
|
propertyInvalidated(Vision3D.Y_SCALE_KEY)
|
||||||
}
|
}
|
||||||
|
|
||||||
var VisualObject3D.scaleZ: Number
|
var Vision3D.scaleZ: Number
|
||||||
get() = scale?.z ?: 1f
|
get() = scale?.z ?: 1f
|
||||||
set(value) {
|
set(value) {
|
||||||
scale().z = value.toDouble()
|
scale().z = value.toDouble()
|
||||||
propertyInvalidated(VisualObject3D.Z_SCALE_KEY)
|
propertyInvalidated(Vision3D.Z_SCALE_KEY)
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ interface PrototypeHolder {
|
|||||||
*/
|
*/
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("group.3d")
|
@SerialName("group.3d")
|
||||||
class VisionGroup3D : AbstractVision(), VisualObject3D, PrototypeHolder {
|
class VisionGroup3D : AbstractVisionGroup(), Vision3D, PrototypeHolder {
|
||||||
|
|
||||||
override var styleSheet: StyleSheet? = null
|
override var styleSheet: StyleSheet? = null
|
||||||
|
|
||||||
@ -82,15 +82,15 @@ class VisionGroup3D : AbstractVision(), VisualObject3D, PrototypeHolder {
|
|||||||
// val PROTOTYPES_KEY = NameToken("@prototypes")
|
// val PROTOTYPES_KEY = NameToken("@prototypes")
|
||||||
|
|
||||||
fun parseJson(json: String): VisionGroup3D =
|
fun parseJson(json: String): VisionGroup3D =
|
||||||
Visual3D.json.parse(serializer(), json).also { it.attachChildren() }
|
SpatialVisionManager.json.parse(serializer(), json).also { it.attachChildren() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ger a prototype redirecting the request to the parent if prototype is not found
|
* Ger a prototype redirecting the request to the parent if prototype is not found
|
||||||
*/
|
*/
|
||||||
tailrec fun PrototypeHolder.getPrototype(name: Name): VisualObject3D? =
|
tailrec fun PrototypeHolder.getPrototype(name: Name): Vision3D? =
|
||||||
prototypes?.get(name) as? VisualObject3D ?: (parent as? PrototypeHolder)?.getPrototype(name)
|
prototypes?.get(name) as? Vision3D ?: (parent as? PrototypeHolder)?.getPrototype(name)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a group with given [name], attach it to this parent and return it.
|
* Define a group with given [name], attach it to this parent and return it.
|
||||||
@ -102,7 +102,7 @@ fun MutableVisionGroup.group(name: String = "", action: VisionGroup3D.() -> Unit
|
|||||||
|
|
||||||
internal class Prototypes(
|
internal class Prototypes(
|
||||||
override var children: MutableMap<NameToken, Vision> = LinkedHashMap()
|
override var children: MutableMap<NameToken, Vision> = LinkedHashMap()
|
||||||
) : AbstractVision(), MutableVisionGroup, PrototypeHolder {
|
) : AbstractVisionGroup(), MutableVisionGroup, PrototypeHolder {
|
||||||
|
|
||||||
override var styleSheet: StyleSheet?
|
override var styleSheet: StyleSheet?
|
||||||
get() = null
|
get() = null
|
||||||
|
@ -21,8 +21,8 @@ operator fun Point2D.component1() = x
|
|||||||
operator fun Point2D.component2() = y
|
operator fun Point2D.component2() = y
|
||||||
|
|
||||||
fun Point2D.toMeta() = Meta {
|
fun Point2D.toMeta() = Meta {
|
||||||
VisualObject3D.X_KEY put x
|
Vision3D.X_KEY put x
|
||||||
VisualObject3D.Y_KEY put y
|
Vision3D.Y_KEY put y
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Meta.point2D() = Point2D(this["x"].number ?: 0, this["y"].number ?: 0)
|
fun Meta.point2D() = Point2D(this["x"].number ?: 0, this["y"].number ?: 0)
|
||||||
@ -42,7 +42,7 @@ operator fun Point3D.component3() = z
|
|||||||
fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0)
|
fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0)
|
||||||
|
|
||||||
fun Point3D.toMeta() = Meta {
|
fun Point3D.toMeta() = Meta {
|
||||||
VisualObject3D.X_KEY put x
|
Vision3D.X_KEY put x
|
||||||
VisualObject3D.Y_KEY put y
|
Vision3D.Y_KEY put y
|
||||||
VisualObject3D.Z_KEY put z
|
Vision3D.Z_KEY put z
|
||||||
}
|
}
|
@ -118,9 +118,9 @@ internal object PrototypesSerializer : KSerializer<MutableVisionGroup> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Vision.stringify(): String = Visual3D.json.stringify(Vision.serializer(), this)
|
fun Vision.stringify(): String = SpatialVisionManager.json.stringify(Vision.serializer(), this)
|
||||||
|
|
||||||
fun Vision.Companion.parseJson(str: String) = Visual3D.json.parse(Vision.serializer(), str).also {
|
fun Vision.Companion.parseJson(str: String) = SpatialVisionManager.json.parse(Vision.serializer(), str).also {
|
||||||
if(it is VisionGroup){
|
if(it is VisionGroup){
|
||||||
it.attachChildren()
|
it.attachChildren()
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ internal fun mergeChild(parent: VisionGroup, child: Vision): Vision {
|
|||||||
|
|
||||||
//parent.properties?.let { config.update(it) }
|
//parent.properties?.let { config.update(it) }
|
||||||
|
|
||||||
if (this is VisualObject3D && parent is VisualObject3D) {
|
if (this is Vision3D && parent is Vision3D) {
|
||||||
position = (position ?: World.ZERO) + (parent.position ?: World.ZERO)
|
position = (position ?: World.ZERO) + (parent.position ?: World.ZERO)
|
||||||
rotation = (parent.rotation ?: World.ZERO) + (parent.rotation ?: World.ZERO)
|
rotation = (parent.rotation ?: World.ZERO) + (parent.rotation ?: World.ZERO)
|
||||||
scale = when {
|
scale = when {
|
||||||
|
@ -26,7 +26,7 @@ class ConvexTest {
|
|||||||
|
|
||||||
val convex = group.children.values.first() as Convex
|
val convex = group.children.values.first() as Convex
|
||||||
|
|
||||||
val json = Visual3D.json.toJson(Convex.serializer(), convex)
|
val json = SpatialVisionManager.json.toJson(Convex.serializer(), convex)
|
||||||
val meta = json.toMetaItem().node!!
|
val meta = json.toMetaItem().node!!
|
||||||
|
|
||||||
val points = meta.getIndexed("points").values.map { (it as MetaItem.NodeItem<*>).node.point3D() }
|
val points = meta.getIndexed("points").values.map { (it as MetaItem.NodeItem<*>).node.point3D() }
|
||||||
|
@ -45,7 +45,7 @@ class GroupTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assertEquals(3, group.children.count())
|
assertEquals(3, group.children.count())
|
||||||
assertEquals(300.0, (group["intersect"] as VisualObject3D).y.toDouble())
|
assertEquals(300.0, (group["intersect"] as Vision3D).y.toDouble())
|
||||||
assertEquals(-300.0, (group["subtract"] as VisualObject3D).y.toDouble())
|
assertEquals(-300.0, (group["subtract"] as Vision3D).y.toDouble())
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import hep.dataforge.names.asName
|
|||||||
import hep.dataforge.names.plus
|
import hep.dataforge.names.plus
|
||||||
import hep.dataforge.names.startsWith
|
import hep.dataforge.names.startsWith
|
||||||
import hep.dataforge.vision.spatial.Material3D
|
import hep.dataforge.vision.spatial.Material3D
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D
|
import hep.dataforge.vision.spatial.Vision3D
|
||||||
import hep.dataforge.vision.spatial.layer
|
import hep.dataforge.vision.spatial.layer
|
||||||
import hep.dataforge.vision.spatial.three.ThreeMaterials.getMaterial
|
import hep.dataforge.vision.spatial.three.ThreeMaterials.getMaterial
|
||||||
import info.laht.threekt.core.BufferGeometry
|
import info.laht.threekt.core.BufferGeometry
|
||||||
@ -19,7 +19,7 @@ import kotlin.reflect.KClass
|
|||||||
/**
|
/**
|
||||||
* Basic geometry-based factory
|
* Basic geometry-based factory
|
||||||
*/
|
*/
|
||||||
abstract class MeshThreeFactory<in T : VisualObject3D>(
|
abstract class MeshThreeFactory<in T : Vision3D>(
|
||||||
override val type: KClass<in T>
|
override val type: KClass<in T>
|
||||||
) : ThreeFactory<T> {
|
) : ThreeFactory<T> {
|
||||||
/**
|
/**
|
||||||
@ -52,7 +52,7 @@ abstract class MeshThreeFactory<in T : VisualObject3D>(
|
|||||||
//add listener to object properties
|
//add listener to object properties
|
||||||
obj.onPropertyChange(this) { name, _, _ ->
|
obj.onPropertyChange(this) { name, _, _ ->
|
||||||
when {
|
when {
|
||||||
name.startsWith(VisualObject3D.GEOMETRY_KEY) -> {
|
name.startsWith(Vision3D.GEOMETRY_KEY) -> {
|
||||||
val oldGeometry = mesh.geometry as BufferGeometry
|
val oldGeometry = mesh.geometry as BufferGeometry
|
||||||
val newGeometry = buildGeometry(obj)
|
val newGeometry = buildGeometry(obj)
|
||||||
oldGeometry.attributes = newGeometry.attributes
|
oldGeometry.attributes = newGeometry.attributes
|
||||||
@ -79,7 +79,7 @@ abstract class MeshThreeFactory<in T : VisualObject3D>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Mesh.applyEdges(obj: VisualObject3D) {
|
fun Mesh.applyEdges(obj: Vision3D) {
|
||||||
children.find { it.name == "@edges" }?.let {
|
children.find { it.name == "@edges" }?.let {
|
||||||
remove(it)
|
remove(it)
|
||||||
(it as LineSegments).dispose()
|
(it as LineSegments).dispose()
|
||||||
@ -99,7 +99,7 @@ fun Mesh.applyEdges(obj: VisualObject3D) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Mesh.applyWireFrame(obj: VisualObject3D) {
|
fun Mesh.applyWireFrame(obj: Vision3D) {
|
||||||
children.find { it.name == "@wireframe" }?.let {
|
children.find { it.name == "@wireframe" }?.let {
|
||||||
remove(it)
|
remove(it)
|
||||||
(it as LineSegments).dispose()
|
(it as LineSegments).dispose()
|
||||||
|
@ -9,7 +9,7 @@ import hep.dataforge.names.plus
|
|||||||
import hep.dataforge.names.toName
|
import hep.dataforge.names.toName
|
||||||
import hep.dataforge.output.Renderer
|
import hep.dataforge.output.Renderer
|
||||||
import hep.dataforge.vision.Colors
|
import hep.dataforge.vision.Colors
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D
|
import hep.dataforge.vision.spatial.Vision3D
|
||||||
import hep.dataforge.vision.spatial.specifications.Camera
|
import hep.dataforge.vision.spatial.specifications.Camera
|
||||||
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
|
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
|
||||||
import hep.dataforge.vision.spatial.specifications.Controls
|
import hep.dataforge.vision.spatial.specifications.Controls
|
||||||
@ -41,11 +41,11 @@ import kotlin.math.sin
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val options: Canvas3DOptions) : Renderer<VisualObject3D> {
|
class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val options: Canvas3DOptions) : Renderer<Vision3D> {
|
||||||
|
|
||||||
override val context: Context get() = three.context
|
override val context: Context get() = three.context
|
||||||
|
|
||||||
var content: VisualObject3D? = null
|
var content: Vision3D? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private var root: Object3D? = null
|
private var root: Object3D? = null
|
||||||
@ -172,7 +172,7 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val options: Can
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(obj: VisualObject3D, meta: Meta) {
|
override fun render(obj: Vision3D, meta: Meta) {
|
||||||
//clear old root
|
//clear old root
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
@ -244,5 +244,5 @@ class ThreeCanvas(element: HTMLElement, val three: ThreePlugin, val options: Can
|
|||||||
fun ThreePlugin.output(element: HTMLElement, spec: Canvas3DOptions = Canvas3DOptions.empty()): ThreeCanvas =
|
fun ThreePlugin.output(element: HTMLElement, spec: Canvas3DOptions = Canvas3DOptions.empty()): ThreeCanvas =
|
||||||
ThreeCanvas(element, this, spec)
|
ThreeCanvas(element, this, spec)
|
||||||
|
|
||||||
fun ThreePlugin.render(element: HTMLElement, obj: VisualObject3D, spec: Canvas3DOptions = Canvas3DOptions.empty()): Unit =
|
fun ThreePlugin.render(element: HTMLElement, obj: Vision3D, spec: Canvas3DOptions = Canvas3DOptions.empty()): Unit =
|
||||||
output(element, spec).render(obj)
|
output(element, spec).render(obj)
|
@ -2,7 +2,7 @@ package hep.dataforge.vision.spatial.three
|
|||||||
|
|
||||||
import hep.dataforge.context.Context
|
import hep.dataforge.context.Context
|
||||||
import hep.dataforge.names.Name
|
import hep.dataforge.names.Name
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D
|
import hep.dataforge.vision.spatial.Vision3D
|
||||||
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
|
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
|
||||||
import org.w3c.dom.Element
|
import org.w3c.dom.Element
|
||||||
import org.w3c.dom.HTMLElement
|
import org.w3c.dom.HTMLElement
|
||||||
@ -15,7 +15,7 @@ import react.dom.findDOMNode
|
|||||||
|
|
||||||
interface ThreeCanvasProps : RProps {
|
interface ThreeCanvasProps : RProps {
|
||||||
var context: Context
|
var context: Context
|
||||||
var obj: VisualObject3D
|
var obj: Vision3D
|
||||||
var options: Canvas3DOptions?
|
var options: Canvas3DOptions?
|
||||||
var selected: Name?
|
var selected: Name?
|
||||||
var clickCallback: (Name?) -> Unit
|
var clickCallback: (Name?) -> Unit
|
||||||
@ -61,7 +61,7 @@ class ThreeCanvasComponent : RComponent<ThreeCanvasProps, ThreeCanvasState>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun RBuilder.threeCanvas(object3D: VisualObject3D, options: Canvas3DOptions.() -> Unit = {}) {
|
fun RBuilder.threeCanvas(object3D: Vision3D, options: Canvas3DOptions.() -> Unit = {}) {
|
||||||
child(ThreeCanvasComponent::class) {
|
child(ThreeCanvasComponent::class) {
|
||||||
attrs {
|
attrs {
|
||||||
this.obj = object3D
|
this.obj = object3D
|
||||||
|
@ -33,7 +33,7 @@ interface ThreeFactory<in T : Vision> {
|
|||||||
*/
|
*/
|
||||||
fun Object3D.updatePosition(obj: Vision) {
|
fun Object3D.updatePosition(obj: Vision) {
|
||||||
visible = obj.visible ?: true
|
visible = obj.visible ?: true
|
||||||
if(obj is VisualObject3D) {
|
if(obj is Vision3D) {
|
||||||
position.set(obj.x, obj.y, obj.z)
|
position.set(obj.x, obj.y, obj.z)
|
||||||
setRotationFromEuler(obj.euler)
|
setRotationFromEuler(obj.euler)
|
||||||
scale.set(obj.scaleX, obj.scaleY, obj.scaleZ)
|
scale.set(obj.scaleX, obj.scaleY, obj.scaleZ)
|
||||||
@ -60,13 +60,13 @@ fun Object3D.updateProperty(source: Vision, propertyName: Name) {
|
|||||||
if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) {
|
if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) {
|
||||||
this.material = getMaterial(source)
|
this.material = getMaterial(source)
|
||||||
} else if (
|
} else if (
|
||||||
propertyName.startsWith(VisualObject3D.POSITION_KEY)
|
propertyName.startsWith(Vision3D.POSITION_KEY)
|
||||||
|| propertyName.startsWith(VisualObject3D.ROTATION)
|
|| propertyName.startsWith(Vision3D.ROTATION)
|
||||||
|| propertyName.startsWith(VisualObject3D.SCALE_KEY)
|
|| propertyName.startsWith(Vision3D.SCALE_KEY)
|
||||||
) {
|
) {
|
||||||
//update position of mesh using this object
|
//update position of mesh using this object
|
||||||
updatePosition(source)
|
updatePosition(source)
|
||||||
} else if (propertyName == VisualObject3D.VISIBLE_KEY) {
|
} else if (propertyName == Vision3D.VISIBLE_KEY) {
|
||||||
visible = source.visible ?: true
|
visible = source.visible ?: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import info.laht.threekt.objects.Group as ThreeGroup
|
|||||||
class ThreePlugin : AbstractPlugin() {
|
class ThreePlugin : AbstractPlugin() {
|
||||||
override val tag: PluginTag get() = Companion.tag
|
override val tag: PluginTag get() = Companion.tag
|
||||||
|
|
||||||
private val objectFactories = HashMap<KClass<out VisualObject3D>, ThreeFactory<*>>()
|
private val objectFactories = HashMap<KClass<out Vision3D>, ThreeFactory<*>>()
|
||||||
private val compositeFactory = ThreeCompositeFactory(this)
|
private val compositeFactory = ThreeCompositeFactory(this)
|
||||||
private val proxyFactory = ThreeProxyFactory(this)
|
private val proxyFactory = ThreeProxyFactory(this)
|
||||||
|
|
||||||
@ -28,20 +28,20 @@ class ThreePlugin : AbstractPlugin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
private fun findObjectFactory(type: KClass<out Vision>): ThreeFactory<VisualObject3D>? {
|
private fun findObjectFactory(type: KClass<out Vision>): ThreeFactory<Vision3D>? {
|
||||||
return (objectFactories[type]
|
return (objectFactories[type]
|
||||||
?: context.content<ThreeFactory<*>>(ThreeFactory.TYPE).values.find { it.type == type })
|
?: context.content<ThreeFactory<*>>(ThreeFactory.TYPE).values.find { it.type == type })
|
||||||
as ThreeFactory<VisualObject3D>?
|
as ThreeFactory<Vision3D>?
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildObject3D(obj: VisualObject3D): Object3D {
|
fun buildObject3D(obj: Vision3D): Object3D {
|
||||||
return when (obj) {
|
return when (obj) {
|
||||||
is ThreeVisualObject -> obj.toObject3D()
|
is ThreeVision -> obj.toObject3D()
|
||||||
is Proxy -> proxyFactory(obj)
|
is Proxy -> proxyFactory(obj)
|
||||||
is VisionGroup3D -> {
|
is VisionGroup3D -> {
|
||||||
val group = ThreeGroup()
|
val group = ThreeGroup()
|
||||||
obj.children.forEach { (token, child) ->
|
obj.children.forEach { (token, child) ->
|
||||||
if (child is VisualObject3D && child.ignore != true) {
|
if (child is Vision3D && child.ignore != true) {
|
||||||
try {
|
try {
|
||||||
val object3D = buildObject3D(child)
|
val object3D = buildObject3D(child)
|
||||||
group[token] = object3D
|
group[token] = object3D
|
||||||
@ -57,13 +57,13 @@ class ThreePlugin : AbstractPlugin() {
|
|||||||
|
|
||||||
obj.onPropertyChange(this) { name, _, _ ->
|
obj.onPropertyChange(this) { name, _, _ ->
|
||||||
if (
|
if (
|
||||||
name.startsWith(VisualObject3D.POSITION_KEY) ||
|
name.startsWith(Vision3D.POSITION_KEY) ||
|
||||||
name.startsWith(VisualObject3D.ROTATION) ||
|
name.startsWith(Vision3D.ROTATION) ||
|
||||||
name.startsWith(VisualObject3D.SCALE_KEY)
|
name.startsWith(Vision3D.SCALE_KEY)
|
||||||
) {
|
) {
|
||||||
//update position of mesh using this object
|
//update position of mesh using this object
|
||||||
updatePosition(obj)
|
updatePosition(obj)
|
||||||
} else if (name == VisualObject3D.VISIBLE_KEY) {
|
} else if (name == Vision3D.VISIBLE_KEY) {
|
||||||
visible = obj.visible ?: true
|
visible = obj.visible ?: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ class ThreePlugin : AbstractPlugin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//adding new object
|
//adding new object
|
||||||
if (child != null && child is VisualObject3D) {
|
if (child != null && child is Vision3D) {
|
||||||
try {
|
try {
|
||||||
val object3D = buildObject3D(child)
|
val object3D = buildObject3D(child)
|
||||||
set(name, object3D)
|
set(name, object3D)
|
||||||
@ -97,7 +97,7 @@ class ThreePlugin : AbstractPlugin() {
|
|||||||
is Composite -> compositeFactory(obj)
|
is Composite -> compositeFactory(obj)
|
||||||
else -> {
|
else -> {
|
||||||
//find specialized factory for this type if it is present
|
//find specialized factory for this type if it is present
|
||||||
val factory: ThreeFactory<VisualObject3D>? = findObjectFactory(obj::class)
|
val factory: ThreeFactory<Vision3D>? = findObjectFactory(obj::class)
|
||||||
when {
|
when {
|
||||||
factory != null -> factory(obj)
|
factory != null -> factory(obj)
|
||||||
obj is Shape -> ThreeShapeFactory(obj)
|
obj is Shape -> ThreeShapeFactory(obj)
|
||||||
|
@ -3,11 +3,11 @@ package hep.dataforge.vision.spatial.three
|
|||||||
import hep.dataforge.names.toName
|
import hep.dataforge.names.toName
|
||||||
import hep.dataforge.vision.spatial.Proxy
|
import hep.dataforge.vision.spatial.Proxy
|
||||||
import hep.dataforge.vision.spatial.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX
|
import hep.dataforge.vision.spatial.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D
|
import hep.dataforge.vision.spatial.Vision3D
|
||||||
import info.laht.threekt.core.Object3D
|
import info.laht.threekt.core.Object3D
|
||||||
|
|
||||||
class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory<Proxy> {
|
class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory<Proxy> {
|
||||||
private val cache = HashMap<VisualObject3D, Object3D>()
|
private val cache = HashMap<Vision3D, Object3D>()
|
||||||
|
|
||||||
override val type = Proxy::class
|
override val type = Proxy::class
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
package hep.dataforge.vision.spatial.three
|
package hep.dataforge.vision.spatial.three
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
import hep.dataforge.vision.AbstractVisualObject
|
import hep.dataforge.vision.AbstractVision
|
||||||
import hep.dataforge.vision.spatial.Point3D
|
import hep.dataforge.vision.spatial.Point3D
|
||||||
import hep.dataforge.vision.spatial.Point3DSerializer
|
import hep.dataforge.vision.spatial.Point3DSerializer
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D
|
import hep.dataforge.vision.spatial.Vision3D
|
||||||
import info.laht.threekt.core.Object3D
|
import info.laht.threekt.core.Object3D
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.UseSerializers
|
import kotlinx.serialization.UseSerializers
|
||||||
@ -14,13 +14,13 @@ import kotlinx.serialization.UseSerializers
|
|||||||
/**
|
/**
|
||||||
* A custom visual object that has its own Three.js renderer
|
* A custom visual object that has its own Three.js renderer
|
||||||
*/
|
*/
|
||||||
interface ThreeVisualObject : VisualObject3D {
|
interface ThreeVision : Vision3D {
|
||||||
fun toObject3D(): Object3D
|
fun toObject3D(): Object3D
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class CustomThreeVisualObject(val threeFactory: ThreeFactory<VisualObject3D>) : AbstractVisualObject(),
|
class CustomThreeVision(val threeFactory: ThreeFactory<Vision3D>) : AbstractVision(),
|
||||||
ThreeVisualObject {
|
ThreeVision {
|
||||||
override var position: Point3D? = null
|
override var position: Point3D? = null
|
||||||
override var rotation: Point3D? = null
|
override var rotation: Point3D? = null
|
||||||
override var scale: Point3D? = null
|
override var scale: Point3D? = null
|
@ -3,8 +3,8 @@ package hep.dataforge.vision.spatial.three
|
|||||||
import hep.dataforge.js.requireJS
|
import hep.dataforge.js.requireJS
|
||||||
import hep.dataforge.vision.bootstrap.accordion
|
import hep.dataforge.vision.bootstrap.accordion
|
||||||
import hep.dataforge.vision.bootstrap.entry
|
import hep.dataforge.vision.bootstrap.entry
|
||||||
|
import hep.dataforge.vision.spatial.SpatialVisionManager
|
||||||
import hep.dataforge.vision.spatial.VisionGroup3D
|
import hep.dataforge.vision.spatial.VisionGroup3D
|
||||||
import hep.dataforge.vision.spatial.Visual3D
|
|
||||||
import kotlinx.html.*
|
import kotlinx.html.*
|
||||||
import kotlinx.html.dom.append
|
import kotlinx.html.dom.append
|
||||||
import kotlinx.html.js.onChangeFunction
|
import kotlinx.html.js.onChangeFunction
|
||||||
@ -53,7 +53,7 @@ fun RBuilder.canvasControls(canvas: ThreeCanvas) = accordion("controls") {
|
|||||||
attrs {
|
attrs {
|
||||||
onClickFunction = {
|
onClickFunction = {
|
||||||
val json = (canvas.content as? VisionGroup3D)?.let { group ->
|
val json = (canvas.content as? VisionGroup3D)?.let { group ->
|
||||||
Visual3D.json.stringify(
|
SpatialVisionManager.json.stringify(
|
||||||
VisionGroup3D.serializer(),
|
VisionGroup3D.serializer(),
|
||||||
group
|
group
|
||||||
)
|
)
|
||||||
@ -117,7 +117,7 @@ fun Element.displayCanvasControls(canvas: ThreeCanvas, block: TagConsumer<HTMLEl
|
|||||||
+"Export"
|
+"Export"
|
||||||
onClickFunction = {
|
onClickFunction = {
|
||||||
val json = (canvas.content as? VisionGroup3D)?.let { group ->
|
val json = (canvas.content as? VisionGroup3D)?.let { group ->
|
||||||
Visual3D.json.stringify(
|
SpatialVisionManager.json.stringify(
|
||||||
VisionGroup3D.serializer(),
|
VisionGroup3D.serializer(),
|
||||||
group
|
group
|
||||||
)
|
)
|
||||||
|
@ -17,7 +17,7 @@ import info.laht.threekt.objects.Mesh
|
|||||||
import info.laht.threekt.textures.Texture
|
import info.laht.threekt.textures.Texture
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
|
|
||||||
val VisualObject3D.euler get() = Euler(rotationX, rotationY, rotationZ, rotationOrder.name)
|
val Vision3D.euler get() = Euler(rotationX, rotationY, rotationZ, rotationOrder.name)
|
||||||
|
|
||||||
val MetaItem<*>.vector get() = Vector3(node["x"].float ?: 0f, node["y"].float ?: 0f, node["z"].float ?: 0f)
|
val MetaItem<*>.vector get() = Vector3(node["x"].float ?: 0f, node["y"].float ?: 0f, node["z"].float ?: 0f)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import kotlin.reflect.KClass
|
|||||||
class FX3DPlugin : AbstractPlugin() {
|
class FX3DPlugin : AbstractPlugin() {
|
||||||
override val tag: PluginTag get() = Companion.tag
|
override val tag: PluginTag get() = Companion.tag
|
||||||
|
|
||||||
private val objectFactories = HashMap<KClass<out VisualObject3D>, FX3DFactory<*>>()
|
private val objectFactories = HashMap<KClass<out Vision3D>, FX3DFactory<*>>()
|
||||||
private val compositeFactory = FXCompositeFactory(this)
|
private val compositeFactory = FXCompositeFactory(this)
|
||||||
private val proxyFactory = FXProxyFactory(this)
|
private val proxyFactory = FXProxyFactory(this)
|
||||||
|
|
||||||
@ -37,18 +37,18 @@ class FX3DPlugin : AbstractPlugin() {
|
|||||||
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
private fun findObjectFactory(type: KClass<out VisualObject3D>): FX3DFactory<VisualObject3D>? {
|
private fun findObjectFactory(type: KClass<out Vision3D>): FX3DFactory<Vision3D>? {
|
||||||
return (objectFactories[type] ?: context.content<FX3DFactory<*>>(TYPE).values.find { it.type == type })
|
return (objectFactories[type] ?: context.content<FX3DFactory<*>>(TYPE).values.find { it.type == type })
|
||||||
as FX3DFactory<VisualObject3D>?
|
as FX3DFactory<Vision3D>?
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildNode(obj: VisualObject3D): Node {
|
fun buildNode(obj: Vision3D): Node {
|
||||||
val binding = VisualObjectFXBinding(obj)
|
val binding = VisualObjectFXBinding(obj)
|
||||||
return when (obj) {
|
return when (obj) {
|
||||||
is Proxy -> proxyFactory(obj, binding)
|
is Proxy -> proxyFactory(obj, binding)
|
||||||
is VisionGroup3D -> {
|
is VisionGroup3D -> {
|
||||||
Group(obj.children.mapNotNull { (token, obj) ->
|
Group(obj.children.mapNotNull { (token, obj) ->
|
||||||
(obj as? VisualObject3D)?.let {
|
(obj as? Vision3D)?.let {
|
||||||
buildNode(it).apply {
|
buildNode(it).apply {
|
||||||
properties["name"] = token.toString()
|
properties["name"] = token.toString()
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ class FX3DPlugin : AbstractPlugin() {
|
|||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
//find specialized factory for this type if it is present
|
//find specialized factory for this type if it is present
|
||||||
val factory: FX3DFactory<VisualObject3D>? = findObjectFactory(obj::class)
|
val factory: FX3DFactory<Vision3D>? = findObjectFactory(obj::class)
|
||||||
when {
|
when {
|
||||||
factory != null -> factory(obj, binding)
|
factory != null -> factory(obj, binding)
|
||||||
obj is Shape -> FXShapeFactory(obj, binding)
|
obj is Shape -> FXShapeFactory(obj, binding)
|
||||||
@ -85,23 +85,23 @@ class FX3DPlugin : AbstractPlugin() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.apply {
|
}.apply {
|
||||||
translateXProperty().bind(binding[VisualObject3D.X_POSITION_KEY].float(obj.x.toFloat()))
|
translateXProperty().bind(binding[Vision3D.X_POSITION_KEY].float(obj.x.toFloat()))
|
||||||
translateYProperty().bind(binding[VisualObject3D.Y_POSITION_KEY].float(obj.y.toFloat()))
|
translateYProperty().bind(binding[Vision3D.Y_POSITION_KEY].float(obj.y.toFloat()))
|
||||||
translateZProperty().bind(binding[VisualObject3D.Z_POSITION_KEY].float(obj.z.toFloat()))
|
translateZProperty().bind(binding[Vision3D.Z_POSITION_KEY].float(obj.z.toFloat()))
|
||||||
scaleXProperty().bind(binding[VisualObject3D.X_SCALE_KEY].float(obj.scaleX.toFloat()))
|
scaleXProperty().bind(binding[Vision3D.X_SCALE_KEY].float(obj.scaleX.toFloat()))
|
||||||
scaleYProperty().bind(binding[VisualObject3D.Y_SCALE_KEY].float(obj.scaleY.toFloat()))
|
scaleYProperty().bind(binding[Vision3D.Y_SCALE_KEY].float(obj.scaleY.toFloat()))
|
||||||
scaleZProperty().bind(binding[VisualObject3D.Z_SCALE_KEY].float(obj.scaleZ.toFloat()))
|
scaleZProperty().bind(binding[Vision3D.Z_SCALE_KEY].float(obj.scaleZ.toFloat()))
|
||||||
|
|
||||||
val rotateX = Rotate(0.0, Rotate.X_AXIS).apply {
|
val rotateX = Rotate(0.0, Rotate.X_AXIS).apply {
|
||||||
angleProperty().bind(binding[VisualObject3D.X_ROTATION_KEY].float(obj.rotationX.toFloat()).multiply(180.0 / PI))
|
angleProperty().bind(binding[Vision3D.X_ROTATION_KEY].float(obj.rotationX.toFloat()).multiply(180.0 / PI))
|
||||||
}
|
}
|
||||||
|
|
||||||
val rotateY = Rotate(0.0, Rotate.Y_AXIS).apply {
|
val rotateY = Rotate(0.0, Rotate.Y_AXIS).apply {
|
||||||
angleProperty().bind(binding[VisualObject3D.Y_ROTATION_KEY].float(obj.rotationY.toFloat()).multiply(180.0 / PI))
|
angleProperty().bind(binding[Vision3D.Y_ROTATION_KEY].float(obj.rotationY.toFloat()).multiply(180.0 / PI))
|
||||||
}
|
}
|
||||||
|
|
||||||
val rotateZ = Rotate(0.0, Rotate.Z_AXIS).apply {
|
val rotateZ = Rotate(0.0, Rotate.Z_AXIS).apply {
|
||||||
angleProperty().bind(binding[VisualObject3D.Z_ROTATION_KEY].float(obj.rotationZ.toFloat()).multiply(180.0 / PI))
|
angleProperty().bind(binding[Vision3D.Z_ROTATION_KEY].float(obj.rotationZ.toFloat()).multiply(180.0 / PI))
|
||||||
}
|
}
|
||||||
|
|
||||||
when (obj.rotationOrder) {
|
when (obj.rotationOrder) {
|
||||||
@ -140,7 +140,7 @@ class FX3DPlugin : AbstractPlugin() {
|
|||||||
* Builder and updater for three.js object
|
* Builder and updater for three.js object
|
||||||
*/
|
*/
|
||||||
@Type(TYPE)
|
@Type(TYPE)
|
||||||
interface FX3DFactory<in T : VisualObject3D> {
|
interface FX3DFactory<in T : Vision3D> {
|
||||||
|
|
||||||
val type: KClass<in T>
|
val type: KClass<in T>
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import hep.dataforge.context.Context
|
|||||||
import hep.dataforge.context.ContextAware
|
import hep.dataforge.context.ContextAware
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import hep.dataforge.output.Renderer
|
import hep.dataforge.output.Renderer
|
||||||
import hep.dataforge.vision.spatial.VisualObject3D
|
import hep.dataforge.vision.spatial.Vision3D
|
||||||
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
|
import hep.dataforge.vision.spatial.specifications.Canvas3DOptions
|
||||||
import javafx.application.Platform
|
import javafx.application.Platform
|
||||||
import javafx.beans.property.ObjectProperty
|
import javafx.beans.property.ObjectProperty
|
||||||
@ -15,7 +15,7 @@ import org.fxyz3d.scene.Axes
|
|||||||
import tornadofx.*
|
import tornadofx.*
|
||||||
|
|
||||||
class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas3DOptions = Canvas3DOptions.empty()) :
|
class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas3DOptions = Canvas3DOptions.empty()) :
|
||||||
Fragment(), Renderer<VisualObject3D>, ContextAware {
|
Fragment(), Renderer<Vision3D>, ContextAware {
|
||||||
|
|
||||||
override val context: Context get() = plugin.context
|
override val context: Context get() = plugin.context
|
||||||
|
|
||||||
@ -58,8 +58,8 @@ class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas3DOptions = Canvas3DOpt
|
|||||||
world.add(it.centerMarker)
|
world.add(it.centerMarker)
|
||||||
}
|
}
|
||||||
|
|
||||||
val rootObjectProperty: ObjectProperty<VisualObject3D> = SimpleObjectProperty()
|
val rootObjectProperty: ObjectProperty<Vision3D> = SimpleObjectProperty()
|
||||||
var rootObject: VisualObject3D? by rootObjectProperty
|
var rootObject: Vision3D? by rootObjectProperty
|
||||||
|
|
||||||
private val rootNodeProperty = rootObjectProperty.objectBinding {
|
private val rootNodeProperty = rootObjectProperty.objectBinding {
|
||||||
it?.let { plugin.buildNode(it) }
|
it?.let { plugin.buildNode(it) }
|
||||||
@ -80,7 +80,7 @@ class FXCanvas3D(val plugin: FX3DPlugin, val spec: Canvas3DOptions = Canvas3DOpt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(obj: VisualObject3D, meta: Meta) {
|
override fun render(obj: Vision3D, meta: Meta) {
|
||||||
rootObject = obj
|
rootObject = obj
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -142,11 +142,11 @@ private fun jsonSchema(descriptor: SerialDescriptor, context: SerialModule): Jso
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val context = Visual3D.serialModule
|
val context = SpatialVisionManager.serialModule
|
||||||
val definitions = json {
|
val definitions = json {
|
||||||
"children" to json {
|
"children" to json {
|
||||||
"anyOf" to jsonArray {
|
"anyOf" to jsonArray {
|
||||||
context.enumerate(VisualObject3D::class).forEach {
|
context.enumerate(Vision3D::class).forEach {
|
||||||
if (it.serialName == "hep.dataforge.vis.spatial.VisualGroup3D") {
|
if (it.serialName == "hep.dataforge.vis.spatial.VisualGroup3D") {
|
||||||
+json {
|
+json {
|
||||||
"\$ref" to "#/$definitionNode/${it.serialName}"
|
"\$ref" to "#/$definitionNode/${it.serialName}"
|
||||||
|
Loading…
Reference in New Issue
Block a user