Bugga it - whilst i still got it on my mind, I built a culling debugging system
Have a go, see what you think.
/// Project: Mesh Template
// Created: 2019-01-12
// show all errors
SetErrorMode(2)
#constant screenwidth=1024
#constant screenheight=768
#constant fullscreen=0
#constant screenrate=0
#constant renderdistance=0 // how many chunks surrounding each other - call it render distance variable
#constant CHUNK_WIDTH=16
#constant CHUNK_HEIGHT=16
// set window properties
SetWindowTitle( "Mesh Template" )
SetWindowSize( screenwidth, screenheight, fullscreen )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( screenwidth, screenheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( screenrate, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
global angx#,angy#,startx#,starty#
global camerax#,cameray#,cameraz#
global size=7 // Size of the chunk in X and Z direction - make this small so the chunk can be quickly rebuilt in processing
global level as integer[20]
global vortexcollisioner as integer[20]
// meshmemblock types
Type Vertex
air as integer
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
endtype
Type Triangle
v1 as integer
v2 as integer
v3 as integer
endtype
Type Mesh
VertexList as Vertex[]
endtype
global MeshID as Mesh
type _chunkdata
faces as integer[5] // 0 -top, 1-bottom, 2-left, 3-right, 4 front, 5 back
air as integer // 0 - air, 1-block
endtype
global chunkdata as _chunkdata[CHUNK_WIDTH,CHUNK_HEIGHT,CHUNK_WIDTH]
// create player collisions units all way raround the player
for a=6 to 12
CreateObjectBox(a,10,10,10)
SetObjectVisible(a,0)
next
img = createtexturesnowy()
SetImageMagFilter(img,0)
SetImageMinFilter(img,0)
startx#=screenwidth/2
starty#=screenheight/2
SetRawMousePosition(startx#,starty#)
setupchunk()
// cull them
cull_chunk_data()
buildchunk()
tree = CreateObjectFromMeshWithUVTexturing(meshid,1,img)
SetObjectPosition(tree,0,0,0)
emptymesh()
camerax#=0
cameray#=20
cameraz#=-30
speed#=.01
SetCameraRange(1,.01,1000)
global cull=1
global tops=1
global minis=1
do
if GetRawKeyState(37) then dec camerax#,.01
if GetRawKeyState(39) then inc camerax#,.01
if GetRawKeyState(38) then dec cameraz#,.01
if GetRawKeyState(40) then inc cameraz#,.01
if GetRawKeyState(32)
RotateObjectLocalY(tree,.05)
endif
if ( GetPointerPressed() )
startx# = GetPointerX()
starty# = GetPointerY()
angx# = GetCameraAngleX(1)
angy# = GetCameraAngleY(1)
pressed = 1
endif
if GetRawKeyPressed(84)
tops=-tops
// resetup the chunk with the cull setting
DeleteObject(tree)
emptychunk() // clears the chunkdata
setupchunk()
if cull=1 then cull_chunk_data()
buildchunk()
tree = CreateObjectFromMeshWithUVTexturing(meshid,1,img)
SetObjectPosition(tree,0,0,0)
emptymesh()
endif
if GetRawKeyPressed(82)
minis=-minis
// resetup the chunk with the cull setting
DeleteObject(tree)
emptychunk() // clears the chunkdata
setupchunk()
if cull=1 then cull_chunk_data()
buildchunk()
tree = CreateObjectFromMeshWithUVTexturing(meshid,1,img)
SetObjectPosition(tree,0,0,0)
emptymesh()
endif
if GetRawKeyPressed(67)
cull=-cull
// resetup the chunk with the cull setting
DeleteObject(tree)
emptychunk() // clears the chunkdata
setupchunk()
if cull=1
cull_chunk_data()
else
standardise_chunk_data()
endif
buildchunk()
tree = CreateObjectFromMeshWithUVTexturing(meshid,1,img)
SetObjectPosition(tree,0,0,0)
emptymesh()
endif
if (minis=1)
print("Mini Cubes : On")
else
print("Mini Cubes : Off")
endif
if (cull=1)
print("Cube Culling : On")
else
print("Cube Culling : Off")
endif
if (tops=1)
print("Top and outside Faces : On")
else
print("Top and outside Faces : Off")
endif
print ("Press Space to spin")
print ("Press C to cull on or off")
print ("Press R to minis on or off")
print ("Press T to make TOP and outside faces on or off - so can see results better")
print(GetRawLastKey())
// get player input
//if ( checkCollisionv2(obj,6,9)<>1 and GetRawKeyState( 38 ) ) then MoveCameraLocalZ( 1, speed# ) // cursor up
//if ( checkCollisionv2(obj,6,10)<>1 and GetRawKeyState( 40 ) ) then MoveCameraLocalZ( 1, -speed# ) // cursor down
//if ( checkCollisionv2(obj,6,11)<>1 and GetRawKeyState( 37 ) ) then MoveCameraLocalX( 1, -speed# ) // cursor iz
//if ( checkCollisionv2(obj,6,12)<>1 and GetRawKeyState( 39 ) ) then MoveCameraLocalX( 1, speed# ) // cursor derecha
/* if checkCollisionv2(obj,6,11)<>1 and GetRawKeyState(37) then dec camerax#,speed#
if checkCollisionv2(obj,6,12)<>1 and GetRawKeyState(39) then inc camerax#,speed#
if checkCollisionv2(obj,6,10)<>1 and GetRawKeyState(40) then dec cameraz#,speed#
if checkCollisionv2(obj,6,9)<>1 and GetRawKeyState(38) then inc cameraz#,speed#
if checkCollisionv2(obj,6,8)<>1 and GetRawKeyState(87)
MoveCameraLocalY(1,speed#)
inc cameray#,speed#
jumping=1
endif
// check if hits the ground by checking the collisioner underneath camera
if jumping=0 and checkCollisionv2(obj,6,7)<>1
MoveCameraLocalY(1,-speed#)
// dec cameray#,speed#
else
jumping=0
endif
setcameradata()
*/
movecamera()
setcameradata()
Print( ScreenFPS() )
Sync()
loop
function emptychunk()
for x=-CHUNK_WIDTH/2 to CHUNK_WIDTH/2
for y=-CHUNK_HEIGHT/2 to CHUNK_HEIGHT/2
for z=-CHUNK_WIDTH/2 to CHUNK_WIDTH/2
chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].air=0
for f=0 to 5
chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].faces[f] = 0
next
next
next
next
endfunction
function buildchunk()
// build the mesh with the Faces data from the cull
for z=-CHUNK_WIDTH/2 to CHUNK_WIDTH/2
for x=-CHUNK_WIDTH/2 to CHUNK_WIDTH/2
for y=-CHUNK_HEIGHT/2 to CHUNK_HEIGHT/2
addCubeToMesh(x,y,z,1,1,1,1 ,chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].faces[0] ,chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].faces[1] ,chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].faces[2] ,chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].faces[3] ,chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].faces[4] ,chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].faces[5])
// draw a smaller cube inside where it should go - thiswill be removed later
if minis = 1 then addCubeToMesh(x,y+1,z,.3,.3,.3,chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].air ,1,1,1,1,1,1)
next
next
next
endfunction
function setupchunk()
// setup chunk - define where blocks are first
for x=-CHUNK_WIDTH/2 to CHUNK_WIDTH/2
for y=-CHUNK_HEIGHT/2 to CHUNK_HEIGHT/2
for z=-CHUNK_WIDTH/2 to CHUNK_WIDTH/2
chunkdata[x+CHUNK_WIDTH/2,y+CHUNK_HEIGHT/2,z+CHUNK_WIDTH/2].air=random(0,1)
next
next
next
endfunction
function standardise_chunk_data()
// faces as integer[5] // 0 -top, 1-bottom, 2-left, 3-right, 4 front, 5 back
for y=0 to CHUNK_HEIGHT
for z=0 to CHUNK_WIDTH
for x=0 to CHUNK_WIDTH
for f=0 to 5
chunkdata[x,y,z].faces[f]=1
next
next
next
next
endfunction
function cull_chunk_data()
// faces as integer[5] // 0 -top, 1-bottom, 2-left, 3-right, 4 front, 5 back
for y=0 to CHUNK_HEIGHT
for z=0 to CHUNK_WIDTH
for x=0 to CHUNK_WIDTH
if (chunkdata[x,y,z].air = 1) // block at this current position
if tops=1
if y=CHUNK_HEIGHT then chunkdata[x,y,z].faces[0] = 1 // put a final top on the Y edge to catch the last block
endif
if x=CHUNK_WIDTH then chunkdata[x,y,z].faces[3] = 1 // put a final edge on the X edge to catch the last block
if z=CHUNK_WIDTH then chunkdata[x,y,z].faces[5] = 1 // put a final edge on the Z edge to catch the last block
if y=0 then chunkdata[x,y,z].faces[1] = 1 // put a final top on the Y edge to catch the last block
if x=0 then chunkdata[x,y,z].faces[2] = 1 // put a final edge on the X edge to catch the last block
if z=0 then chunkdata[x,y,z].faces[4] = 1 // put a final edge on the Z edge to catch the last block
if y-1>=0
if (chunkdata[x,y - 1,z].air = 0 ) // is there a NO block at the previous Y positin
chunkdata[x,y - 1,z].faces[0] = 0 // topface = 0
if tops=1 then chunkdata[x,y ,z].faces[1] = 1 // bottomface = 1 // change this to have a bottom face
endif
if (chunkdata[x,y - 1,z].air = 1 ) // there is a block at the previous but also at this location, so
chunkdata[x,y - 1,z].faces[0] = 0 // topface = 0 (otherwise will have visible faces inside two connected cubes
chunkdata[x,y ,z].faces[1]= 0 // bottom = 0 (otherwise will have visible faces inside two connected cubes
endif
endif
if z-1>=0
if (chunkdata[x,y,z - 1].air = 0) // is the NO block on the previous Z
chunkdata[x,y,z - 1].faces[5] = 0 // frontface = 0 then change that blocks front face to invisible
chunkdata[x,y,z ].faces[4] = 1 // backface = 1 change this blocks backface to visible
endif
if (chunkdata[x,y,z - 1].air = 1) // if there is a block at previous Z
chunkdata[x,y,z - 1].faces[5] = 0 // frontface = 0 // change that blocks front face to also invisible (otherwise will have visible faces inside two connected cubes
chunkdata[x,y,z ].faces[4] = 0 // backface = 0 // change this block back face to also invisible (otherwise will have visible faces inside two connected cubes
endif
endif
if x-1>=0
if (chunkdata[x - 1 ,y,z].air = 0) // there is NO block at the previous X position
chunkdata[x - 1 ,y,z].faces[3] = 0 //rightface = 0 // remove the right face of the previous block
chunkdata[x ,y,z].faces[2] = 1 // leftface = 1 // add a left face to the current position cube
endif
if ( chunkdata[x - 1,y,z].air =1 ) // is there a block there - if so then remove the inner faces
chunkdata[x - 1,y,z].faces[3] = 0 // rightface = 0 (otherwise will have visible faces inside two connected cubes
chunkdata[x, y,z].faces[2] = 0 // leftface = 0 (otherwise will have visible faces inside two connected cubes
endif
endif
endif
if (chunkdata[x,y,z].air = 0) // empty space at this current position
if y-1>=0
if (chunkdata[x,y - 1 ,z].air = 0 ) // is there a NO block at the previous Y positin
chunkdata[x,y - 1 ,z].faces[0] = 0 // topface = 0 (otherwise will have visible faces outside two connected cubes
chunkdata[x,y ,z].faces[1]=0 // bottomface = 0 (otherwise will have visible faces outside two connected cubes
endif
if (chunkdata[x,y - 1 ,z].air = 1 ) // there is a block at the previous but also at this location, so
if tops=1 then chunkdata[x,y - 1 ,z].faces[0] = 1 // topface = 1
chunkdata[x,y ,z].faces[1] = 0 // bottom = 0
endif
endif
if z-1>=0
if (chunkdata[x,y,z - 1].air = 0) // is there no block previus Z
chunkdata[x,y,z - 1].faces[5] = 0 // frontface = 0 // change its front to no face (otherwise will have visible faces outside two connected cubes
chunkdata[x,y,z ].faces[4] = 0 // backface = 0 // change current backface to no face.(otherwise will have visible faces outside two connected cubes
endif
if (chunkdata[x,y,z - 1].air = 1) // is there a block prebious Z
chunkdata[x,y,z - 1].faces[5] = 1 // frontface 1 // change its front have have a face
chunkdata[x,y,z ].faces[4] = 0 // backface 0 // change this block backface to not have a face
endif
endif
if x-1>=0
if ( chunkdata[x - 1,y,z].air = 0 ) // there is no block at the previous X positin either
chunkdata[x - 1,y,z].faces[3]=0 // rightface = 0;(otherwise will have visible faces outside two connected cubes
chunkdata[x ,y,z].faces[2]=0 //x leftface = 0;(otherwise will have visible faces outside two connected cubes
endif
if (chunkdata[x - 1,y,z].air = 1 ) // there is a block at the previous position, so enable its rightface
chunkdata[x - 1,y,z].faces[3]=1 // rightface = 1;
chunkdata[x ,y,z].faces[2] = 0 // leftface = 0;
endif
endif
endif
next
next
next
endfunction
function setcameradata()
SetCameraPosition(1,camerax#,cameray#,cameraz#)
camerax#=getcamerax(1)
cameray#=getcameray(1)
cameraz#=getcameraz(1)
//collision object centre
SetObjectPosition(6,camerax#,cameray#,cameraz#)
//collision object bottom
SetObjectPosition(7,camerax#,cameray#-.5,cameraz#)
//collision object above
SetObjectPosition(8,camerax#,cameray#+.5,cameraz#)
//collision object front
SetObjectPosition(9,camerax#,cameray#,cameraz#+.5)
//collision object behin
SetObjectPosition(10,camerax#,cameray#,cameraz#-.5)
//collision object left
SetObjectPosition(11,camerax#-.5,cameray#,cameraz#)
//collision object right
SetObjectPosition(12,camerax#+.5,cameray#,cameraz#)
endfunction
function movecamera()
if GetPointerState()=1
fDiffX# = (GetPointerX() - startx#)/4.0
fDiffY# = (GetPointerY() - starty#)/4.0
newX# = angx# + fDiffY#
if ( newX# > 89 ) then newX# = 89
if ( newX# < -89 ) then newX# = -89
SetCameraRotation(1, newX#, angy# + fDiffX#, 0 )
endif
endfunction
function addCubeToMesh(x#,y#,z#,sizex#,sizey#,sizez#,c,top,bottom,lft,rght,front,back)
// do adjacent culling check
cx = floor(x#)
cy = floor(y#)
cz = floor(z#)
if top=1
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0, 0 ,0 , c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2) ,z#+(sizez#/2)-sizez# , 0,1,0, 0 ,.5 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0, .5 ,0 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0, .5 ,0 , c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2) ,z#+(sizez#/2)-sizez# , 0,1,0, 0 ,.5 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2)-sizez# , 0,1,0, .5 ,.5 , c)
endif
if bottom=1
// BOTTOM face - top right corner texture
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2) , 0,1,0, 0.5,0 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2) , 0,1,0, 1,0 , c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0, 0.5,0.5 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2) , 0,1,0, 1,0 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0, 1,0.5 , c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0, 0.5,0.5 , c)
endif
if back=1
// front Side - bottom left corner texture
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0, 0,0.5, c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0, 0.5,0.5, c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2) , 0,1,0, 0,1, c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0, 0.5,0.5, c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2) , 0,1,0, 0.5,1, c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2) , 0,1,0, 0,1, c)
endif
if front=1
// Right Side - bottom left corner texture
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2) ,z#+(sizez#/2)-sizez# , 0,1,0, 0,0.5, c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0, 0,1, c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2)-sizez# , 0,1,0, 0.5,0.5, c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2)-sizez# , 0,1,0, 0.5,0.5, c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0, 0,1, c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0, 0.5,1, c)
endif
if lft=1
// Front Side - bottom left corner texture
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0 , 0 , 0.5, c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2) , 0,1,0 , 0 , 1 , c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0 , .5 , 1 , c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0 , .5 , 1, c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2) ,z#+(sizez#/2)-sizez# , 0,1,0 , .5 , .5 , c)
AddVertex(meshid, x#-(sizex#/2) ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0 , 0 , .5 , c)
endif
if rght=1
// Back Side - bottom left corner texture
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0 , 0 , 0.5, c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0 , .5 , 1 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2) , 0,1,0 , 0 , 1 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2)-sizey# ,z#+(sizez#/2)-sizez# , 0,1,0 , .5 , 1, c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2) , 0,1,0 , 0 , .5 , c)
AddVertex(meshid, x#-(sizex#/2)+sizex# ,y#+(sizey#/2) ,z#+(sizez#/2)-sizez# , 0,1,0 , .5 , .5 , c)
endif
endfunction
function emptymesh()
meshid.VertexList.length=-1
endfunction
Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, air as integer)
vert as vertex
vert.x = x
vert.y = y
vert.z = z
vert.nx = nx
vert.ny = ny
vert.nz = nz
vert.u = u
vert.v = v
vert.air = air
m.VertexList.Insert(vert)
endfunction
Function CreateObjectFromMeshWithUVTexturing(m ref as mesh, MeshIndex,texture)
objID=1
DeleteMemblock(chunkmesh)
VertexCount = m.VertexList.Length + 1
IndexCount = 0
IndexOffset = 60 + VertexCount*36
chunkmesh = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(chunkmesh,0,VertexCount)
SetMemblockInt(chunkmesh,4,IndexCount)
SetMemblockInt(chunkmesh,8,3)
SetMemblockInt(chunkmesh,12,32) // no color - 36 if color
SetmemblockInt(chunkmesh,16,60)
SetMemblockInt(chunkmesh,20,IndexOffset)
SetMemblockInt(chunkmesh,24,0x0c000300)
SetMemblockString(chunkmesh,28,"position")
SetMemblockInt(chunkmesh,40,0x08000300)
SetMemblockString(chunkmesh,44,"normal")
SetMemblockInt(chunkmesh,52,0x04000200)
SetMemblockString(chunkmesh,56,"uv")
//SetMemblockInt(memblock,60,0x08010401) // maybe one day or year in 2019 lol
//SetMemblockString(memblock,64,"color") // maybe one day or year in 2019 lol
for i = 0 to m.VertexList.Length
if m.VertexList[i].air = 1 // has a block there
SetMemblockFloat(chunkmesh,60+i*32,m.VertexList[i].x)
SetMemblockFloat(chunkmesh,64+i*32,m.VertexList[i].y)
SetMemblockFloat(chunkmesh,68+i*32,m.VertexList[i].z)
SetMemblockFloat(chunkmesh,72+i*32,m.VertexList[i].nx)
SetMemblockFloat(chunkmesh,76+i*32,m.VertexList[i].ny)
SetMemblockFloat(chunkmesh,80+i*32,m.VertexList[i].nz)
SetMemblockFloat(chunkmesh,84+i*32,m.VertexList[i].u)
SetMemblockFloat(chunkmesh,88+i*32,m.VertexList[i].v)
endif
//SetMemblockInt(memblock,104+i*36,m.VertexList[i].color) //maybe one day or year in 2019 lol
next
// DeleteAllObjects()
objID = CreateObjectFromMeshMemblock(chunkmesh)
SetObjectImage(objID,texture,0)
SetObjectColor(objID,255,255,255,10)
endfunction objID
function checkCollisionv2(objwith,objID as integer,objID2 as integer)
start_x#=getobjectx(objID)
start_y#=getobjecty(objID)
start_z#=getobjectz(objID)
end_x#=getobjectx(objID2)
end_y#=getobjecty(objID2)
end_z#=getobjectz(objID2)
// determine which object has been hit
object_Hit = ObjectRayCast(objwith,start_x#,start_y#,start_z#,end_x#,end_y#,end_z#)
endfunction object_Hit
function createtexturesnowy()
countx=2
stp = 1
//top - snowy
for x=0 to 16 step stp
for y=0 to 16 step stp
// if random(1,0)=1
c=MakeColor(random(240,255),random(240,255),random(240,255)) // green
//else
// c=MakeColor(random(200,255),random(200,255),random(200,255)) // white
//endif
DrawBox(x,y,x+4,y+4,c,c,c,c,1)
next
next
//bottom - dirt
for x=16 to 32 step stp
for y=0 to 16 step stp
c=MakeColor(random(100,140),random(30,130),0)
DrawBox(x,y,x+4,y+4,c,c,c,c,1)
next
next
// 3 sides - a bit of green at top and orange at bottom
for x=0 to 16 step stp
for y=16 to 32 step stp
if y<20
if random(0,10)>1
c=MakeColor(random(240,255),random(240,255),random(240,255)) // green
else
c=MakeColor(random(100,140),random(30,130),0)
endif
else
c=MakeColor(random(100,140),random(30,130),0)
endif
DrawBox(x,y,x+4,y+4,c,c,c,c,1)
next
next
img = GetImage(0,0,32,32)
SaveImage(img,"test.png")
endfunction img
function createtexturegreeny()
countx=2
stp = 1
//top - snowy
for x=0 to 16 step stp
for y=0 to 16 step stp
c=MakeColor(0,random(40,155),0) // green
DrawBox(x,y,x+4,y+4,c,c,c,c,1)
next
next
//bottom - dirt
for x=16 to 32 step stp
for y=0 to 16 step stp
c=MakeColor(0,random(40,155),0) // green
DrawBox(x,y,x+4,y+4,c,c,c,c,1)
next
next
// 3 sides - a bit of green at top and orange at bottom
for x=0 to 16 step stp
for y=16 to 32 step stp
c=MakeColor(0,random(40,155),0) // green
DrawBox(x,y,x+4,y+4,c,c,c,c,1)
next
next
img = GetImage(0,0,32,32)
SaveImage(img,"test.png")
endfunction img
function createtreestructure(x#,y#,z#)
// 111
// 111
// 1111111
// 1 1 111
// 11111111
// 1 1 111
// 1111111
// 111
// 111
//
height=8
/*
addCubeToMesh(x#+0,y#+8,z#,1,1,1,1)
addCubeToMesh(x#-1,y#+7,z#,1,1,1,1)
addCubeToMesh(x#+1,y#+7,z#,1,1,1,1)
addCubeToMesh(x#,y#+7,z#-1,1,1,1,1)
addCubeToMesh(x#,y#+7,z#+1,1,1,1,1)
addCubeToMesh(x#-1,y#+6,z#+1,1,1,1,1)
addCubeToMesh(x#-1,y#+6,z#,1,1,1,1)
addCubeToMesh(x#-1,y#+6,z#-1,1,1,1,1)
addCubeToMesh(x#,y#+6,z#-1,1,1,1,1)
addCubeToMesh(x#,y#+6,z#,1,1,1,1)
addCubeToMesh(x#,y#+6,z#+1,1,1,1,1)
addCubeToMesh(x#+1,y#+6,z#-1,1,1,1,1)
addCubeToMesh(x#+1,y#+6,z#,1,1,1,1)
addCubeToMesh(x#+1,y#+6,z#+1,1,1,1,1)
addCubeToMesh(x#-1,y#+5,z#+1,1,1,1,1)
addCubeToMesh(x#-1,y#+5,z#,1,1,1,1)
addCubeToMesh(x#-1,y#+5,z#-1,1,1,1,1)
addCubeToMesh(x#,y#+5,z#-1,1,1,1,1)
addCubeToMesh(x#,y#+5,z#,1,1,1,1)
addCubeToMesh(x#,y#+5,z#+1,1,1,1,1)
addCubeToMesh(x#+1,y#+5,z#-1,1,1,1,1)
addCubeToMesh(x#+1,y#+5,z#,1,1,1,1)
addCubeToMesh(x#+1,y#+5,z#+1,1,1,1,1)
addCubeToMesh(x#-2,y#+5,z#,1,1,1,1)
addCubeToMesh(x#+2,y#+5,z#,1,1,1,1)
addCubeToMesh(x#,y#+5,z#-2,1,1,1,1)
addCubeToMesh(x#,y#+5,z#,1,1,1,1)
addCubeToMesh(x#-1,y#+4,z#+1,1,1,1,1)
addCubeToMesh(x#-1,y#+4,z#,1,1,1,1)
addCubeToMesh(x#-1,y#+4,z#-1,1,1,1,1)
addCubeToMesh(x#,y#+4,z#-1,1,1,1,1)
addCubeToMesh(x#,y#+4,z#,1,1,1,1)
addCubeToMesh(x#,y#+4,z#+1,1,1,1,1)
addCubeToMesh(x#+1,y#+4,z#-1,1,1,1,1)
addCubeToMesh(x#+1,y#+4,z#,1,1,1,1)
addCubeToMesh(x#+1,y#+4,z#+1,1,1,1,1)
addCubeToMesh(x#-2,y#+4,z#,1,1,1,1)
addCubeToMesh(x#+2,y#+4,z#,1,1,1,1)
addCubeToMesh(x#,y#+4,z#-2,1,1,1,1)
addCubeToMesh(x#,y#+4,z#+2,1,1,1,1)
addCubeToMesh(x#-2,y#+4,z#-1,1,1,1,1)
addCubeToMesh(x#+2,y#+4,z#-1,1,1,1,1)
addCubeToMesh(x#-2,y#+4,z#+1,1,1,1,1)
addCubeToMesh(x#+2,y#+4,z#+1,1,1,1,1)
addCubeToMesh(x#-1,y#+4,z#-2,1,1,1,1)
addCubeToMesh(x#+1,y#+4,z#-2,1,1,1,1)
addCubeToMesh(x#-1,y#+4,z#+2,1,1,1,1)
addCubeToMesh(x#+1,y#+4,z#+2,1,1,1,1)
addCubeToMesh(x#-1,y#+3,z#-1,1,1,1,1)
addCubeToMesh(x#-1,y#+3,z#,1,1,1,1)
addCubeToMesh(x#-1,y#+3,z#+1,1,1,1,1)
addCubeToMesh(x#+1,y#+3,z#-1,1,1,1,1)
addCubeToMesh(x#+1,y#+3,z#,1,1,1,1)
addCubeToMesh(x#+1,y#+3,z#+1,1,1,1,1)
addCubeToMesh(x#,y#+3,z#-1,1,1,1,1)
addCubeToMesh(x#,y#+3,z#+1,1,1,1,1)
addCubeToMesh(x#,y#+2,z#,1,1,1,1)
addCubeToMesh(x#,y#+1,z#,1,1,1,1)
addCubeToMesh(x#,y#+0,z#,1,1,1,1)
*/
endfunction
/*
for (y = 0; y < 7; y++ )
for (z = 0; z < 7; z++ )
for (x = 0; x < 7; x++)
if (x = block) // block at this current position
if (y - 1 == air ) // is there a NO block at the previous Y positin
y - 1 topface = 0
y bottomface = 1 // change this to have a bottom face
endif
if (y - 1 == block ) // there is a block at the previous but also at this location, so
y - 1 topface = 0 (otherwise will have visible faces inside two connected cubes
y bottom = 0 (otherwise will have visible faces inside two connected cubes
endif
endif
if (z - 1 == air) // is the NO block on the previous Z
z - 1 frontface = 0 then change that blocks front face to invisible
z backface = 1 change this blocks backface to visible
endif
if (z - 1 = block) // if there is a block at previous Z
z - 1 frontface = 0 // change that blocks front face to also invisible (otherwise will have visible faces inside two connected cubes
z backface = 0 // change this block back face to also invisible (otherwise will have visible faces inside two connected cubes
endif
if (x - 1 == air) // there is NO block at the previous X position
x - 1 rightface = 0 // remove the right face of the previous block
x leftface = 1 // add a left face to the current position cube
endif
if ( x - 1 == block ) // is there a block there - if so then remove the inner faces
x - 1 rightface = 0 (otherwise will have visible faces inside two connected cubes
x leftface = 0 (otherwise will have visible faces inside two connected cubes
endif
endif
if (x == air) // empty space at this current position
if (y - 1 == air ) // is there a NO block at the previous Y positin
y - 1 topface = 0 (otherwise will have visible faces outside two connected cubes
y bottomface = 0 (otherwise will have visible faces outside two connected cubes
endif
if (y - 1 == block ) // there is a block at the previous but also at this location, so
y - 1 topface = 1
y bottom = 0
endif
if (z - 1) == air // is there no block previus Z
z - 1 frontface = 0 // change its front to no face (otherwise will have visible faces outside two connected cubes
z backface = 0 // change current backface to no face.(otherwise will have visible faces outside two connected cubes
endif
if (z - 1) == block // is there a block prebious Z
z - 1 frontface 1 // change its front have have a face
z backface 0 // change this block backface to not have a face
endif
if ( x - 1 == air ) // there is no block at the previous X positin either
x - 1 rightface = 0;(otherwise will have visible faces outside two connected cubes
x leftface = 0;(otherwise will have visible faces outside two connected cubes
endif
if (x - 1 == block ) // there is a block at the previous position, so enable its rightface
x - 1 rightface = 1;
x leftface = 0;
endif
endif
next
next
next
*/
print ("Press Space to spin")
print ("Press C to cull on or off")
print ("Press R to minis on or off")
print ("Press T to make TOP and outside faces on or off - so can see results better")
Be good for debugging purposes, I think the Pseudo I did worked a treat, but will only know this with a few others seeing if its correct
Catch up soon - Lemmings now..