Merged fx module into vis-common

This commit is contained in:
Alexander Nozik 2019-10-12 17:17:05 +03:00
parent 554eaa24d8
commit 017995e045
22 changed files with 73 additions and 64 deletions

View File

@ -2,7 +2,7 @@ val dataforgeVersion by extra("0.1.3")
plugins {
val kotlinVersion = "1.3.50"
val toolsVersion = "0.2.0"
val toolsVersion = "0.2.1"
kotlin("jvm") version kotlinVersion apply false
id("kotlin-dce-js") version kotlinVersion apply false

View File

@ -1,5 +1,8 @@
import org.openjfx.gradle.JavaFXOptions
plugins {
id("scientifik.mpp")
id("org.openjfx.javafxplugin")
}
scientifik{
@ -9,13 +12,23 @@ scientifik{
val dataforgeVersion: String by rootProject.extra
kotlin {
jvm{
withJava()
}
sourceSets {
val commonMain by getting {
commonMain{
dependencies {
api("hep.dataforge:dataforge-output:$dataforgeVersion")
}
}
val jsMain by getting {
jvmMain{
dependencies {
api("no.tornado:tornadofx:1.7.19")
api("no.tornado:tornadofx-controlsfx:0.1")
}
}
jsMain{
dependencies {
api("hep.dataforge:dataforge-output-html:$dataforgeVersion")
api(npm("text-encoding"))
@ -25,3 +38,7 @@ kotlin {
}
}
}
configure<JavaFXOptions> {
modules("javafx.controls")
}

View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -1,23 +0,0 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.openjfx.gradle.JavaFXOptions
plugins {
id("scientifik.jvm")
id("org.openjfx.javafxplugin")
}
dependencies {
api(project(":dataforge-vis-common"))
api("no.tornado:tornadofx:1.7.19")
api("no.tornado:tornadofx-controlsfx:0.1")
}
configure<JavaFXOptions> {
modules("javafx.controls")
}
tasks.withType<KotlinCompile> {
kotlinOptions{
jvmTarget = "1.8"
}
}

View File

@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
plugins {
id("scientifik.mpp")
}
@ -22,3 +24,9 @@ kotlin {
}
}
}
tasks{
val jsBrowserWebpack by getting(KotlinWebpack::class) {
sourceMaps = false
}
}

View File

@ -19,8 +19,8 @@ import kotlin.reflect.KClass
/**
* Basic geometry-based factory
*/
abstract class MeshThreeFactory<T : VisualObject3D>(
override val type: KClass<out T>
abstract class MeshThreeFactory<in T : VisualObject3D>(
override val type: KClass<in T>
) : ThreeFactory<T> {
/**
* Build a geometry for an object

View File

@ -16,9 +16,9 @@ import kotlin.reflect.KClass
* Builder and updater for three.js object
*/
@Type(TYPE)
interface ThreeFactory<T : VisualObject3D> {
interface ThreeFactory<in T : VisualObject> {
val type: KClass<out T>
val type: KClass<in T>
operator fun invoke(obj: T): Object3D
@ -30,7 +30,7 @@ interface ThreeFactory<T : VisualObject3D> {
/**
* Update position, rotation and visibility
*/
internal fun Object3D.updatePosition(obj: VisualObject3D) {
fun Object3D.updatePosition(obj: VisualObject3D) {
visible = obj.visible ?: true
position.set(obj.x, obj.y, obj.z)
setRotationFromEuler(obj.euler)
@ -50,6 +50,9 @@ operator fun <T : VisualObject3D> ThreeFactory<T>.invoke(obj: Any): Object3D {
}
}
/**
* Update non-position non-geometry property
*/
fun Object3D.updateProperty(source: VisualObject, propertyName: Name) {
if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) {
//updated material

View File

@ -10,6 +10,9 @@ import info.laht.threekt.core.Face3
import info.laht.threekt.core.Geometry
import info.laht.threekt.math.Vector3
/**
* An implementation of geometry builder for Three.js [BufferGeometry]
*/
class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
private val vertices = ArrayList<Point3D>()

View File

@ -9,7 +9,7 @@ import info.laht.threekt.objects.LineSegments
import kotlin.reflect.KClass
object ThreeLineFactory : ThreeFactory<PolyLine> {
override val type: KClass<out PolyLine> get() = PolyLine::class
override val type: KClass<PolyLine> get() = PolyLine::class
override fun invoke(obj: PolyLine): Object3D {
val geometry = Geometry().apply {

View File

@ -5,11 +5,16 @@ import hep.dataforge.meta.*
import hep.dataforge.output.Output
import hep.dataforge.vis.common.Colors
import hep.dataforge.vis.spatial.VisualObject3D
import hep.dataforge.vis.spatial.World
import info.laht.threekt.WebGLRenderer
import info.laht.threekt.cameras.PerspectiveCamera
import info.laht.threekt.external.controls.OrbitControls
import info.laht.threekt.external.controls.TrackballControls
import info.laht.threekt.helpers.AxesHelper
import info.laht.threekt.lights.AmbientLight
import info.laht.threekt.scenes.Scene
import org.w3c.dom.HTMLElement
import org.w3c.dom.Node
import kotlin.browser.window
import kotlin.dom.clear
import kotlin.math.max
@ -28,7 +33,28 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<V
add(axes)
}
val camera = three.buildCamera(meta["camera"].node ?: EmptyMeta)
private fun buildCamera(meta: Meta) = PerspectiveCamera(
meta["fov"].int ?: 75,
meta["aspect"].double ?: 1.0,
meta["nearClip"].double ?: World.CAMERA_NEAR_CLIP,
meta["farClip"].double ?: World.CAMERA_FAR_CLIP
).apply {
position.setZ(World.CAMERA_INITIAL_DISTANCE)
rotation.set(
World.CAMERA_INITIAL_X_ANGLE,
World.CAMERA_INITIAL_Y_ANGLE,
World.CAMERA_INITIAL_Z_ANGLE
)
}
val camera = buildCamera(meta["camera"].node ?: EmptyMeta)
private fun addControls(element: Node, meta: Meta) {
when (meta["type"].string) {
"trackball" -> TrackballControls(camera, element)
else -> OrbitControls(camera, element)
}
}
fun attach(element: HTMLElement) {
element.clear()
@ -40,7 +66,7 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<V
}
three.addControls(camera, renderer.domElement, meta["controls"].node ?: EmptyMeta)
addControls(renderer.domElement, meta["controls"].node ?: EmptyMeta)
fun animate() {
window.requestAnimationFrame {

View File

@ -4,18 +4,14 @@ import hep.dataforge.context.AbstractPlugin
import hep.dataforge.context.PluginFactory
import hep.dataforge.context.PluginTag
import hep.dataforge.context.content
import hep.dataforge.meta.*
import hep.dataforge.meta.Meta
import hep.dataforge.names.Name
import hep.dataforge.names.asName
import hep.dataforge.names.isEmpty
import hep.dataforge.names.startsWith
import hep.dataforge.vis.common.VisualObject
import hep.dataforge.vis.spatial.*
import info.laht.threekt.cameras.Camera
import info.laht.threekt.cameras.PerspectiveCamera
import info.laht.threekt.core.Object3D
import info.laht.threekt.external.controls.OrbitControls
import info.laht.threekt.external.controls.TrackballControls
import org.w3c.dom.Node
import kotlin.collections.set
import kotlin.reflect.KClass
import info.laht.threekt.objects.Group as ThreeGroup
@ -23,7 +19,7 @@ import info.laht.threekt.objects.Group as ThreeGroup
class ThreePlugin : AbstractPlugin() {
override val tag: PluginTag get() = Companion.tag
private val objectFactories = HashMap<KClass<out VisualObject3D>, ThreeFactory<*>>()
private val objectFactories = HashMap<KClass<out VisualObject>, ThreeFactory<*>>()
private val compositeFactory = ThreeCompositeFactory(this)
private val proxyFactory = ThreeProxyFactory(this)
@ -36,7 +32,7 @@ class ThreePlugin : AbstractPlugin() {
objectFactories[PolyLine::class] = ThreeLineFactory
}
private fun findObjectFactory(type: KClass<out VisualObject3D>): ThreeFactory<*>? {
private fun findObjectFactory(type: KClass<out VisualObject>): ThreeFactory<*>? {
return objectFactories[type]
?: context.content<ThreeFactory<*>>(ThreeFactory.TYPE).values.find { it.type == type }
}
@ -89,27 +85,6 @@ class ThreePlugin : AbstractPlugin() {
}
}
fun buildCamera(meta: Meta) = PerspectiveCamera(
meta["fov"].int ?: 75,
meta["aspect"].double ?: 1.0,
meta["nearClip"].double ?: World.CAMERA_NEAR_CLIP,
meta["farClip"].double ?: World.CAMERA_FAR_CLIP
).apply {
position.setZ(World.CAMERA_INITIAL_DISTANCE)
rotation.set(
World.CAMERA_INITIAL_X_ANGLE,
World.CAMERA_INITIAL_Y_ANGLE,
World.CAMERA_INITIAL_Z_ANGLE
)
}
fun addControls(camera: Camera, element: Node, meta: Meta) {
when (meta["type"].string) {
"trackball" -> TrackballControls(camera, element)
else -> OrbitControls(camera, element)
}
}
companion object : PluginFactory<ThreePlugin> {
override val tag = PluginTag("visual.three", PluginTag.DATAFORGE_GROUP)
override val type = ThreePlugin::class