replicate mesh
This commit is contained in:
parent
b362f86f9b
commit
998afb1ce0
@ -1,5 +1,6 @@
|
||||
import scientifik.DependencyConfiguration
|
||||
import scientifik.FXModule
|
||||
import scientifik.useFx
|
||||
|
||||
plugins {
|
||||
id("scientifik.mpp")
|
||||
|
@ -67,7 +67,6 @@ val GDMLApp = component<GDMLAppProps> { props ->
|
||||
error("File extension is not recognized: $name")
|
||||
}
|
||||
}
|
||||
parsedVision.config["edges.enabled"] = false
|
||||
|
||||
vision = parsedVision
|
||||
}
|
||||
|
@ -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<GDMLMaterial, Meta>()
|
||||
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<Name, Meta>()
|
||||
|
||||
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
|
||||
|
@ -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<Proxy> {
|
||||
|
||||
override val type: KClass<Proxy> = 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<Proxy> {
|
||||
three.buildObject3D(template)
|
||||
}
|
||||
|
||||
val object3D: Object3D = cachedObject.clone()//cachedObject.replicate()
|
||||
val object3D: Object3D = cachedObject.replicate()
|
||||
object3D.updatePosition(obj)
|
||||
|
||||
if(object3D is Mesh){
|
||||
|
Loading…
Reference in New Issue
Block a user