forked from kscience/visionforge
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
|
package space.kscience.visionforge.examples
|
||||||
|
|
||||||
import space.kscience.gdml.GdmlShowCase
|
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.Solids
|
||||||
|
import space.kscience.visionforge.solid.ambientLight
|
||||||
|
import space.kscience.visionforge.solid.invoke
|
||||||
|
import space.kscience.visionforge.solid.solid
|
||||||
|
|
||||||
fun main() = makeVisionFile {
|
fun main() = makeVisionFile {
|
||||||
vision("canvas") {
|
vision("canvas") {
|
||||||
requirePlugin(Solids)
|
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.div
|
||||||
import kotlinx.html.h1
|
import kotlinx.html.h1
|
||||||
|
import space.kscience.visionforge.Colors
|
||||||
import space.kscience.visionforge.html.ResourceLocation
|
import space.kscience.visionforge.html.ResourceLocation
|
||||||
import space.kscience.visionforge.solid.*
|
import space.kscience.visionforge.solid.*
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
@ -17,6 +18,9 @@ fun main() = makeVisionFile(
|
|||||||
div {
|
div {
|
||||||
vision {
|
vision {
|
||||||
solid {
|
solid {
|
||||||
|
ambientLight {
|
||||||
|
color(Colors.white)
|
||||||
|
}
|
||||||
repeat(100) {
|
repeat(100) {
|
||||||
sphere(5, name = "sphere[$it]") {
|
sphere(5, name = "sphere[$it]") {
|
||||||
x = random.nextDouble(-300.0, 300.0)
|
x = random.nextDouble(-300.0, 300.0)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
kotlin.mpp.stability.nowarn=true
|
kotlin.mpp.stability.nowarn=true
|
||||||
kotlin.jupyter.add.scanner=false
|
kotlin.jupyter.add.scanner=false
|
||||||
|
#kotlin.incremental.js.ir=true
|
||||||
|
|
||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
org.gradle.jvmargs=-Xmx4G
|
org.gradle.jvmargs=-Xmx4G
|
||||||
|
@ -11,5 +11,5 @@ kotlin{
|
|||||||
dependencies {
|
dependencies {
|
||||||
api(project(":visionforge-solid"))
|
api(project(":visionforge-solid"))
|
||||||
implementation(npm("three", "0.137.4"))
|
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 val type: KClass<in Composite> get() = Composite::class
|
||||||
|
|
||||||
override fun invoke(three: ThreePlugin, obj: Composite): Mesh {
|
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 first = three.buildObject3D(obj.first).takeIfMesh() ?: 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 second = three.buildObject3D(obj.second).takeIfMesh() ?: error("Second part of composite is not a mesh")
|
||||||
return when (obj.compositeType) {
|
return when (obj.compositeType) {
|
||||||
CompositeType.GROUP, CompositeType.UNION -> CSG.union(first, second)
|
CompositeType.GROUP, CompositeType.UNION -> CSG.union(first, second)
|
||||||
CompositeType.INTERSECT -> CSG.intersect(first, second)
|
CompositeType.INTERSECT -> CSG.intersect(first, second)
|
||||||
|
@ -161,17 +161,14 @@ public fun Mesh.updateMaterialProperty(vision: Vision, propertyName: Name) {
|
|||||||
SolidMaterial.MATERIAL_COLOR_KEY -> {
|
SolidMaterial.MATERIAL_COLOR_KEY -> {
|
||||||
material.asDynamic().color = vision.computePropertyNode(SolidMaterial.MATERIAL_COLOR_KEY)?.threeColor()
|
material.asDynamic().color = vision.computePropertyNode(SolidMaterial.MATERIAL_COLOR_KEY)?.threeColor()
|
||||||
?: ThreeMaterials.DEFAULT_COLOR
|
?: ThreeMaterials.DEFAULT_COLOR
|
||||||
material.needsUpdate = true
|
|
||||||
}
|
}
|
||||||
SolidMaterial.SPECULAR_COLOR_KEY -> {
|
SolidMaterial.SPECULAR_COLOR_KEY -> {
|
||||||
material.asDynamic().specular = vision.computePropertyNode(SolidMaterial.SPECULAR_COLOR_KEY)?.threeColor()
|
material.asDynamic().specular = vision.computePropertyNode(SolidMaterial.SPECULAR_COLOR_KEY)?.threeColor()
|
||||||
?: ThreeMaterials.DEFAULT_COLOR
|
?: ThreeMaterials.DEFAULT_COLOR
|
||||||
material.needsUpdate = true
|
|
||||||
}
|
}
|
||||||
SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY -> {
|
SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY -> {
|
||||||
material.asDynamic().emissive = vision.computePropertyNode(SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY)?.threeColor()
|
material.asDynamic().emissive = vision.computePropertyNode(SolidMaterial.MATERIAL_EMISSIVE_COLOR_KEY)?.threeColor()
|
||||||
?: ThreeMaterials.BLACK_COLOR
|
?: ThreeMaterials.BLACK_COLOR
|
||||||
material.needsUpdate = true
|
|
||||||
}
|
}
|
||||||
SolidMaterial.MATERIAL_OPACITY_KEY -> {
|
SolidMaterial.MATERIAL_OPACITY_KEY -> {
|
||||||
val opacity = vision.getPropertyValue(
|
val opacity = vision.getPropertyValue(
|
||||||
@ -180,16 +177,15 @@ public fun Mesh.updateMaterialProperty(vision: Vision, propertyName: Name) {
|
|||||||
)?.double ?: 1.0
|
)?.double ?: 1.0
|
||||||
material.opacity = opacity
|
material.opacity = opacity
|
||||||
material.transparent = opacity < 1.0
|
material.transparent = opacity < 1.0
|
||||||
material.needsUpdate = true
|
|
||||||
}
|
}
|
||||||
SolidMaterial.MATERIAL_WIREFRAME_KEY -> {
|
SolidMaterial.MATERIAL_WIREFRAME_KEY -> {
|
||||||
material.asDynamic().wireframe = vision.getPropertyValue(
|
material.asDynamic().wireframe = vision.getPropertyValue(
|
||||||
SolidMaterial.MATERIAL_WIREFRAME_KEY,
|
SolidMaterial.MATERIAL_WIREFRAME_KEY,
|
||||||
inherit = true,
|
inherit = true,
|
||||||
)?.boolean ?: false
|
)?.boolean ?: false
|
||||||
material.needsUpdate = true
|
|
||||||
}
|
}
|
||||||
else -> console.warn("Unrecognized material property: $propertyName")
|
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.BufferGeometry
|
||||||
import info.laht.threekt.core.Layers
|
import info.laht.threekt.core.Layers
|
||||||
|
import info.laht.threekt.core.Object3D
|
||||||
import info.laht.threekt.external.controls.OrbitControls
|
import info.laht.threekt.external.controls.OrbitControls
|
||||||
import info.laht.threekt.materials.Material
|
import info.laht.threekt.materials.Material
|
||||||
import info.laht.threekt.math.Vector3
|
import info.laht.threekt.math.Vector3
|
||||||
@ -32,3 +33,12 @@ 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