diff --git a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeFactory.kt b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeFactory.kt index 31de44dd..b265d007 100644 --- a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeFactory.kt +++ b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeFactory.kt @@ -11,7 +11,6 @@ import hep.dataforge.vis.spatial.ThreeFactory.Companion.updateMesh import hep.dataforge.vis.spatial.three.ConvexBufferGeometry import hep.dataforge.vis.spatial.three.EdgesGeometry import hep.dataforge.vis.spatial.three.euler -import hep.dataforge.vis.spatial.three.toBufferGeometry import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.Object3D import info.laht.threekt.geometries.BoxBufferGeometry @@ -106,7 +105,7 @@ object ThreeShapeFactory : MeshThreeFactory(Shape::class) { override fun buildGeometry(obj: Shape): BufferGeometry { return obj.run { ThreeGeometryBuilder().apply { buildGeometry() }.build() - }.toBufferGeometry() + } } } diff --git a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeGeometryBuilder.kt b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeGeometryBuilder.kt index adb75831..a22e8846 100644 --- a/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeGeometryBuilder.kt +++ b/dataforge-vis-spatial-js/src/main/kotlin/hep/dataforge/vis/spatial/ThreeGeometryBuilder.kt @@ -3,22 +3,27 @@ package hep.dataforge.vis.spatial import hep.dataforge.meta.Meta import hep.dataforge.meta.get import hep.dataforge.meta.int +import hep.dataforge.vis.spatial.three.toBufferGeometry +import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.Face3 import info.laht.threekt.core.Geometry import info.laht.threekt.math.Color import info.laht.threekt.math.Vector3 -class ThreeGeometryBuilder : GeometryBuilder { +class ThreeGeometryBuilder : GeometryBuilder { private val vertices = ArrayList() private val faces = ArrayList() + private val vertexCache = HashMap() + private fun append(vertex: Point3D): Int { - val index = vertices.indexOf(vertex) + val index = vertexCache[vertex] ?: -1//vertices.indexOf(vertex) return if (index > 0) { index } else { vertices.add(vertex) + vertexCache[vertex] = vertices.size - 1 vertices.size - 1 } } @@ -38,10 +43,10 @@ class ThreeGeometryBuilder : GeometryBuilder { ) } - override fun build(): Geometry { + override fun build(): BufferGeometry { return Geometry().apply { vertices = this@ThreeGeometryBuilder.vertices.map { it.asVector() }.toTypedArray() faces = this@ThreeGeometryBuilder.faces.toTypedArray() - } + }.toBufferGeometry() } } \ No newline at end of file