Roll back to basic three renderer for examples

This commit is contained in:
Alexander Nozik 2021-06-30 18:23:30 +03:00
parent b0cd80a4e6
commit 230cd5dc61
3 changed files with 25 additions and 24 deletions

View File

@ -1,10 +1,10 @@
import space.kscience.dataforge.misc.DFExperimental import space.kscience.dataforge.misc.DFExperimental
import space.kscience.visionforge.plotly.PlotlyPlugin import space.kscience.visionforge.plotly.PlotlyPlugin
import space.kscience.visionforge.ring.ThreeWithControlsPlugin
import space.kscience.visionforge.runVisionClient import space.kscience.visionforge.runVisionClient
import space.kscience.visionforge.solid.three.ThreePlugin
@DFExperimental @DFExperimental
fun main() = runVisionClient { fun main() = runVisionClient {
plugin(PlotlyPlugin) plugin(PlotlyPlugin)
plugin(ThreeWithControlsPlugin) plugin(ThreePlugin)
} }

View File

@ -1,5 +1,6 @@
package space.kscience.visionforge.examples package space.kscience.visionforge.examples
import kotlinx.html.div
import kotlinx.html.h1 import kotlinx.html.h1
import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.Context
import space.kscience.visionforge.html.ResourceLocation import space.kscience.visionforge.html.ResourceLocation
@ -19,18 +20,19 @@ fun main() {
resourceLocation = ResourceLocation.EMBED resourceLocation = ResourceLocation.EMBED
) { ) {
h1 { +"Happy new year!" } h1 { +"Happy new year!" }
vision { div {
solid { vision {
repeat(100) { solid {
sphere(5, name = "sphere[$it]") { repeat(100) {
x = random.nextDouble(-300.0, 300.0) sphere(5, name = "sphere[$it]") {
y = random.nextDouble(-300.0, 300.0) x = random.nextDouble(-300.0, 300.0)
z = random.nextDouble(-300.0, 300.0) y = random.nextDouble(-300.0, 300.0)
material { z = random.nextDouble(-300.0, 300.0)
color(random.nextInt()) material {
specularColor(random.nextInt()) color(random.nextInt())
}
detail = 16
} }
detail = 16
} }
} }
} }

View File

@ -59,12 +59,12 @@ public object ThreeMaterials {
private val materialCache = HashMap<Meta, Material>() private val materialCache = HashMap<Meta, Material>()
internal fun buildMaterial(meta: Meta): Material { internal fun buildMaterial(meta: Meta): Material {
return if (meta[SolidMaterial.SPECULAR_COLOR_KEY] != null) { return meta[SolidMaterial.SPECULAR_COLOR_KEY]?.let { specularColor ->
MeshPhongMaterial().apply { MeshPhongMaterial().apply {
color = meta[SolidMaterial.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR color = meta[SolidMaterial.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR
specular = meta[SolidMaterial.SPECULAR_COLOR_KEY]!!.getColor() specular = specularColor.getColor()
emissive = specular emissive = specular
reflectivity = 1.0 reflectivity = 0.5
refractionRatio = 1.0 refractionRatio = 1.0
shininess = 100.0 shininess = 100.0
opacity = meta[SolidMaterial.OPACITY_KEY]?.double ?: 1.0 opacity = meta[SolidMaterial.OPACITY_KEY]?.double ?: 1.0
@ -72,15 +72,14 @@ public object ThreeMaterials {
wireframe = meta[SolidMaterial.WIREFRAME_KEY].boolean ?: false wireframe = meta[SolidMaterial.WIREFRAME_KEY].boolean ?: false
needsUpdate = true needsUpdate = true
} }
} else { } ?: MeshBasicMaterial().apply {
MeshBasicMaterial().apply { color = meta[SolidMaterial.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR
color = meta[SolidMaterial.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR opacity = meta[SolidMaterial.OPACITY_KEY]?.double ?: 1.0
opacity = meta[SolidMaterial.OPACITY_KEY]?.double ?: 1.0 transparent = opacity < 1.0
transparent = opacity < 1.0 wireframe = meta[SolidMaterial.WIREFRAME_KEY].boolean ?: false
wireframe = meta[SolidMaterial.WIREFRAME_KEY].boolean ?: false needsUpdate = true
needsUpdate = true
}
} }
} }
internal fun cacheMaterial(meta: Meta): Material = materialCache.getOrPut(meta) { internal fun cacheMaterial(meta: Meta): Material = materialCache.getOrPut(meta) {