Remove unnecessary coordinates and properties for solids after serialization fix.
This commit is contained in:
parent
7571b58e99
commit
8f6c3822ff
@ -2,13 +2,16 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
|
- Server module
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
- Primary modules dependencies on UI
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
- Version conflicts
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
@ -19,7 +19,7 @@ private class MMDemoApp : Application {
|
|||||||
|
|
||||||
private val connection = HttpClient {
|
private val connection = HttpClient {
|
||||||
install(JsonFeature) {
|
install(JsonFeature) {
|
||||||
serializer = KotlinxSerializer(Json { serializersModule = SolidManager.serialModule })
|
serializer = KotlinxSerializer(Json { serializersModule = SolidManager.serializersModule })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package ru.mipt.npm.muon.monitor
|
package ru.mipt.npm.muon.monitor
|
||||||
|
|
||||||
import hep.dataforge.js.requireJS
|
|
||||||
|
|
||||||
actual fun readResource(path: String): String {
|
actual fun readResource(path: String): String {
|
||||||
return requireJS(path) as String
|
return kotlinext.js.require(path) as String
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO replace by resource
|
// TODO replace by resource
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package hep.dataforge.vision.bootstrap
|
package hep.dataforge.vision.bootstrap
|
||||||
|
|
||||||
import hep.dataforge.js.requireJS
|
|
||||||
import hep.dataforge.meta.DFExperimental
|
import hep.dataforge.meta.DFExperimental
|
||||||
import hep.dataforge.vision.solid.SolidGroup
|
import hep.dataforge.vision.solid.SolidGroup
|
||||||
import hep.dataforge.vision.solid.SolidManager
|
import hep.dataforge.vision.solid.SolidManager
|
||||||
@ -27,7 +26,7 @@ private fun saveData(event: Event, fileName: String, mimeType: String = "text/pl
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
val fileSaver = requireJS("file-saver")
|
val fileSaver = kotlinext.js.require("file-saver")
|
||||||
val blob = Blob(arrayOf(dataBuilder()), BlobPropertyBag("$mimeType;charset=utf-8"))
|
val blob = Blob(arrayOf(dataBuilder()), BlobPropertyBag("$mimeType;charset=utf-8"))
|
||||||
fileSaver.saveAs(blob, fileName)
|
fileSaver.saveAs(blob, fileName)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import org.w3c.dom.Element
|
|||||||
import react.RBuilder
|
import react.RBuilder
|
||||||
import react.dom.render
|
import react.dom.render
|
||||||
|
|
||||||
fun RBuilder.visionPropertyEditor(
|
public fun RBuilder.visionPropertyEditor(
|
||||||
item: Vision,
|
item: Vision,
|
||||||
descriptor: NodeDescriptor? = item.descriptor,
|
descriptor: NodeDescriptor? = item.descriptor,
|
||||||
default: Meta? = null,
|
default: Meta? = null,
|
||||||
@ -36,7 +36,7 @@ fun RBuilder.visionPropertyEditor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Element.visionPropertyEditor(
|
public fun Element.visionPropertyEditor(
|
||||||
item: Vision,
|
item: Vision,
|
||||||
descriptor: NodeDescriptor? = item.descriptor,
|
descriptor: NodeDescriptor? = item.descriptor,
|
||||||
default: Meta? = null
|
default: Meta? = null
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package ringui
|
package ringui
|
||||||
|
|
||||||
import ringui.header.HeaderProps
|
|
||||||
import react.RClass
|
import react.RClass
|
||||||
|
import ringui.header.HeaderProps
|
||||||
|
|
||||||
@JsModule("@jetbrains/ring-ui")
|
@JsModule("@jetbrains/ring-ui")
|
||||||
external object RingUI {
|
external object RingUI {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package ringui.header
|
package ringui.header
|
||||||
|
|
||||||
import ringui.RingUI
|
|
||||||
import react.RBuilder
|
import react.RBuilder
|
||||||
import react.RClass
|
import react.RClass
|
||||||
import react.RHandler
|
import react.RHandler
|
||||||
import react.dom.WithClassName
|
import react.dom.WithClassName
|
||||||
|
import ringui.RingUI
|
||||||
|
|
||||||
@JsModule("@jetbrains/ring-ui/components/header/header")
|
@JsModule("@jetbrains/ring-ui/components/header/header")
|
||||||
internal external object HeaderModule {
|
internal external object HeaderModule {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package ringui.header
|
package ringui.header
|
||||||
|
|
||||||
import ringui.IconProps
|
|
||||||
import kotlinx.html.A
|
import kotlinx.html.A
|
||||||
import react.RElementBuilder
|
import react.RElementBuilder
|
||||||
import react.RHandler
|
import react.RHandler
|
||||||
|
import ringui.IconProps
|
||||||
import styled.StyledDOMBuilder
|
import styled.StyledDOMBuilder
|
||||||
|
|
||||||
external interface HeaderLogoProps : IconProps
|
external interface HeaderLogoProps : IconProps
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package ringui.header
|
package ringui.header
|
||||||
|
|
||||||
import ringui.ButtonProps
|
|
||||||
import react.RElementBuilder
|
import react.RElementBuilder
|
||||||
import react.RHandler
|
import react.RHandler
|
||||||
import react.dom.WithClassName
|
import react.dom.WithClassName
|
||||||
|
import ringui.ButtonProps
|
||||||
|
|
||||||
// https://github.com/JetBrains/ring-ui/blob/master/components/header/tray.js
|
// https://github.com/JetBrains/ring-ui/blob/master/components/header/tray.js
|
||||||
external interface HeaderTrayProps : WithClassName
|
external interface HeaderTrayProps : WithClassName
|
||||||
|
@ -7,7 +7,6 @@ val kotlinWrappersVersion: String by rootProject.extra
|
|||||||
|
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package hep.dataforge.properties
|
|
||||||
|
|
||||||
import hep.dataforge.meta.*
|
|
||||||
import hep.dataforge.names.Name
|
|
||||||
|
|
||||||
@DFExperimental
|
|
||||||
internal class ConfigProperty(val config: Config, val name: Name) : Property<MetaItem<*>?> {
|
|
||||||
override var value: MetaItem<*>?
|
|
||||||
get() = config[name]
|
|
||||||
set(value) {
|
|
||||||
config[name] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onChange(owner: Any?, callback: (MetaItem<*>?) -> Unit) {
|
|
||||||
config.onChange(owner) { name, oldItem, newItem ->
|
|
||||||
if (name == this.name && oldItem != newItem) callback(newItem)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun removeChangeListener(owner: Any?) {
|
|
||||||
config.removeListener(owner)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
package hep.dataforge.properties
|
|
||||||
|
|
||||||
import hep.dataforge.meta.DFExperimental
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.channels.awaitClose
|
|
||||||
import kotlinx.coroutines.flow.callbackFlow
|
|
||||||
import kotlinx.coroutines.flow.collect
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
//TODO move to core
|
|
||||||
|
|
||||||
@DFExperimental
|
|
||||||
interface Property<T> {
|
|
||||||
var value: T
|
|
||||||
|
|
||||||
fun onChange(owner: Any? = null, callback: (T) -> Unit)
|
|
||||||
fun removeChangeListener(owner: Any? = null)
|
|
||||||
}
|
|
||||||
|
|
||||||
@DFExperimental
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
fun <T> Property<T>.flow() = callbackFlow<T> {
|
|
||||||
send(value)
|
|
||||||
onChange(this) {
|
|
||||||
//TODO add exception handler?
|
|
||||||
launch {
|
|
||||||
send(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
awaitClose { removeChangeListener(this) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reflect all changes in the [source] property onto this property
|
|
||||||
*
|
|
||||||
* @return a mirroring job
|
|
||||||
*/
|
|
||||||
@DFExperimental
|
|
||||||
fun <T> Property<T>.mirror(source: Property<T>, scope: CoroutineScope): Job {
|
|
||||||
return scope.launch {
|
|
||||||
source.flow().collect {
|
|
||||||
value = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bi-directional connection between properties
|
|
||||||
*/
|
|
||||||
@DFExperimental
|
|
||||||
fun <T> Property<T>.bind(other: Property<T>) {
|
|
||||||
onChange(other) {
|
|
||||||
other.value = it
|
|
||||||
}
|
|
||||||
other.onChange {
|
|
||||||
this.value = it
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,6 +6,7 @@ import hep.dataforge.names.Name
|
|||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
import hep.dataforge.values.ValueType
|
import hep.dataforge.values.ValueType
|
||||||
import hep.dataforge.vision.Vision.Companion.STYLE_KEY
|
import hep.dataforge.vision.Vision.Companion.STYLE_KEY
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
|
|
||||||
internal data class PropertyListener(
|
internal data class PropertyListener(
|
||||||
@ -13,7 +14,8 @@ internal data class PropertyListener(
|
|||||||
val action: (name: Name) -> Unit
|
val action: (name: Name) -> Unit
|
||||||
)
|
)
|
||||||
|
|
||||||
abstract class AbstractVision : Vision {
|
@Serializable
|
||||||
|
public open class AbstractVision : Vision {
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
override var parent: VisionGroup? = null
|
override var parent: VisionGroup? = null
|
||||||
@ -21,7 +23,7 @@ abstract class AbstractVision : Vision {
|
|||||||
/**
|
/**
|
||||||
* Object own properties excluding styles and inheritance
|
* Object own properties excluding styles and inheritance
|
||||||
*/
|
*/
|
||||||
abstract override var properties: Config?
|
override var properties: Config? = null
|
||||||
protected set
|
protected set
|
||||||
|
|
||||||
protected fun updateStyles(names: List<String>) {
|
protected fun updateStyles(names: List<String>) {
|
||||||
|
@ -9,6 +9,7 @@ import hep.dataforge.values.asValue
|
|||||||
import hep.dataforge.vision.Vision.Companion.TYPE
|
import hep.dataforge.vision.Vision.Companion.TYPE
|
||||||
import hep.dataforge.vision.Vision.Companion.VISIBLE_KEY
|
import hep.dataforge.vision.Vision.Companion.VISIBLE_KEY
|
||||||
import kotlinx.serialization.PolymorphicSerializer
|
import kotlinx.serialization.PolymorphicSerializer
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
package hep.dataforge.js
|
package hep.dataforge.js
|
||||||
|
|
||||||
import kotlin.browser.document
|
import kotlinx.browser.document
|
||||||
import kotlin.dom.hasClass
|
import kotlinx.dom.hasClass
|
||||||
|
|
||||||
external val module: Module
|
|
||||||
|
|
||||||
external interface Hot {
|
public external val module: Module
|
||||||
val data: dynamic
|
|
||||||
|
|
||||||
fun accept()
|
public external interface Hot {
|
||||||
fun accept(dependency: String, callback: () -> Unit)
|
public val data: dynamic
|
||||||
fun accept(dependencies: Array<String>, callback: (updated: Array<String>) -> Unit)
|
|
||||||
|
|
||||||
fun dispose(callback: (data: dynamic) -> Unit)
|
public fun accept()
|
||||||
|
public fun accept(dependency: String, callback: () -> Unit)
|
||||||
|
public fun accept(dependencies: Array<String>, callback: (updated: Array<String>) -> Unit)
|
||||||
|
|
||||||
|
public fun dispose(callback: (data: dynamic) -> Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
external interface Module {
|
public external interface Module {
|
||||||
val hot: Hot?
|
public val hot: Hot?
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,21 +25,21 @@ external interface Module {
|
|||||||
*
|
*
|
||||||
* Base interface for applications supporting Hot Module Replacement (HMR).
|
* Base interface for applications supporting Hot Module Replacement (HMR).
|
||||||
*/
|
*/
|
||||||
interface Application {
|
public interface Application {
|
||||||
/**
|
/**
|
||||||
* Starting point for an application.
|
* Starting point for an application.
|
||||||
* @param state Initial state between Hot Module Replacement (HMR).
|
* @param state Initial state between Hot Module Replacement (HMR).
|
||||||
*/
|
*/
|
||||||
fun start(state: Map<String, Any>)
|
public fun start(state: Map<String, Any>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ending point for an application.
|
* Ending point for an application.
|
||||||
* @return final state for Hot Module Replacement (HMR).
|
* @return final state for Hot Module Replacement (HMR).
|
||||||
*/
|
*/
|
||||||
fun dispose(): Map<String, Any> = emptyMap()
|
public fun dispose(): Map<String, Any> = emptyMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startApplication(builder: () -> Application) {
|
public fun startApplication(builder: () -> Application) {
|
||||||
fun start(state: dynamic): Application? {
|
fun start(state: dynamic): Application? {
|
||||||
return if (document.body?.hasClass("application") == true) {
|
return if (document.body?.hasClass("application") == true) {
|
||||||
val application = builder()
|
val application = builder()
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
package hep.dataforge.js
|
|
||||||
|
|
||||||
import hep.dataforge.meta.DFExperimental
|
|
||||||
import hep.dataforge.properties.Property
|
|
||||||
import org.w3c.dom.HTMLInputElement
|
|
||||||
|
|
||||||
@DFExperimental
|
|
||||||
fun HTMLInputElement.bindValue(property: Property<String>) {
|
|
||||||
if (this.onchange != null) error("Input element already bound")
|
|
||||||
this.onchange = {
|
|
||||||
property.value = this.value
|
|
||||||
Unit
|
|
||||||
}
|
|
||||||
property.onChange(this) {
|
|
||||||
if (value != it) {
|
|
||||||
value = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@DFExperimental
|
|
||||||
fun HTMLInputElement.bindChecked(property: Property<Boolean>) {
|
|
||||||
if (this.onchange != null) error("Input element already bound")
|
|
||||||
this.onchange = {
|
|
||||||
property.value = this.checked
|
|
||||||
Unit
|
|
||||||
}
|
|
||||||
property.onChange(this) {
|
|
||||||
if (checked != it) {
|
|
||||||
checked = it
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package hep.dataforge.js
|
|
||||||
|
|
||||||
@JsName("require")
|
|
||||||
external fun requireJS(name: String): dynamic
|
|
||||||
|
|
||||||
inline fun <T : Any> jsObject(builder: T.() -> Unit): T {
|
|
||||||
val obj: T = js("({})") as T
|
|
||||||
return obj.apply {
|
|
||||||
builder()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun js(builder: dynamic.() -> Unit): dynamic = jsObject(builder)
|
|
||||||
|
|
||||||
fun toPlainObjectStripNull(obj: Any) = js {
|
|
||||||
for (key in Object.keys(obj)) {
|
|
||||||
val value = obj.asDynamic()[key]
|
|
||||||
if (value != null) this[key] = value
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +1,38 @@
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
//import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("ru.mipt.npm.mpp")
|
id("ru.mipt.npm.mpp")
|
||||||
application
|
// application
|
||||||
}
|
}
|
||||||
|
|
||||||
val ktorVersion: String by rootProject.extra
|
val ktorVersion: String by rootProject.extra
|
||||||
|
|
||||||
kscience {
|
//kscience {
|
||||||
application()
|
// application()
|
||||||
}
|
//}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
afterEvaluate {
|
// afterEvaluate {
|
||||||
val jsBrowserDistribution by tasks.getting
|
// val jsBrowserDistribution by tasks.getting
|
||||||
|
//
|
||||||
jvm {
|
// jvm {
|
||||||
withJava()
|
// withJava()
|
||||||
compilations[MAIN_COMPILATION_NAME]?.apply {
|
// compilations[MAIN_COMPILATION_NAME]?.apply {
|
||||||
tasks.getByName<ProcessResources>(processResourcesTaskName) {
|
// tasks.getByName<ProcessResources>(processResourcesTaskName) {
|
||||||
dependsOn(jsBrowserDistribution)
|
// dependsOn(jsBrowserDistribution)
|
||||||
afterEvaluate {
|
// afterEvaluate {
|
||||||
from(jsBrowserDistribution)
|
// from(jsBrowserDistribution)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":visionforge-solid"))
|
implementation(project(":visionforge-core"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jvmMain {
|
jvmMain {
|
||||||
@ -50,9 +50,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
|
||||||
mainClass.set("ru.mipt.npm.muon.monitor.server.MMServerKt")
|
|
||||||
}
|
|
||||||
|
|
||||||
//distributions {
|
//distributions {
|
||||||
// main {
|
// main {
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
|
import hep.dataforge.vision.AbstractVision
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.UseSerializers
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
public open class AbstractSolid: AbstractVision(), Solid {
|
||||||
|
@Serializable(Point3DSerializer::class)
|
||||||
|
override var position: Point3D? = null
|
||||||
|
|
||||||
|
@Serializable(Point3DSerializer::class)
|
||||||
|
override var rotation: Point3D? = null
|
||||||
|
|
||||||
|
@Serializable(Point3DSerializer::class)
|
||||||
|
override var scale: Point3D? = null
|
||||||
|
}
|
@ -18,13 +18,7 @@ public class Box(
|
|||||||
public val xSize: Float,
|
public val xSize: Float,
|
||||||
public val ySize: Float,
|
public val ySize: Float,
|
||||||
public val zSize: Float
|
public val zSize: Float
|
||||||
) : AbstractVision(), GeometrySolid {
|
) : AbstractSolid(), GeometrySolid {
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
//TODO add helper for color configuration
|
//TODO add helper for color configuration
|
||||||
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
||||||
|
@ -22,19 +22,13 @@ public class Composite(
|
|||||||
public val compositeType: CompositeType,
|
public val compositeType: CompositeType,
|
||||||
public val first: Solid,
|
public val first: Solid,
|
||||||
public val second: Solid
|
public val second: Solid
|
||||||
) : AbstractVision(), Solid, VisionGroup {
|
) : AbstractSolid(), Solid, VisionGroup {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
first.parent = this
|
first.parent = this
|
||||||
second.parent = this
|
second.parent = this
|
||||||
}
|
}
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
override val children: Map<NameToken, Vision>
|
override val children: Map<NameToken, Vision>
|
||||||
get() = mapOf(NameToken("first") to first, NameToken("second") to second)
|
get() = mapOf(NameToken("first") to first, NameToken("second") to second)
|
||||||
|
|
||||||
|
@ -24,13 +24,7 @@ public class ConeSegment(
|
|||||||
public var upperRadius: Float,
|
public var upperRadius: Float,
|
||||||
public var startAngle: Float = 0f,
|
public var startAngle: Float = 0f,
|
||||||
public var angle: Float = PI2
|
public var angle: Float = PI2
|
||||||
) : AbstractVision(), GeometrySolid {
|
) : AbstractSolid(), GeometrySolid {
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
||||||
val segments = detail ?: 8
|
val segments = detail ?: 8
|
||||||
|
@ -13,16 +13,7 @@ import kotlinx.serialization.UseSerializers
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("solid.convex")
|
@SerialName("solid.convex")
|
||||||
public class Convex(public val points: List<Point3D>) : AbstractVision(), Solid {
|
public class Convex(public val points: List<Point3D>) : AbstractSolid(), Solid
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public inline fun VisionContainerBuilder<Solid>.convex(name: String = "", action: ConvexBuilder.() -> Unit = {}): Convex =
|
public inline fun VisionContainerBuilder<Solid>.convex(name: String = "", action: ConvexBuilder.() -> Unit = {}): Convex =
|
||||||
ConvexBuilder().apply(action).build().also { set(name, it) }
|
ConvexBuilder().apply(action).build().also { set(name, it) }
|
||||||
|
@ -44,13 +44,7 @@ public data class Layer(var x: Float, var y: Float, var z: Float, var scale: Flo
|
|||||||
public class Extruded(
|
public class Extruded(
|
||||||
public var shape: List<Point2D> = ArrayList(),
|
public var shape: List<Point2D> = ArrayList(),
|
||||||
public var layers: MutableList<Layer> = ArrayList()
|
public var layers: MutableList<Layer> = ArrayList()
|
||||||
) : AbstractVision(), GeometrySolid {
|
) : AbstractSolid(), GeometrySolid {
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
public fun shape(block: Shape2DBuilder.() -> Unit) {
|
public fun shape(block: Shape2DBuilder.() -> Unit) {
|
||||||
this.shape = Shape2DBuilder().apply(block).build()
|
this.shape = Shape2DBuilder().apply(block).build()
|
||||||
|
@ -2,13 +2,10 @@
|
|||||||
|
|
||||||
package hep.dataforge.vision.solid
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
|
||||||
import hep.dataforge.meta.number
|
import hep.dataforge.meta.number
|
||||||
import hep.dataforge.names.Name
|
import hep.dataforge.names.Name
|
||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
import hep.dataforge.names.plus
|
import hep.dataforge.names.plus
|
||||||
import hep.dataforge.vision.AbstractVision
|
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
|
||||||
import hep.dataforge.vision.VisionContainerBuilder
|
import hep.dataforge.vision.VisionContainerBuilder
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
@ -17,12 +14,7 @@ import kotlinx.serialization.UseSerializers
|
|||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("solid.line")
|
@SerialName("solid.line")
|
||||||
public class PolyLine(public var points: List<Point3D>) : AbstractVision(), Solid {
|
public class PolyLine(public var points: List<Point3D>) : AbstractSolid(), Solid {
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
//var lineType by string()
|
//var lineType by string()
|
||||||
public var thickness: Number by number(1.0, key = SolidMaterial.MATERIAL_KEY + THICKNESS_KEY)
|
public var thickness: Number by number(1.0, key = SolidMaterial.MATERIAL_KEY + THICKNESS_KEY)
|
||||||
@ -33,5 +25,9 @@ public class PolyLine(public var points: List<Point3D>) : AbstractVision(), Soli
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun VisionContainerBuilder<Solid>.polyline(vararg points: Point3D, name: String = "", action: PolyLine.() -> Unit = {}): PolyLine =
|
public fun VisionContainerBuilder<Solid>.polyline(
|
||||||
|
vararg points: Point3D,
|
||||||
|
name: String = "",
|
||||||
|
action: PolyLine.() -> Unit = {},
|
||||||
|
): PolyLine =
|
||||||
PolyLine(points.toList()).apply(action).also { set(name, it) }
|
PolyLine(points.toList()).apply(action).also { set(name, it) }
|
@ -1,5 +1,3 @@
|
|||||||
@file:UseSerializers(Point3DSerializer::class)
|
|
||||||
|
|
||||||
package hep.dataforge.vision.solid
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
import hep.dataforge.meta.*
|
import hep.dataforge.meta.*
|
||||||
@ -9,10 +7,9 @@ import hep.dataforge.vision.*
|
|||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
import kotlinx.serialization.UseSerializers
|
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
public abstract class AbstractProxy : AbstractVision(), VisionGroup {
|
public abstract class AbstractProxy : AbstractSolid(), VisionGroup {
|
||||||
public abstract val prototype: Vision
|
public abstract val prototype: Vision
|
||||||
|
|
||||||
override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? {
|
override fun getProperty(name: Name, inherit: Boolean): MetaItem<*>? {
|
||||||
@ -54,19 +51,13 @@ public abstract class AbstractProxy : AbstractVision(), VisionGroup {
|
|||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("solid.proxy")
|
@SerialName("solid.proxy")
|
||||||
public class Proxy private constructor(
|
public class Proxy private constructor(
|
||||||
public val templateName: Name
|
public val templateName: Name,
|
||||||
) : AbstractProxy(), Solid {
|
) : AbstractProxy(), Solid {
|
||||||
|
|
||||||
public constructor(parent: SolidGroup, templateName: Name) : this(templateName) {
|
public constructor(parent: SolidGroup, templateName: Name) : this(templateName) {
|
||||||
this.parent = parent
|
this.parent = parent
|
||||||
}
|
}
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively search for defined template in the parent
|
* Recursively search for defined template in the parent
|
||||||
*/
|
*/
|
||||||
@ -155,7 +146,7 @@ public val Vision.prototype: Vision
|
|||||||
*/
|
*/
|
||||||
public fun SolidGroup.ref(
|
public fun SolidGroup.ref(
|
||||||
templateName: Name,
|
templateName: Name,
|
||||||
name: String = ""
|
name: String = "",
|
||||||
): Proxy = Proxy(this, templateName).also { set(name, it) }
|
): Proxy = Proxy(this, templateName).also { set(name, it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -164,7 +155,7 @@ public fun SolidGroup.ref(
|
|||||||
public fun SolidGroup.proxy(
|
public fun SolidGroup.proxy(
|
||||||
name: String,
|
name: String,
|
||||||
obj: Solid,
|
obj: Solid,
|
||||||
templateName: Name = name.toName()
|
templateName: Name = name.toName(),
|
||||||
): Proxy {
|
): Proxy {
|
||||||
val existing = getPrototype(templateName)
|
val existing = getPrototype(templateName)
|
||||||
if (existing == null) {
|
if (existing == null) {
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
@file:UseSerializers(Point3DSerializer::class)
|
|
||||||
|
|
||||||
package hep.dataforge.vision.solid
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
import hep.dataforge.meta.*
|
import hep.dataforge.meta.*
|
||||||
@ -75,7 +73,7 @@ public interface Solid : Vision {
|
|||||||
|
|
||||||
item(SolidMaterial.MATERIAL_KEY.toString(), SolidMaterial.descriptor)
|
item(SolidMaterial.MATERIAL_KEY.toString(), SolidMaterial.descriptor)
|
||||||
|
|
||||||
enum<RotationOrder>(ROTATION_ORDER_KEY,default = RotationOrder.XYZ)
|
enum(ROTATION_ORDER_KEY,default = RotationOrder.XYZ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
@file:UseSerializers(
|
|
||||||
Point3DSerializer::class
|
|
||||||
)
|
|
||||||
|
|
||||||
package hep.dataforge.vision.solid
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.meta.Config
|
||||||
|
@ -1,26 +1,17 @@
|
|||||||
@file:UseSerializers(Point3DSerializer::class)
|
|
||||||
|
|
||||||
package hep.dataforge.vision.solid
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
|
||||||
import hep.dataforge.vision.AbstractVision
|
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
|
||||||
import hep.dataforge.vision.VisionContainerBuilder
|
import hep.dataforge.vision.VisionContainerBuilder
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.UseSerializers
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@SerialName("solid.label")
|
@SerialName("solid.label")
|
||||||
public class SolidLabel(public var text: String, public var fontSize: Double, public var fontFamily: String) : AbstractVision(), Solid {
|
public class SolidLabel(
|
||||||
override var properties: Config? = null
|
public var text: String,
|
||||||
|
public var fontSize: Double,
|
||||||
override var position: Point3D? = null
|
public var fontFamily: String,
|
||||||
override var rotation: Point3D? = null
|
) : AbstractSolid(), Solid
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun VisionContainerBuilder<Solid>.label(
|
public fun VisionContainerBuilder<Solid>.label(
|
||||||
text: String,
|
text: String,
|
||||||
|
@ -85,8 +85,8 @@ public class SolidManager(meta: Meta) : AbstractPlugin(meta) {
|
|||||||
override val tag: PluginTag get() = Companion.tag
|
override val tag: PluginTag get() = Companion.tag
|
||||||
|
|
||||||
override fun content(target: String): Map<Name, Any> = when (target) {
|
override fun content(target: String): Map<Name, Any> = when (target) {
|
||||||
VisionForm.TYPE -> serialModule.extractFactories().associateBy { it.name }
|
VisionForm.TYPE -> serializersModule.extractFactories().associateBy { it.name }
|
||||||
VISION_SERIAL_MODULE_TARGET -> mapOf(tag.name.toName() to serialModule)
|
VISION_SERIAL_MODULE_TARGET -> mapOf(tag.name.toName() to serializersModule)
|
||||||
else -> super.content(target)
|
else -> super.content(target)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public class SolidManager(meta: Meta) : AbstractPlugin(meta) {
|
|||||||
override val type: KClass<out SolidManager> = SolidManager::class
|
override val type: KClass<out SolidManager> = SolidManager::class
|
||||||
override fun invoke(meta: Meta, context: Context): SolidManager = SolidManager(meta)
|
override fun invoke(meta: Meta, context: Context): SolidManager = SolidManager(meta)
|
||||||
|
|
||||||
public val serialModule: SerializersModule = SerializersModule {
|
public val serializersModule: SerializersModule = SerializersModule {
|
||||||
contextual(Point3DSerializer)
|
contextual(Point3DSerializer)
|
||||||
contextual(Point2DSerializer)
|
contextual(Point2DSerializer)
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ public class SolidManager(meta: Meta) : AbstractPlugin(meta) {
|
|||||||
useArrayPolymorphism = false
|
useArrayPolymorphism = false
|
||||||
encodeDefaults = false
|
encodeDefaults = false
|
||||||
ignoreUnknownKeys = true
|
ignoreUnknownKeys = true
|
||||||
serializersModule = this@Companion.serialModule
|
serializersModule = this@Companion.serializersModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
@file:UseSerializers(Point3DSerializer::class)
|
|
||||||
|
|
||||||
package hep.dataforge.vision.solid
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
|
||||||
import hep.dataforge.vision.AbstractVision
|
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
|
||||||
import hep.dataforge.vision.VisionContainerBuilder
|
import hep.dataforge.vision.VisionContainerBuilder
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.UseSerializers
|
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
@ -21,14 +15,8 @@ public class Sphere(
|
|||||||
public var phiStart: Float = 0f,
|
public var phiStart: Float = 0f,
|
||||||
public var phi: Float = PI2,
|
public var phi: Float = PI2,
|
||||||
public var thetaStart: Float = 0f,
|
public var thetaStart: Float = 0f,
|
||||||
public var theta: Float = PI.toFloat()
|
public var theta: Float = PI.toFloat(),
|
||||||
) : AbstractVision(), GeometrySolid {
|
) : AbstractSolid(), GeometrySolid {
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
||||||
fun point3DfromSphCoord(r: Float, theta: Float, phi: Float): Point3D {
|
fun point3DfromSphCoord(r: Float, theta: Float, phi: Float): Point3D {
|
||||||
@ -38,6 +26,7 @@ public class Sphere(
|
|||||||
val x = -r * sin(theta) * cos(phi)
|
val x = -r * sin(theta) * cos(phi)
|
||||||
return Point3D(x, y, z)
|
return Point3D(x, y, z)
|
||||||
}
|
}
|
||||||
|
|
||||||
val segments = this.detail ?: 8
|
val segments = this.detail ?: 8
|
||||||
require(segments >= 4) { "The detail for sphere must be >= 4" }
|
require(segments >= 4) { "The detail for sphere must be >= 4" }
|
||||||
val phiStep = phi / segments
|
val phiStep = phi / segments
|
||||||
@ -66,7 +55,7 @@ public inline fun VisionContainerBuilder<Solid>.sphere(
|
|||||||
phi: Number = 2 * PI,
|
phi: Number = 2 * PI,
|
||||||
theta: Number = PI,
|
theta: Number = PI,
|
||||||
name: String = "",
|
name: String = "",
|
||||||
action: Sphere.() -> Unit = {}
|
action: Sphere.() -> Unit = {},
|
||||||
): Sphere = Sphere(
|
): Sphere = Sphere(
|
||||||
radius.toFloat(),
|
radius.toFloat(),
|
||||||
phi = phi.toFloat(),
|
phi = phi.toFloat(),
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
@file:UseSerializers(Point3DSerializer::class)
|
|
||||||
|
|
||||||
package hep.dataforge.vision.solid
|
package hep.dataforge.vision.solid
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
|
||||||
import hep.dataforge.vision.AbstractVision
|
|
||||||
import hep.dataforge.vision.MutableVisionGroup
|
|
||||||
import hep.dataforge.vision.VisionContainerBuilder
|
import hep.dataforge.vision.VisionContainerBuilder
|
||||||
import hep.dataforge.vision.set
|
import hep.dataforge.vision.set
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.UseSerializers
|
|
||||||
import kotlin.math.PI
|
import kotlin.math.PI
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
@ -24,14 +18,8 @@ public class Tube(
|
|||||||
public var height: Float,
|
public var height: Float,
|
||||||
public var innerRadius: Float = 0f,
|
public var innerRadius: Float = 0f,
|
||||||
public var startAngle: Float = 0f,
|
public var startAngle: Float = 0f,
|
||||||
public var angle: Float = PI2
|
public var angle: Float = PI2,
|
||||||
) : AbstractVision(), GeometrySolid {
|
) : AbstractSolid(), GeometrySolid {
|
||||||
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
require(radius > 0)
|
require(radius > 0)
|
||||||
@ -137,7 +125,7 @@ public inline fun VisionContainerBuilder<Solid>.tube(
|
|||||||
startAngle: Number = 0f,
|
startAngle: Number = 0f,
|
||||||
angle: Number = 2 * PI,
|
angle: Number = 2 * PI,
|
||||||
name: String = "",
|
name: String = "",
|
||||||
block: Tube.() -> Unit = {}
|
block: Tube.() -> Unit = {},
|
||||||
): Tube = Tube(
|
): Tube = Tube(
|
||||||
r.toFloat(),
|
r.toFloat(),
|
||||||
height.toFloat(),
|
height.toFloat(),
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package hep.dataforge.vision.solid.three
|
package hep.dataforge.vision.solid.three
|
||||||
|
|
||||||
import hep.dataforge.js.jsObject
|
|
||||||
import hep.dataforge.vision.solid.SolidLabel
|
import hep.dataforge.vision.solid.SolidLabel
|
||||||
import hep.dataforge.vision.solid.three.ThreeMaterials.getMaterial
|
import hep.dataforge.vision.solid.three.ThreeMaterials.getMaterial
|
||||||
import info.laht.threekt.core.Object3D
|
import info.laht.threekt.core.Object3D
|
||||||
import info.laht.threekt.geometries.TextBufferGeometry
|
import info.laht.threekt.geometries.TextBufferGeometry
|
||||||
import info.laht.threekt.objects.Mesh
|
import info.laht.threekt.objects.Mesh
|
||||||
|
import kotlinext.js.jsObject
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,32 +1,18 @@
|
|||||||
@file:UseSerializers(Point3DSerializer::class)
|
|
||||||
|
|
||||||
package hep.dataforge.vision.solid.three
|
package hep.dataforge.vision.solid.three
|
||||||
|
|
||||||
import hep.dataforge.meta.Config
|
import hep.dataforge.vision.solid.AbstractSolid
|
||||||
import hep.dataforge.vision.AbstractVision
|
|
||||||
import hep.dataforge.vision.solid.Point3D
|
|
||||||
import hep.dataforge.vision.solid.Point3DSerializer
|
|
||||||
import hep.dataforge.vision.solid.Solid
|
import hep.dataforge.vision.solid.Solid
|
||||||
import info.laht.threekt.core.Object3D
|
import info.laht.threekt.core.Object3D
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
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 ThreeVision : Solid {
|
public interface ThreeVision : Solid {
|
||||||
fun toObject3D(): Object3D
|
public fun toObject3D(): Object3D
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class CustomThreeVision(val threeFactory: ThreeFactory<Solid>) : AbstractVision(),
|
public class CustomThreeVision(public val threeFactory: ThreeFactory<Solid>) : AbstractSolid(), ThreeVision {
|
||||||
ThreeVision {
|
|
||||||
override var position: Point3D? = null
|
|
||||||
override var rotation: Point3D? = null
|
|
||||||
override var scale: Point3D? = null
|
|
||||||
|
|
||||||
override var properties: Config? = null
|
|
||||||
|
|
||||||
override fun toObject3D(): Object3D = threeFactory(this)
|
override fun toObject3D(): Object3D = threeFactory(this)
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user