# Constructing CubeTextures in BabylonNative

**URL:** <https://forum.babylonjs.com/t/constructing-cubetextures-in-babylonnative/54950>\
**Category:** Questions\
**Tags:** babylon-native, cubetexture\
**Created:** [November 23, 2024, 7:04am UTC](https://forum.babylonjs.com/t/constructing-cubetextures-in-babylonnative/54950 "2024-11-23T07:04:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmatzen](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kmatzen/32/42356_2.png) [@kmatzen](https://forum.babylonjs.com/u/kmatzen)\
**Post date:** [November 23, 2024, 7:04am UTC](https://forum.babylonjs.com/t/constructing-cubetextures-in-babylonnative/54950/1 "2024-11-23T07:04:15Z")

</div>

I’m generating some texture data in a C++ app and I would like to construct a CubeTexture in BabylonNative to assign it to scene.environmentTexture and as a skybox. I originally planned to use RawCubeTexture, but it seems like it’s not implemented for BabylonNative. Is there a supported solution for this task? I see in the readme that only .env is supported.

---

<div class="post-metadata">

**Author:** ![kmatzen](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kmatzen/32/42356_2.png) [@kmatzen](https://forum.babylonjs.com/u/kmatzen)\
**Post date:** [November 24, 2024, 7:23am UTC](https://forum.babylonjs.com/t/constructing-cubetextures-in-babylonnative/54950/2 "2024-11-24T07:23:53Z")

</div>

I got something to work. If anyone wants some pointers, I extended NativeEngine to include a loadRawCubeTexture function, although the existing one probably works if you prepend an appropriate header (I’m guessing TGA is the easiest?). Then I created an InternalTexture with CubeRaw type, then pattern matched the setup from createRawTexture. The hard part that took a long time to track down was that the spherical polynomial computation doesn’t work in BabylonNative because “Reading cubemap faces is not supported” (This error gets swallowed, which is what made it time consuming to track down.). Instead, you can assign an irradianceTexture to the reflectionTexture and it won’t compute the polynomials. The last piece is that I had to set coordinatesMode to CUBIC\_MODE since the default appears to select the same pixel coordinate in the cube map all the time.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [November 25, 2024, 3:59pm UTC](https://forum.babylonjs.com/t/constructing-cubetextures-in-babylonnative/54950/3 "2024-11-25T15:59:19Z")

</div>

cc [@BabylonNative](https://forum.babylonjs.com/groups/babylonnative)

---

<div class="post-metadata">

**Author:** ![bghgary](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bghgary/32/48532_2.png) [@bghgary](https://forum.babylonjs.com/u/bghgary)\
**Post date:** [November 25, 2024, 10:32pm UTC](https://forum.babylonjs.com/t/constructing-cubetextures-in-babylonnative/54950/4 "2024-11-25T22:32:19Z")

</div>

> [@kmatzen](#):
>
> This error gets swallowed, which is what made it time consuming to track down

This would be great to fix. Can you help with a repro?

> [@kmatzen](#):
>
> I extended NativeEngine to include a loadRawCubeTexture function

It would be great if you can contribute a fix for this, but if not, can you provide some code snippets of the implementation?
