Convert 2:1 equirectangular panorama to cube map

前端 未结 11 1151
情深已故
情深已故 2020-11-30 17:30

I\'m currently working on a simple 3D panorama viewer for a website. For mobile performance reasons I\'m using the three.js CSS3 renderer. This requires a cube

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 18:14

    Found this question, and even though the answers are good, I think there is still some ground uncovered, so here are my two cents.

    First: unless you really have to convert the images yourself (i.e. because of some specific software requirement), don't.

    The reason is that, even though there is a very simple mapping between equirectangular projection and cubic projection, the mapping between the areas is not simple: when you establish a correspondence between a specific point of your destination image and a point in the source with an elementary computation, as soon as you convert both points to pixels by rounding you are doing a very raw approximation that doesn't consider the size of the pixels, and the quality of the image is bound to be low.

    Second: even if you need to do the conversion at runtime, are you sure that you need to do the conversion at all? Unless there is some very stringent performance problem, if you just need a skybox, create a very big sphere, stitch the equirectangular texure on it, and off you go. Three JS provides the sphere already, as far as I remember ;-)

    Third: NASA provides a tool to convert between all conceivable projections (I just found out, tested it, and works like a charm). You can find it here:

    G.Projector — Global Map Projector

    and I find reasonable to think that the guys know what they are doing ;-)

    Hope this helps

    UPDATE: it turns out that the "guys" know what they do up to some point: the generated cubemap has an hideous border which makes the conversion not that easy...

    UPDATE 2: found the definitive tool for equirectangular to cubemap conversion, and it's called erect2cubic.

    It's a small utility that generates a script to be fed to hugin, in this way:

    $ erect2cubic --erect=input.png --ptofile=cube.pto
    $ nona -o cube_prefix cube.pto 
    

    (information siphoned from Vinay's Hacks page)

    and will generate all 6 cubemap faces. I'm using it for my project and it works like a charm!

    The only downside of this approach is that the script erect2cubit it's not in the standard Ubuntu distribution (which is what I'm using) and I had to resort to the instructions at this link:

    Blog describing how to install and use erect2cubic

    to find out how to install it.

    Totally worth it!

提交回复
热议问题