forked from kscience/visionforge
Performance fix for vertices index
This commit is contained in:
parent
397cc4b679
commit
4274dfff88
@ -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>(Shape::class) {
|
||||
override fun buildGeometry(obj: Shape): BufferGeometry {
|
||||
return obj.run {
|
||||
ThreeGeometryBuilder().apply { buildGeometry() }.build()
|
||||
}.toBufferGeometry()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Geometry> {
|
||||
class ThreeGeometryBuilder : GeometryBuilder<BufferGeometry> {
|
||||
|
||||
private val vertices = ArrayList<Point3D>()
|
||||
private val faces = ArrayList<Face3>()
|
||||
|
||||
private val vertexCache = HashMap<Point3D, Int>()
|
||||
|
||||
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<Geometry> {
|
||||
)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user