Move Vector3D to common instead of expect/actual

This commit is contained in:
Alexander Nozik 2020-11-21 10:04:15 +03:00
parent dc805228b4
commit d1607459a1
26 changed files with 78 additions and 246 deletions

View File

@ -78,7 +78,7 @@ val GDMLApp = functionalComponent<GDMLAppProps>("GDMLApp") { props ->
} }
flexColumn { flexColumn {
css { css {
flex(10.0, 10.0, FlexBasis.zero) flex(1.0, 1.0, FlexBasis.auto)
} }
styledDiv { styledDiv {
css { css {
@ -106,10 +106,11 @@ val GDMLApp = functionalComponent<GDMLAppProps>("GDMLApp") { props ->
} }
flexColumn { flexColumn {
css { css {
minWidth = 500.px minWidth = 400.px
height = 100.pct height = 100.pct
margin(left = 4.px, right = 4.px, top = 4.px) margin(left = 4.px, right = 4.px, top = 4.px)
border(1.px, BorderStyle.solid, Color.lightGray) border(1.px, BorderStyle.solid, Color.lightGray)
flex(0.0,1.0, FlexBasis.zero)
} }
fileDrop("(drag file here)") { files -> fileDrop("(drag file here)") { files ->
val file = files?.get(0) val file = files?.get(0)

View File

@ -1,10 +1,7 @@
@file:UseSerializers(Point3DSerializer::class)
package ru.mipt.npm.muon.monitor package ru.mipt.npm.muon.monitor
import hep.dataforge.vision.solid.Point3D import hep.dataforge.vision.solid.Point3D
import hep.dataforge.vision.solid.Point3DSerializer
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
typealias Track = List<Point3D> typealias Track = List<Point3D>

View File

@ -1,5 +1,3 @@
@file:UseSerializers(Point3DSerializer::class)
package hep.dataforge.vision.solid.demo package hep.dataforge.vision.solid.demo
import hep.dataforge.meta.int import hep.dataforge.meta.int
@ -20,7 +18,6 @@ import info.laht.threekt.core.BufferGeometry
import info.laht.threekt.core.Object3D import info.laht.threekt.core.Object3D
import info.laht.threekt.geometries.BoxBufferGeometry import info.laht.threekt.geometries.BoxBufferGeometry
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
import kotlinx.serialization.UseSerializers
import kotlin.math.max import kotlin.math.max
internal fun SolidGroup.varBox( internal fun SolidGroup.varBox(

View File

@ -1,7 +1,6 @@
package hep.dataforge.vision.bootstrap package hep.dataforge.vision.bootstrap
import hep.dataforge.vision.react.flexColumn import hep.dataforge.vision.react.flexColumn
import kotlinx.css.*
import kotlinx.html.DIV import kotlinx.html.DIV
import kotlinx.html.classes import kotlinx.html.classes
import kotlinx.html.js.onClickFunction import kotlinx.html.js.onClickFunction
@ -10,7 +9,6 @@ import react.dom.button
import react.dom.li import react.dom.li
import react.dom.ul import react.dom.ul
import styled.StyledDOMBuilder import styled.StyledDOMBuilder
import styled.css
import styled.styledDiv import styled.styledDiv
public external class TabProps : RProps { public external class TabProps : RProps {
@ -40,9 +38,6 @@ public val TabPane: FunctionalComponent<TabPaneProps> = functionalComponent("Tab
} }
flexColumn { flexColumn {
css {
flexGrow = 1.0
}
ul("nav nav-tabs") { ul("nav nav-tabs") {
childrenProps.forEach { cp -> childrenProps.forEach { cp ->
li("nav-item") { li("nav-item") {
@ -74,10 +69,6 @@ public class TabBuilder(internal val parentBuilder: RBuilder) {
this.title = title this.title = title
} }
styledDiv { styledDiv {
css {
height = 100.pct
overflowY = Overflow.auto
}
builder() builder()
} }
} }

View File

@ -36,7 +36,7 @@ public val ThreeControls: FunctionalComponent<ThreeControlsProps> = functionalCo
h2 { +"Object tree" } h2 { +"Object tree" }
styledDiv { styledDiv {
css { css {
flex(1.0, 0.0, FlexBasis.auto) flex(1.0, 1.0, FlexBasis.inherit)
} }
props.canvas.content?.let { props.canvas.content?.let {
objectTree(it, props.selected, props.onSelect) objectTree(it, props.selected, props.onSelect)

View File

@ -14,7 +14,7 @@ import tornadofx.*
/** /**
* Created by darksnake on 01-May-17. * Created by darksnake on 01-May-17.
*/ */
class ColorValueChooser : ValueChooserBase<ColorPicker>() { public class ColorValueChooser : ValueChooserBase<ColorPicker>() {
private fun ColorPicker.setColor(value: Value?) { private fun ColorPicker.setColor(value: Value?) {
if (value != null && value != Null) { if (value != null && value != Null) {
try { try {

View File

@ -17,7 +17,7 @@ import javafx.scene.control.ComboBox
import javafx.util.StringConverter import javafx.util.StringConverter
import java.util.* import java.util.*
class ComboBoxValueChooser(val values: Collection<Value>? = null) : ValueChooserBase<ComboBox<Value>>() { public class ComboBoxValueChooser(public val values: Collection<Value>? = null) : ValueChooserBase<ComboBox<Value>>() {
// @Override // @Override
// protected void displayError(String error) { // protected void displayError(String error) {

View File

@ -114,20 +114,20 @@ private class GDMLTransformer(val settings: GDMLTransformerSettings) {
): T = apply { ): T = apply {
newPos?.let { newPos?.let {
val point = Point3D(it.x(settings.lUnit), it.y(settings.lUnit), it.z(settings.lUnit)) val point = Point3D(it.x(settings.lUnit), it.y(settings.lUnit), it.z(settings.lUnit))
if (position != null || point != World.ZERO) { if (position != null || point != Point3D.ZERO) {
position = point position = point
} }
} }
newRotation?.let { newRotation?.let {
val point = Point3D(it.x(settings.aUnit), it.y(settings.aUnit), it.z(settings.aUnit)) val point = Point3D(it.x(settings.aUnit), it.y(settings.aUnit), it.z(settings.aUnit))
if (rotation != null || point != World.ZERO) { if (rotation != null || point != Point3D.ZERO) {
rotation = point rotation = point
} }
//this@withPosition.rotationOrder = RotationOrder.ZXY //this@withPosition.rotationOrder = RotationOrder.ZXY
} }
newScale?.let { newScale?.let {
val point = Point3D(it.x, it.y, it.z) val point = Point3D(it.x, it.y, it.z)
if (scale != null || point != World.ONE) { if (scale != null || point != Point3D.ONE) {
scale = point scale = point
} }
} }

View File

@ -15,13 +15,10 @@ import kotlinx.serialization.Serializable
public open class BasicSolid : VisionBase(), Solid { public open class BasicSolid : VisionBase(), Solid {
override val descriptor: NodeDescriptor get() = Solid.descriptor override val descriptor: NodeDescriptor get() = Solid.descriptor
@Serializable(Point3DSerializer::class)
override var position: Point3D? = null override var position: Point3D? = null
@Serializable(Point3DSerializer::class)
override var rotation: Point3D? = null override var rotation: Point3D? = null
@Serializable(Point3DSerializer::class)
override var scale: Point3D? = null override var scale: Point3D? = null
override fun update(change: Vision) { override fun update(change: Vision) {

View File

@ -1,5 +1,3 @@
@file:UseSerializers(Point3DSerializer::class)
package hep.dataforge.vision.solid package hep.dataforge.vision.solid
import hep.dataforge.vision.VisionContainerBuilder import hep.dataforge.vision.VisionContainerBuilder
@ -7,7 +5,6 @@ import hep.dataforge.vision.set
import hep.dataforge.vision.solid.Solid.Companion.solidEquals import hep.dataforge.vision.solid.Solid.Companion.solidEquals
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
@Serializable @Serializable
@SerialName("solid.box") @SerialName("solid.box")

View File

@ -1,4 +1,3 @@
@file:UseSerializers(Point3DSerializer::class)
package hep.dataforge.vision.solid package hep.dataforge.vision.solid
@ -7,7 +6,6 @@ import hep.dataforge.names.NameToken
import hep.dataforge.vision.* import hep.dataforge.vision.*
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
public enum class CompositeType { public enum class CompositeType {
UNION, UNION,

View File

@ -1,12 +1,9 @@
@file:UseSerializers(Point3DSerializer::class)
package hep.dataforge.vision.solid package hep.dataforge.vision.solid
import hep.dataforge.vision.VisionContainerBuilder import hep.dataforge.vision.VisionContainerBuilder
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.sin import kotlin.math.sin

View File

@ -1,12 +1,9 @@
@file:UseSerializers(Point3DSerializer::class)
package hep.dataforge.vision.solid package hep.dataforge.vision.solid
import hep.dataforge.vision.VisionContainerBuilder import hep.dataforge.vision.VisionContainerBuilder
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
@Serializable @Serializable
@SerialName("solid.convex") @SerialName("solid.convex")

View File

@ -1,11 +1,9 @@
@file:UseSerializers(Point2DSerializer::class, Point3DSerializer::class)
package hep.dataforge.vision.solid package hep.dataforge.vision.solid
import hep.dataforge.vision.VisionContainerBuilder import hep.dataforge.vision.VisionContainerBuilder
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
import kotlin.math.PI import kotlin.math.PI
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.sin import kotlin.math.sin

View File

@ -1,5 +1,3 @@
@file:UseSerializers(Point3DSerializer::class)
package hep.dataforge.vision.solid package hep.dataforge.vision.solid
import hep.dataforge.meta.number import hep.dataforge.meta.number
@ -11,7 +9,6 @@ import hep.dataforge.vision.props
import hep.dataforge.vision.set import hep.dataforge.vision.set
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.UseSerializers
@Serializable @Serializable
@SerialName("solid.line") @SerialName("solid.line")

View File

@ -5,8 +5,13 @@ import hep.dataforge.meta.descriptors.NodeDescriptor
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.names.NameToken import hep.dataforge.names.NameToken
import hep.dataforge.vision.* import hep.dataforge.vision.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
public interface PrototypeHolder { public interface PrototypeHolder {
public val parent: VisionGroup? public val parent: VisionGroup?
@ -25,7 +30,7 @@ public class SolidGroup : VisionGroupBase(), Solid, PrototypeHolder {
/** /**
* A container for templates visible inside this group * A container for templates visible inside this group
*/ */
@Serializable(PrototypesSerializer::class) @Serializable(Prototypes.Companion::class)
override var prototypes: MutableVisionGroup? = null override var prototypes: MutableVisionGroup? = null
private set private set
@ -39,13 +44,10 @@ public class SolidGroup : VisionGroupBase(), Solid, PrototypeHolder {
}).run(builder) }).run(builder)
} }
@Serializable(Point3DSerializer::class)
override var position: Point3D? = null override var position: Point3D? = null
@Serializable(Point3DSerializer::class)
override var rotation: Point3D? = null override var rotation: Point3D? = null
@Serializable(Point3DSerializer::class)
override var scale: Point3D? = null override var scale: Point3D? = null
override fun attachChildren() { override fun attachChildren() {
@ -91,7 +93,7 @@ public fun MutableVisionGroup.group(name: String, action: SolidGroup.() -> Unit
/** /**
* A special class which works as a holder for prototypes * A special class which works as a holder for prototypes
*/ */
@Serializable(PrototypesSerializer::class) @Serializable(Prototypes.Companion::class)
internal class Prototypes( internal class Prototypes(
children: Map<NameToken, Vision> = emptyMap(), children: Map<NameToken, Vision> = emptyMap(),
) : VisionGroupBase(), PrototypeHolder { ) : VisionGroupBase(), PrototypeHolder {
@ -118,4 +120,24 @@ internal class Prototypes(
(it as? VisionGroup)?.attachChildren() (it as? VisionGroup)?.attachChildren()
} }
} }
companion object : KSerializer<MutableVisionGroup> {
private val mapSerializer: KSerializer<Map<NameToken, Vision>> =
MapSerializer(
NameToken.serializer(),
Vision.serializer()
)
override val descriptor: SerialDescriptor get() = mapSerializer.descriptor
override fun deserialize(decoder: Decoder): MutableVisionGroup {
val map = mapSerializer.deserialize(decoder)
return Prototypes(map)
}
override fun serialize(encoder: Encoder, value: MutableVisionGroup) {
mapSerializer.serialize(encoder, value.children)
}
}
} }

View File

@ -13,7 +13,10 @@ import hep.dataforge.vision.VisionGroupBase
import hep.dataforge.vision.VisionManager import hep.dataforge.vision.VisionManager
import hep.dataforge.vision.VisionManager.Companion.VISION_SERIALIZER_MODULE_TARGET import hep.dataforge.vision.VisionManager.Companion.VISION_SERIALIZER_MODULE_TARGET
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.* import kotlinx.serialization.modules.PolymorphicModuleBuilder
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.polymorphic
import kotlinx.serialization.modules.subclass
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -47,9 +50,6 @@ public class SolidManager(meta: Meta) : AbstractPlugin(meta) {
} }
public val serializersModuleForSolids: SerializersModule = SerializersModule { public val serializersModuleForSolids: SerializersModule = SerializersModule {
contextual(Point3DSerializer)
contextual(Point2DSerializer)
polymorphic(Vision::class) { polymorphic(Vision::class) {
subclass(VisionGroupBase.serializer()) subclass(VisionGroupBase.serializer())
solids() solids()

View File

@ -2,45 +2,47 @@ package hep.dataforge.vision.solid
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaBuilder
import hep.dataforge.meta.double
import hep.dataforge.meta.get import hep.dataforge.meta.get
import hep.dataforge.meta.number import kotlinx.serialization.Serializable
import kotlin.math.PI import kotlin.math.PI
public object World {
public val ZERO: Point3D = Point3D(0.0, 0.0, 0.0)
public val ONE: Point3D = Point3D(1.0, 1.0, 1.0)
}
public const val PI2: Float = 2 * PI.toFloat() public const val PI2: Float = 2 * PI.toFloat()
public expect class Point2D(x: Number, y: Number) { @Serializable
public var x: Double public data class Point2D(public var x: Double, public var y: Double){
public var y: Double public constructor(x: Number, y: Number) : this(x.toDouble(), y.toDouble())
} }
public operator fun Point2D.component1(): Double = x
public operator fun Point2D.component2(): Double = y
public fun Point2D.toMeta(): Meta = Meta { public fun Point2D.toMeta(): Meta = Meta {
Solid.X_KEY put x Solid.X_KEY put x
Solid.Y_KEY put y Solid.Y_KEY put y
} }
internal fun Meta.point2D(): Point2D = Point2D(this["x"].number ?: 0, this["y"].number ?: 0) internal fun Meta.point2D(): Point2D = Point2D(this["x"].double ?: 0.0, this["y"].double ?: 0.0)
public expect class Point3D(x: Number, y: Number, z: Number) { @Serializable
public var x: Double public data class Point3D(
public var y: Double public var x: Double,
public var z: Double public var y: Double,
public var z: Double,
) {
public constructor(x: Number, y: Number, z: Number) : this(x.toDouble(), y.toDouble(), z.toDouble())
public companion object{
public val ZERO: Point3D = Point3D(0.0, 0.0, 0.0)
public val ONE: Point3D = Point3D(1.0, 1.0, 1.0)
}
} }
public expect operator fun Point3D.plus(other: Point3D): Point3D public operator fun Point3D.plus(other: Point3D): Point3D = Point3D(
this.x + other.x,
this.y + other.y,
this.z + other.z
)
public operator fun Point3D.component1(): Double = x internal fun Meta.point3D() = Point3D(this["x"].double ?: 0.0, this["y"].double ?: 0.0, this["y"].double ?: 0.0)
public operator fun Point3D.component2(): Double = y
public operator fun Point3D.component3(): Double = z
internal fun Meta.point3D() = Point3D(this["x"].number ?: 0, this["y"].number ?: 0, this["y"].number ?: 0)
public fun Point3D.toMeta(): MetaBuilder = Meta { public fun Point3D.toMeta(): MetaBuilder = Meta {
Solid.X_KEY put x Solid.X_KEY put x

View File

@ -1,100 +0,0 @@
package hep.dataforge.vision.solid
import hep.dataforge.names.NameToken
import hep.dataforge.vision.MutableVisionGroup
import hep.dataforge.vision.Vision
import kotlinx.serialization.*
import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.nullable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.descriptors.element
import kotlinx.serialization.encoding.*
@OptIn(ExperimentalSerializationApi::class)
public object Point3DSerializer : KSerializer<Point3D> {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("hep.dataforge.vis.spatial.Point3D") {
element<Double>("x")
element<Double>("y")
element<Double>("z")
}
override fun deserialize(decoder: Decoder): Point3D {
var x: Double? = null
var y: Double? = null
var z: Double? = null
decoder.decodeStructure(descriptor) {
loop@ while (true) {
when (val i = decodeElementIndex(descriptor)) {
CompositeDecoder.DECODE_DONE -> break@loop
0 -> x = decodeNullableSerializableElement(descriptor, 0, Double.serializer().nullable) ?: 0.0
1 -> y = decodeNullableSerializableElement(descriptor, 1, Double.serializer().nullable) ?: 0.0
2 -> z = decodeNullableSerializableElement(descriptor, 2, Double.serializer().nullable) ?: 0.0
else -> throw SerializationException("Unknown index $i")
}
}
}
return Point3D(x ?: 0.0, y ?: 0.0, z ?: 0.0)
}
override fun serialize(encoder: Encoder, value: Point3D) {
encoder.encodeStructure(descriptor) {
if (value.x != 0.0) encodeDoubleElement(descriptor, 0, value.x)
if (value.y != 0.0) encodeDoubleElement(descriptor, 1, value.y)
if (value.z != 0.0) encodeDoubleElement(descriptor, 2, value.z)
}
}
}
@OptIn(ExperimentalSerializationApi::class)
public object Point2DSerializer : KSerializer<Point2D> {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("hep.dataforge.vis.spatial.Point2D") {
element<Double>("x")
element<Double>("y")
}
override fun deserialize(decoder: Decoder): Point2D {
var x: Double? = null
var y: Double? = null
decoder.decodeStructure(descriptor) {
loop@ while (true) {
when (val i = decodeElementIndex(descriptor)) {
CompositeDecoder.DECODE_DONE -> break@loop
0 -> x = decodeNullableSerializableElement(descriptor, 0, Double.serializer().nullable) ?: 0.0
1 -> y = decodeNullableSerializableElement(descriptor, 1, Double.serializer().nullable) ?: 0.0
else -> throw SerializationException("Unknown index $i")
}
}
}
return Point2D(x ?: 0.0, y ?: 0.0)
}
override fun serialize(encoder: Encoder, value: Point2D) {
encoder.encodeStructure(descriptor) {
if (value.x != 0.0) encodeDoubleElement(descriptor, 0, value.x)
if (value.y != 0.0) encodeDoubleElement(descriptor, 1, value.y)
}
}
}
internal object PrototypesSerializer : KSerializer<MutableVisionGroup> {
private val mapSerializer: KSerializer<Map<NameToken, Vision>> =
MapSerializer(
NameToken.serializer(),
Vision.serializer()
)
override val descriptor: SerialDescriptor get() = mapSerializer.descriptor
override fun deserialize(decoder: Decoder): MutableVisionGroup {
val map = mapSerializer.deserialize(decoder)
return Prototypes(map)
}
override fun serialize(encoder: Encoder, value: MutableVisionGroup) {
mapSerializer.serialize(encoder, value.children)
}
}

View File

@ -17,8 +17,8 @@ internal fun mergeChild(parent: VisionGroup, child: Vision): Vision {
//parent.properties?.let { config.update(it) } //parent.properties?.let { config.update(it) }
if (this is Solid && parent is Solid) { if (this is Solid && parent is Solid) {
position = (position ?: World.ZERO) + (parent.position ?: World.ZERO) position = (position ?: Point3D.ZERO) + (parent.position ?: Point3D.ZERO)
rotation = (parent.rotation ?: World.ZERO) + (parent.rotation ?: World.ZERO) rotation = (parent.rotation ?: Point3D.ZERO) + (parent.rotation ?: Point3D.ZERO)
scale = when { scale = when {
scale == null && parent.scale == null -> null scale == null && parent.scale == null -> null
scale == null -> parent.scale scale == null -> parent.scale

View File

@ -1,14 +0,0 @@
package hep.dataforge.vision.solid
import info.laht.threekt.math.Vector2
import info.laht.threekt.math.Vector3
import info.laht.threekt.math.plus
public actual typealias Point2D = Vector2
public actual typealias Point3D = Vector3
public actual operator fun Point3D.plus(other: Point3D): Point3D {
return this.plus(other)
}

View File

@ -10,12 +10,14 @@ 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
internal fun Point3D.toVector() = Vector3(x, y, z)
/** /**
* An implementation of geometry builder for Three.js [BufferGeometry] * An implementation of geometry builder for Three.js [BufferGeometry]
*/ */
public class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> { public class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
private val vertices = ArrayList<Point3D>() private val vertices = ArrayList<Vector3>()
private val faces = ArrayList<Face3>() private val faces = ArrayList<Face3>()
private val vertexCache = HashMap<Point3D, Int>() private val vertexCache = HashMap<Point3D, Int>()
@ -25,14 +27,14 @@ public class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
return if (index > 0) { return if (index > 0) {
index index
} else { } else {
vertices.add(vertex) vertices.add(vertex.toVector())
vertexCache[vertex] = vertices.size - 1 vertexCache[vertex] = vertices.size - 1
vertices.size - 1 vertices.size - 1
} }
} }
override fun face(vertex1: Point3D, vertex2: Point3D, vertex3: Point3D, normal: Point3D?, meta: Meta) { override fun face(vertex1: Point3D, vertex2: Point3D, vertex3: Point3D, normal: Point3D?, meta: Meta) {
val face = Face3(append(vertex1), append(vertex2), append(vertex3), normal ?: Vector3(0, 0, 0)) val face = Face3(append(vertex1), append(vertex2), append(vertex3), normal?.toVector() ?: Vector3(0, 0, 0))
meta["materialIndex"].int?.let { face.materialIndex = it } meta["materialIndex"].int?.let { face.materialIndex = it }
meta["color"]?.getColor()?.let { face.color = it } meta["color"]?.getColor()?.let { face.color = it }
faces.add(face) faces.add(face)

View File

@ -15,7 +15,7 @@ public object ThreeLineFactory : ThreeFactory<PolyLine> {
override fun invoke(obj: PolyLine): Object3D { override fun invoke(obj: PolyLine): Object3D {
val geometry = Geometry().apply { val geometry = Geometry().apply {
vertices = obj.points.toTypedArray() vertices = Array(obj.points.size) { obj.points[it].toVector() }
} }
val material = ThreeMaterials.getLineMaterial(obj.getProperty(MeshThreeFactory.EDGES_MATERIAL_KEY).node, true) val material = ThreeMaterials.getLineMaterial(obj.getProperty(MeshThreeFactory.EDGES_MATERIAL_KEY).node, true)

View File

@ -22,6 +22,8 @@ public fun Geometry.toBufferGeometry(): BufferGeometry = BufferGeometry().apply
internal fun Double.toRadians() = this * PI / 180 internal fun Double.toRadians() = this * PI / 180
internal val ZERO = Vector3(0,0,0)
public fun CSG.toGeometry(): Geometry { public fun CSG.toGeometry(): Geometry {
val geom = Geometry() val geom = Geometry()
@ -37,7 +39,7 @@ public fun CSG.toGeometry(): Geometry {
} }
for (j in 3..polygon.vertices.size) { for (j in 3..polygon.vertices.size) {
val fc = Face3(v0, v0 + j - 2, v0 + j - 1, World.ZERO) val fc = Face3(v0, v0 + j - 2, v0 + j - 1, ZERO)
fc.vertexNormals = arrayOf( fc.vertexNormals = arrayOf(
Vector3().copy(pvs[0].normal), Vector3().copy(pvs[0].normal),
Vector3().copy(pvs[j - 2].normal), Vector3().copy(pvs[j - 2].normal),

View File

@ -16,6 +16,7 @@ import javafx.scene.shape.Shape3D
import javafx.scene.text.Font import javafx.scene.text.Font
import javafx.scene.text.Text import javafx.scene.text.Text
import javafx.scene.transform.Rotate import javafx.scene.transform.Rotate
import org.fxyz3d.geometry.Point3D
import org.fxyz3d.shapes.composites.PolyLine3D import org.fxyz3d.shapes.composites.PolyLine3D
import org.fxyz3d.shapes.primitives.CuboidMesh import org.fxyz3d.shapes.primitives.CuboidMesh
import org.fxyz3d.shapes.primitives.SpheroidMesh import org.fxyz3d.shapes.primitives.SpheroidMesh
@ -69,7 +70,7 @@ class FX3DPlugin : AbstractPlugin() {
y = layoutBounds.height / 2 y = layoutBounds.height / 2
} }
is PolyLine -> PolyLine3D( is PolyLine -> PolyLine3D(
obj.points.map { it.point }, obj.points.map { Point3D(it.x, it.y, it.z) },
obj.thickness.toFloat(), obj.thickness.toFloat(),
obj.getProperty(SolidMaterial.MATERIAL_COLOR_KEY)?.color() obj.getProperty(SolidMaterial.MATERIAL_COLOR_KEY)?.color()
).apply { ).apply {

View File

@ -1,50 +0,0 @@
package hep.dataforge.vision.solid
import org.fxyz3d.geometry.Point3D as FXPoint3D
public actual data class Point2D(public actual var x: Double, public actual var y: Double) {
actual constructor(x: Number, y: Number) : this(x.toDouble(), y.toDouble())
}
public actual class Point3D(val point: FXPoint3D) {
actual constructor(x: Number, y: Number, z: Number) : this(
FXPoint3D(
x.toFloat(),
y.toFloat(),
z.toFloat()
)
)
public actual var x: Double
inline get() = point.x.toDouble()
inline set(value) {
point.x = value.toFloat()
}
public actual var y: Double
inline get() = point.y.toDouble()
inline set(value) {
point.y = value.toFloat()
}
public actual var z: Double
inline get() = point.z.toDouble()
inline set(value) {
point.z = value.toFloat()
}
override fun equals(other: Any?): Boolean {
return this.point == (other as? Point3D)?.point
}
override fun hashCode(): Int {
return point.hashCode()
}
override fun toString(): String {
return point.toString()
}
}
public actual operator fun Point3D.plus(other: Point3D): Point3D {
return Point3D(point.add(other.point))
}