Add quaternion support

This commit is contained in:
Alexander Nozik 2022-08-21 17:21:36 +03:00
parent 40b784f551
commit 75540a078f
No known key found for this signature in database
GPG Key ID: F7FCF2DD25C71357
5 changed files with 41 additions and 5 deletions

View File

@ -34,11 +34,11 @@ public interface HtmlVisionContext : ContextAware {
public typealias HtmlVisionContextFragment = context(HtmlVisionContext) TagConsumer<*>.() -> Unit public typealias HtmlVisionContextFragment = context(HtmlVisionContext) TagConsumer<*>.() -> Unit
context(HtmlVisionContext) context(HtmlVisionContext) public fun HtmlVisionFragment(
public fun HtmlVisionContextFragment(content: TagConsumer<*>.() -> Unit): HtmlVisionFragment = content content: TagConsumer<*>.() -> Unit
): HtmlVisionFragment = content
context(HtmlVisionContext) context(HtmlVisionContext) private fun <T> TagConsumer<T>.vision(
private fun <T> TagConsumer<T>.vision(
visionManager: VisionManager, visionManager: VisionManager,
name: Name, name: Name,
vision: Vision, vision: Vision,

View File

@ -97,6 +97,8 @@ public class FX3DPlugin : AbstractPlugin() {
scaleYProperty().bind(binding[Solid.Y_SCALE_KEY].float(obj.scaleY.toFloat())) scaleYProperty().bind(binding[Solid.Y_SCALE_KEY].float(obj.scaleY.toFloat()))
scaleZProperty().bind(binding[Solid.Z_SCALE_KEY].float(obj.scaleZ.toFloat())) scaleZProperty().bind(binding[Solid.Z_SCALE_KEY].float(obj.scaleZ.toFloat()))
if(obj.quaternion!= null) TODO("Quaternion support not implemented")
val rotateX = Rotate(0.0, Rotate.X_AXIS).apply { val rotateX = Rotate(0.0, Rotate.X_AXIS).apply {
angleProperty().bind(binding[Solid.X_ROTATION_KEY].float(obj.rotationX.toFloat()).multiply(180.0 / PI)) angleProperty().bind(binding[Solid.X_ROTATION_KEY].float(obj.rotationX.toFloat()).multiply(180.0 / PI))
} }

View File

@ -203,6 +203,26 @@ 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: Pair<Float, Point3D>?
get() = properties.getValue(Solid.QUATERNION_KEY)?.list?.let {
require(it.size == 4) { "Quaternion must be a number array of 4 elements" }
it[0].float to Point3D(it[1].float, it[2].float, it[3].float)
}
set(value) {
properties.setValue(
Solid.QUATERNION_KEY,
value?.let {
ListValue(
value.first,
value.second.x,
value.second.y,
value.second.z
)
}
)
}
//public var Solid.quaternion: Quaternion? //public var Solid.quaternion: Quaternion?
// get() = meta[Solid::quaternion.name]?.value?.doubleArray?.let { Quaternion(it) } // get() = meta[Solid::quaternion.name]?.value?.doubleArray?.let { Quaternion(it) }
// set(value) { // set(value) {

View File

@ -14,6 +14,7 @@ internal fun Solid.updateFrom(other: Solid): Solid {
x += other.x x += other.x
y += other.y y += other.y
z += other.y z += other.y
if(quaternion != null || other.quaternion != null) TODO("Quaternion support not implemented")
rotationX += other.rotationX rotationX += other.rotationX
rotationY += other.rotationY rotationY += other.rotationY
rotationZ += other.rotationZ rotationZ += other.rotationZ

View File

@ -11,6 +11,7 @@ import space.kscience.visionforge.visible
import three.core.BufferGeometry import three.core.BufferGeometry
import three.core.Object3D import three.core.Object3D
import three.math.Euler import three.math.Euler
import three.math.Quaternion
import kotlin.reflect.KClass import kotlin.reflect.KClass
/** /**
@ -48,8 +49,20 @@ public fun Object3D.updatePosition(vision: Vision) {
// } else { // } else {
// setRotationFromEuler( Euler(obj.rotationX, obj.rotationY, obj.rotationZ, obj.rotationOrder.name)) // setRotationFromEuler( Euler(obj.rotationX, obj.rotationY, obj.rotationZ, obj.rotationOrder.name))
// } // }
val quaternion = vision.quaternion
setRotationFromEuler(Euler(vision.rotationX, vision.rotationY, vision.rotationZ, vision.rotationOrder.name)) if (quaternion != null) {
setRotationFromQuaternion(
Quaternion(
quaternion.second.x,
quaternion.second.y,
quaternion.second.z,
quaternion.first
)
)
} else {
setRotationFromEuler(Euler(vision.rotationX, vision.rotationY, vision.rotationZ, vision.rotationOrder.name))
}
scale.set(vision.scaleX, vision.scaleY, vision.scaleZ) scale.set(vision.scaleX, vision.scaleY, vision.scaleZ)
updateMatrix() updateMatrix()