@UberGoober Here a modification of my original code showing the volume raycast. I draw a Craft volume wall and do the raycast towards it. Looking at the print window you’ll see it returns true and stops when it reaches the volume wall. So the volume raycast is working. I made the floor “ error “ so you can count the blocks. The blocks start at 0 which puts the volume wall at 20 where it returned true.
viewer.mode=STANDARD
function setup()
assert(OrbitViewer, "Please include Cameras as a dependency")
scene=craft.scene()
craft.scene.main=scene
v=scene.camera:add(OrbitViewer,vec3(20,0,0),100,0,200)
v.rx=10
scene.voxels.blocks:addAssetPack("Blocks")
error=scene.voxels.blocks:new("Error")
error.setTexture(ALL,"Blocks:Error")
scene.voxels:resize(vec3(16,1,16))
scene.voxels.coordinates=vec3(20,0,20)
-- draw a red error floor 40x40
scene.voxels:fill(BLOCK_NAME,"Error",COLOR,color(255,0,0))
scene.voxels:box(0,0,0,40,0,40)
-- draw a white wall 40x40
scene.voxels:fill(BLOCK_NAME,"Solid",COLOR,color(255))
scene.voxels:box(0,0,40,40,40,40)
-- draw a volume wall
volume = scene:entity():add(craft.volume,25,40,30)
for x=10,25 do
for y=0,40 do
for z=20,20 do
volume:set(x,y,z,COLOR,color(0,222,255),BLOCK_NAME,"Solid")
end
end
end
-- do a raycast
origin=vec3(20,20,0)
rt,rf=0,0 -- return true, return false
doRaycast(origin,vec3(0,0,40),60)
-- draw the origin box
scene.voxels:fill(BLOCK_NAME,"Solid",COLOR,color(0, 255, 22))
scene.voxels:block(origin)
end
function draw()
scene:draw()
end
function doRaycast(origin,dir,dist)
volume:raycast(origin,dir,dist,
function(coord, id, face)
if coord and id ~= 0 then
rt=rt+1 -- return true
print("rt ",rt,coord)
return true
end
rf=rf+1 -- return false
print("rf ",rf,coord)
end)
end