Add Hexagon. Second part of #39 fix
This commit is contained in:
parent
ff80629f24
commit
e644b1b20a
@ -6,6 +6,7 @@
|
||||
- Change collector
|
||||
- Customizable accessors for colors
|
||||
- SphereLayer solid
|
||||
- Hexagon interface and GenericHexagon implementation (Box inherits Hexagon)
|
||||
|
||||
### Changed
|
||||
- Vision does not implement ItemProvider anymore. Property changes are done via `getProperty`/`setProperty` and `property` delegate.
|
||||
@ -15,6 +16,7 @@
|
||||
- \[Format breaking change!\] Stylesheets are moved into properties under `@stylesheet` key
|
||||
- VisionGroup builder accepts `null` as name for statics instead of `""`
|
||||
- gdml sphere is rendered as a SphereLayer instead of Sphere (#35)
|
||||
- Tube is replaced by more general ConeSurface
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
@ -10,6 +10,7 @@ fun main() {
|
||||
val context = Context {
|
||||
plugin(Solids)
|
||||
}
|
||||
|
||||
context.makeVisionFile(resourceLocation = ResourceLocation.EMBED) {
|
||||
vision("canvas") {
|
||||
GdmlShowCase.babyIaxo().toVision()
|
||||
|
@ -25,7 +25,6 @@ public fun Context.makeVisionFile(
|
||||
show: Boolean = true,
|
||||
content: VisionTagConsumer<*>.() -> Unit
|
||||
): Unit {
|
||||
|
||||
val actualPath = page(title, content = content).makeFile(path) { actualPath ->
|
||||
mapOf("threeJs" to scriptHeader("js/visionforge-playground.js", resourceLocation, actualPath))
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ fun VisionLayout<Solid>.showcaseCSG() {
|
||||
|
||||
demo("CSG.custom", "CSG with manually created object") {
|
||||
intersect {
|
||||
tube(60, 10) {
|
||||
cylinder(60, 10) {
|
||||
detail = 32
|
||||
}
|
||||
box(100, 100, 100)
|
||||
|
@ -282,13 +282,28 @@ private class GdmlTransformer(val settings: GdmlTransformerSettings) {
|
||||
|
||||
}
|
||||
}
|
||||
is GdmlTrapezoid -> {
|
||||
val dxBottom = solid.x1.toDouble()
|
||||
val dxTop = solid.x2.toDouble()
|
||||
val dyBottom = solid.y1.toDouble()
|
||||
val dyTop = solid.y2.toDouble()
|
||||
val dz = solid.z.toDouble()
|
||||
val node1 = Point3D(-dxBottom, -dyBottom, -dz)
|
||||
val node2 = Point3D(dxBottom, -dyBottom, -dz)
|
||||
val node3 = Point3D(dxBottom, dyBottom, -dz)
|
||||
val node4 = Point3D(-dxBottom, dyBottom, -dz)
|
||||
val node5 = Point3D(-dxTop, -dyTop, dz)
|
||||
val node6 = Point3D(dxTop, -dyTop, dz)
|
||||
val node7 = Point3D(dxTop, dyTop, dz)
|
||||
val node8 = Point3D(-dxTop, dyTop, dz)
|
||||
hexagon(node1, node2, node3, node4, node5, node6, node7, node8, name)
|
||||
}
|
||||
is GdmlEllipsoid -> TODO("Renderer for $solid not supported yet")
|
||||
is GdmlElTube -> TODO("Renderer for $solid not supported yet")
|
||||
is GdmlElCone -> TODO("Renderer for $solid not supported yet")
|
||||
is GdmlParaboloid -> TODO("Renderer for $solid not supported yet")
|
||||
is GdmlParallelepiped -> TODO("Renderer for $solid not supported yet")
|
||||
is GdmlTorus -> TODO("Renderer for $solid not supported yet")
|
||||
is GdmlTrapezoid -> TODO("Renderer for $solid not supported yet")
|
||||
is GdmlPolycone -> TODO("Renderer for $solid not supported yet")
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
package space.kscience.visionforge.solid
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import space.kscience.visionforge.VisionBuilder
|
||||
import space.kscience.visionforge.VisionContainerBuilder
|
||||
import space.kscience.visionforge.set
|
||||
|
||||
@Serializable
|
||||
@SerialName("solid.box")
|
||||
public class Box(
|
||||
public val xSize: Float,
|
||||
public val ySize: Float,
|
||||
public val zSize: Float
|
||||
) : SolidBase(), GeometrySolid {
|
||||
|
||||
//TODO add helper for color configuration
|
||||
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
||||
val dx = xSize / 2
|
||||
val dy = ySize / 2
|
||||
val dz = zSize / 2
|
||||
val node1 = Point3D(-dx, -dy, -dz)
|
||||
val node2 = Point3D(dx, -dy, -dz)
|
||||
val node3 = Point3D(dx, dy, -dz)
|
||||
val node4 = Point3D(-dx, dy, -dz)
|
||||
val node5 = Point3D(-dx, -dy, dz)
|
||||
val node6 = Point3D(dx, -dy, dz)
|
||||
val node7 = Point3D(dx, dy, dz)
|
||||
val node8 = Point3D(-dx, dy, dz)
|
||||
geometryBuilder.face4(node1, node4, node3, node2)
|
||||
geometryBuilder.face4(node1, node2, node6, node5)
|
||||
geometryBuilder.face4(node2, node3, node7, node6)
|
||||
geometryBuilder.face4(node4, node8, node7, node3)
|
||||
geometryBuilder.face4(node1, node5, node8, node4)
|
||||
geometryBuilder.face4(node8, node5, node6, node7)
|
||||
}
|
||||
|
||||
public companion object {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@VisionBuilder
|
||||
public inline fun VisionContainerBuilder<Solid>.box(
|
||||
xSize: Number,
|
||||
ySize: Number,
|
||||
zSize: Number,
|
||||
name: String? = null,
|
||||
action: Box.() -> Unit = {}
|
||||
): Box = Box(xSize.toFloat(), ySize.toFloat(), zSize.toFloat()).apply(action).also { set(name, it) }
|
@ -2,6 +2,7 @@ package space.kscience.visionforge.solid
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import space.kscience.visionforge.VisionBuilder
|
||||
import space.kscience.visionforge.VisionContainerBuilder
|
||||
import space.kscience.visionforge.set
|
||||
import kotlin.math.cos
|
||||
@ -64,6 +65,7 @@ public class ConeSegment(
|
||||
|
||||
}
|
||||
|
||||
@VisionBuilder
|
||||
public inline fun VisionContainerBuilder<Solid>.cylinder(
|
||||
r: Number,
|
||||
height: Number,
|
||||
@ -75,7 +77,7 @@ public inline fun VisionContainerBuilder<Solid>.cylinder(
|
||||
r.toFloat()
|
||||
).apply(block).also { set(name, it) }
|
||||
|
||||
|
||||
@VisionBuilder
|
||||
public inline fun VisionContainerBuilder<Solid>.cone(
|
||||
bottomRadius: Number,
|
||||
height: Number,
|
||||
|
@ -0,0 +1,88 @@
|
||||
package space.kscience.visionforge.solid
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import space.kscience.visionforge.VisionBuilder
|
||||
import space.kscience.visionforge.VisionContainerBuilder
|
||||
import space.kscience.visionforge.set
|
||||
|
||||
public interface Hexagon : GeometrySolid {
|
||||
public val node1: Point3D
|
||||
public val node2: Point3D
|
||||
public val node3: Point3D
|
||||
public val node4: Point3D
|
||||
public val node5: Point3D
|
||||
public val node6: Point3D
|
||||
public val node7: Point3D
|
||||
public val node8: Point3D
|
||||
|
||||
override fun <T : Any> toGeometry(geometryBuilder: GeometryBuilder<T>) {
|
||||
geometryBuilder.face4(node1, node4, node3, node2)
|
||||
geometryBuilder.face4(node1, node2, node6, node5)
|
||||
geometryBuilder.face4(node2, node3, node7, node6)
|
||||
geometryBuilder.face4(node4, node8, node7, node3)
|
||||
geometryBuilder.face4(node1, node5, node8, node4)
|
||||
geometryBuilder.face4(node8, node5, node6, node7)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A separate class is created to optimize native rendering
|
||||
*/
|
||||
@Serializable
|
||||
@SerialName("solid.box")
|
||||
public class Box(
|
||||
public val xSize: Float,
|
||||
public val ySize: Float,
|
||||
public val zSize: Float,
|
||||
) : SolidBase(), Hexagon {
|
||||
|
||||
private inline val dx get() = xSize / 2
|
||||
private inline val dy get() = ySize / 2
|
||||
private inline val dz get() = zSize / 2
|
||||
|
||||
override val node1: Point3D get() = Point3D(-dx, -dy, -dz)
|
||||
override val node2: Point3D get() = Point3D(dx, -dy, -dz)
|
||||
override val node3: Point3D get() = Point3D(dx, dy, -dz)
|
||||
override val node4: Point3D get() = Point3D(-dx, dy, -dz)
|
||||
override val node5: Point3D get() = Point3D(-dx, -dy, dz)
|
||||
override val node6: Point3D get() = Point3D(dx, -dy, dz)
|
||||
override val node7: Point3D get() = Point3D(dx, dy, dz)
|
||||
override val node8: Point3D get() = Point3D(-dx, dy, dz)
|
||||
}
|
||||
|
||||
@VisionBuilder
|
||||
public inline fun VisionContainerBuilder<Solid>.box(
|
||||
xSize: Number,
|
||||
ySize: Number,
|
||||
zSize: Number,
|
||||
name: String? = null,
|
||||
action: Box.() -> Unit = {},
|
||||
): Box = Box(xSize.toFloat(), ySize.toFloat(), zSize.toFloat()).apply(action).also { set(name, it) }
|
||||
|
||||
@Serializable
|
||||
@SerialName("solid.hexagon")
|
||||
public class GenericHexagon(
|
||||
override val node1: Point3D,
|
||||
override val node2: Point3D,
|
||||
override val node3: Point3D,
|
||||
override val node4: Point3D,
|
||||
override val node5: Point3D,
|
||||
override val node6: Point3D,
|
||||
override val node7: Point3D,
|
||||
override val node8: Point3D,
|
||||
) : SolidBase(), Hexagon
|
||||
|
||||
@VisionBuilder
|
||||
public inline fun VisionContainerBuilder<Solid>.hexagon(
|
||||
node1: Point3D,
|
||||
node2: Point3D,
|
||||
node3: Point3D,
|
||||
node4: Point3D,
|
||||
node5: Point3D,
|
||||
node6: Point3D,
|
||||
node7: Point3D,
|
||||
node8: Point3D,
|
||||
name: String? = null,
|
||||
action: Hexagon.() -> Unit = {},
|
||||
): Hexagon = GenericHexagon(node1, node2, node3, node4, node5, node6, node7, node8).apply(action).also { set(name, it) }
|
@ -30,6 +30,7 @@ public class Solids(meta: Meta) : VisionPlugin(meta) {
|
||||
subclass(SolidReferenceGroup.serializer())
|
||||
subclass(Composite.serializer())
|
||||
subclass(Box.serializer())
|
||||
subclass(GenericHexagon.serializer())
|
||||
subclass(ConeSegment.serializer())
|
||||
subclass(ConeSurface.serializer())
|
||||
subclass(Convex.serializer())
|
||||
|
Loading…
Reference in New Issue
Block a user