From 230cd5dc6110ce7c90c74694888cd56951c83adc Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 30 Jun 2021 18:23:30 +0300 Subject: [PATCH] Roll back to basic three renderer for examples --- .../src/jsMain/kotlin/playgroundMain.kt | 4 ++-- .../src/jvmMain/kotlin/randomSpheres.kt | 24 ++++++++++--------- .../visionforge/solid/three/ThreeMaterials.kt | 21 ++++++++-------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/demo/playground/src/jsMain/kotlin/playgroundMain.kt b/demo/playground/src/jsMain/kotlin/playgroundMain.kt index 71431841..9ee2dc93 100644 --- a/demo/playground/src/jsMain/kotlin/playgroundMain.kt +++ b/demo/playground/src/jsMain/kotlin/playgroundMain.kt @@ -1,10 +1,10 @@ import space.kscience.dataforge.misc.DFExperimental import space.kscience.visionforge.plotly.PlotlyPlugin -import space.kscience.visionforge.ring.ThreeWithControlsPlugin import space.kscience.visionforge.runVisionClient +import space.kscience.visionforge.solid.three.ThreePlugin @DFExperimental fun main() = runVisionClient { plugin(PlotlyPlugin) - plugin(ThreeWithControlsPlugin) + plugin(ThreePlugin) } \ No newline at end of file diff --git a/demo/playground/src/jvmMain/kotlin/randomSpheres.kt b/demo/playground/src/jvmMain/kotlin/randomSpheres.kt index 855c99c1..383f3d3a 100644 --- a/demo/playground/src/jvmMain/kotlin/randomSpheres.kt +++ b/demo/playground/src/jvmMain/kotlin/randomSpheres.kt @@ -1,5 +1,6 @@ package space.kscience.visionforge.examples +import kotlinx.html.div import kotlinx.html.h1 import space.kscience.dataforge.context.Context import space.kscience.visionforge.html.ResourceLocation @@ -19,18 +20,19 @@ fun main() { resourceLocation = ResourceLocation.EMBED ) { h1 { +"Happy new year!" } - vision { - solid { - repeat(100) { - sphere(5, name = "sphere[$it]") { - x = random.nextDouble(-300.0, 300.0) - y = random.nextDouble(-300.0, 300.0) - z = random.nextDouble(-300.0, 300.0) - material { - color(random.nextInt()) - specularColor(random.nextInt()) + div { + vision { + solid { + repeat(100) { + sphere(5, name = "sphere[$it]") { + x = random.nextDouble(-300.0, 300.0) + y = random.nextDouble(-300.0, 300.0) + z = random.nextDouble(-300.0, 300.0) + material { + color(random.nextInt()) + } + detail = 16 } - detail = 16 } } } diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeMaterials.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeMaterials.kt index 7f79ce37..5f7ef051 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeMaterials.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeMaterials.kt @@ -59,12 +59,12 @@ public object ThreeMaterials { private val materialCache = HashMap() internal fun buildMaterial(meta: Meta): Material { - return if (meta[SolidMaterial.SPECULAR_COLOR_KEY] != null) { + return meta[SolidMaterial.SPECULAR_COLOR_KEY]?.let { specularColor -> MeshPhongMaterial().apply { color = meta[SolidMaterial.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR - specular = meta[SolidMaterial.SPECULAR_COLOR_KEY]!!.getColor() + specular = specularColor.getColor() emissive = specular - reflectivity = 1.0 + reflectivity = 0.5 refractionRatio = 1.0 shininess = 100.0 opacity = meta[SolidMaterial.OPACITY_KEY]?.double ?: 1.0 @@ -72,15 +72,14 @@ public object ThreeMaterials { wireframe = meta[SolidMaterial.WIREFRAME_KEY].boolean ?: false needsUpdate = true } - } else { - MeshBasicMaterial().apply { - color = meta[SolidMaterial.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR - opacity = meta[SolidMaterial.OPACITY_KEY]?.double ?: 1.0 - transparent = opacity < 1.0 - wireframe = meta[SolidMaterial.WIREFRAME_KEY].boolean ?: false - needsUpdate = true - } + } ?: MeshBasicMaterial().apply { + color = meta[SolidMaterial.COLOR_KEY]?.getColor() ?: DEFAULT_COLOR + opacity = meta[SolidMaterial.OPACITY_KEY]?.double ?: 1.0 + transparent = opacity < 1.0 + wireframe = meta[SolidMaterial.WIREFRAME_KEY].boolean ?: false + needsUpdate = true } + } internal fun cacheMaterial(meta: Meta): Material = materialCache.getOrPut(meta) {