From 998afb1ce0c1b3a9b3f6bb75bc9351c3cd7c9bfc Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 26 Aug 2020 22:54:26 +0300 Subject: [PATCH] replicate mesh --- demo/gdml/build.gradle.kts | 1 + .../vision/gdml/demo/GDMLAppComponent.kt | 1 - .../dataforge/vision/gdml/GDMLTransformer.kt | 24 ++++++++++++++---- .../vision/solid/three/ThreeProxyFactory.kt | 25 +++++++++++-------- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/demo/gdml/build.gradle.kts b/demo/gdml/build.gradle.kts index 8d5342c3..1ae0ffd9 100644 --- a/demo/gdml/build.gradle.kts +++ b/demo/gdml/build.gradle.kts @@ -1,5 +1,6 @@ import scientifik.DependencyConfiguration import scientifik.FXModule +import scientifik.useFx plugins { id("scientifik.mpp") diff --git a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GDMLAppComponent.kt b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GDMLAppComponent.kt index ae1dce60..99d4bc59 100644 --- a/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GDMLAppComponent.kt +++ b/demo/gdml/src/jsMain/kotlin/hep/dataforge/vision/gdml/demo/GDMLAppComponent.kt @@ -67,7 +67,6 @@ val GDMLApp = component { props -> error("File extension is not recognized: $name") } } - parsedVision.config["edges.enabled"] = false vision = parsedVision } 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 ad48480b..299a9b16 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 @@ -2,6 +2,7 @@ package hep.dataforge.vision.gdml import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder +import hep.dataforge.meta.set import hep.dataforge.names.Name import hep.dataforge.names.asName import hep.dataforge.names.plus @@ -15,6 +16,9 @@ import kotlin.math.cos import kotlin.math.sin import kotlin.random.Random +private val solidsName = "solids".asName() +private val volumesName = "volumes".asName() + class GDMLTransformer(val root: GDML) { //private val materialCache = HashMap() private val random = Random(222) @@ -35,6 +39,18 @@ class GDMLTransformer(val root: GDML) { * A special group for local templates */ internal val proto by lazy { SolidGroup() } + + internal val solids by lazy { + proto.group(solidsName) { + config["edges.enabled"] = false + } + } + + internal val volumes by lazy { + proto.group(volumesName) { + config["edges.enabled"] = true + } + } private val styleCache = HashMap() var solidConfiguration: Solid.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ -> @@ -231,7 +247,7 @@ private fun SolidGroup.addSolid( } -private val solidsName = "solids".asName() + private fun SolidGroup.addSolidWithCaching( context: GDMLTransformer, @@ -245,8 +261,7 @@ private fun SolidGroup.addSolidWithCaching( GDMLTransformer.Action.CACHE -> { val fullName = solidsName + solid.name.asName() if (context.proto[fullName] == null) { - val parent = (context.proto[solidsName] as? SolidGroup) ?: context.proto.group(solidsName) - parent.addSolid(context, solid, solid.name) + context.solids.addSolid(context, solid, solid.name) } ref(fullName, name) } @@ -257,7 +272,6 @@ private fun SolidGroup.addSolidWithCaching( } } -private val volumesName = "volumes".asName() private fun SolidGroup.addPhysicalVolume( context: GDMLTransformer, @@ -288,7 +302,7 @@ private fun SolidGroup.addPhysicalVolume( context.proto[fullName] = volume(context, volume) } - this[physVolume.name ?: ""] = Proxy(this, fullName).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 9063a968..2ceb75aa 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 @@ -4,6 +4,7 @@ import hep.dataforge.names.toName import hep.dataforge.vision.solid.Proxy import hep.dataforge.vision.solid.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX import hep.dataforge.vision.solid.Solid +import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.Object3D import info.laht.threekt.objects.Mesh import kotlin.reflect.KClass @@ -13,16 +14,18 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { override val type: KClass = Proxy::class -// private fun Object3D.replicate(): Object3D { -// return when (this) { -// is Mesh -> Mesh(geometry as BufferGeometry, material) -// else -> clone(false) -// }.also { obj: Object3D -> -// children.forEach { child: Object3D -> -// obj.add(child.replicate()) -// } -// } -// } + private fun Object3D.replicate(): Object3D { + return when (this) { + is Mesh -> Mesh(geometry as BufferGeometry, material).also { + it.applyMatrix(matrix) + } + else -> clone(false) + }.also { obj: Object3D -> + children.forEach { child: Object3D -> + obj.add(child.replicate()) + } + } + } override fun invoke(obj: Proxy): Object3D { val template = obj.prototype @@ -30,7 +33,7 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory { three.buildObject3D(template) } - val object3D: Object3D = cachedObject.clone()//cachedObject.replicate() + val object3D: Object3D = cachedObject.replicate() object3D.updatePosition(obj) if(object3D is Mesh){