# Object display truncated by camera

**URL:** <https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632>\
**Category:** Questions\
**Tags:** camera, arcrotatecamera\
**Created:** [May 17, 2024, 8:55am UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632 "2024-05-17T08:55:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![brightMoon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brightmoon/32/9959_2.png) [@brightMoon](https://forum.babylonjs.com/u/brightMoon)\
**Post date:** [May 17, 2024, 8:55am UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/1 "2024-05-17T08:55:43Z")

</div>

Please watch the video. I have adjusted minZ and maxZ, but the situation in the video may occur

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [May 17, 2024, 12:13pm UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/2 "2024-05-17T12:13:13Z")

</div>

I bet on wrong bounding boxes/ wrong bounding volume.  
Does it still happen if you freeze the scene? `scene.freezeActiveMeshes`  
Is there a way to display bounding volumes? @sebavan

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 17, 2024, 5:00pm UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/3 "2024-05-17T17:00:34Z")

</div>

@brightMoon, as usual, can you provide a PG please ?

---

<div class="post-metadata">

**Author:** ![qq2315137135](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qq2315137135/32/32219_2.png) [@qq2315137135](https://forum.babylonjs.com/u/qq2315137135)\
**Post date:** [May 17, 2024, 5:10pm UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/4 "2024-05-17T17:10:42Z")

</div>

Simple way to show all bounding boxes.

```javascript
scene.meshes.forEach(e => {
    e.showBoundingBox = true
})

```

Although the skeletal model in the video is static, I’m guessing that it’s actually animated, causing the mesh to actually be far away from the bounding box.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 17, 2024, 5:19pm UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/5 "2024-05-17T17:19:22Z")

</div>

The simplest fix is to force alwaysSelectAsActiveMesh on all the meshes from the character in this case but a playground is always great to also demo the issue and help others.

---

<div class="post-metadata">

**Author:** ![brightMoon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brightmoon/32/9959_2.png) [@brightMoon](https://forum.babylonjs.com/u/brightMoon)\
**Post date:** [May 20, 2024, 4:52am UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/6 "2024-05-20T04:52:02Z")

</div>

Normal display:

 ![noMeshDebug](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/d/bd2337952ab5b8125c536c573b40c8290c112398.jpeg)

MeshDebugPluginMaterial:

 ![haveMeshDebug](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/7/476c61bfa638a6d815ca4d84261cd7a9a3b0a60a.jpeg)

I am certain that the issue is caused by MeshDebugPluginMaterial.

Please comment on line 8 of the pg code to see the effect

Look at this example:

> **[Babylon.js Playground](https://playground.babylonjs.com/#KPLZWF%239)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

@sebavan @Cedric @qq2315137135

---

<div class="post-metadata">

**Author:** ![brightMoon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brightmoon/32/9959_2.png) [@brightMoon](https://forum.babylonjs.com/u/brightMoon)\
**Post date:** [May 20, 2024, 4:54am UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/7 "2024-05-20T04:54:44Z")

</div>

So why can MeshDebugPluginMaterial affect the borders of objects?

---

<div class="post-metadata">

**Author:** ![qq2315137135](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qq2315137135/32/32219_2.png) [@qq2315137135](https://forum.babylonjs.com/u/qq2315137135)\
**Post date:** [May 20, 2024, 7:56am UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/8 "2024-05-20T07:56:28Z")

</div>

See pg.  
It appears that `PrepareMeshForTrianglesAndVerticesMode(mesh)`  
is causing the problem.

I checked the source code, and the deeper reason is that he is calling **`mesh.convertToUnIndexedMesh()`**, which modifies the mesh vertices (line 26).

A simpler solution would be to call **`mesh.refreshBoundingInfo(true)`**, which refreshes the boundinginfo, and takes the skeleton into account (line 28).

> **[Babylon.js Playground](https://playground.babylonjs.com/#KPLZWF%2311)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

But I’m not sure why calling convertToUnIndexedMesh() on the skeleton mesh results in a boundingBox error.

Translated with [DeepL Translate: The world's most accurate translator](http://www.DeepL.com/Translator) (free version)

---

<div class="post-metadata">

**Author:** ![brightMoon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brightmoon/32/9959_2.png) [@brightMoon](https://forum.babylonjs.com/u/brightMoon)\
**Post date:** [May 20, 2024, 8:08am UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/9 "2024-05-20T08:08:11Z")

</div>

Very good, `mesh.refreshBoundingInfo (true)` can indeed solve the problem 👍  
The specific reason needs to be explained by the official maintainer 😃

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [May 20, 2024, 4:01pm UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/10 "2024-05-20T16:01:11Z")

</div>

> [@qq2315137135](#):
>
> convertToUnIndexedMesh

@Evgeni_Popov could it be related to your latest changes there ? I do not think so cause the stride as nothing to do here but just wondering before having a deeper look

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 21, 2024, 9:14am UTC](https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/11 "2024-05-21T09:14:12Z")

</div>

The bounding infos are lost when calling `convertToUnIndexedMesh`, indeed. This PR will fix it:

> <https://github.com/BabylonJS/Babylon.js/pull/15122>
>
> See https://forum.babylonjs.com/t/object-display-truncated-by-camera/50632/8
> 
> …I preferred to save and restore the existing submeshes / mesh bounding info rather than recalculate them with a call to \`mesh.refreshBoundingInfo(true)\`, because the bounding info may come from a glTF file, in which case the extents may be different from the extents calculated by \`refreshBoundingInfo\`. In addition, the user may have defined a custom bounding info.
