Skip to content

Commit

Permalink
Merge pull request #567 from scenerygraphics/atmosphere
Browse files Browse the repository at this point in the history
Add Atmosphere background shader to the scene
  • Loading branch information
smlpt authored Apr 21, 2024
2 parents 92c84d6 + e7fffbd commit c4f9319
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/sc/iview/commands/MenuWeights.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ object MenuWeights {
const val EDIT_ADD_SLICING_PLANE = 10.0
const val EDIT_ADD_SPHERE = 11.0
const val EDIT_ADD_VOLUME = 12.0
const val EDIT_ADD_ATMOSPHERE = 13.0

// Edit/Settings
const val EDIT_SETTINGS_BINDINGS = 0.0
Expand Down
33 changes: 33 additions & 0 deletions src/main/kotlin/sc/iview/commands/add/AddAtmosphere.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package sc.iview.commands.add

import graphics.scenery.primitives.Atmosphere
import org.scijava.command.Command
import org.scijava.plugin.Menu
import org.scijava.plugin.Parameter
import org.scijava.plugin.Plugin
import org.scijava.widget.NumberWidget
import sc.iview.SciView
import sc.iview.commands.MenuWeights

/**
* Command to add an atmosphere background to the scene
*
* @author Samuel Pantze
*/
@Plugin(
type = Command::class,
menuRoot = "SciView",
menu = [Menu(label = "Add", weight = MenuWeights.ADD), Menu(
label = "Atmosphere...",
weight = MenuWeights.EDIT_ADD_ATMOSPHERE
)]
)
class AddAtmosphere : Command {
@Parameter
private lateinit var sciView: SciView

override fun run() {
val atmos = Atmosphere()
sciView.addNode(atmos)
}
}
47 changes: 47 additions & 0 deletions src/main/kotlin/sc/iview/commands/edit/Properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ package sc.iview.commands.edit

import graphics.scenery.*
import graphics.scenery.attribute.material.HasMaterial
import graphics.scenery.primitives.Atmosphere
import graphics.scenery.primitives.Line
import graphics.scenery.primitives.TextBoard
import graphics.scenery.volumes.Colormap
Expand Down Expand Up @@ -208,6 +209,23 @@ class Properties : InteractiveCommand() {

private val slicingModeChoices = Volume.SlicingMode.values().toMutableList()

/* Atmosphere properties*/

@Parameter(label = "Latitude", style = NumberWidget.SPINNER_STYLE+"group:Atmosphere"+",format:0.0", min = "-90", max = "90", stepSize = "1", callback = "updateNodeProperties")
private var atmosphereLatitude = 50f

@Parameter(label = "Enable keybindings and manual control", style = "group:Atmosphere", callback = "updateNodeProperties", description = "Use key bindings for controlling the sun.\nCtrl + Arrow Keys = large increments.\nCtrl + Shift + Arrow keys = small increments.")
private var isSunManual = false

@Parameter(label = "Sun Azimuth", style = "group:Atmosphere" + ",format:0.0", callback = "updateNodeProperties", description = "Azimuth value of the sun in degrees", min = "0", max = "360", stepSize = "1")
private var sunAzimuth = 180f

@Parameter(label = "Sun Elevation", style = "group:Atmosphere" + ",format:0.0", callback = "updateNodeProperties", description = "Elevation value of the sun in degrees", min = "-90", max = "90", stepSize = "1")
private var sunElevation = 45f

@Parameter(label = "Emission Strength", style = NumberWidget.SPINNER_STYLE+"group:Atmosphere"+",format:0.00", min = "0", max="10", stepSize = "0.1", callback = "updateNodeProperties")
private var atmosphereStrength = 1f

var fieldsUpdating = true
var sceneNodeChoices = ArrayList<String>()
private var currentSceneNode: Node? = null
Expand Down Expand Up @@ -470,6 +488,20 @@ class Properties : InteractiveCommand() {
maybeRemoveInput("edgeWidth", Integer::class.java)
}

if (node is Atmosphere) {
isSunManual = !node.isSunAnimated
atmosphereLatitude = node.latitude
atmosphereStrength = node.emissionStrength
sunAzimuth = node.azimuth
sunElevation = node.elevation
} else {
maybeRemoveInput("isSunManual", java.lang.Boolean::class.java)
maybeRemoveInput("atmosphereLatitude", java.lang.Float::class.java)
maybeRemoveInput("atmosphereStrength", java.lang.Float::class.java)
maybeRemoveInput("sunAzimuth", java.lang.Float::class.java)
maybeRemoveInput("sunElevation", java.lang.Float::class.java)
}

name = node.name
fieldsUpdating = false
}
Expand Down Expand Up @@ -570,6 +602,21 @@ class Properties : InteractiveCommand() {
node.edgeWidth = edgeWidth.toFloat()
}

if (node is Atmosphere) {
node.latitude = atmosphereLatitude
node.emissionStrength = atmosphereStrength
// attach/detach methods also handle the update of node.updateControls
if (isSunManual) {
sciView.sceneryInputHandler?.let { node.attachBehaviors(it) }
node.setSunPosition(sunElevation, sunAzimuth)
} else {
sciView.sceneryInputHandler?.let { node.detachBehaviors(it) }
// Update the sun position immediately
node.setSunPositionFromTime()
}

}

events.publish(NodeChangedEvent(node))
}

Expand Down

0 comments on commit c4f9319

Please sign in to comment.