2021-05-10 22:07:16 +03:00
|
|
|
package space.kscience.visionforge.ring
|
2021-03-10 21:58:28 +03:00
|
|
|
|
|
|
|
import org.w3c.dom.Element
|
|
|
|
import react.child
|
|
|
|
import space.kscience.dataforge.context.AbstractPlugin
|
|
|
|
import space.kscience.dataforge.context.Context
|
|
|
|
import space.kscience.dataforge.context.PluginFactory
|
|
|
|
import space.kscience.dataforge.context.PluginTag
|
|
|
|
import space.kscience.dataforge.meta.Meta
|
|
|
|
import space.kscience.dataforge.names.Name
|
|
|
|
import space.kscience.dataforge.names.asName
|
|
|
|
import space.kscience.visionforge.ElementVisionRenderer
|
|
|
|
import space.kscience.visionforge.Vision
|
|
|
|
import space.kscience.visionforge.solid.Solid
|
|
|
|
import space.kscience.visionforge.solid.three.ThreePlugin
|
|
|
|
import kotlin.reflect.KClass
|
|
|
|
|
2021-05-10 22:07:16 +03:00
|
|
|
public class ThreeWithControls : AbstractPlugin(), ElementVisionRenderer {
|
2021-05-11 11:33:12 +03:00
|
|
|
public val three: ThreePlugin by require(ThreePlugin)
|
2021-03-10 21:58:28 +03:00
|
|
|
|
|
|
|
override val tag: PluginTag get() = Companion.tag
|
|
|
|
|
|
|
|
override fun rateVision(vision: Vision): Int =
|
|
|
|
if (vision is Solid) ElementVisionRenderer.DEFAULT_RATING * 2 else ElementVisionRenderer.ZERO_RATING
|
|
|
|
|
|
|
|
override fun render(element: Element, vision: Vision, meta: Meta) {
|
|
|
|
react.dom.render(element) {
|
2021-05-10 22:07:16 +03:00
|
|
|
child(ThreeViewWithControls) {
|
2021-03-10 21:58:28 +03:00
|
|
|
attrs {
|
|
|
|
this.context = this@ThreeWithControls.context
|
2021-06-06 20:57:39 +03:00
|
|
|
this.vision = vision
|
2021-03-10 21:58:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun content(target: String): Map<Name, Any> {
|
|
|
|
return when (target) {
|
|
|
|
ElementVisionRenderer.TYPE -> mapOf("three.withControls".asName() to this)
|
|
|
|
else -> super.content(target)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-10 22:07:16 +03:00
|
|
|
public companion object : PluginFactory<ThreeWithControls> {
|
2021-03-10 21:58:28 +03:00
|
|
|
override val tag: PluginTag = PluginTag("vision.threejs.withControls", PluginTag.DATAFORGE_GROUP)
|
|
|
|
override val type: KClass<ThreeWithControls> = ThreeWithControls::class
|
|
|
|
override fun invoke(meta: Meta, context: Context): ThreeWithControls = ThreeWithControls()
|
|
|
|
}
|
|
|
|
}
|