Wireframe for a cube

This commit is contained in:
Alexander Nozik 2019-03-08 21:38:49 +03:00
parent 4db090c240
commit c2d15ded20
3 changed files with 22 additions and 3 deletions

View File

@ -12,8 +12,10 @@ import info.laht.threekt.cameras.PerspectiveCamera
import info.laht.threekt.core.Object3D import info.laht.threekt.core.Object3D
import info.laht.threekt.external.controls.OrbitControls import info.laht.threekt.external.controls.OrbitControls
import info.laht.threekt.geometries.BoxBufferGeometry import info.laht.threekt.geometries.BoxBufferGeometry
import info.laht.threekt.geometries.WireframeGeometry
import info.laht.threekt.lights.AmbientLight import info.laht.threekt.lights.AmbientLight
import info.laht.threekt.math.ColorConstants import info.laht.threekt.math.ColorConstants
import info.laht.threekt.objects.LineSegments
import info.laht.threekt.objects.Mesh import info.laht.threekt.objects.Mesh
import info.laht.threekt.scenes.Scene import info.laht.threekt.scenes.Scene
import org.w3c.dom.Element import org.w3c.dom.Element
@ -82,6 +84,8 @@ class ThreeOutput(override val context: Context) : Output<DisplayObject> {
material = box["color"].material() material = box["color"].material()
} }
Mesh(geometry, obj["color"].material()).also { mesh -> 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) { _, _, _ -> obj.onChange(this) { _, _, _ ->
mesh.updateProperties(obj) mesh.updateProperties(obj)
mesh.update(obj) mesh.update(obj)
@ -98,7 +102,9 @@ class ThreeOutput(override val context: Context) : Output<DisplayObject> {
} }
override fun render(obj: DisplayObject, meta: Meta) { override fun render(obj: DisplayObject, meta: Meta) {
buildNode(obj)?.let { scene.add(it) } buildNode(obj)?.let {
scene.add(it)
}
} }
// init { // init {

View File

@ -1,18 +1,26 @@
package hep.dataforge.vis.spatial package hep.dataforge.vis.spatial
import hep.dataforge.meta.EmptyMeta import hep.dataforge.meta.*
import hep.dataforge.meta.Meta import hep.dataforge.names.toName
import hep.dataforge.vis.DisplayGroup import hep.dataforge.vis.DisplayGroup
import hep.dataforge.vis.DisplayLeaf import hep.dataforge.vis.DisplayLeaf
import hep.dataforge.vis.DisplayObject import hep.dataforge.vis.DisplayObject
class Extruded(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, TYPE, meta) { class Extruded(parent: DisplayObject?, meta: Meta) : DisplayLeaf(parent, TYPE, meta) {
val shape get() = shape(properties["shape"] ?: error("Shape not defined"))
companion object { companion object {
const val TYPE = "geometry.spatial.extruded" 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 = {}) = fun DisplayGroup.extrude(meta: Meta = EmptyMeta, action: Extruded.() -> Unit = {}) =
Extruded(this, meta).apply(action).also { addChild(it) } Extruded(this, meta).apply(action).also { addChild(it) }

View File

@ -1 +1,6 @@
package hep.dataforge.vis.spatial package hep.dataforge.vis.spatial
data class Point2D(val x: Number, val y: Number)
typealias Shape2D = List<Point2D>