forked from kscience/visionforge
BMN rendering optimization
This commit is contained in:
parent
e5a27ab56f
commit
e9d73b28fe
@ -2,7 +2,6 @@ package hep.dataforge.vis.spatial.gdml
|
||||
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.meta.buildMeta
|
||||
import hep.dataforge.meta.builder
|
||||
import hep.dataforge.vis.spatial.VisualGroup3D
|
||||
import hep.dataforge.vis.spatial.VisualObject3D
|
||||
import hep.dataforge.vis.spatial.material
|
||||
@ -30,9 +29,9 @@ class GDMLTransformer(val root: GDML) {
|
||||
var volumeAction: (GDMLGroup) -> Action = { Action.ACCEPT }
|
||||
|
||||
|
||||
var transparent: GDMLVolume.(GDMLSolid?) -> Boolean = { !physVolumes.isEmpty() }
|
||||
var configure: VisualObject3D.(parent: GDMLVolume, solid: GDMLSolid) -> Unit = { _, _ -> }
|
||||
|
||||
internal fun configureSolid(obj: VisualObject3D, parent: GDMLVolume, solid: GDMLSolid?) {
|
||||
internal fun configureSolid(obj: VisualObject3D, parent: GDMLVolume, solid: GDMLSolid) {
|
||||
val material = parent.materialref.resolve(root) ?: GDMLElement(parent.materialref.ref)
|
||||
|
||||
val materialColor = materialCache.getOrPut(material) {
|
||||
@ -41,11 +40,8 @@ class GDMLTransformer(val root: GDML) {
|
||||
}
|
||||
}
|
||||
|
||||
obj.material = if (parent.transparent(solid)) {
|
||||
materialColor.builder().apply { "opacity" to 0.5 }
|
||||
} else {
|
||||
materialColor
|
||||
}
|
||||
obj.material = materialColor
|
||||
obj.configure(parent, solid)
|
||||
}
|
||||
|
||||
fun printStatistics() {
|
||||
|
@ -6,6 +6,7 @@ import hep.dataforge.vis.hmr.startApplication
|
||||
import hep.dataforge.vis.spatial.gdml.GDMLTransformer
|
||||
import hep.dataforge.vis.spatial.gdml.LUnit
|
||||
import hep.dataforge.vis.spatial.gdml.toVisual
|
||||
import hep.dataforge.vis.spatial.opacity
|
||||
import hep.dataforge.vis.spatial.three.ThreePlugin
|
||||
import hep.dataforge.vis.spatial.three.output
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@ -93,22 +94,41 @@ private class GDMLDemoApp : ApplicationBase() {
|
||||
lUnit = LUnit.CM
|
||||
volumeAction = { volume ->
|
||||
when {
|
||||
volume.name.startsWith("ecal") -> GDMLTransformer.Action.REJECT
|
||||
volume.name.startsWith("ecal01lay") -> GDMLTransformer.Action.REJECT
|
||||
volume.name.startsWith("ecal") -> GDMLTransformer.Action.CACHE
|
||||
volume.name.startsWith("UPBL") -> GDMLTransformer.Action.REJECT
|
||||
volume.name.startsWith("USCL") -> GDMLTransformer.Action.REJECT
|
||||
volume.name.startsWith("U") -> GDMLTransformer.Action.CACHE
|
||||
volume.name.startsWith("VPBL") -> GDMLTransformer.Action.REJECT
|
||||
volume.name.startsWith("VSCL") -> GDMLTransformer.Action.REJECT
|
||||
volume.name.startsWith("V") -> GDMLTransformer.Action.CACHE
|
||||
else -> GDMLTransformer.Action.ACCEPT
|
||||
}
|
||||
}
|
||||
|
||||
transparent = { !physVolumes.isEmpty() || (it?.name?.startsWith("Coil") ?: false) }
|
||||
|
||||
configure = { parent, solid ->
|
||||
if (!parent.physVolumes.isEmpty()) {
|
||||
opacity = 0.3
|
||||
}
|
||||
if (solid.name.startsWith("Coil")
|
||||
|| solid.name.startsWith("Yoke")
|
||||
|| solid.name.startsWith("Magnet")
|
||||
|| solid.name.startsWith("Pole")
|
||||
) {
|
||||
opacity = 0.3
|
||||
}
|
||||
}
|
||||
}
|
||||
launch { message("Rendering") }
|
||||
val output = three.output(canvas) {
|
||||
"axis" to {
|
||||
"size" to 100
|
||||
}
|
||||
// "axis" to {
|
||||
// "size" to 100
|
||||
// }
|
||||
}
|
||||
//make top layer visible
|
||||
//output.camera.layers.disable(0)
|
||||
output.camera.layers.enable(1)
|
||||
|
||||
output.render(visual)
|
||||
launch {
|
||||
message(null)
|
||||
|
@ -17,7 +17,7 @@ import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.UseSerializers
|
||||
|
||||
@Serializable
|
||||
class VisualGroup3D() : AbstractVisualGroup(), VisualObject3D {
|
||||
class VisualGroup3D : AbstractVisualGroup(), VisualObject3D {
|
||||
/**
|
||||
* A container for templates visible inside this group
|
||||
*/
|
||||
|
@ -94,12 +94,20 @@ var VisualObject.material: Meta?
|
||||
get() = getProperty(MATERIAL_KEY).node
|
||||
set(value) = setProperty(MATERIAL_KEY, value)
|
||||
|
||||
var VisualObject.opacity: Double
|
||||
get() = material?.get("opacity").double ?: 1.0
|
||||
set(value) {
|
||||
material = (material?.builder() ?: MetaBuilder()).apply {
|
||||
"opacity" to value
|
||||
}
|
||||
}
|
||||
|
||||
var VisualObject.visible: Boolean?
|
||||
get() = getProperty(VISIBLE_KEY).boolean
|
||||
set(value) = setProperty(VISIBLE_KEY, value)
|
||||
|
||||
fun VisualObject.color(rgb: Int) {
|
||||
material = buildMeta { "color" to rgb }
|
||||
material = (material?.builder() ?: MetaBuilder()).apply { "color" to rgb }
|
||||
}
|
||||
|
||||
fun VisualObject3D.material(builder: MetaBuilder.() -> Unit) {
|
||||
|
@ -43,6 +43,13 @@ internal fun Object3D.updatePosition(obj: VisualObject3D) {
|
||||
updateMatrix()
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of layers to the top object. Return 1 if this is top layer
|
||||
*/
|
||||
val VisualObject3D.layer: Int
|
||||
get() = getProperty(MeshThreeFactory.LAYER_KEY).int ?: ((parent as? VisualObject3D)?.layer ?: 0 + 1)
|
||||
|
||||
|
||||
internal fun <T : VisualObject3D> Mesh.updateFrom(obj: T) {
|
||||
matrixAutoUpdate = false
|
||||
|
||||
@ -61,8 +68,9 @@ internal fun <T : VisualObject3D> Mesh.updateFrom(obj: T) {
|
||||
//set position for mesh
|
||||
updatePosition(obj)
|
||||
|
||||
obj.getProperty(MeshThreeFactory.LAYER_KEY).int?.let {
|
||||
layers.set(it)
|
||||
layers.enable(obj.layer)
|
||||
children.forEach {
|
||||
it.layers.enable(obj.layer)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<V
|
||||
}
|
||||
}
|
||||
|
||||
private val camera = three.buildCamera(meta["camera"].node ?: EmptyMeta)
|
||||
val camera = three.buildCamera(meta["camera"].node ?: EmptyMeta)
|
||||
|
||||
fun attach(element: Element, computeWidth: Element.() -> Int = { element.clientWidth }) {
|
||||
val width by meta.number(computeWidth(element)).int
|
||||
|
@ -71,5 +71,5 @@ external class Layers {
|
||||
* Returns true if this and the passed layers object are members of the same set of layers.
|
||||
* @param layers a Layers object
|
||||
*/
|
||||
fun test(layers: Int)
|
||||
fun test(layers: Layers): Boolean
|
||||
}
|
Loading…
Reference in New Issue
Block a user