Is a Craft texture pack possible?

@dave1707 I know, I just couldn’t get it right. The voxels always got clipped off of one side of the designated block or something. I know the math must be pretty simple but I just couldn’t do it. I didn’t move the camera at all actually.

@UberGoober You can only draw voxels that are positive. If a block has negative values it gets clipped. That’s why I’m adding the ss value to keep all the values positive.

@dave1707 that’s good to know, and still, having spent so much time trying every combination I could think of to get things in the right place, I kinda give up. I tried adjusting these variables and those variables and the other variables and every time I ran it I got results that made no sense to me. I could never predict what it would do or where things would be drawn.

I’m sure it’s really simple, I guess its just too simple for me. Or vice versa, more like.

I’m okay with mine being broken. Your example is good and stands on its own.

@UberGoober Try this.

viewer.mode=FULLSCREEN

function setup()
    --  3, 9, 27, 81
    ss=3     
    assert(OrbitViewer, "Please include Cameras as a dependency")
    scene1 = craft.scene() 
    v=scene1.camera:add(OrbitViewer,vec3(50,50,50), ss*3, 0, 1000)
    
    scene1.voxels.blocks:addAssetPack("Blocks")
    tab = scene1.voxels.blocks:new("Table")
    tab.setTexture(ALL, "Blocks:Table")
    
    scene1.voxels:fill("Table")    
    scene1.voxels.visibleRadius=200
    scene1.voxels:resize(vec3(60,1,60))          
    scene1.voxels.coordinates = vec3(50,50,50) 
        
    cube(0,0,0,ss)
end

function update(dt)
    scene1:update(dt)
end

function draw()
    update(DeltaTime)
    scene1: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
                        scene1.voxels:block((x1+x+50),(y1+y+50),(z1+z+50))
                    end
                end
            end            
        end
    end
end   

@dave1707 - sorry, I used multiples of 3 not powers, makes sense now it’s power as it needs to be to ensure each dimension of the cube is correct.

But, that still doesn’t explain why the code crashes Codea.

@UberGoober - ran your code seemed OK until I tried to make a project icon and Codea crashed.

@John @Simeon - seems like there is an issue here probably an untraced error in Craft.

@dave1707 thanks! That really helped.

Can you help me delete blocks? The documentation is really frustrating and unhelpful, to me at least.

This is what I was trying, from the documentation alone I had absolutely no idea what to do, but I found something like this in the cave-generating code:


function clearBlocks()
    scene.voxels:iterateBounds(vec3(0,0,0), vec3(ss, ss, ss), function(i,j,k,id)
        scene.voxels:set(vec3(i,j,k), "id", 0)
    end)
end

…doesn’t work though.

@UberGoober Here’s an update, not perfect. Not too sure how to remove blocks. Things I tried didn’t work all the time and I’m not very familiar with the Voxel stuff.

Updated version below

@dave1707 that’s super fun, and I like how you’re placing the camera. The one thing I miss is how, at the biggest size, you used to be able to see it build itself piece by piece. That was cool.

@dave1707 it seems like for some reason your latest one skips past the final iteration.

I see it for a second and then it goes back to the single block, not sure why.

Also it looks like this is how you are clearing blocks:

volume:set((x1+x+50), (y1+y+50), (z1+z+50), 'name', 'empty')

How did you figure that out?

@dave1707 sorry to spam the thread: the other thing I miss is the depth, with all the colors it’s hard to see where the holes are in the structure. Is there a way to deepen the shadows? I tried creating a light entity and boosting the intensity really high but it didn’t seem to do anything

Edit

This seems to do something like it:


    scene.sun.rotation = quat.eulerAngles(45,0,45)   
    scene.ambientColor = color(0)   
    skyMaterial = scene.sky.material
    skyMaterial.horizon = color(46, 70, 76)    
    cameraComponent = scene.camera:get(craft.camera)
    cameraComponent.hdr = true
    cameraComponent.colorTextureEnabled = true
    sunLight = scene.sun:get(craft.light)
    sunLight.intenstity =  100

@dave1707 I like your update, the colors are cool.

Here’s the adjustment I made to your previous update, it’s very similar to what you did. I can’t decide if I like it better with or without colors.


viewer.mode=FULLSCREEN

function setup()
    --  3, 9, 27, 81
    ss=3     
    assert(OrbitViewer, "Please include Cameras as a dependency")
    scene1 = craft.scene() 
    v=scene1.camera:add(OrbitViewer,vec3(50,50,50), ss*3, 0, 1000)
    
    scene1.voxels.blocks:addAssetPack("Blocks")
    tab = scene1.voxels.blocks:new("Table")
    tab.setTexture(ALL, "Blocks:Table")
    
    scene1.voxels:fill("Table")    
    scene1.voxels.visibleRadius=200
    scene1.voxels:resize(vec3(60,1,60))          
    scene1.voxels.coordinates = vec3(50,50,50) 
    
    cube(0,0,0,ss)
    
    parameter.action("cycleSideSize", function()
        ss = ss * 3
        if ss > 81 then ss = 3 end
        cube(0,0,0,ss)
    end)
end

function update(dt)
    scene1:update(dt)
end

function draw()
    update(DeltaTime)
    scene1: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
                        scene1.voxels:block((x1+x+50),(y1+y+50),(z1+z+50))
                    end
                end
            end            
        end
    end
    v.zoom = size * 2
end   

@John, @Simeon: if neither dave1707 nor I can easily figure out how to delete voxels maybe that means it needs clearer documentation?

@dave1707 - your lates demo crashes if the parameter variable size gets above 3. @Simeon - had a crash with this, didn’t send report but will reproduce and forward report.

@dave1707 , @Bri_G it must be a device thing, because it didn’t crash for me.

@dave1707 @UberGoober @Simeon - it seems to be getting progressively worse. Now crashing when I load the project.

What’s the safe way of re-installing without losing projects? Installing an older version?

Reverted to 279 but still crashing.

@Bri_G You can load older versions of the beta code by going into TestFlight and selecting Previous builds for Codea. It does nothing to the projects when loading other versions.

@dave1707 - just as I suspected, thanks. I don’t find the need often so just checking. Already switched to 279 and have the same problem with crashing on changing the size.

@Bri_G What device are you using and memory size

@dave1707 - iPad pro 11" 256 meg.

@Bri_G The above code ran OK on my 12.9” iPad Pro 1 with 128gb.

Here’s an updated version.

viewer.mode=STANDARD

function setup()
    tab1={3,9,27,81}
    parameter.action("next",nxt)    
    colr={color(255,0,0),color(0,255,0),
            color(0,255,255),color(255,255,0)}
    assert(OrbitViewer, "Please include Cameras as a dependency")
    scene = craft.scene() 
    v=scene.camera:add(OrbitViewer,vec3(50,50,50), 8, 0, 1000)
    v.rx=30
    v.ry=30
    count=-1
    entity = scene:entity()
    volume = entity:add(craft.volume, 300, 300, 300)
    ss=3
    val=1
    cube(0,0,0,3)  
end

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

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

function nxt()   
    clr=true
    cube(0,0,0,ss)
    val=val+1
    if val>4 then
        val=1
        v.zoom=3
    end
    ss=tab1[val]
    clr=false
    cube(0,0,0,ss)
    v.zoom=v.zoom*2.8
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
                        if clr then
                            volume:set((x1+x+50), (y1+y+50), (z1+z+50), 'name', 'empty')
                        else
                            volume:set((x1+x+50), (y1+y+50), (z1+z+50), 'name', 'solid', 'color', colr[val])
                        end
                    end
                end
            end            
        end
    end
end