forked from kscience/visionforge
Merged fx module into vis-common
This commit is contained in:
parent
554eaa24d8
commit
017995e045
@ -2,7 +2,7 @@ val dataforgeVersion by extra("0.1.3")
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
val kotlinVersion = "1.3.50"
|
val kotlinVersion = "1.3.50"
|
||||||
val toolsVersion = "0.2.0"
|
val toolsVersion = "0.2.1"
|
||||||
|
|
||||||
kotlin("jvm") version kotlinVersion apply false
|
kotlin("jvm") version kotlinVersion apply false
|
||||||
id("kotlin-dce-js") version kotlinVersion apply false
|
id("kotlin-dce-js") version kotlinVersion apply false
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import org.openjfx.gradle.JavaFXOptions
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("scientifik.mpp")
|
id("scientifik.mpp")
|
||||||
|
id("org.openjfx.javafxplugin")
|
||||||
}
|
}
|
||||||
|
|
||||||
scientifik{
|
scientifik{
|
||||||
@ -9,13 +12,23 @@ scientifik{
|
|||||||
val dataforgeVersion: String by rootProject.extra
|
val dataforgeVersion: String by rootProject.extra
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
jvm{
|
||||||
|
withJava()
|
||||||
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
val commonMain by getting {
|
commonMain{
|
||||||
dependencies {
|
dependencies {
|
||||||
api("hep.dataforge:dataforge-output:$dataforgeVersion")
|
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 {
|
dependencies {
|
||||||
api("hep.dataforge:dataforge-output-html:$dataforgeVersion")
|
api("hep.dataforge:dataforge-output-html:$dataforgeVersion")
|
||||||
api(npm("text-encoding"))
|
api(npm("text-encoding"))
|
||||||
@ -25,3 +38,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configure<JavaFXOptions> {
|
||||||
|
modules("javafx.controls")
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +1,5 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("scientifik.mpp")
|
id("scientifik.mpp")
|
||||||
}
|
}
|
||||||
@ -22,3 +24,9 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks{
|
||||||
|
val jsBrowserWebpack by getting(KotlinWebpack::class) {
|
||||||
|
sourceMaps = false
|
||||||
|
}
|
||||||
|
}
|
@ -19,8 +19,8 @@ import kotlin.reflect.KClass
|
|||||||
/**
|
/**
|
||||||
* Basic geometry-based factory
|
* Basic geometry-based factory
|
||||||
*/
|
*/
|
||||||
abstract class MeshThreeFactory<T : VisualObject3D>(
|
abstract class MeshThreeFactory<in T : VisualObject3D>(
|
||||||
override val type: KClass<out T>
|
override val type: KClass<in T>
|
||||||
) : ThreeFactory<T> {
|
) : ThreeFactory<T> {
|
||||||
/**
|
/**
|
||||||
* Build a geometry for an object
|
* Build a geometry for an object
|
||||||
|
@ -16,9 +16,9 @@ import kotlin.reflect.KClass
|
|||||||
* Builder and updater for three.js object
|
* Builder and updater for three.js object
|
||||||
*/
|
*/
|
||||||
@Type(TYPE)
|
@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
|
operator fun invoke(obj: T): Object3D
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ interface ThreeFactory<T : VisualObject3D> {
|
|||||||
/**
|
/**
|
||||||
* Update position, rotation and visibility
|
* Update position, rotation and visibility
|
||||||
*/
|
*/
|
||||||
internal fun Object3D.updatePosition(obj: VisualObject3D) {
|
fun Object3D.updatePosition(obj: VisualObject3D) {
|
||||||
visible = obj.visible ?: true
|
visible = obj.visible ?: true
|
||||||
position.set(obj.x, obj.y, obj.z)
|
position.set(obj.x, obj.y, obj.z)
|
||||||
setRotationFromEuler(obj.euler)
|
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) {
|
fun Object3D.updateProperty(source: VisualObject, propertyName: Name) {
|
||||||
if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) {
|
if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) {
|
||||||
//updated material
|
//updated material
|
||||||
|
@ -10,6 +10,9 @@ import info.laht.threekt.core.Face3
|
|||||||
import info.laht.threekt.core.Geometry
|
import info.laht.threekt.core.Geometry
|
||||||
import info.laht.threekt.math.Vector3
|
import info.laht.threekt.math.Vector3
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of geometry builder for Three.js [BufferGeometry]
|
||||||
|
*/
|
||||||
class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
|
class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
|
||||||
|
|
||||||
private val vertices = ArrayList<Point3D>()
|
private val vertices = ArrayList<Point3D>()
|
||||||
|
@ -9,7 +9,7 @@ import info.laht.threekt.objects.LineSegments
|
|||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
object ThreeLineFactory : ThreeFactory<PolyLine> {
|
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 {
|
override fun invoke(obj: PolyLine): Object3D {
|
||||||
val geometry = Geometry().apply {
|
val geometry = Geometry().apply {
|
||||||
|
@ -5,11 +5,16 @@ import hep.dataforge.meta.*
|
|||||||
import hep.dataforge.output.Output
|
import hep.dataforge.output.Output
|
||||||
import hep.dataforge.vis.common.Colors
|
import hep.dataforge.vis.common.Colors
|
||||||
import hep.dataforge.vis.spatial.VisualObject3D
|
import hep.dataforge.vis.spatial.VisualObject3D
|
||||||
|
import hep.dataforge.vis.spatial.World
|
||||||
import info.laht.threekt.WebGLRenderer
|
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.helpers.AxesHelper
|
||||||
import info.laht.threekt.lights.AmbientLight
|
import info.laht.threekt.lights.AmbientLight
|
||||||
import info.laht.threekt.scenes.Scene
|
import info.laht.threekt.scenes.Scene
|
||||||
import org.w3c.dom.HTMLElement
|
import org.w3c.dom.HTMLElement
|
||||||
|
import org.w3c.dom.Node
|
||||||
import kotlin.browser.window
|
import kotlin.browser.window
|
||||||
import kotlin.dom.clear
|
import kotlin.dom.clear
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
@ -28,7 +33,28 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<V
|
|||||||
add(axes)
|
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) {
|
fun attach(element: HTMLElement) {
|
||||||
element.clear()
|
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() {
|
fun animate() {
|
||||||
window.requestAnimationFrame {
|
window.requestAnimationFrame {
|
||||||
|
@ -4,18 +4,14 @@ import hep.dataforge.context.AbstractPlugin
|
|||||||
import hep.dataforge.context.PluginFactory
|
import hep.dataforge.context.PluginFactory
|
||||||
import hep.dataforge.context.PluginTag
|
import hep.dataforge.context.PluginTag
|
||||||
import hep.dataforge.context.content
|
import hep.dataforge.context.content
|
||||||
import hep.dataforge.meta.*
|
import hep.dataforge.meta.Meta
|
||||||
import hep.dataforge.names.Name
|
import hep.dataforge.names.Name
|
||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
import hep.dataforge.names.isEmpty
|
import hep.dataforge.names.isEmpty
|
||||||
import hep.dataforge.names.startsWith
|
import hep.dataforge.names.startsWith
|
||||||
|
import hep.dataforge.vis.common.VisualObject
|
||||||
import hep.dataforge.vis.spatial.*
|
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.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.collections.set
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import info.laht.threekt.objects.Group as ThreeGroup
|
import info.laht.threekt.objects.Group as ThreeGroup
|
||||||
@ -23,7 +19,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 VisualObject>, ThreeFactory<*>>()
|
||||||
private val compositeFactory = ThreeCompositeFactory(this)
|
private val compositeFactory = ThreeCompositeFactory(this)
|
||||||
private val proxyFactory = ThreeProxyFactory(this)
|
private val proxyFactory = ThreeProxyFactory(this)
|
||||||
|
|
||||||
@ -36,7 +32,7 @@ class ThreePlugin : AbstractPlugin() {
|
|||||||
objectFactories[PolyLine::class] = ThreeLineFactory
|
objectFactories[PolyLine::class] = ThreeLineFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun findObjectFactory(type: KClass<out VisualObject3D>): ThreeFactory<*>? {
|
private fun findObjectFactory(type: KClass<out VisualObject>): ThreeFactory<*>? {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
@ -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> {
|
companion object : PluginFactory<ThreePlugin> {
|
||||||
override val tag = PluginTag("visual.three", PluginTag.DATAFORGE_GROUP)
|
override val tag = PluginTag("visual.three", PluginTag.DATAFORGE_GROUP)
|
||||||
override val type = ThreePlugin::class
|
override val type = ThreePlugin::class
|
||||||
|
Loading…
Reference in New Issue
Block a user