Fixed colors and sizes for demo
This commit is contained in:
parent
28625ebe58
commit
47c1a30c89
@ -1,6 +1,6 @@
|
||||
val dataforgeVersion by extra("0.1.3")
|
||||
|
||||
plugins{
|
||||
plugins {
|
||||
val kotlinVersion = "1.3.50"
|
||||
val toolsVersion = "0.2.0"
|
||||
|
||||
@ -16,6 +16,7 @@ plugins{
|
||||
allprojects {
|
||||
repositories {
|
||||
maven("https://dl.bintray.com/pdvrieze/maven")
|
||||
maven("http://maven.jzy3d.org/releases")
|
||||
}
|
||||
|
||||
group = "hep.dataforge"
|
||||
|
@ -178,7 +178,19 @@ object Colors {
|
||||
const val yellowgreen = 0x9ACD32
|
||||
|
||||
fun rgbToString(rgb: Int): String {
|
||||
val string = rgb.toString(16)
|
||||
val string = rgb.toString(16).padStart(6, '0')
|
||||
return "#" + string.substring(max(0, string.length - 6))
|
||||
}
|
||||
|
||||
fun rgbToString(red: UByte, green: UByte, blue: UByte): String {
|
||||
fun colorToString(color: UByte): String{
|
||||
return color.toString(16).padStart(2,'0')
|
||||
}
|
||||
return buildString {
|
||||
append("#")
|
||||
append(colorToString(red))
|
||||
append(colorToString(green))
|
||||
append(colorToString(blue))
|
||||
}
|
||||
}
|
||||
}
|
@ -8,10 +8,10 @@ import hep.dataforge.names.toName
|
||||
import hep.dataforge.vis.common.Colors
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.common.applyStyle
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.COLOR_KEY
|
||||
import hep.dataforge.vis.spatial.RotationOrder
|
||||
import hep.dataforge.vis.spatial.VisualGroup3D
|
||||
import hep.dataforge.vis.spatial.VisualObject3D
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY
|
||||
import hep.dataforge.vis.spatial.rotationOrder
|
||||
import scientifik.gdml.*
|
||||
import kotlin.collections.set
|
||||
|
@ -4,6 +4,7 @@ import hep.dataforge.context.Global
|
||||
import hep.dataforge.vis.common.VisualGroup
|
||||
import hep.dataforge.vis.hmr.ApplicationBase
|
||||
import hep.dataforge.vis.hmr.startApplication
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.OPACITY_KEY
|
||||
import hep.dataforge.vis.spatial.Visual3DPlugin
|
||||
import hep.dataforge.vis.spatial.VisualGroup3D
|
||||
import hep.dataforge.vis.spatial.VisualObject3D
|
||||
@ -147,7 +148,7 @@ private class GDMLDemoApp : ApplicationBase() {
|
||||
|| solid.name.startsWith("Pole")
|
||||
) {
|
||||
useStyle("opaque") {
|
||||
VisualObject3D.OPACITY_KEY to 0.3
|
||||
OPACITY_KEY to 0.3
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,12 @@ import org.junit.Test
|
||||
import scientifik.gdml.GDML
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
import kotlin.test.Ignore
|
||||
|
||||
class TestConvertor {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
fun testBMNGeometry() {
|
||||
val url = URL("https://drive.google.com/open?id=1w5e7fILMN83JGgB8WANJUYm8OW2s0WVO")
|
||||
val file = File("D:\\Work\\Projects\\gdml.kt\\gdml-source\\BM@N.gdml")
|
||||
@ -24,6 +26,7 @@ class TestConvertor {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
fun testCubes() {
|
||||
val file = File("D:\\Work\\Projects\\gdml.kt\\gdml-source\\cubes.gdml ")
|
||||
val stream = if (file.exists()) {
|
||||
|
@ -22,7 +22,7 @@ kotlin {
|
||||
jvmMain {
|
||||
dependencies {
|
||||
implementation(project(":dataforge-vis-fx"))
|
||||
implementation("org.fxyz3d:fxyz3d:0.4.0")
|
||||
implementation("org.fxyz3d:fxyz3d:0.5.2")
|
||||
}
|
||||
}
|
||||
jsMain {
|
||||
@ -30,7 +30,6 @@ kotlin {
|
||||
implementation(npm("three", "0.106.2"))
|
||||
implementation(npm("@hi-level/three-csg", "1.0.6"))
|
||||
implementation(npm("style-loader"))
|
||||
implementation(npm("element-resize-event"))
|
||||
implementation(npm("inspire-tree","6.0.1"))
|
||||
implementation(npm("inspire-tree-dom","4.0.6"))
|
||||
implementation(npm("jsoneditor"))
|
||||
|
@ -0,0 +1,56 @@
|
||||
package hep.dataforge.vis.spatial
|
||||
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.names.asName
|
||||
import hep.dataforge.names.plus
|
||||
import hep.dataforge.vis.common.Colors
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.COLOR_KEY
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_KEY
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.OPACITY_KEY
|
||||
|
||||
class Material3D(override val config: Config) : Specific {
|
||||
|
||||
val color by string()
|
||||
|
||||
val opacity by float(1f)
|
||||
|
||||
companion object : Specification<Material3D> {
|
||||
override fun wrap(config: Config): Material3D = Material3D(config)
|
||||
|
||||
val MATERIAL_KEY = "material".asName()
|
||||
val COLOR_KEY = MATERIAL_KEY + "color"
|
||||
val OPACITY_KEY = MATERIAL_KEY + "opacity"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun VisualObject.color(rgb: String) {
|
||||
setProperty(COLOR_KEY, rgb)
|
||||
}
|
||||
|
||||
fun VisualObject.color(rgb: Int) = color(Colors.rgbToString(rgb))
|
||||
|
||||
fun VisualObject.color(r: UByte, g: UByte, b: UByte) = color( Colors.rgbToString(r,g,b))
|
||||
|
||||
var VisualObject.color: String?
|
||||
get() = getProperty(COLOR_KEY).string
|
||||
set(value) {
|
||||
if (value != null) {
|
||||
color(value)
|
||||
}
|
||||
}
|
||||
|
||||
var VisualObject.material: Material3D?
|
||||
get() = getProperty(MATERIAL_KEY).node?.let { Material3D.wrap(it) }
|
||||
set(value) = setProperty(MATERIAL_KEY, value?.config)
|
||||
|
||||
fun VisualObject.material(builder: Material3D.() -> Unit) {
|
||||
material = Material3D.build(builder)
|
||||
}
|
||||
|
||||
var VisualObject.opacity: Double?
|
||||
get() = getProperty(OPACITY_KEY).double
|
||||
set(value) {
|
||||
setProperty(OPACITY_KEY, value)
|
||||
}
|
@ -35,9 +35,7 @@ class Proxy(val templateName: Name) : AbstractVisualObject(), VisualGroup, Visua
|
||||
/**
|
||||
* Recursively search for defined template in the parent
|
||||
*/
|
||||
val prototype: VisualObject3D get() = getPrototype()
|
||||
|
||||
private fun getPrototype(): VisualObject3D = (parent as? VisualGroup3D)?.getTemplate(templateName)
|
||||
val prototype: VisualObject3D get() = (parent as? VisualGroup3D)?.getTemplate(templateName)
|
||||
?: error("Template with name $templateName not found in $parent")
|
||||
|
||||
override fun getStyle(name: Name): Meta? = (parent as VisualGroup?)?.getStyle(name)
|
||||
|
@ -7,13 +7,9 @@ import hep.dataforge.meta.*
|
||||
import hep.dataforge.names.asName
|
||||
import hep.dataforge.names.plus
|
||||
import hep.dataforge.output.Output
|
||||
import hep.dataforge.vis.common.Colors.rgbToString
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.DETAIL_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.LAYER_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.MATERIAL_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.OPACITY_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.SELECTED_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
|
||||
import kotlinx.serialization.UseSerializers
|
||||
@ -36,7 +32,7 @@ interface VisualObject3D : VisualObject {
|
||||
}
|
||||
|
||||
companion object {
|
||||
val MATERIAL_KEY = "material".asName()
|
||||
|
||||
val VISIBLE_KEY = "visible".asName()
|
||||
val SELECTED_KEY = "selected".asName()
|
||||
val DETAIL_KEY = "detail".asName()
|
||||
@ -44,9 +40,6 @@ interface VisualObject3D : VisualObject {
|
||||
|
||||
val GEOMETRY_KEY = "geometey".asName()
|
||||
|
||||
val COLOR_KEY = MATERIAL_KEY + "color"
|
||||
val OPACITY_KEY = MATERIAL_KEY + "opacity"
|
||||
|
||||
val x = "x".asName()
|
||||
val y = "y".asName()
|
||||
val z = "z".asName()
|
||||
@ -111,16 +104,6 @@ var VisualObject3D.detail: Int?
|
||||
get() = getProperty(DETAIL_KEY, false).int
|
||||
set(value) = setProperty(DETAIL_KEY, value)
|
||||
|
||||
var VisualObject.material: Meta?
|
||||
get() = getProperty(MATERIAL_KEY).node
|
||||
set(value) = setProperty(MATERIAL_KEY, value)
|
||||
|
||||
var VisualObject.opacity: Double?
|
||||
get() = getProperty(OPACITY_KEY).double
|
||||
set(value) {
|
||||
setProperty(OPACITY_KEY, value)
|
||||
}
|
||||
|
||||
var VisualObject.visible: Boolean?
|
||||
get() = getProperty(VISIBLE_KEY).boolean
|
||||
set(value) = setProperty(VISIBLE_KEY, value)
|
||||
@ -129,32 +112,6 @@ var VisualObject.selected: Boolean?
|
||||
get() = getProperty(SELECTED_KEY).boolean
|
||||
set(value) = setProperty(SELECTED_KEY, value)
|
||||
|
||||
fun VisualObject.color(rgb: Int) {
|
||||
setProperty(COLOR_KEY, rgbToString(rgb))
|
||||
}
|
||||
|
||||
fun VisualObject.color(rgb: String) {
|
||||
setProperty(COLOR_KEY, rgb)
|
||||
}
|
||||
|
||||
var VisualObject.color: String?
|
||||
get() = getProperty(COLOR_KEY).string
|
||||
set(value) {
|
||||
if (value != null) {
|
||||
color(value)
|
||||
}
|
||||
}
|
||||
|
||||
fun VisualObject3D.material(builder: MetaBuilder.() -> Unit) {
|
||||
material = buildMeta(builder)
|
||||
}
|
||||
|
||||
fun VisualObject3D.color(r: Int, g: Int, b: Int) = material {
|
||||
"red" to r
|
||||
"green" to g
|
||||
"blue" to b
|
||||
}
|
||||
|
||||
private fun VisualObject3D.position(): Point3D =
|
||||
position ?: Point3D(0.0, 0.0, 0.0).also { position = it }
|
||||
|
||||
|
@ -8,6 +8,7 @@ import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ConvexTest {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
@Test
|
||||
fun testConvexBuilder() {
|
||||
val group = VisualGroup3D().apply {
|
||||
|
@ -3,6 +3,7 @@ package hep.dataforge.vis.spatial.three
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.values.ValueType
|
||||
import hep.dataforge.vis.common.Colors
|
||||
import hep.dataforge.vis.spatial.Material3D
|
||||
import info.laht.threekt.materials.Material
|
||||
import info.laht.threekt.materials.MeshBasicMaterial
|
||||
import info.laht.threekt.materials.MeshPhongMaterial
|
||||
@ -61,3 +62,5 @@ fun Meta?.jsMaterial(): Material {
|
||||
}
|
||||
}
|
||||
|
||||
fun Material3D?.jsMaterial(): Material = this?.config.jsMaterial()
|
||||
|
||||
|
@ -9,6 +9,7 @@ import hep.dataforge.names.startsWith
|
||||
import hep.dataforge.provider.Type
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.spatial.*
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.MATERIAL_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.GEOMETRY_KEY
|
||||
import hep.dataforge.vis.spatial.three.ThreeFactory.Companion.TYPE
|
||||
import info.laht.threekt.core.BufferGeometry
|
||||
@ -101,9 +102,9 @@ abstract class MeshThreeFactory<T : VisualObject3D>(override val type: KClass<ou
|
||||
val WIREFRAME_KEY = "wireframe".asName()
|
||||
val ENABLED_KEY = "enabled".asName()
|
||||
val EDGES_ENABLED_KEY = EDGES_KEY + ENABLED_KEY
|
||||
val EDGES_MATERIAL_KEY = EDGES_KEY + VisualObject3D.MATERIAL_KEY
|
||||
val EDGES_MATERIAL_KEY = EDGES_KEY + MATERIAL_KEY
|
||||
val WIREFRAME_ENABLED_KEY = WIREFRAME_KEY + ENABLED_KEY
|
||||
val WIREFRAME_MATERIAL_KEY = WIREFRAME_KEY + VisualObject3D.MATERIAL_KEY
|
||||
val WIREFRAME_MATERIAL_KEY = WIREFRAME_KEY + MATERIAL_KEY
|
||||
|
||||
fun <T : VisualObject3D> buildMesh(obj: T, geometryBuilder: (T) -> BufferGeometry): Mesh {
|
||||
//TODO add caching for geometries using templates
|
||||
@ -129,7 +130,7 @@ abstract class MeshThreeFactory<T : VisualObject3D>(override val type: KClass<ou
|
||||
}
|
||||
|
||||
fun Object3D.updateProperty(source: VisualObject, propertyName: Name) {
|
||||
if (this is Mesh && propertyName.startsWith(VisualObject3D.MATERIAL_KEY)) {
|
||||
if (this is Mesh && propertyName.startsWith(MATERIAL_KEY)) {
|
||||
//updated material
|
||||
material = source.material.jsMaterial()
|
||||
} else if (
|
||||
|
@ -4,7 +4,6 @@ import hep.dataforge.context.Context
|
||||
import hep.dataforge.meta.*
|
||||
import hep.dataforge.output.Output
|
||||
import hep.dataforge.vis.common.Colors
|
||||
import hep.dataforge.vis.hmr.require
|
||||
import hep.dataforge.vis.spatial.VisualObject3D
|
||||
import info.laht.threekt.WebGLRenderer
|
||||
import info.laht.threekt.helpers.AxesHelper
|
||||
@ -13,8 +12,7 @@ import info.laht.threekt.scenes.Scene
|
||||
import org.w3c.dom.HTMLElement
|
||||
import kotlin.browser.window
|
||||
import kotlin.dom.clear
|
||||
|
||||
private val elementResizeEvent = require("element-resize-event")
|
||||
import kotlin.math.max
|
||||
|
||||
class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<VisualObject3D> {
|
||||
|
||||
@ -53,13 +51,15 @@ class ThreeOutput(val three: ThreePlugin, val meta: Meta = EmptyMeta) : Output<V
|
||||
|
||||
element.appendChild(renderer.domElement)
|
||||
|
||||
elementResizeEvent(element) {
|
||||
val minSize by meta.number(0).int
|
||||
|
||||
renderer.setSize(max(minSize, element.offsetWidth), max(minSize, element.offsetWidth))
|
||||
|
||||
element.onresize = {
|
||||
renderer.setSize(element.offsetWidth, element.offsetWidth)
|
||||
camera.updateProjectionMatrix()
|
||||
}
|
||||
|
||||
renderer.setSize(element.offsetWidth, element.offsetWidth)
|
||||
|
||||
animate()
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@ import hep.dataforge.meta.DynamicMeta
|
||||
import hep.dataforge.meta.builder
|
||||
import hep.dataforge.meta.update
|
||||
import hep.dataforge.vis.common.VisualObject
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.COLOR_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.OPACITY_KEY
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.COLOR_KEY
|
||||
import hep.dataforge.vis.spatial.Material3D.Companion.OPACITY_KEY
|
||||
import hep.dataforge.vis.spatial.VisualObject3D.Companion.VISIBLE_KEY
|
||||
import hep.dataforge.vis.spatial.color
|
||||
import hep.dataforge.vis.spatial.opacity
|
||||
|
@ -7,12 +7,3 @@ dependencies {
|
||||
api(project(":dataforge-vis-spatial"))
|
||||
testCompile(kotlin("test-js"))
|
||||
}
|
||||
|
||||
//kotlin{
|
||||
// sourceSets["main"].dependencies{
|
||||
// implementation(npm("three","0.106.2"))
|
||||
// implementation(npm("@hi-level/three-csg"))
|
||||
// implementation(npm("style-loader"))
|
||||
// implementation(npm("element-resize-event"))
|
||||
// }
|
||||
//}
|
||||
|
@ -52,6 +52,7 @@ class ThreeDemoGrid(meta: Meta) : AbstractPlugin(meta), OutputManager {
|
||||
return outputs.getOrPut(name) {
|
||||
if (type != VisualObject::class) error("Supports only DisplayObject")
|
||||
val output = three.output(meta = meta) {
|
||||
"minSize" to 500
|
||||
"axis" to {
|
||||
"size" to 500
|
||||
}
|
||||
@ -86,6 +87,6 @@ fun ThreeDemoGrid.demo(name: String, title: String = name, block: VisualGroup3D.
|
||||
val meta = buildMeta {
|
||||
"title" to title
|
||||
}
|
||||
val output = get<VisualObject>(VisualObject::class, name.toName(), meta = meta)
|
||||
val output = get(VisualObject::class, name.toName(), meta = meta)
|
||||
output.render(action = block)
|
||||
}
|
Loading…
Reference in New Issue
Block a user