Skip to content

Commit

Permalink
Files as found from the end of BAAAHS Campout 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
xian committed Aug 25, 2024
1 parent 5142d31 commit e4cefee
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/BAAAHS Campout 2024.scene
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"model":{"title":"BAAAHS Campout 2024","entities":[{"type":"Grid","title":"Left Drop A","position":{"x":-24.532906,"y":0.009870256,"z":0.0},"rows":40,"columns":12,"rowGap":1.0,"columnGap":1.0},{"type":"Grid","title":"Right Drop B","position":{"x":15.984995,"y":-0.08263471,"z":0.0},"rows":40,"columns":12,"rowGap":1.0,"columnGap":1.0},{"type":"Grid","title":"Right Drop A","position":{"x":4.0874286,"y":0.0042497697,"z":0.0},"rows":40,"columns":12,"rowGap":1.0,"columnGap":1.0},{"type":"Grid","title":"Left Drop B","position":{"x":-12.694629,"y":-0.05184719,"z":0.0},"rows":40,"columns":12,"rowGap":1.0,"columnGap":1.0}],"units":"Inches"},"controllers":{"Brain:C78450":{"type":"Brain","title":"C78450","fixtures":[{"entityId":"Right Drop A","fixtureConfig":{"type":"PixelArray","pixelFormat":"GRB8"}}]},"Brain:C78498":{"type":"Brain","title":"C78498","fixtures":[{"entityId":"Right Drop A","fixtureConfig":{"type":"PixelArray","pixelFormat":"GRB8"}}]},"Brain:CAF59C":{"type":"Brain","title":"CAF59C","fixtures":[{"entityId":"Left Drop A","fixtureConfig":{"type":"PixelArray","pixelFormat":"GRB8"}}]},"Brain:CB1640":{"type":"Brain","title":"CB1640","fixtures":[{"entityId":"Left Drop B","fixtureConfig":{"type":"PixelArray","pixelFormat":"GRB8"}}]},"Brain:C78438":{"type":"Brain","title":"C78438","fixtures":[{"entityId":"Right Drop B","fixtureConfig":{"type":"PixelArray","pixelFormat":"GRB8"}}]}},"version":1}
1 change: 1 addition & 0 deletions data/Campout 2024.sparkle

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"runningShowPath":"PastureBedtime.sparkle","runningScenePath":"BAAAHS.scene"}
{"runningShowPath":"Campout 2024.sparkle","runningScenePath":"BAAAHS Campout 2024.scene","version":0}
19 changes: 12 additions & 7 deletions src/commonMain/kotlin/baaahs/sm/brain/BrainManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ class BrainManager(
entity: Model.Entity?,
fixtureConfig: FixtureConfig,
transportConfig: TransportConfig?
): Transport = BrainTransport(this, brainAddress, brainId, isSimulatedBrain)
): Transport = BrainTransport(
this, brainAddress, brainId, isSimulatedBrain,
transportConfig = transportConfig
)

override fun getAnonymousFixtureMappings(): List<FixtureMapping> {
return listOf(FixtureMapping(
Expand All @@ -186,27 +189,29 @@ class BrainManager(
val brainId: BrainId,
private val isSimulatedBrain: Boolean,
val firmwareVersion: String? = null,
val idfVersion: String? = null
val idfVersion: String? = null,
val transportConfig: TransportConfig?
) : Transport {
private var pixelBuffer = pixelShader.createBuffer(0)
private val pixelOffset = 4

override val name: String
get() = "Brain ${brainId.uuid} at $brainAddress"
override val controller: Controller
get() = brainController
override val config: TransportConfig?
get() = null
get() = transportConfig

override fun deliverBytes(byteArray: ByteArray) {
val pixelCount = byteArray.size / 3

if (pixelCount != pixelBuffer.colors.size) {
pixelBuffer = pixelShader.createBuffer(pixelCount)
pixelBuffer = pixelShader.createBuffer(pixelCount + pixelOffset)
}

for (i in 0 until pixelCount) {
val j = i * 3
pixelBuffer.colors[i] = Color(byteArray[j], byteArray[j + 1], byteArray[j + 2])
pixelBuffer.colors[i + pixelOffset * 3] = Color(byteArray[j], byteArray[j + 1], byteArray[j + 2])
}

deliverShaderMessage()
Expand All @@ -218,7 +223,7 @@ class BrainManager(
fn: (componentIndex: Int, buf: ByteArrayWriter) -> Unit
) {
if (componentCount != pixelBuffer.colors.size) {
pixelBuffer = pixelShader.createBuffer(componentCount)
pixelBuffer = pixelShader.createBuffer(componentCount + pixelOffset)
}

val buf = ByteArrayWriter(bytesPerComponent)
Expand All @@ -229,7 +234,7 @@ class BrainManager(

// Using Color's int constructor fixes a bug in Safari causing
// color values above 127 to be treated as 0. Untested. :-(
pixelBuffer.colors[i] = Color(
pixelBuffer.colors[i + pixelOffset] = Color(
colorBytes[0].toInt() and 0xff,
colorBytes[1].toInt() and 0xff,
colorBytes[2].toInt() and 0xff)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ object WebcamCaptureVideoProvider : VideoProvider {
private var textureResource: TextureResource? = null
private var isOpen = false

private val webcam: Webcam = run {
private val webcam: Webcam? = run {
Webcam.setDriver(NativeDriver())
Webcam.getDefault()
}

private val noImage = BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB)

override fun isReady(): Boolean = isOpen.also { ensureOpen() }

override fun getTextureResource(): TextureResource {
ensureOpen()

val image: BufferedImage = webcam.image ?: noImage
val image: BufferedImage = webcam?.image ?: noImage
if (textureResource == null || textureResource!!.width != image.width || textureResource!!.height != image.height) {
val vals = ByteBuffer(image.width * image.height * 3)
textureResource = TextureResource(
Expand Down Expand Up @@ -58,6 +59,7 @@ object WebcamCaptureVideoProvider : VideoProvider {

private fun ensureOpen() {
if (!isOpen) {
if (webcam != null)
isOpen = webcam.open(true)
}
}
Expand Down

0 comments on commit e4cefee

Please sign in to comment.