Fix mesh conversion and lightning for examples
This commit is contained in:
parent
212d729afb
commit
ce02a18c09
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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"))
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ public class ThreeCompositeFactory(public val three: ThreePlugin) : ThreeFactory
|
||||
override val type: KClass<in Composite> 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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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
|
||||
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<Mesh>()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user