From 68cf4748d8e8aca5b2110263617322ecc933803d Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 27 Aug 2020 11:10:28 +0300 Subject: [PATCH] Fix name replication --- .../dataforge/vision/gdml/GDMLTransformer.kt | 33 +++++++++++-------- .../vision/solid/three/ThreeProxyFactory.kt | 3 +- .../info/laht/threekt/core/BufferGeometry.kt | 2 +- .../kotlin/info/laht/threekt/core/Geometry.kt | 2 +- .../kotlin/info/laht/threekt/core/Object3D.kt | 2 +- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GDMLTransformer.kt b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GDMLTransformer.kt index df14eb40..94749b45 100644 --- a/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GDMLTransformer.kt +++ b/visionforge-gdml/src/commonMain/kotlin/hep/dataforge/vision/gdml/GDMLTransformer.kt @@ -24,16 +24,16 @@ class GDMLTransformer(val root: GDML) { private val random = Random(222) enum class Action { - ACCEPT, + ADD, REJECT, - CACHE + PROTOTYPE } var lUnit: LUnit = LUnit.MM var aUnit: AUnit = AUnit.RADIAN - var solidAction: (GDMLSolid) -> Action = { Action.CACHE } - var volumeAction: (GDMLGroup) -> Action = { Action.CACHE } + var solidAction: (GDMLSolid) -> Action = { Action.PROTOTYPE } + var volumeAction: (GDMLGroup) -> Action = { Action.PROTOTYPE } /** * A special group for local templates @@ -49,6 +49,15 @@ class GDMLTransformer(val root: GDML) { internal val volumes by lazy { proto.group(volumesName) } + +// fun proxySolid(group: SolidGroup, solid: GDMLSolid, name: String): Proxy { +// val fullName = solidsName + name +// if (proto[fullName] == null) { +// solids.addSolid(this, solid, name) +// } +// return group.ref(fullName, name) +// } + private val styleCache = HashMap() var solidConfiguration: Solid.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ -> @@ -245,19 +254,17 @@ private fun SolidGroup.addSolid( } } - - - private fun SolidGroup.addSolidWithCaching( context: GDMLTransformer, solid: GDMLSolid, name: String = solid.name ): Solid? { return when (context.solidAction(solid)) { - GDMLTransformer.Action.ACCEPT -> { + GDMLTransformer.Action.ADD -> { addSolid(context, solid, name) } - GDMLTransformer.Action.CACHE -> { + GDMLTransformer.Action.PROTOTYPE -> { +// context.proxySolid(this, solid, name) val fullName = solidsName + solid.name.asName() if (context.proto[fullName] == null) { context.solids.addSolid(context, solid, solid.name) @@ -271,7 +278,6 @@ private fun SolidGroup.addSolidWithCaching( } } - private fun SolidGroup.addPhysicalVolume( context: GDMLTransformer, physVolume: GDMLPhysVolume @@ -291,17 +297,16 @@ private fun SolidGroup.addPhysicalVolume( } when (context.volumeAction(volume)) { - GDMLTransformer.Action.ACCEPT -> { + GDMLTransformer.Action.ADD -> { val group: SolidGroup = volume(context, volume) this[physVolume.name ?: ""] = group.withPosition(context, physVolume) } - GDMLTransformer.Action.CACHE -> { + GDMLTransformer.Action.PROTOTYPE -> { val fullName = volumesName + volume.name.asName() if (context.proto[fullName] == null) { context.proto[fullName] = volume(context, volume) } - - ref(fullName,physVolume.name ?: "").withPosition(context, physVolume) + ref(fullName, physVolume.name ?: "").withPosition(context, physVolume) } GDMLTransformer.Action.REJECT -> { //ignore diff --git a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeProxyFactory.kt b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeProxyFactory.kt index 2ceb75aa..832dd32d 100644 --- a/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeProxyFactory.kt +++ b/visionforge-solid/src/jsMain/kotlin/hep/dataforge/vision/solid/three/ThreeProxyFactory.kt @@ -17,10 +17,11 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { private fun Object3D.replicate(): Object3D { return when (this) { is Mesh -> Mesh(geometry as BufferGeometry, material).also { - it.applyMatrix(matrix) + it.applyMatrix4(matrix) } else -> clone(false) }.also { obj: Object3D -> + obj.name = this.name children.forEach { child: Object3D -> obj.add(child.replicate()) } diff --git a/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/BufferGeometry.kt b/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/BufferGeometry.kt index a4219aeb..c3fd093b 100644 --- a/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/BufferGeometry.kt +++ b/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/BufferGeometry.kt @@ -99,7 +99,7 @@ open external class BufferGeometry { fun merge(bufferGeometry: BufferGeometry, offset: Int = definedExternally): BufferGeometry - fun applyMatrix(matrix: Matrix4) + fun applyMatrix4(matrix: Matrix4) fun lookAt(vector: Vector3): BufferGeometry fun rotateX(radians: Double): BufferGeometry fun rotateY(radians: Double): BufferGeometry diff --git a/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/Geometry.kt b/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/Geometry.kt index 518cc6d6..522ab07c 100644 --- a/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/Geometry.kt +++ b/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/Geometry.kt @@ -70,7 +70,7 @@ open external class Geometry { var lineDistancesNeedUpdate: Boolean var groupsNeedUpdate: Boolean - fun applyMatrix(matrix: Matrix4): Geometry + fun applyMatrix4(matrix: Matrix4): Geometry fun rotateX(angle: Number): Geometry fun rotateY(angle: Number): Geometry fun rotateZ(angle: Number): Geometry diff --git a/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/Object3D.kt b/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/Object3D.kt index be7a95d5..e49add5e 100644 --- a/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/Object3D.kt +++ b/visionforge-solid/src/jsMain/kotlin/info/laht/threekt/core/Object3D.kt @@ -165,7 +165,7 @@ open external class Object3D { /** * Applies the matrix transform to the object and updates the object's position, rotation and scale. */ - fun applyMatrix(matrix: Matrix4) + fun applyMatrix4(matrix: Matrix4) /** * Applies the rotation represented by the quaternion to the object.