From c2d15ded20ab355818d0f4e7b3f33e91e102ee14 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 8 Mar 2019 21:38:49 +0300 Subject: [PATCH] Wireframe for a cube --- .../kotlin/hep/dataforge/vis/spatial/ThreeOutput.kt | 8 +++++++- .../kotlin/hep/dataforge/vis/spatial/Extruded.kt | 12 ++++++++++-- .../kotlin/hep/dataforge/vis/spatial/Geometry.kt | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeOutput.kt b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeOutput.kt index 52156552..3d8aaae8 100644 --- a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeOutput.kt +++ b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeOutput.kt @@ -12,8 +12,10 @@ import info.laht.threekt.cameras.PerspectiveCamera import info.laht.threekt.core.Object3D import info.laht.threekt.external.controls.OrbitControls import info.laht.threekt.geometries.BoxBufferGeometry +import info.laht.threekt.geometries.WireframeGeometry import info.laht.threekt.lights.AmbientLight import info.laht.threekt.math.ColorConstants +import info.laht.threekt.objects.LineSegments import info.laht.threekt.objects.Mesh import info.laht.threekt.scenes.Scene import org.w3c.dom.Element @@ -82,6 +84,8 @@ class ThreeOutput(override val context: Context) : Output { material = box["color"].material() } Mesh(geometry, obj["color"].material()).also { mesh -> + //TODO replace by edges after adding it to three.kt + mesh.add(LineSegments(WireframeGeometry(geometry),Materials.DEFAULT)) obj.onChange(this) { _, _, _ -> mesh.updateProperties(obj) mesh.update(obj) @@ -98,7 +102,9 @@ class ThreeOutput(override val context: Context) : Output { } override fun render(obj: DisplayObject, meta: Meta) { - buildNode(obj)?.let { scene.add(it) } + buildNode(obj)?.let { + scene.add(it) + } } // init { diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt index 86ae35a0..6f914ebf 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Extruded.kt @@ -1,18 +1,26 @@ package hep.dataforge.vis.spatial -import hep.dataforge.meta.EmptyMeta -import hep.dataforge.meta.Meta +import hep.dataforge.meta.* +import hep.dataforge.names.toName import hep.dataforge.vis.DisplayGroup import hep.dataforge.vis.DisplayLeaf import hep.dataforge.vis.DisplayObject class Extruded(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, TYPE, meta) { + val shape get() = shape(properties["shape"] ?: error("Shape not defined")) companion object { const val TYPE = "geometry.spatial.extruded" + + fun shape(item: MetaItem<*>): Shape2D { + return item.node?.getAll("xyPoint".toName())?.map { (_, value) -> + Point2D(value.node["x"].number ?: 0, value.node["y"].number ?: 0) + } ?: emptyList() + } } } + fun DisplayGroup.extrude(meta: Meta = EmptyMeta, action: Extruded.() -> Unit = {}) = Extruded(this, meta).apply(action).also { addChild(it) } \ No newline at end of file diff --git a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Geometry.kt b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Geometry.kt index b5664343..af41b44d 100644 --- a/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Geometry.kt +++ b/dataforge-vis-spatial/src/commonMain/kotlin/hep/dataforge/vis/spatial/Geometry.kt @@ -1 +1,6 @@ package hep.dataforge.vis.spatial + + +data class Point2D(val x: Number, val y: Number) + +typealias Shape2D = List \ No newline at end of file