2021-05-10 22:07:16 +03:00
|
|
|
package space.kscience.visionforge.ring
|
2021-03-10 21:58:28 +03:00
|
|
|
|
2021-08-15 20:04:21 +03:00
|
|
|
import kotlinx.coroutines.async
|
2021-03-10 21:58:28 +03:00
|
|
|
import org.w3c.dom.Element
|
|
|
|
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
|
2023-07-25 13:35:55 +03:00
|
|
|
import space.kscience.dataforge.meta.boolean
|
|
|
|
import space.kscience.dataforge.meta.get
|
2021-03-10 21:58:28 +03:00
|
|
|
import space.kscience.dataforge.names.Name
|
|
|
|
import space.kscience.dataforge.names.asName
|
|
|
|
import space.kscience.visionforge.ElementVisionRenderer
|
|
|
|
import space.kscience.visionforge.Vision
|
2022-07-06 11:11:48 +03:00
|
|
|
import space.kscience.visionforge.react.render
|
2021-03-10 21:58:28 +03:00
|
|
|
import space.kscience.visionforge.solid.Solid
|
2023-07-25 13:35:55 +03:00
|
|
|
import space.kscience.visionforge.solid.specifications.Canvas3DOptions
|
2021-03-10 21:58:28 +03:00
|
|
|
import space.kscience.visionforge.solid.three.ThreePlugin
|
|
|
|
|
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
|
|
|
|
|
2022-12-06 15:54:34 +03:00
|
|
|
override fun render(element: Element, name: Name, vision: Vision, meta: Meta) {
|
2023-07-25 13:35:55 +03:00
|
|
|
if(meta["controls.enabled"].boolean == false){
|
|
|
|
three.render(element, name, vision, meta)
|
|
|
|
} else {
|
|
|
|
space.kscience.visionforge.react.createRoot(element).render {
|
|
|
|
child(ThreeCanvasWithControls) {
|
|
|
|
attrs {
|
|
|
|
this.solids = three.solids
|
|
|
|
this.options = Canvas3DOptions.read(meta)
|
|
|
|
this.builderOfSolid = context.async { 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)
|
2022-07-06 11:11:48 +03:00
|
|
|
|
|
|
|
override fun build(context: Context, meta: Meta): ThreeWithControlsPlugin = ThreeWithControlsPlugin()
|
2021-03-10 21:58:28 +03:00
|
|
|
}
|
|
|
|
}
|