0.2.0 #71

Merged
altavir merged 139 commits from dev into master 2022-01-24 09:44:18 +03:00
10 changed files with 62 additions and 32 deletions
Showing only changes of commit bfa7f5ea57 - Show all commits

View File

@ -1,6 +1,5 @@
package space.kscience.visionforge.examples package space.kscience.visionforge.examples
import kotlinx.html.h1
import kotlinx.html.h2 import kotlinx.html.h2
import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.Context
import space.kscience.dataforge.values.ValueType 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.markup.markdown
import space.kscience.visionforge.plotly.PlotlyPlugin import space.kscience.visionforge.plotly.PlotlyPlugin
import space.kscience.visionforge.plotly.plotly 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.TableVisionPlugin
import space.kscience.visionforge.tables.columnTable import space.kscience.visionforge.tables.columnTable
import java.nio.file.Paths import java.nio.file.Paths
fun main() { fun main() {
val context = Context { val context = Context {
plugin(Solids) plugin(Solids)
@ -41,7 +44,9 @@ fun main() {
h2 { +"3D visualization with Three-js" } h2 { +"3D visualization with Three-js" }
vision("3D") { vision("3D") {
solid { solid {
box(100, 100, 100, name = "aBox") box(100, 100, 100, name = "aBox"){
z = 50.0
}
} }
} }

View File

@ -29,7 +29,6 @@ public fun Context.makeVisionFile(
val actualPath = visionManager.page(title, content = content).makeFile(path) { actualPath -> val actualPath = visionManager.page(title, content = content).makeFile(path) { actualPath ->
mapOf( mapOf(
"playground" to scriptHeader("js/visionforge-playground.js", resourceLocation, actualPath), "playground" to scriptHeader("js/visionforge-playground.js", resourceLocation, actualPath),
//"tables" to tabulatorCssHader
) )
} }
if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI()) if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI())

View File

@ -4,6 +4,8 @@ import kotlinx.html.*
import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.misc.DFExperimental
import space.kscience.visionforge.VisionManager import space.kscience.visionforge.VisionManager
//data class HeaderContainer
public data class Page( public data class Page(
public val visionManager: VisionManager, public val visionManager: VisionManager,
public val title: String, public val title: String,

View File

@ -39,16 +39,6 @@ public inline fun VisionContainerBuilder<Solid>.composite(
res.meta.update(group.meta) 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) set(name, res)
return res return res
} }

View File

@ -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]

View File

@ -1,13 +1,21 @@
package space.kscience.visionforge.solid package space.kscience.visionforge.solid
import space.kscience.dataforge.meta.* import space.kscience.dataforge.meta.descriptors.MetaDescriptor
import space.kscience.dataforge.meta.descriptors.* 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.Name
import space.kscience.dataforge.names.asName import space.kscience.dataforge.names.asName
import space.kscience.dataforge.names.plus import space.kscience.dataforge.names.plus
import space.kscience.dataforge.values.* 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.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.DETAIL_KEY
import space.kscience.visionforge.solid.Solid.Companion.IGNORE_KEY import space.kscience.visionforge.solid.Solid.Companion.IGNORE_KEY
import space.kscience.visionforge.solid.Solid.Companion.LAYER_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.rotationY: Number by float(Y_ROTATION_KEY, 0f)
public var Solid.rotationZ: Number by float(Z_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.scaleX: Number by float(X_SCALE_KEY, 1f)
public var Solid.scaleY: Number by float(Y_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) public var Solid.scaleZ: Number by float(Z_SCALE_KEY, 1f)

View File

@ -60,10 +60,11 @@ public class SolidGroup : VisionGroupBase(), Solid, PrototypeHolder {
override fun createGroup(): SolidGroup = SolidGroup() override fun createGroup(): SolidGroup = SolidGroup()
override fun update(change: VisionChange) { //
updatePosition(change.properties) // override fun update(change: VisionChange) {
super.update(change) // updatePosition(change.properties)
} // super.update(change)
// }
public companion object { public companion object {
public val PROTOTYPES_TOKEN: NameToken = NameToken("@prototypes") public val PROTOTYPES_TOKEN: NameToken = NameToken("@prototypes")

View File

@ -117,8 +117,8 @@ internal fun Meta.toVector(default: Float = 0f) = Point3D(
this[Solid.Z_KEY].float ?: default this[Solid.Z_KEY].float ?: default
) )
internal fun Solid.updatePosition(meta: Meta?) { //internal fun Solid.updatePosition(meta: Meta?) {
meta?.get(Solid.POSITION_KEY)?.toVector()?.let { position = it } // meta?.get(Solid.POSITION_KEY)?.toVector()?.let { position = it }
meta?.get(Solid.ROTATION_KEY)?.toVector()?.let { rotation = it } // meta?.get(Solid.ROTATION_KEY)?.toVector()?.let { rotation = it }
meta?.get(Solid.SCALE_KEY)?.toVector(1f)?.let { scale = it } // meta?.get(Solid.SCALE_KEY)?.toVector(1f)?.let { scale = it }
} //}

View File

@ -2,6 +2,7 @@ package space.kscience.visionforge.solid.three
import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.BufferGeometry
import info.laht.threekt.core.Object3D import info.laht.threekt.core.Object3D
import info.laht.threekt.math.Euler
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
import space.kscience.dataforge.misc.Type import space.kscience.dataforge.misc.Type
import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.Name
@ -36,7 +37,18 @@ public fun Object3D.updatePosition(obj: Vision) {
visible = obj.visible ?: true visible = obj.visible ?: true
if (obj is Solid) { if (obj is Solid) {
position.set(obj.x, obj.y, obj.z) 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) scale.set(obj.scaleX, obj.scaleY, obj.scaleZ)
updateMatrix() updateMatrix()
} }

View File

@ -4,19 +4,14 @@ import info.laht.threekt.core.BufferGeometry
import info.laht.threekt.core.Layers import info.laht.threekt.core.Layers
import info.laht.threekt.external.controls.OrbitControls import info.laht.threekt.external.controls.OrbitControls
import info.laht.threekt.materials.Material import info.laht.threekt.materials.Material
import info.laht.threekt.math.Euler
import info.laht.threekt.math.Vector3 import info.laht.threekt.math.Vector3
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
import info.laht.threekt.textures.Texture import info.laht.threekt.textures.Texture
import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.float import space.kscience.dataforge.meta.float
import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.node
import space.kscience.visionforge.solid.*
import kotlin.math.PI 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) public val Meta.vector: Vector3 get() = Vector3(this["x"].float ?: 0f, this["y"].float ?: 0f, this["z"].float ?: 0f)