From bfa7f5ea573d0c30c63b179d1da752923a88465b Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Tue, 11 Jan 2022 20:49:15 +0300 Subject: [PATCH] Remove unnecessary rotation and position updates --- .../src/jvmMain/kotlin/allThingsDemo.kt | 11 +++++++--- .../src/jvmMain/kotlin/serverExtensions.kt | 1 - .../space/kscience/visionforge/html/Page.kt | 2 ++ .../kscience/visionforge/solid/Composite.kt | 10 --------- .../kscience/visionforge/solid/Quaternion.kt | 11 ++++++++++ .../space/kscience/visionforge/solid/Solid.kt | 21 ++++++++++++++++--- .../kscience/visionforge/solid/SolidGroup.kt | 9 ++++---- .../kscience/visionforge/solid/geometry.kt | 10 ++++----- .../visionforge/solid/three/ThreeFactory.kt | 14 ++++++++++++- .../kscience/visionforge/solid/three/three.kt | 5 ----- 10 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Quaternion.kt diff --git a/demo/playground/src/jvmMain/kotlin/allThingsDemo.kt b/demo/playground/src/jvmMain/kotlin/allThingsDemo.kt index 0ff49d40..9c68af8b 100644 --- a/demo/playground/src/jvmMain/kotlin/allThingsDemo.kt +++ b/demo/playground/src/jvmMain/kotlin/allThingsDemo.kt @@ -1,6 +1,5 @@ package space.kscience.visionforge.examples -import kotlinx.html.h1 import kotlinx.html.h2 import space.kscience.dataforge.context.Context import space.kscience.dataforge.values.ValueType @@ -13,11 +12,15 @@ import space.kscience.visionforge.html.ResourceLocation import space.kscience.visionforge.markup.markdown import space.kscience.visionforge.plotly.PlotlyPlugin import space.kscience.visionforge.plotly.plotly -import space.kscience.visionforge.solid.* +import space.kscience.visionforge.solid.Solids +import space.kscience.visionforge.solid.box +import space.kscience.visionforge.solid.solid +import space.kscience.visionforge.solid.z import space.kscience.visionforge.tables.TableVisionPlugin import space.kscience.visionforge.tables.columnTable import java.nio.file.Paths + fun main() { val context = Context { plugin(Solids) @@ -41,7 +44,9 @@ fun main() { h2 { +"3D visualization with Three-js" } vision("3D") { solid { - box(100, 100, 100, name = "aBox") + box(100, 100, 100, name = "aBox"){ + z = 50.0 + } } } diff --git a/demo/playground/src/jvmMain/kotlin/serverExtensions.kt b/demo/playground/src/jvmMain/kotlin/serverExtensions.kt index b8bb633a..62d318ad 100644 --- a/demo/playground/src/jvmMain/kotlin/serverExtensions.kt +++ b/demo/playground/src/jvmMain/kotlin/serverExtensions.kt @@ -29,7 +29,6 @@ public fun Context.makeVisionFile( val actualPath = visionManager.page(title, content = content).makeFile(path) { actualPath -> mapOf( "playground" to scriptHeader("js/visionforge-playground.js", resourceLocation, actualPath), - //"tables" to tabulatorCssHader ) } if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI()) diff --git a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/html/Page.kt b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/html/Page.kt index 96cae1ce..d575208e 100644 --- a/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/html/Page.kt +++ b/visionforge-core/src/commonMain/kotlin/space/kscience/visionforge/html/Page.kt @@ -4,6 +4,8 @@ import kotlinx.html.* import space.kscience.dataforge.misc.DFExperimental import space.kscience.visionforge.VisionManager +//data class HeaderContainer + public data class Page( public val visionManager: VisionManager, public val title: String, diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Composite.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Composite.kt index 3c7773bc..d63e08b6 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Composite.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Composite.kt @@ -39,16 +39,6 @@ public inline fun VisionContainerBuilder.composite( res.meta.update(group.meta) - if (group.position != null) { - res.position = group.position - } - if (group.rotation != null) { - res.rotation = group.rotation - } - if (group.scale != null) { - res.scale = group.scale - } - set(name, res) return res } diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Quaternion.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Quaternion.kt new file mode 100644 index 00000000..617c7a38 --- /dev/null +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Quaternion.kt @@ -0,0 +1,11 @@ +package space.kscience.visionforge.solid + +import kotlin.jvm.JvmInline + +@JvmInline +public value class Quaternion(public val values: DoubleArray) + +public operator fun Quaternion.component1(): Double = values[0] +public operator fun Quaternion.component2(): Double = values[1] +public operator fun Quaternion.component3(): Double = values[2] +public operator fun Quaternion.component4(): Double = values[3] \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solid.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solid.kt index 39ed06ac..2b9c883b 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solid.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/Solid.kt @@ -1,13 +1,21 @@ package space.kscience.visionforge.solid -import space.kscience.dataforge.meta.* -import space.kscience.dataforge.meta.descriptors.* +import space.kscience.dataforge.meta.descriptors.MetaDescriptor +import space.kscience.dataforge.meta.descriptors.enum +import space.kscience.dataforge.meta.descriptors.node +import space.kscience.dataforge.meta.descriptors.value +import space.kscience.dataforge.meta.float +import space.kscience.dataforge.meta.get +import space.kscience.dataforge.meta.number import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.asName import space.kscience.dataforge.names.plus import space.kscience.dataforge.values.* -import space.kscience.visionforge.* +import space.kscience.visionforge.Vision import space.kscience.visionforge.Vision.Companion.VISIBLE_KEY +import space.kscience.visionforge.hide +import space.kscience.visionforge.inherited +import space.kscience.visionforge.setProperty import space.kscience.visionforge.solid.Solid.Companion.DETAIL_KEY import space.kscience.visionforge.solid.Solid.Companion.IGNORE_KEY import space.kscience.visionforge.solid.Solid.Companion.LAYER_KEY @@ -199,6 +207,13 @@ public var Solid.rotationX: Number by float(X_ROTATION_KEY, 0f) public var Solid.rotationY: Number by float(Y_ROTATION_KEY, 0f) public var Solid.rotationZ: Number by float(Z_ROTATION_KEY, 0f) +//public var Solid.quaternion: Quaternion? +// get() = meta[Solid::quaternion.name]?.value?.doubleArray?.let { Quaternion(it) } +// set(value) { +// meta[Solid::quaternion.name] = value?.values?.asValue() +// } + + public var Solid.scaleX: Number by float(X_SCALE_KEY, 1f) public var Solid.scaleY: Number by float(Y_SCALE_KEY, 1f) public var Solid.scaleZ: Number by float(Z_SCALE_KEY, 1f) \ No newline at end of file diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt index b3e8ccd8..a501f7a0 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/SolidGroup.kt @@ -60,10 +60,11 @@ public class SolidGroup : VisionGroupBase(), Solid, PrototypeHolder { override fun createGroup(): SolidGroup = SolidGroup() - override fun update(change: VisionChange) { - updatePosition(change.properties) - super.update(change) - } +// +// override fun update(change: VisionChange) { +// updatePosition(change.properties) +// super.update(change) +// } public companion object { public val PROTOTYPES_TOKEN: NameToken = NameToken("@prototypes") diff --git a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/geometry.kt b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/geometry.kt index f815a262..a0ad09a0 100644 --- a/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/geometry.kt +++ b/visionforge-solid/src/commonMain/kotlin/space/kscience/visionforge/solid/geometry.kt @@ -117,8 +117,8 @@ internal fun Meta.toVector(default: Float = 0f) = Point3D( this[Solid.Z_KEY].float ?: default ) -internal fun Solid.updatePosition(meta: Meta?) { - meta?.get(Solid.POSITION_KEY)?.toVector()?.let { position = it } - meta?.get(Solid.ROTATION_KEY)?.toVector()?.let { rotation = it } - meta?.get(Solid.SCALE_KEY)?.toVector(1f)?.let { scale = it } -} \ No newline at end of file +//internal fun Solid.updatePosition(meta: Meta?) { +// meta?.get(Solid.POSITION_KEY)?.toVector()?.let { position = it } +// meta?.get(Solid.ROTATION_KEY)?.toVector()?.let { rotation = it } +// meta?.get(Solid.SCALE_KEY)?.toVector(1f)?.let { scale = it } +//} \ No newline at end of file diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeFactory.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeFactory.kt index 81749fd3..df9f2c94 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeFactory.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeFactory.kt @@ -2,6 +2,7 @@ package space.kscience.visionforge.solid.three import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.Object3D +import info.laht.threekt.math.Euler import info.laht.threekt.objects.Mesh import space.kscience.dataforge.misc.Type import space.kscience.dataforge.names.Name @@ -36,7 +37,18 @@ public fun Object3D.updatePosition(obj: Vision) { visible = obj.visible ?: true if (obj is Solid) { position.set(obj.x, obj.y, obj.z) - setRotationFromEuler(obj.euler) + +// val quaternion = obj.quaternion +// +// if (quaternion != null) { +// val (x, y, z, w) = quaternion +// setRotationFromQuaternion(Quaternion(x, y, z, w)) +// } else { +// setRotationFromEuler( Euler(obj.rotationX, obj.rotationY, obj.rotationZ, obj.rotationOrder.name)) +// } + + setRotationFromEuler( Euler(obj.rotationX, obj.rotationY, obj.rotationZ, obj.rotationOrder.name)) + scale.set(obj.scaleX, obj.scaleY, obj.scaleZ) updateMatrix() } diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/three.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/three.kt index ea609e58..447cf4b6 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/three.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/three.kt @@ -4,19 +4,14 @@ import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.Layers import info.laht.threekt.external.controls.OrbitControls import info.laht.threekt.materials.Material -import info.laht.threekt.math.Euler import info.laht.threekt.math.Vector3 import info.laht.threekt.objects.Mesh import info.laht.threekt.textures.Texture import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.float import space.kscience.dataforge.meta.get -import space.kscience.dataforge.meta.node -import space.kscience.visionforge.solid.* import kotlin.math.PI -public val Solid.euler: Euler get() = Euler(rotationX, rotationY, rotationZ, rotationOrder.name) - public val Meta.vector: Vector3 get() = Vector3(this["x"].float ?: 0f, this["y"].float ?: 0f, this["z"].float ?: 0f)