0

I want to load an HDRi map (similar to Google Maps) in an iPhone application, and then I want to be able to load some 3D characters to play around in the scene.

You can see here an example of what I would like to load:

enter image description here

http://www.hdri-hub.com/hdrishop/freesamples/freehdri/item/117-hdr-041-path-free

Currently I'm using Cocos3D for loading 3D models from Blender through POD export files, so maybe there is a way to load HDRi in Cocos3D. I found out this class CC3STBImage which can be used to load HDR types, but I don't know exactly how to use it (and no example found). I've seen that CC3Texture2DContent has the initFromSTBIFile: method for 'phdr' file extension, so maybe the HDRi could be loaded as a texture?

[Edit]

I managed to load a spherical mesh with the image, see the answer and comments below. Hereby some screenshots of the result by looking through a CC3Camera at the skybox:

enter image description here enter image description here enter image description here

Andrei Marincas
  • 446
  • 5
  • 13

1 Answers1

1

As you mention, HDRi support is provided by the CC3STBImage class. The list of file extensions that use this class is available in the CC3STBImage useForFileExtensions method. If you don't want to rename your files to *.phdr, you can add the file extension that you want to this collection.

Once you've ensured that your HDRi file extension is in the above collection, you can load an HDRi file into a CC3Texture by simply using:

[CC3Texture textureFromFile: @"myFile.phdr"];

CC3STBImage uses the third-party library provided in the stb_image.c file. Have a look at the notes in that file for more on HDRi support, and any potential limitations.

Keep in mind that the iOS OpenGL implementation limits the size of textures. Cocos3D logs the maximum texture size for the current platform during app start-up. Look in the logs for an entry such as:

[info] Maximum texture size: 4096

which indicates the maximum OpenGL texture width and height supported by that platform.

Bill Hollings
  • 2,344
  • 17
  • 25
  • Hi, thank you for the answer! Unfortunately 4096 is too small, so I could only load a smaller 'jpg' version of my hdr, which is this one: https://www.dropbox.com/s/eln43djuvyruvef/HDR_041_Path_Prev.jpg Anyway, I load it as the backdrop of a CC3Scene, but it only sets it as a plain bg image, like so: https://www.dropbox.com/s/mztcs8rett0vt7e/IMG_1875.PNG I'm actually trying to set it as an 'environmental' background image, so that I can rotate it around. This is how it's done in Blender https://www.youtube.com/watch?v=qgfw2QwXtA4 , and I don't know if it's doable in Cocos3D world :( – Andrei Marincas Jul 07 '14 at 08:08
  • 1
    This is really a separate question. What you need is a skybox. Create a spherical mesh in Blender and wrap the HDRi file around it. You'll probably want the mesh to face inwards, or use the shouldCullBackFaces property in Cocos3D. Export to POD, load in Cocos3D, and size it to wrap around your scene. See the CC3DemoMashUpScene addSkybox method for an example of a skybox that uses a cube-map texture (which is different than your flat texture) instead. – Bill Hollings Jul 10 '14 at 19:09
  • Done it in Blender using a UV sphere and mapping the texture to a 4096 x 2048 HDRi (jpg), which I was able to load in Cocos3D afterwards. I can smoothly rotate the camera inside the sphere on my iPhone, looks good to me: https://www.dropbox.com/sh/9wj5iaje2v098ut/AAC99BnuQKe03tQk6U1p2c16a Haven't looked into the DemoMashUp scene for this yet, but I'll give it a try. Thanks for the help on this! – Andrei Marincas Jul 11 '14 at 13:19