Skip to content

Commit

Permalink
Overridable Node.onAddedToScene(scene) and `Node.onRemovedFromScene…
Browse files Browse the repository at this point in the history
…(scene)`
  • Loading branch information
ThomasGorisse committed Dec 7, 2023
1 parent 877387c commit 0356d47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sceneview/src/main/java/io/github/sceneview/SceneView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ open class SceneView @JvmOverloads constructor(
addEntities(node.sceneEntities)
node.onChildAdded += ::addNode
node.onChildRemoved += ::removeNode
node.onAddedToScene(scene)
node.childNodes.forEach { addNode(it) }
}

Expand All @@ -675,6 +676,7 @@ open class SceneView @JvmOverloads constructor(
removeEntities(node.sceneEntities)
node.onChildAdded -= ::addNode
node.onChildRemoved -= ::removeNode
node.onRemovedFromScene(scene)
node.childNodes.forEach { removeNode(it) }
}

Expand Down
12 changes: 11 additions & 1 deletion sceneview/src/main/java/io/github/sceneview/node/Node.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.GestureDetector.OnDoubleTapListener
import android.view.MotionEvent
import com.google.android.filament.Engine
import com.google.android.filament.EntityManager
import com.google.android.filament.Scene
import com.google.android.filament.TransformManager
import dev.romainguy.kotlin.math.Float2
import dev.romainguy.kotlin.math.Float3
Expand All @@ -27,7 +28,6 @@ import io.github.sceneview.collision.CollisionShape
import io.github.sceneview.collision.CollisionSystem
import io.github.sceneview.collision.Matrix
import io.github.sceneview.collision.TransformProvider
import io.github.sceneview.collision.Vector3
import io.github.sceneview.gesture.MoveGestureDetector
import io.github.sceneview.gesture.RotateGestureDetector
import io.github.sceneview.gesture.ScaleGestureDetector
Expand Down Expand Up @@ -377,6 +377,8 @@ open class Node(

var onFrame: ((frameTimeNanos: Long) -> Unit)? = null
var onSmoothEnd: ((node: Node) -> Unit)? = null
var onAddedToScene: ((scene: Scene) -> Unit)? = null
var onRemovedFromScene: ((scene: Scene) -> Unit)? = null

var onDown: ((e: MotionEvent) -> Boolean)? = null
var onShowPress: ((e: MotionEvent) -> Unit)? = null
Expand Down Expand Up @@ -810,6 +812,14 @@ open class Node(
onWorldTransformChanged()
}

open fun onAddedToScene(scene: Scene) {
onAddedToScene?.invoke(scene)
}

open fun onRemovedFromScene(scene: Scene) {
onRemovedFromScene?.invoke(scene)
}

/**
* The transformation (position, rotation or scale) of the [Node] has changed.
*
Expand Down

0 comments on commit 0356d47

Please sign in to comment.