forked from kscience/visionforge
replicate mesh
This commit is contained in:
parent
b362f86f9b
commit
998afb1ce0
@ -1,5 +1,6 @@
|
|||||||
import scientifik.DependencyConfiguration
|
import scientifik.DependencyConfiguration
|
||||||
import scientifik.FXModule
|
import scientifik.FXModule
|
||||||
|
import scientifik.useFx
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("scientifik.mpp")
|
id("scientifik.mpp")
|
||||||
|
@ -67,7 +67,6 @@ val GDMLApp = component<GDMLAppProps> { props ->
|
|||||||
error("File extension is not recognized: $name")
|
error("File extension is not recognized: $name")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parsedVision.config["edges.enabled"] = false
|
|
||||||
|
|
||||||
vision = parsedVision
|
vision = parsedVision
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package hep.dataforge.vision.gdml
|
|||||||
|
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import hep.dataforge.meta.MetaBuilder
|
import hep.dataforge.meta.MetaBuilder
|
||||||
|
import hep.dataforge.meta.set
|
||||||
import hep.dataforge.names.Name
|
import hep.dataforge.names.Name
|
||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
import hep.dataforge.names.plus
|
import hep.dataforge.names.plus
|
||||||
@ -15,6 +16,9 @@ import kotlin.math.cos
|
|||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
private val solidsName = "solids".asName()
|
||||||
|
private val volumesName = "volumes".asName()
|
||||||
|
|
||||||
class GDMLTransformer(val root: GDML) {
|
class GDMLTransformer(val root: GDML) {
|
||||||
//private val materialCache = HashMap<GDMLMaterial, Meta>()
|
//private val materialCache = HashMap<GDMLMaterial, Meta>()
|
||||||
private val random = Random(222)
|
private val random = Random(222)
|
||||||
@ -35,6 +39,18 @@ class GDMLTransformer(val root: GDML) {
|
|||||||
* A special group for local templates
|
* A special group for local templates
|
||||||
*/
|
*/
|
||||||
internal val proto by lazy { SolidGroup() }
|
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>()
|
private val styleCache = HashMap<Name, Meta>()
|
||||||
|
|
||||||
var solidConfiguration: Solid.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { parent, _ ->
|
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(
|
private fun SolidGroup.addSolidWithCaching(
|
||||||
context: GDMLTransformer,
|
context: GDMLTransformer,
|
||||||
@ -245,8 +261,7 @@ private fun SolidGroup.addSolidWithCaching(
|
|||||||
GDMLTransformer.Action.CACHE -> {
|
GDMLTransformer.Action.CACHE -> {
|
||||||
val fullName = solidsName + solid.name.asName()
|
val fullName = solidsName + solid.name.asName()
|
||||||
if (context.proto[fullName] == null) {
|
if (context.proto[fullName] == null) {
|
||||||
val parent = (context.proto[solidsName] as? SolidGroup) ?: context.proto.group(solidsName)
|
context.solids.addSolid(context, solid, solid.name)
|
||||||
parent.addSolid(context, solid, solid.name)
|
|
||||||
}
|
}
|
||||||
ref(fullName, name)
|
ref(fullName, name)
|
||||||
}
|
}
|
||||||
@ -257,7 +272,6 @@ private fun SolidGroup.addSolidWithCaching(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val volumesName = "volumes".asName()
|
|
||||||
|
|
||||||
private fun SolidGroup.addPhysicalVolume(
|
private fun SolidGroup.addPhysicalVolume(
|
||||||
context: GDMLTransformer,
|
context: GDMLTransformer,
|
||||||
@ -288,7 +302,7 @@ private fun SolidGroup.addPhysicalVolume(
|
|||||||
context.proto[fullName] = volume(context, volume)
|
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 -> {
|
GDMLTransformer.Action.REJECT -> {
|
||||||
//ignore
|
//ignore
|
||||||
|
@ -4,6 +4,7 @@ import hep.dataforge.names.toName
|
|||||||
import hep.dataforge.vision.solid.Proxy
|
import hep.dataforge.vision.solid.Proxy
|
||||||
import hep.dataforge.vision.solid.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX
|
import hep.dataforge.vision.solid.Proxy.Companion.PROXY_CHILD_PROPERTY_PREFIX
|
||||||
import hep.dataforge.vision.solid.Solid
|
import hep.dataforge.vision.solid.Solid
|
||||||
|
import info.laht.threekt.core.BufferGeometry
|
||||||
import info.laht.threekt.core.Object3D
|
import info.laht.threekt.core.Object3D
|
||||||
import info.laht.threekt.objects.Mesh
|
import info.laht.threekt.objects.Mesh
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
@ -13,16 +14,18 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory<Proxy> {
|
|||||||
|
|
||||||
override val type: KClass<Proxy> = Proxy::class
|
override val type: KClass<Proxy> = Proxy::class
|
||||||
|
|
||||||
// private fun Object3D.replicate(): Object3D {
|
private fun Object3D.replicate(): Object3D {
|
||||||
// return when (this) {
|
return when (this) {
|
||||||
// is Mesh -> Mesh(geometry as BufferGeometry, material)
|
is Mesh -> Mesh(geometry as BufferGeometry, material).also {
|
||||||
// else -> clone(false)
|
it.applyMatrix(matrix)
|
||||||
// }.also { obj: Object3D ->
|
}
|
||||||
// children.forEach { child: Object3D ->
|
else -> clone(false)
|
||||||
// obj.add(child.replicate())
|
}.also { obj: Object3D ->
|
||||||
// }
|
children.forEach { child: Object3D ->
|
||||||
// }
|
obj.add(child.replicate())
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun invoke(obj: Proxy): Object3D {
|
override fun invoke(obj: Proxy): Object3D {
|
||||||
val template = obj.prototype
|
val template = obj.prototype
|
||||||
@ -30,7 +33,7 @@ class ThreeProxyFactory(val three: ThreePlugin) : ThreeFactory<Proxy> {
|
|||||||
three.buildObject3D(template)
|
three.buildObject3D(template)
|
||||||
}
|
}
|
||||||
|
|
||||||
val object3D: Object3D = cachedObject.clone()//cachedObject.replicate()
|
val object3D: Object3D = cachedObject.replicate()
|
||||||
object3D.updatePosition(obj)
|
object3D.updatePosition(obj)
|
||||||
|
|
||||||
if(object3D is Mesh){
|
if(object3D is Mesh){
|
||||||
|
Loading…
Reference in New Issue
Block a user