forked from kscience/visionforge
Fix color inheritance issues
This commit is contained in:
parent
ccb916cff7
commit
4c235b0f53
@ -9,6 +9,8 @@ import hep.dataforge.names.asName
|
|||||||
import hep.dataforge.names.toName
|
import hep.dataforge.names.toName
|
||||||
import hep.dataforge.provider.Type
|
import hep.dataforge.provider.Type
|
||||||
import hep.dataforge.vision.Vision.Companion.TYPE
|
import hep.dataforge.vision.Vision.Companion.TYPE
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.serialization.Transient
|
import kotlinx.serialization.Transient
|
||||||
|
|
||||||
@ -24,6 +26,11 @@ public interface Vision : Described {
|
|||||||
@Transient
|
@Transient
|
||||||
public var parent: VisionGroup?
|
public var parent: VisionGroup?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A coroutine scope for asynchronous calls and locks
|
||||||
|
*/
|
||||||
|
public val scope: CoroutineScope get() = parent?.scope?: GlobalScope
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fast accessor method to get own property (no inheritance or styles).
|
* A fast accessor method to get own property (no inheritance or styles).
|
||||||
* Should be equivalent to `getProperty(name,false,false,false)`.
|
* Should be equivalent to `getProperty(name,false,false,false)`.
|
||||||
@ -32,8 +39,8 @@ public interface Vision : Described {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get property.
|
* Get property.
|
||||||
* @param inherit toggles parent node property lookup. Null means default inheritance.
|
* @param inherit toggles parent node property lookup. Null means inference from descriptor. Default is false.
|
||||||
* @param includeStyles toggles inclusion of. Null means default style inclusion.
|
* @param includeStyles toggles inclusion of. Null means inference from descriptor. Default is true.
|
||||||
*/
|
*/
|
||||||
public fun getProperty(
|
public fun getProperty(
|
||||||
name: Name,
|
name: Name,
|
||||||
|
@ -11,7 +11,6 @@ import hep.dataforge.names.Name
|
|||||||
import hep.dataforge.names.asName
|
import hep.dataforge.names.asName
|
||||||
import hep.dataforge.values.ValueType
|
import hep.dataforge.values.ValueType
|
||||||
import hep.dataforge.vision.Vision.Companion.STYLE_KEY
|
import hep.dataforge.vision.Vision.Companion.STYLE_KEY
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -103,7 +102,7 @@ public open class VisionBase : Vision {
|
|||||||
if (propertyName == STYLE_KEY) {
|
if (propertyName == STYLE_KEY) {
|
||||||
updateStyles(styles)
|
updateStyles(styles)
|
||||||
}
|
}
|
||||||
GlobalScope.launch {
|
scope.launch {
|
||||||
_propertyInvalidationFlow.emit(propertyName)
|
_propertyInvalidationFlow.emit(propertyName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package hep.dataforge.vision
|
package hep.dataforge.vision
|
||||||
|
|
||||||
import hep.dataforge.names.*
|
import hep.dataforge.names.*
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.SharedFlow
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -45,7 +44,7 @@ public open class VisionGroupBase : VisionBase(), MutableVisionGroup {
|
|||||||
* Propagate children change event upwards
|
* Propagate children change event upwards
|
||||||
*/
|
*/
|
||||||
private fun childrenChanged(name: NameToken, before: Vision?, after: Vision?) {
|
private fun childrenChanged(name: NameToken, before: Vision?, after: Vision?) {
|
||||||
GlobalScope.launch {
|
scope.launch {
|
||||||
_structureChanges.emit(MutableVisionGroup.StructureChange(name, before, after))
|
_structureChanges.emit(MutableVisionGroup.StructureChange(name, before, after))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ class FX3DPlugin : AbstractPlugin() {
|
|||||||
is PolyLine -> PolyLine3D(
|
is PolyLine -> PolyLine3D(
|
||||||
obj.points.map { Point3D(it.x, it.y, it.z) },
|
obj.points.map { Point3D(it.x, it.y, it.z) },
|
||||||
obj.thickness.toFloat(),
|
obj.thickness.toFloat(),
|
||||||
obj.getProperty(SolidMaterial.MATERIAL_COLOR_KEY)?.color()
|
obj.getProperty(SolidMaterial.MATERIAL_COLOR_KEY, inherit = true)?.color()
|
||||||
).apply {
|
).apply {
|
||||||
this.meshView.cullFace = CullFace.FRONT
|
this.meshView.cullFace = CullFace.FRONT
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,6 @@ import kotlinx.serialization.encoding.Decoder
|
|||||||
import kotlinx.serialization.encoding.Encoder
|
import kotlinx.serialization.encoding.Encoder
|
||||||
|
|
||||||
public interface PrototypeHolder {
|
public interface PrototypeHolder {
|
||||||
public val parent: VisionGroup?
|
|
||||||
|
|
||||||
@VisionBuilder
|
@VisionBuilder
|
||||||
public fun prototypes(builder: VisionContainerBuilder<Solid>.() -> Unit)
|
public fun prototypes(builder: VisionContainerBuilder<Solid>.() -> Unit)
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public object ThreeMaterials {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun getMaterial(vision3D: Vision, cache: Boolean): Material {
|
public fun getMaterial(vision3D: Vision, cache: Boolean): Material {
|
||||||
val meta = vision3D.getProperty(SolidMaterial.MATERIAL_KEY).node ?: return DEFAULT
|
val meta = vision3D.getProperty(SolidMaterial.MATERIAL_KEY, inherit = true).node ?: return DEFAULT
|
||||||
return if (cache) {
|
return if (cache) {
|
||||||
materialCache.getOrPut(meta) { buildMaterial(meta) }
|
materialCache.getOrPut(meta) { buildMaterial(meta) }
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user