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-06-09 11:48:03 +03:00
|
|
|
public class ThreeWithControlsPlugin : 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-06-08 18:45:03 +03:00
|
|
|
child(ThreeCanvasWithControls) {
|
2021-03-10 21:58:28 +03:00
|
|
|
attrs {
|
2021-06-09 11:48:03 +03:00
|
|
|
this.context = this@ThreeWithControlsPlugin.context
|
2021-06-08 18:45:03 +03:00
|
|
|
this.solid = vision as? Solid
|
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-06-09 11:48:03 +03:00
|
|
|
public companion object : PluginFactory<ThreeWithControlsPlugin> {
|
2021-03-10 21:58:28 +03:00
|
|
|
override val tag: PluginTag = PluginTag("vision.threejs.withControls", PluginTag.DATAFORGE_GROUP)
|
2021-06-09 11:48:03 +03:00
|
|
|
override val type: KClass<ThreeWithControlsPlugin> = ThreeWithControlsPlugin::class
|
|
|
|
override fun invoke(meta: Meta, context: Context): ThreeWithControlsPlugin = ThreeWithControlsPlugin()
|
2021-03-10 21:58:28 +03:00
|
|
|
}
|
|
|
|
}
|