Fix name replication

This commit is contained in:
Alexander Nozik 2020-08-27 11:10:28 +03:00
parent ea82082304
commit 68cf4748d8
5 changed files with 24 additions and 18 deletions

View File

@ -24,16 +24,16 @@ class GDMLTransformer(val root: GDML) {
private val random = Random(222) private val random = Random(222)
enum class Action { enum class Action {
ACCEPT, ADD,
REJECT, REJECT,
CACHE PROTOTYPE
} }
var lUnit: LUnit = LUnit.MM var lUnit: LUnit = LUnit.MM
var aUnit: AUnit = AUnit.RADIAN var aUnit: AUnit = AUnit.RADIAN
var solidAction: (GDMLSolid) -> Action = { Action.CACHE } var solidAction: (GDMLSolid) -> Action = { Action.PROTOTYPE }
var volumeAction: (GDMLGroup) -> Action = { Action.CACHE } var volumeAction: (GDMLGroup) -> Action = { Action.PROTOTYPE }
/** /**
* A special group for local templates * A special group for local templates
@ -49,6 +49,15 @@ class GDMLTransformer(val root: GDML) {
internal val volumes by lazy { internal val volumes by lazy {
proto.group(volumesName) 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<Name, Meta>() private val styleCache = HashMap<Name, Meta>()
var solidConfiguration: Solid.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ -> var solidConfiguration: Solid.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ ->
@ -245,19 +254,17 @@ private fun SolidGroup.addSolid(
} }
} }
private fun SolidGroup.addSolidWithCaching( private fun SolidGroup.addSolidWithCaching(
context: GDMLTransformer, context: GDMLTransformer,
solid: GDMLSolid, solid: GDMLSolid,
name: String = solid.name name: String = solid.name
): Solid? { ): Solid? {
return when (context.solidAction(solid)) { return when (context.solidAction(solid)) {
GDMLTransformer.Action.ACCEPT -> { GDMLTransformer.Action.ADD -> {
addSolid(context, solid, name) addSolid(context, solid, name)
} }
GDMLTransformer.Action.CACHE -> { GDMLTransformer.Action.PROTOTYPE -> {
// context.proxySolid(this, solid, name)
val fullName = solidsName + solid.name.asName() val fullName = solidsName + solid.name.asName()
if (context.proto[fullName] == null) { if (context.proto[fullName] == null) {
context.solids.addSolid(context, solid, solid.name) context.solids.addSolid(context, solid, solid.name)
@ -271,7 +278,6 @@ private fun SolidGroup.addSolidWithCaching(
} }
} }
private fun SolidGroup.addPhysicalVolume( private fun SolidGroup.addPhysicalVolume(
context: GDMLTransformer, context: GDMLTransformer,
physVolume: GDMLPhysVolume physVolume: GDMLPhysVolume
@ -291,16 +297,15 @@ private fun SolidGroup.addPhysicalVolume(
} }
when (context.volumeAction(volume)) { when (context.volumeAction(volume)) {
GDMLTransformer.Action.ACCEPT -> { GDMLTransformer.Action.ADD -> {
val group: SolidGroup = volume(context, volume) val group: SolidGroup = volume(context, volume)
this[physVolume.name ?: ""] = group.withPosition(context, physVolume) this[physVolume.name ?: ""] = group.withPosition(context, physVolume)
} }
GDMLTransformer.Action.CACHE -> { GDMLTransformer.Action.PROTOTYPE -> {
val fullName = volumesName + volume.name.asName() val fullName = volumesName + volume.name.asName()
if (context.proto[fullName] == null) { if (context.proto[fullName] == null) {
context.proto[fullName] = volume(context, volume) context.proto[fullName] = volume(context, volume)
} }
ref(fullName, physVolume.name ?: "").withPosition(context, physVolume) ref(fullName, physVolume.name ?: "").withPosition(context, physVolume)
} }
GDMLTransformer.Action.REJECT -> { GDMLTransformer.Action.REJECT -> {

View File

@ -17,10 +17,11 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory<Proxy> {
private fun Object3D.replicate(): Object3D { private fun Object3D.replicate(): Object3D {
return when (this) { return when (this) {
is Mesh -> Mesh(geometry as BufferGeometry, material).also { is Mesh -> Mesh(geometry as BufferGeometry, material).also {
it.applyMatrix(matrix) it.applyMatrix4(matrix)
} }
else -> clone(false) else -> clone(false)
}.also { obj: Object3D -> }.also { obj: Object3D ->
obj.name = this.name
children.forEach { child: Object3D -> children.forEach { child: Object3D ->
obj.add(child.replicate()) obj.add(child.replicate())
} }

View File

@ -99,7 +99,7 @@ open external class BufferGeometry {
fun merge(bufferGeometry: BufferGeometry, offset: Int = definedExternally): BufferGeometry fun merge(bufferGeometry: BufferGeometry, offset: Int = definedExternally): BufferGeometry
fun applyMatrix(matrix: Matrix4) fun applyMatrix4(matrix: Matrix4)
fun lookAt(vector: Vector3): BufferGeometry fun lookAt(vector: Vector3): BufferGeometry
fun rotateX(radians: Double): BufferGeometry fun rotateX(radians: Double): BufferGeometry
fun rotateY(radians: Double): BufferGeometry fun rotateY(radians: Double): BufferGeometry

View File

@ -70,7 +70,7 @@ open external class Geometry {
var lineDistancesNeedUpdate: Boolean var lineDistancesNeedUpdate: Boolean
var groupsNeedUpdate: Boolean var groupsNeedUpdate: Boolean
fun applyMatrix(matrix: Matrix4): Geometry fun applyMatrix4(matrix: Matrix4): Geometry
fun rotateX(angle: Number): Geometry fun rotateX(angle: Number): Geometry
fun rotateY(angle: Number): Geometry fun rotateY(angle: Number): Geometry
fun rotateZ(angle: Number): Geometry fun rotateZ(angle: Number): Geometry

View File

@ -165,7 +165,7 @@ open external class Object3D {
/** /**
* Applies the matrix transform to the object and updates the object's position, rotation and scale. * 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. * Applies the rotation represented by the quaternion to the object.