Build fixed. JS visualization loop added

This commit is contained in:
Alexander Nozik 2019-03-07 09:52:04 +03:00
parent ec01b0d7a8
commit f8266d35c2
13 changed files with 195 additions and 134 deletions

View File

@ -1,4 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript { buildscript {
val kotlinVersion: String by rootProject.extra("1.3.21") val kotlinVersion: String by rootProject.extra("1.3.21")
@ -39,7 +40,7 @@ allprojects {
} }
group = "hep.dataforge" group = "hep.dataforge"
version = "0.1.1-dev-4" version = "0.1.1-dev-5"
// apply bintray configuration // apply bintray configuration
apply(from = "${rootProject.rootDir}/gradle/bintray.gradle") apply(from = "${rootProject.rootDir}/gradle/bintray.gradle")
@ -50,42 +51,6 @@ allprojects {
} }
subprojects { subprojects {
extensions.findByType<KotlinMultiplatformExtension>()?.apply {
jvm {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
js{
configure(listOf(compilations["main"], compilations["test"])) {
tasks.getByName(compileKotlinTaskName) {
kotlinOptions {
metaInfo = true
sourceMap = true
sourceMapEmbedSources = "always"
moduleKind = "umd"
}
}
}
configure(listOf(compilations["main"])) {
tasks.getByName(compileKotlinTaskName) {
kotlinOptions {
main = "call"
}
}
}
}
targets.all {
sourceSets.all {
languageSettings.progressiveMode = true
}
}
}
// dokka { // dokka {
// outputFormat = "html" // outputFormat = "html"
@ -97,46 +62,79 @@ subprojects {
// classifier = "javadoc" // classifier = "javadoc"
// } // }
// Create empty jar for sources classifier to satisfy maven requirements
val stubSources by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
//from(sourceSets.main.get().allSource)
}
if (!name.startsWith("dataforge")) return@subprojects // Create empty jar for javadoc classifier to satisfy maven requirements
val stubJavadoc by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}
extensions.findByType<PublishingExtension>()?.apply { tasks.withType<KotlinCompile> {
publications.filterIsInstance<MavenPublication>().forEach { publication -> kotlinOptions{
if (publication.name == "kotlinMultiplatform") { jvmTarget = "1.8"
// for our root metadata publication, set artifactId with a package and project name
publication.artifactId = project.name
} else {
// for targets, set artifactId with a package, project name and target name (e.g. iosX64)
publication.artifactId = "${project.name}-${publication.name}"
}
} }
}
// Create empty jar for sources classifier to satisfy maven requirements
val stubSources by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
//from(sourceSets.main.get().allSource)
}
// Create empty jar for javadoc classifier to satisfy maven requirements
val stubJavadoc by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}
afterEvaluate {
extensions.findByType<KotlinMultiplatformExtension>()?.apply { extensions.findByType<KotlinMultiplatformExtension>()?.apply {
jvm {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
targets.forEach { target -> js {
val publication = publications.findByName(target.name) as MavenPublication compilations.all {
tasks.getByName(compileKotlinTaskName) {
kotlinOptions {
metaInfo = true
sourceMap = true
sourceMapEmbedSources = "always"
moduleKind = "umd"
}
}
}
// Patch publications with fake javadoc configure(listOf(compilations["main"])) {
publication.artifact(stubJavadoc) tasks.getByName(compileKotlinTaskName) {
kotlinOptions {
main = "call"
}
}
}
}
// Remove gradle metadata publishing from all targets which are not native targets.all {
// if (target.platformType.name != "native") { sourceSets.all {
// publication.gradleModuleMetadataFile = null languageSettings.progressiveMode = true
// tasks.matching { it.name == "generateMetadataFileFor${name.capitalize()}Publication" }.all { }
// onlyIf { false } }
// }
// } configure<PublishingExtension> {
publications.filterIsInstance<MavenPublication>().forEach { publication ->
if (publication.name == "kotlinMultiplatform") {
// for our root metadata publication, set artifactId with a package and project name
publication.artifactId = project.name
} else {
// for targets, set artifactId with a package, project name and target name (e.g. iosX64)
publication.artifactId = "${project.name}-${publication.name}"
}
}
targets.all {
val publication = publications.findByName(name) as MavenPublication
// Patch publications with fake javadoc
publication.artifact(stubJavadoc.get())
}
} }
} }
} }

View File

@ -47,4 +47,14 @@ kotlin {
// mingwTest { // mingwTest {
// } // }
} }
} }
//tasks.withType<Kotlin2JsCompile>{
// kotlinOptions{
// metaInfo = true
// outputFile = "${project.buildDir.path}/js/${project.name}.js"
// sourceMap = true
// moduleKind = "umd"
// main = "call"
// }
//}

View File

@ -14,9 +14,9 @@ class MetaDelegateTest {
fun delegateTest() { fun delegateTest() {
val testObject = object : Specification { val testObject = object : Specification {
override val config: Config = Config() override val config: Config = Config()
var myValue by string() var myValue by config.string()
var safeValue by number(2.2) var safeValue by config.number(2.2)
var enumValue by enum(TestEnum.YES) var enumValue by config.enum(TestEnum.YES)
} }
testObject.config["myValue"] = "theString" testObject.config["myValue"] = "theString"
testObject.enumValue = TestEnum.NO testObject.enumValue = TestEnum.NO

View File

@ -1,8 +1,5 @@
import org.openjfx.gradle.JavaFXOptions
plugins { plugins {
kotlin("multiplatform") kotlin("multiplatform")
id("org.openjfx.javafxplugin")
} }
kotlin { kotlin {
@ -25,8 +22,4 @@ kotlin {
} }
} }
} }
}
configure<JavaFXOptions>{
modules("javafx.controls")
} }

View File

@ -1,4 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.openjfx.gradle.JavaFXOptions import org.openjfx.gradle.JavaFXOptions
plugins { plugins {
@ -6,7 +5,8 @@ plugins {
id("org.openjfx.javafxplugin") id("org.openjfx.javafxplugin")
} }
dependencies{ dependencies {
api(project(":dataforge-vis"))
api(project(":dataforge-vis:dataforge-vis-spatial")) api(project(":dataforge-vis:dataforge-vis-spatial"))
api("no.tornado:tornadofx:1.7.18") api("no.tornado:tornadofx:1.7.18")
implementation("org.fxyz3d:fxyz3d:0.4.0") implementation("org.fxyz3d:fxyz3d:0.4.0")
@ -14,10 +14,4 @@ dependencies{
configure<JavaFXOptions> { configure<JavaFXOptions> {
modules("javafx.controls") modules("javafx.controls")
}
tasks.withType<KotlinCompile> {
kotlinOptions{
jvmTarget = "1.8"
}
} }

View File

@ -1,5 +1,8 @@
package hep.dataforge.vis package hep.dataforge.vis
import hep.dataforge.meta.*
import hep.dataforge.names.Name
import hep.dataforge.names.toName
import javafx.beans.binding.ObjectBinding import javafx.beans.binding.ObjectBinding
import tornadofx.* import tornadofx.*

View File

@ -1,6 +1,12 @@
package hep.dataforge.vis.spatial package hep.dataforge.vis.spatial
import hep.dataforge.context.Context
import hep.dataforge.io.Output
import hep.dataforge.meta.Meta
import hep.dataforge.vis.DisplayGroup
import hep.dataforge.vis.DisplayObjectPropertyListener import hep.dataforge.vis.DisplayObjectPropertyListener
import hep.dataforge.vis.float
import hep.dataforge.vis.transform
import javafx.scene.Group import javafx.scene.Group
import javafx.scene.Node import javafx.scene.Node
import org.fxyz3d.shapes.primitives.CuboidMesh import org.fxyz3d.shapes.primitives.CuboidMesh
@ -22,7 +28,7 @@ class FX3DOutput(override val context: Context) : Output<Any> {
val y = listener["y"].float() val y = listener["y"].float()
val z = listener["z"].float() val z = listener["z"].float()
val center = objectBinding(x, y, z) { val center = objectBinding(x, y, z) {
Point3D(x.value ?: 0f, y.value ?: 0f, z.value ?: 0f) org.fxyz3d.geometry.Point3D(x.value ?: 0f, y.value ?: 0f, z.value ?: 0f)
} }
when (obj) { when (obj) {
is DisplayGroup3D -> Group(obj.children.map { buildNode(it) }).apply { is DisplayGroup3D -> Group(obj.children.map { buildNode(it) }).apply {

View File

@ -1,5 +1,10 @@
package hep.dataforge.vis.spatial package hep.dataforge.vis.spatial
import hep.dataforge.meta.MetaItem
import hep.dataforge.meta.double
import hep.dataforge.meta.get
import hep.dataforge.meta.int
import hep.dataforge.values.ValueType
import javafx.scene.paint.Color import javafx.scene.paint.Color
import javafx.scene.paint.Material import javafx.scene.paint.Material
import javafx.scene.paint.PhongMaterial import javafx.scene.paint.PhongMaterial
@ -51,11 +56,12 @@ fun MetaItem<*>.color(): Color {
/** /**
* Infer FX material based on meta item * Infer FX material based on meta item
*/ */
fun MetaItem<*>.material(): Material { fun MetaItem<*>?.material(): Material {
return when (this) { return when (this) {
null -> Materials.GREY
is MetaItem.ValueItem -> PhongMaterial(color()) is MetaItem.ValueItem -> PhongMaterial(color())
is MetaItem.NodeItem -> PhongMaterial().apply { is MetaItem.NodeItem -> PhongMaterial().apply {
node["color"]?.let { diffuseColor = it.color() } (node["color"]?: this@material).let { diffuseColor = it.color() }
node["specularColor"]?.let { specularColor = it.color() } node["specularColor"]?.let { specularColor = it.color() }
} }
} }

View File

@ -1,5 +1,8 @@
package hep.dataforge.vis.spatial package hep.dataforge.vis.spatial
import hep.dataforge.context.Global
import hep.dataforge.meta.number
import hep.dataforge.vis.DisplayGroup
import javafx.scene.Parent import javafx.scene.Parent
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay

View File

@ -0,0 +1,59 @@
package hep.dataforge.vis.spatial
import hep.dataforge.meta.MetaItem
import hep.dataforge.meta.double
import hep.dataforge.meta.get
import hep.dataforge.meta.int
import hep.dataforge.values.ValueType
import info.laht.threekt.materials.Material
import info.laht.threekt.materials.MeshPhongMaterial
import info.laht.threekt.math.Color
import info.laht.threekt.math.ColorConstants
object Materials {
val DEFAULT = MeshPhongMaterial().apply {
this.color.set(ColorConstants.darkgreen)
}
}
/**
* Infer color based on meta item
*/
fun MetaItem<*>.color(): Color {
return when (this) {
is MetaItem.ValueItem -> if (this.value.type == ValueType.STRING) {
Color(this.value.string)
} else {
val int = value.number.toInt()
val red = int and 0x00ff0000 shr 16
val green = int and 0x0000ff00 shr 8
val blue = int and 0x000000ff
Color(red, green, blue)
}
is MetaItem.NodeItem -> {
Color(
node["red"]?.int ?: 0,
node["green"]?.int ?: 0,
node["blue"]?.int ?: 0
)
}
}
}
/**
* Infer FX material based on meta item
*/
fun MetaItem<*>?.material(): Material {
return when (this) {
null -> Materials.DEFAULT
is MetaItem.ValueItem -> MeshPhongMaterial().apply {
color = this@material.color()
}
is MetaItem.NodeItem -> MeshPhongMaterial().apply {
(node["color"] ?: this@material).let { color = it.color() }
opacity = node["opacity"]?.double ?: 1.0
node["specularColor"]?.let { specular = it.color() }
}
}
}

View File

@ -4,6 +4,7 @@ import hep.dataforge.context.Global
import hep.dataforge.meta.number import hep.dataforge.meta.number
import hep.dataforge.vis.ApplicationBase import hep.dataforge.vis.ApplicationBase
import hep.dataforge.vis.DisplayGroup import hep.dataforge.vis.DisplayGroup
import info.laht.threekt.external.controls.OrbitControls
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
@ -17,9 +18,9 @@ class ThreeDemoApp : ApplicationBase() {
override val stateKeys: List<String> = emptyList() override val stateKeys: List<String> = emptyList()
override fun start(state: Map<String, Any>) { override fun start(state: Map<String, Any>) {
println("started")
val renderer = ThreeOutput(Global) val renderer = ThreeOutput(Global)
document.getElementById("canvas")?.appendChild(renderer.root) renderer.start(document.getElementById("canvas")!!)
println("started")
lateinit var group: DisplayGroup lateinit var group: DisplayGroup

View File

@ -3,17 +3,25 @@ package hep.dataforge.vis.spatial
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.io.Output import hep.dataforge.io.Output
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.get
import hep.dataforge.vis.DisplayGroup import hep.dataforge.vis.DisplayGroup
import info.laht.threekt.WebGLRenderer import info.laht.threekt.WebGLRenderer
import info.laht.threekt.cameras.PerspectiveCamera import info.laht.threekt.cameras.PerspectiveCamera
import info.laht.threekt.core.BufferGeometry
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.OrbitControls
import info.laht.threekt.extras.curves.CatmullRomCurve3
import info.laht.threekt.geometries.BoxBufferGeometry import info.laht.threekt.geometries.BoxBufferGeometry
import info.laht.threekt.lights.AmbientLight import info.laht.threekt.lights.AmbientLight
import info.laht.threekt.materials.LineBasicMaterial
import info.laht.threekt.materials.MeshBasicMaterial
import info.laht.threekt.materials.MeshPhongMaterial import info.laht.threekt.materials.MeshPhongMaterial
import info.laht.threekt.math.ColorConstants import info.laht.threekt.math.ColorConstants
import info.laht.threekt.math.Vector3
import info.laht.threekt.objects.Line
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
import info.laht.threekt.scenes.Scene import info.laht.threekt.scenes.Scene
import org.w3c.dom.Element
import kotlin.browser.window import kotlin.browser.window
class ThreeOutput(override val context: Context) : Output<Any> { class ThreeOutput(override val context: Context) : Output<Any> {
@ -23,28 +31,39 @@ class ThreeOutput(override val context: Context) : Output<Any> {
setSize(window.innerWidth, window.innerHeight) setSize(window.innerWidth, window.innerHeight)
} }
private val scene: Scene = Scene().apply { val scene: Scene = Scene().apply {
add(AmbientLight()) add(AmbientLight())
} }
private val camera = PerspectiveCamera(
val camera = PerspectiveCamera(
75, 75,
window.innerWidth.toDouble() / window.innerHeight, window.innerWidth.toDouble() / window.innerHeight,
0.1, 0.1,
10000 10000
).apply { ).apply {
position.z = 4500.0 position.setZ(1000)
} }
private val controls: OrbitControls = OrbitControls(camera, renderer.domElement) val controls: OrbitControls = OrbitControls(camera, renderer.domElement)
val root by lazy { val root get() = renderer.domElement
private fun animate() {
window.requestAnimationFrame {
animate()
}
renderer.render(scene, camera)
}
fun start(element: Element) {
window.addEventListener("resize", { window.addEventListener("resize", {
camera.aspect = window.innerWidth.toDouble() / window.innerHeight; camera.aspect = window.innerWidth.toDouble() / window.innerHeight;
camera.updateProjectionMatrix(); camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight) renderer.setSize(window.innerWidth, window.innerHeight)
}, false) }, false)
renderer.domElement element.appendChild(root)
animate()
} }
@ -65,12 +84,10 @@ class ThreeOutput(override val context: Context) : Output<Any> {
this.translateZ(obj.z) this.translateZ(obj.z)
} }
is Box -> { is Box -> {
//TODO add bindings
val geometry = BoxBufferGeometry(obj.xSize, obj.ySize, obj.zSize) val geometry = BoxBufferGeometry(obj.xSize, obj.ySize, obj.zSize)
.translate(obj.x, obj.y, obj.z) .translate(obj.x, obj.y, obj.z)
val material = MeshPhongMaterial().apply { Mesh(geometry, obj.properties["color"].material())
this.color.set(ColorConstants.darkgreen)
}
Mesh(geometry, material)
} }
else -> { else -> {
logger.error { "No renderer defined for ${obj::class}" } logger.error { "No renderer defined for ${obj::class}" }
@ -90,9 +107,9 @@ class ThreeOutput(override val context: Context) : Output<Any> {
buildNode(obj)?.let { scene.add(it) } buildNode(obj)?.let { scene.add(it) }
} }
// init { // init {
// val cube: Mesh // val cube: Mesh
//
// cube = Mesh( // cube = Mesh(
// BoxBufferGeometry(1, 1, 1), // BoxBufferGeometry(1, 1, 1),
// MeshPhongMaterial().apply { // MeshPhongMaterial().apply {
@ -125,16 +142,6 @@ class ThreeOutput(override val context: Context) : Output<Any> {
// //
// // Create the final object to add to the scene // // Create the final object to add to the scene
// Line(geometry, material).apply(scene::add) // Line(geometry, material).apply(scene::add)
// }
// fun animate() {
// window.requestAnimationFrame {
// cube.rotation.x += 0.01
// cube.rotation.y += 0.01
// animate()
// }
// renderer.render(scene, camera)
// } // }
} }

View File

@ -4,26 +4,7 @@ plugins {
kotlin { kotlin {
jvm() jvm()
js { js()
configure(listOf(compilations["main"], compilations["test"])) {
tasks.getByName(compileKotlinTaskName) {
kotlinOptions {
metaInfo = true
sourceMap = true
sourceMapEmbedSources = "always"
moduleKind = "umd"
}
}
}
configure(listOf(compilations["main"])) {
tasks.getByName(compileKotlinTaskName) {
kotlinOptions {
main = "call"
}
}
}
}
sourceSets { sourceSets {
val commonMain by getting { val commonMain by getting {