Loading HDRi maps in Cocos3D

不问归期 提交于 2019-12-12 02:42:11

问题


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:

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:


回答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.



来源:https://stackoverflow.com/questions/24569374/loading-hdri-maps-in-cocos3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!