Is a Craft texture pack possible?

@UberGoober I modified the above code again.

@dave1707 I think this got lost in the posts but I am genuinely interested: how did you figure out how to delete blocks?

I feel like there are all these Craft features buried somewhere that I can’t learn about directly from the documentation.

@UberGoober I looked thru the Craft examples and reference for anything that looked like it might work. That’s about all you can do.

@dave1707 @Simeon - Codea 3.3.2 (276) doesn’t crash - that’s with the latter demos.

Update - when run the earlier @dave1707 demo with manual editing the value of ss - with 9 it was OK, 27 OK then 21 crash.

Subsequently crashed as before, even with other demos above. Can someone try to duplicate this, starting to worry about my machine.

@Bri_G The only ss values that will work with that code is 3, 9, 27, and 81. Going one more increment to 243 doesn’t display the cube, but just one layer, or else it crashes.

@dave1707 - thanks for the feedback, you confirmed that it crashes. After the first crash I found running the other demos started to crash. Almost like some part of Craft had been damaged with the out of bounds entry for ss.

@Bri_G It only crashes sometimes when ss = 243. The other 4 values run OK. Here’s a smaller version.


function setup()
    ss=3
    assert(OrbitViewer, "Please include Cameras as a dependency")
    scene = craft.scene() 
    v=scene.camera:add(OrbitViewer,vec3(50,50,50), 6*ss, 0, 1000)
    v.rx=30
    v.ry=30
    entity = scene:entity()
    volume = entity:add(craft.volume, 300, 300, 300)
    cube(0,0,0,ss)  
end

function update(dt)
    scene:update(dt)
end

function draw()
    update(DeltaTime)
    scene:draw()  
end

function cube(x,y,z,size)
    local s=size//3
    for x1=-s,s,s do
        for y1=-s,s,s do
            for z1=-s,s,s do
                if (y1~=0 or z1~=0) and (x1~=0 or z1~=0) and (x1~=0 or y1~=0) then
                    if size~=3 then
                        cube(x1+x,y1+y,z1+z,s)
                    else
                        volume:set((x1+x+50), (y1+y+50), (z1+z+50), 'name', 'solid', 'color', color(255,255,0))
                    end
                end
            end            
        end
    end
end   

@dave1707 - hmmm, sounds like there is a problem in Craft. In some. of the other values entered for ss Codea fired out a series of errors. Very inconsistent.

@Bri_G I think for ss=243, I might be exceeding the limits that are set for Craft, so I don’t see that as a problem, just a limit. The other values, 3,9,27,81 should run fine. Any other value for ss will cause problems because the code in the function cube() is only for powers of 3. Anything else and it will get messed up.

PS. At ss=243, I’m trying to plot 3.2 million cubes on the screen.

@dave1707 “plotting” doesn’t mean rendering thought right?

I thought one of the tricks of the voxel engine is that it doesn’t render non-visible edges, so the ones that can’t be seen are really just coordinates in a table, or do I have that wrong?

@UberGoober I don’t know if they’re being rendered or not. I just know at ss=243, I’m calling volume:set 3.2 million times. Sometimes I get a partial cube, other times it crashes.

Here’s something that might explain what’s happening at ss=243. Looks like there’s some kind of limit. Run the below code. It should create a cube with 205x205x205 blocks. I show black lines every 10 blocks. Change ss to 206 and run it again. It takes about 7 seconds on my iPad to run.

viewer.mode=FULLSCREEN

function setup()
    ss=205          -- 205 is OK  206 isnt
    assert(OrbitViewer, "Please include Cameras as a dependency")
    scene = craft.scene() 
    v=scene.camera:add(OrbitViewer,vec3(50,50,50), 300, 0, 6000)
    v.camera.farplane=10000
    v.rx=30
    v.ry=30
    entity = scene:entity()
    volume = entity:add(craft.volume, 400, 400, 400)
    cube(0,0,0,ss)  
end

function update(dt)
    scene:update(dt)
end

function draw()
    update(DeltaTime)
    scene:draw()  
end

function cube(x,y,z,size)
    local s=size
    for x1=1,s do
        for y1=1,s do
            for z1=1,s do
                if x1%10==0 or y1%10==0 or z1%10==0 then
                    colr=color(0)
                else
                    colr=color(math.random(255),math.random(255),math.random(255))
                end
                volume:set((x1+50), (y1+50), (z1+50), 'name', 'solid', 'color', colr)
            end
        end
    end            
end   

@UberGoober Heres one for you, slow motion.

viewer.mode=FULLSCREEN

function setup()
    tab={}
    ss=27
    assert(OrbitViewer, "Please include Cameras as a dependency")
    scene = craft.scene() 
    v=scene.camera:add(OrbitViewer,vec3(50,50,50), 6*ss, 0, 1000)
    v.rx=45
    v.ry=270
    entity = scene:entity()
    volume = entity:add(craft.volume, 300, 300, 300)
    cube(0,0,0,ss) 
    count=0
end

function update(dt)
    scene:update(dt)
end

function draw()
    update(DeltaTime)
    scene:draw() 
    show()
    collectgarbage()
end

function show()
    if count>=#tab then return end
    count=count+1
    volume:set(tab[count].x,tab[count].y,tab[count].z, 'name', 'solid', 'color', color(0,255,0))
end

function cube(x,y,z,size)
    local s=size//3
    for x1=-s,s,s do
        for y1=-s,s,s do
            for z1=-s,s,s do
                if (y1~=0 or z1~=0) and (x1~=0 or z1~=0) and (x1~=0 or y1~=0) then
                    if size~=3 then
                        cube(x1+x,y1+y,z1+z,s)
                    else
                        table.insert(tab,vec3(x1+x+50,y1+y+50,z1+z+50))
                    end
                end
            end            
        end
    end
end   

For anyone interested here’s a project that’s a compilation of the different versions of the code @dave1707 posted, with maybe a few color tweaks here and there.