New properties #34

Merged
altavir merged 19 commits from new-properties into dev 2020-12-29 13:35:01 +03:00
5 changed files with 51 additions and 18 deletions
Showing only changes of commit 346b61724f - Show all commits

View File

@ -131,8 +131,20 @@ public open class VisionBase(internal var properties: Config? = null) : Vision {
}
override fun update(change: VisionChange) {
change.properties?.let {
updateProperties(Name.EMPTY, it.asMetaItem())
}
}
fun updateProperties(at: Name, item: MetaItem) {
public companion object {
public val descriptor: NodeDescriptor = NodeDescriptor {
value(STYLE_KEY) {
type(ValueType.STRING)
multiple = true
}
}
public fun Vision.updateProperties(at: Name, item: MetaItem) {
when (item) {
is ValueItem -> {
if (item.value == Null) {
@ -146,18 +158,6 @@ public open class VisionBase(internal var properties: Config? = null) : Vision {
}
}
change.properties?.let {
updateProperties(Name.EMPTY, it.asMetaItem())
}
}
public companion object {
public val descriptor: NodeDescriptor = NodeDescriptor {
value(STYLE_KEY) {
type(ValueType.STRING)
multiple = true
}
}
}
}

View File

@ -3,6 +3,7 @@ package hep.dataforge.vision.solid
import hep.dataforge.meta.*
import hep.dataforge.meta.descriptors.NodeDescriptor
import hep.dataforge.names.*
import hep.dataforge.values.Null
import hep.dataforge.vision.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.serialization.SerialName
@ -99,7 +100,7 @@ public class SolidReferenceGroup(
ReferenceChild(childName + key.asName())
} ?: emptyMap()
override val meta: Meta get() =TODO()// getChildProperty(childName, Name.EMPTY).node ?: Meta.EMPTY
override val meta: Meta get() = TODO()// getChildProperty(childName, Name.EMPTY).node ?: Meta.EMPTY
override fun getOwnProperty(name: Name): MetaItem? = getChildProperty(childName, name)
@ -136,7 +137,9 @@ public class SolidReferenceGroup(
}
override fun update(change: VisionChange) {
TODO("Not yet implemented")
change.properties?.let {
updateProperties(Name.EMPTY, it.asMetaItem())
}
}
override val descriptor: NodeDescriptor get() = prototype.descriptor

View File

@ -0,0 +1,26 @@
package hep.dataforge.vision.solid
import hep.dataforge.vision.get
import hep.dataforge.vision.style
import hep.dataforge.vision.styles
import hep.dataforge.vision.useStyle
import kotlin.test.Test
import kotlin.test.assertEquals
class SolidReferenceTest {
val groupWithReference = SolidGroup {
val referenceStyle by style {
SolidMaterial.MATERIAL_COLOR_KEY put "red"
}
ref("test", Box(100f,100f,100f).apply {
color("blue")
useStyle(referenceStyle)
})
}
@Test
fun testReferenceProperty(){
assertEquals("blue", (groupWithReference["test"] as Solid).color.string)
}
}

View File

@ -8,7 +8,6 @@ import hep.dataforge.values.string
import hep.dataforge.vision.Colors
import hep.dataforge.vision.Vision
import hep.dataforge.vision.allStyles
import hep.dataforge.vision.merge
import hep.dataforge.vision.solid.SolidMaterial
import info.laht.threekt.materials.LineBasicMaterial
import info.laht.threekt.materials.Material
@ -143,6 +142,7 @@ public fun Mesh.updateMaterial(vision: Vision) {
includeStyles = false,
includeDefaults = false
)
material = when {
ownMaterialMeta == null && stylesMaterialMeta == null && parentMaterialMeta == null -> {
//use default is not material properties are defined
@ -153,8 +153,9 @@ public fun Mesh.updateMaterial(vision: Vision) {
ThreeMaterials.cacheMeta(stylesMaterialMeta.node ?: Meta.EMPTY)
}
else -> {
val merge = sequenceOf(ownMaterialMeta, stylesMaterialMeta, parentMaterialMeta).merge().node ?: Meta.EMPTY
ThreeMaterials.buildMaterial(merge)
vision.getProperty(SolidMaterial.MATERIAL_KEY).node?.let {
ThreeMaterials.buildMaterial(it)
} ?: ThreeMaterials.DEFAULT
}
}
}

View File

@ -1,9 +1,11 @@
package hep.dataforge.vision.solid.three
import hep.dataforge.meta.node
import hep.dataforge.names.cutFirst
import hep.dataforge.names.firstOrNull
import hep.dataforge.names.toName
import hep.dataforge.vision.solid.Solid
import hep.dataforge.vision.solid.SolidMaterial
import hep.dataforge.vision.solid.SolidReferenceGroup
import hep.dataforge.vision.solid.SolidReferenceGroup.Companion.REFERENCE_CHILD_PROPERTY_PREFIX
import info.laht.threekt.core.BufferGeometry
@ -40,6 +42,7 @@ public object ThreeReferenceFactory : ThreeFactory<SolidReferenceGroup> {
object3D.updatePosition(obj)
if(object3D is Mesh){
//object3D.material = ThreeMaterials.buildMaterial(obj.getProperty(SolidMaterial.MATERIAL_KEY).node!!)
object3D.applyProperties(obj)
}