Skip to content

Commit

Permalink
Enhance RenderableNode
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGorisse committed Nov 15, 2023
1 parent 8dcbfc5 commit 5803060
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions sceneview/src/main/java/io/github/sceneview/node/RenderableNode.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package io.github.sceneview.node

import com.google.android.filament.Box
import com.google.android.filament.Engine
import com.google.android.filament.EntityManager
import com.google.android.filament.MaterialInstance
import com.google.android.filament.RenderableManager
import io.github.sceneview.Entity
import io.github.sceneview.FilamentEntity
import io.github.sceneview.SceneView
import io.github.sceneview.components.RenderableComponent
import io.github.sceneview.math.toVector3Box

/**
* A Node represents a transformation within the scene graph's hierarchy.
Expand All @@ -31,9 +35,41 @@ open class RenderableNode(
parent: Node? = null
) : Node(engine, entity, parent), RenderableComponent {

constructor(
engine: Engine,
@FilamentEntity entity: Entity = EntityManager.get().create(),
parent: Node? = null,
/**
* Count the number of primitives that will be supplied to the builder
*/
primitiveCount: Int,
boundingBox: Box,
/**
* Binds a material instance.
*
* If no material is specified, Filament will fall back to a basic default material.
*/
materialInstances: List<MaterialInstance?> = listOf(),
builder: RenderableManager.Builder.() -> Unit,
) : this(engine, entity, parent) {
RenderableManager.Builder(primitiveCount)
.boundingBox(boundingBox)
.apply {
materialInstances.forEachIndexed { index, materialInstance ->
materialInstance?.let { material(index, materialInstance) }
}
}.apply(builder)
.build(engine, entity)
updateCollisionShape()
}

override fun updateVisibility() {
super.updateVisibility()

setLayerVisible(isVisible)
}

fun updateCollisionShape() {
collisionShape = axisAlignedBoundingBox.toVector3Box()
}
}

0 comments on commit 5803060

Please sign in to comment.