Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Crafty Sky Box

in Codea Craft Posts: 1,757

Hi All,
Just posting hoping I can gets few tips from the forum. Recently several good posts on textured cubes, notably ones from @dave1707, have given me a different approach to them using Craft (most of mine used meshes).
Good learning from that - so I turned my mind to Sky Boxes from Craft. Naively thinking all you had to do was place the camera at the centre of the box - but it doesn't work!

So - can anyone point me to the essential differences between cubes and Sky boxes? Is it anything to do with the Craft camera routines or the environment parameters for the scene?

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 8,464

    @Bri_G All you have to do to get the inside view to work is either just reverse the uvs table or append a reverse of the uvs table to itself for an outside and inside view.

  • Posts: 1,757

    @dave1707 - OK, but what exactly do you mean by reverse the table. Change the order of the textures or change the values of the vertices?

  • dave1707dave1707 Mod
    Posts: 8,464

    @Bri_G My mistake, it’s not the uvs but the indices table. Just take the indices table and read the table in reverse order and append it to the original table.

  • dave1707dave1707 Mod
    Posts: 8,464

    @bri Here’s an example. The reverse code is at the bottom. Just zoom in to get inside of the box.

    displayMode(FULLSCREEN)
    
    function setup()
        assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
        fill(255)
        scene = craft.scene()
        skyMaterial=scene.sky.material
        skyMaterial.sky=color(0, 62, 255, 255)
        skyMaterial.horizon=color(99, 255, 0, 255)
        scene.sun.rotation=quat.eulerAngles(20,45,-30)
        v=scene.camera:add(OrbitViewer, vec3(0,0,0), 20, 0, 200)
        v.rx,v.ry=20,20
        createRect()
    end
    
    function draw()
        update(DeltaTime)
        scene:draw() 
    end
    
    function update(dt)
        scene:update(dt)
    end
    
    function createRect() 
        c1=scene:entity()
        c1.position=vec3(0,0,0)
        c1.model = craft.model.cube(vec3(5,10,5))
        c1.material = craft.material(asset.builtin.Materials.Standard)
        c1.material.map = readImage(asset.builtin.Cargo_Bot.Startup_Screen)
    
        -- reverse and append indices table
        temp=c1.model.indices
        for z=#c1.model.indices,1,-1 do
            table.insert(temp,c1.model.indices[z])
        end
        c1.model.indices=temp
    end
    
  • Posts: 1,757

    @dave1707 - thanks for the post, clarified how to do this in Craft now got a model universe on my pad.

  • Posts: 1,757

    @Simeon @John - just playing with skybox again and ran into the old problem of having seams visible. I know John updated the skybox to one line but I have run a few skybox maps and encountered the seam lines again. I think in the past I got round the problem by using separate faces and increasing the size which worked but at the expense of clashes across the seams - mismatching of graphics. Did the problem get resolved? Also an issue with mirroring if I remember correctly.

  • dave1707dave1707 Mod
    edited February 23 Posts: 8,464

    @Bri_G Check the size of your skybox image. Make sure the width is an exact multiple of 4 and the height an exact multiple of 3.

    img=readImage(skybox image)
    print(img.width)
    print(img.height)
    

    If they’re not exact multiples, then the uvs calculations will be off which might cause the seams.

  • edited February 23 Posts: 1,757
    @dave1707 - ran the map that @John provided and it seemed Ok, although John said there were some issues with it at the time.
    Some of my own have shown the seams and a couple demo ones that I downloaded. I'll check dimensions of textures. Already tried adjusting texture sizes using your texture building routine to 102px faces vs 100px as mentioned above. Most of my face images are 256px squares for the builder.
  • JohnJohn Admin Mod
    Posts: 622

    @Bri_G Can I see a screenshot of the seams and the cubemaps you are using?

  • Posts: 1,757
    @John - I think I have sorted it. I am using a graphics package with large images which I scale down. Placing images is very tricky so I have had to repeat some skybox maps until the seams disappear. The graphics package sometimes quotes to a fraction of a pixel!!

    I have had errors on occasion when that the ratio is not correct and should be 4:3 - but always managed to resolve the problem.

    Thanks for the offer of help - I'll post images if I can't resolve them.
Sign In or Register to comment.