Skip to content

How to get the dimensions of the box around a GLTF/GLB model ? #243

Answered by grassydragon
agGitHub asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!
You can access bounding box if you save a reference to RendereableInstance when setting Renderable. For example:

// Create a model node and fit it inside a unit cube
val modelNode = Node()
modelNode.parent = transformableNode

val instance = modelNode.setRenderable(state.model)
val boundingBox = instance.filamentAsset?.boundingBox

if (boundingBox != null) {
    val maxHalfExtent = boundingBox.halfExtent.maxOrNull()!!
    val scale = 0.5f / maxHalfExtent
    modelNode.localScale = Vector3(scale, scale, scale)
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Yeafun
Comment options

@grassydragon
Comment options

Answer selected by ThomasGorisse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants