diff --git a/demo/playground/src/jvmMain/kotlin/gdmlIaxo.kt b/demo/playground/src/jvmMain/kotlin/gdmlIaxo.kt index 6ee718a2..24c56304 100644 --- a/demo/playground/src/jvmMain/kotlin/gdmlIaxo.kt +++ b/demo/playground/src/jvmMain/kotlin/gdmlIaxo.kt @@ -1,12 +1,21 @@ package space.kscience.visionforge.examples import space.kscience.gdml.GdmlShowCase -import space.kscience.visionforge.gdml.toVision +import space.kscience.visionforge.Colors +import space.kscience.visionforge.gdml.gdml import space.kscience.visionforge.solid.Solids +import space.kscience.visionforge.solid.ambientLight +import space.kscience.visionforge.solid.invoke +import space.kscience.visionforge.solid.solid fun main() = makeVisionFile { vision("canvas") { requirePlugin(Solids) - GdmlShowCase.babyIaxo().toVision() + solid { + ambientLight { + color(Colors.white) + } + gdml(GdmlShowCase.babyIaxo(), "D0") + } } } \ 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 2d9a5f05..fd1b9865 100644 --- a/demo/playground/src/jvmMain/kotlin/randomSpheres.kt +++ b/demo/playground/src/jvmMain/kotlin/randomSpheres.kt @@ -2,6 +2,7 @@ package space.kscience.visionforge.examples import kotlinx.html.div import kotlinx.html.h1 +import space.kscience.visionforge.Colors import space.kscience.visionforge.html.ResourceLocation import space.kscience.visionforge.solid.* import java.nio.file.Paths @@ -17,6 +18,9 @@ fun main() = makeVisionFile( div { vision { solid { + ambientLight { + color(Colors.white) + } repeat(100) { sphere(5, name = "sphere[$it]") { x = random.nextDouble(-300.0, 300.0) diff --git a/gradle.properties b/gradle.properties index f6fbbfc2..5a1cefb4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,7 @@ kotlin.code.style=official kotlin.mpp.stability.nowarn=true kotlin.jupyter.add.scanner=false +#kotlin.incremental.js.ir=true org.gradle.parallel=true org.gradle.jvmargs=-Xmx4G diff --git a/visionforge-threejs/build.gradle.kts b/visionforge-threejs/build.gradle.kts index 3aa1ef5e..f0462837 100644 --- a/visionforge-threejs/build.gradle.kts +++ b/visionforge-threejs/build.gradle.kts @@ -11,5 +11,5 @@ kotlin{ dependencies { api(project(":visionforge-solid")) implementation(npm("three", "0.137.4")) - implementation(npm("three-csg-ts", "3.1.9")) + implementation(npm("three-csg-ts", "3.1.10")) } diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeCompositeFactory.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeCompositeFactory.kt index f57530b3..74528c50 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeCompositeFactory.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/ThreeCompositeFactory.kt @@ -38,8 +38,8 @@ public class ThreeCompositeFactory(public val three: ThreePlugin) : ThreeFactory override val type: KClass get() = Composite::class override fun invoke(three: ThreePlugin, obj: Composite): Mesh { - val first = three.buildObject3D(obj.first) as? Mesh ?: error("First part of composite is not a mesh") - val second = three.buildObject3D(obj.second) as? Mesh ?: error("Second part of composite is not a mesh") + val first = three.buildObject3D(obj.first).takeIfMesh() ?: error("First part of composite is not a mesh") + val second = three.buildObject3D(obj.second).takeIfMesh() ?: error("Second part of composite is not a mesh") return when (obj.compositeType) { CompositeType.GROUP, CompositeType.UNION -> CSG.union(first, second) CompositeType.INTERSECT -> CSG.intersect(first, second) 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 5b4fa220..82b088e5 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 @@ -161,17 +161,14 @@ public fun Mesh.updateMaterialProperty(vision: Vision, propertyName: Name) { SolidMaterial.MATERIAL_COLOR_KEY -> { material.asDynamic().color = vision.computePropertyNode(SolidMaterial.MATERIAL_COLOR_KEY)?.threeColor() ?: ThreeMaterials.DEFAULT_COLOR - material.needsUpdate = true } SolidMaterial.SPECULAR_COLOR_KEY -> { material.asDynamic().specular = vision.computePropertyNode(SolidMaterial.SPECULAR_COLOR_KEY)?.threeColor() ?: ThreeMaterials.DEFAULT_COLOR - material.needsUpdate = true } SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY -> { material.asDynamic().emissive = vision.computePropertyNode(SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY)?.threeColor() ?: ThreeMaterials.BLACK_COLOR - material.needsUpdate = true } SolidMaterial.MATERIAL_OPACITY_KEY -> { val opacity = vision.getPropertyValue( @@ -180,16 +177,15 @@ public fun Mesh.updateMaterialProperty(vision: Vision, propertyName: Name) { )?.double ?: 1.0 material.opacity = opacity material.transparent = opacity < 1.0 - material.needsUpdate = true } SolidMaterial.MATERIAL_WIREFRAME_KEY -> { material.asDynamic().wireframe = vision.getPropertyValue( SolidMaterial.MATERIAL_WIREFRAME_KEY, inherit = true, )?.boolean ?: false - material.needsUpdate = true } else -> console.warn("Unrecognized material property: $propertyName") } + material.needsUpdate = true } } \ No newline at end of file diff --git a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/three.kt b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/three.kt index 447cf4b6..d21ff544 100644 --- a/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/three.kt +++ b/visionforge-threejs/src/main/kotlin/space/kscience/visionforge/solid/three/three.kt @@ -2,6 +2,7 @@ package space.kscience.visionforge.solid.three import info.laht.threekt.core.BufferGeometry import info.laht.threekt.core.Layers +import info.laht.threekt.core.Object3D import info.laht.threekt.external.controls.OrbitControls import info.laht.threekt.materials.Material import info.laht.threekt.math.Vector3 @@ -31,4 +32,13 @@ internal fun Any.dispose() { } } -public fun Layers.check(layer: Int): Boolean = (mask shr(layer) and 0x00000001) > 0 \ No newline at end of file +public fun Layers.check(layer: Int): Boolean = (mask shr (layer) and 0x00000001) > 0 + +internal fun Object3D.takeIfMesh(): Mesh? { + val d = asDynamic() + return if(d.isMesh as Boolean){ + d.unsafeCast() + } else { + null + } +} \ No newline at end of file