Fix material generations for SolidReference

This commit is contained in:
Alexander Nozik 2020-12-26 17:11:52 +03:00
parent 2b02f151d2
commit 346b61724f
5 changed files with 51 additions and 18 deletions

View File

@ -131,8 +131,20 @@ public open class VisionBase(internal var properties: Config? = null) : Vision {
} }
override fun update(change: VisionChange) { 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) { when (item) {
is ValueItem -> { is ValueItem -> {
if (item.value == Null) { 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.*
import hep.dataforge.meta.descriptors.NodeDescriptor import hep.dataforge.meta.descriptors.NodeDescriptor
import hep.dataforge.names.* import hep.dataforge.names.*
import hep.dataforge.values.Null
import hep.dataforge.vision.* import hep.dataforge.vision.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
@ -136,7 +137,9 @@ public class SolidReferenceGroup(
} }
override fun update(change: VisionChange) { override fun update(change: VisionChange) {
TODO("Not yet implemented") change.properties?.let {
updateProperties(Name.EMPTY, it.asMetaItem())
}
} }
override val descriptor: NodeDescriptor get() = prototype.descriptor 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.Colors
import hep.dataforge.vision.Vision import hep.dataforge.vision.Vision
import hep.dataforge.vision.allStyles import hep.dataforge.vision.allStyles
import hep.dataforge.vision.merge
import hep.dataforge.vision.solid.SolidMaterial import hep.dataforge.vision.solid.SolidMaterial
import info.laht.threekt.materials.LineBasicMaterial import info.laht.threekt.materials.LineBasicMaterial
import info.laht.threekt.materials.Material import info.laht.threekt.materials.Material
@ -143,6 +142,7 @@ public fun Mesh.updateMaterial(vision: Vision) {
includeStyles = false, includeStyles = false,
includeDefaults = false includeDefaults = false
) )
material = when { material = when {
ownMaterialMeta == null && stylesMaterialMeta == null && parentMaterialMeta == null -> { ownMaterialMeta == null && stylesMaterialMeta == null && parentMaterialMeta == null -> {
//use default is not material properties are defined //use default is not material properties are defined
@ -153,8 +153,9 @@ public fun Mesh.updateMaterial(vision: Vision) {
ThreeMaterials.cacheMeta(stylesMaterialMeta.node ?: Meta.EMPTY) ThreeMaterials.cacheMeta(stylesMaterialMeta.node ?: Meta.EMPTY)
} }
else -> { else -> {
val merge = sequenceOf(ownMaterialMeta, stylesMaterialMeta, parentMaterialMeta).merge().node ?: Meta.EMPTY vision.getProperty(SolidMaterial.MATERIAL_KEY).node?.let {
ThreeMaterials.buildMaterial(merge) ThreeMaterials.buildMaterial(it)
} ?: ThreeMaterials.DEFAULT
} }
} }
} }

View File

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