// Project: Mesh Objects // Created: 2018-08-04 // show all errors SetErrorMode(2) #constant PI# = 3.14159265359 #constant screenwidth=1024 #constant screenheight=768 #constant fullscreen=0 // set window properties SetWindowTitle( "Mesh Objects" ) 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( 1200, 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 ang#, angx#, angy#, fDiffY#, fDiffX#,newX#,startx#, starty#, camerax#, cameray#, cameraz# // ************************************************* // ** Perlin Setup - please dont upset these variables // ************************************************* #constant perlinw = 1024 //power of 2 #constant perlinh = 1024 //power of 2 #constant perlinz = 0 // doesnt work yet - required 3D perlin noise - Yikes #constant perlinheight=120.0 type _perlinmap r,g, b, a, x, y level texture noise endtype // ************************************************* // ** Mesh Memblock Types - please dont upset these variables // ************************************************* global Cubed, VertexCount, MaxObjects, object, memblock global peices as integer[] global perlinmap as _perlinmap[perlinw,perlinh,perlinz] global perlinx, perlinzz,mapsprite Type Vertex x as float y as float z as float nx as float ny as float nz as float u as float v as float color as integer endtype Type Triangle v1 as integer v2 as integer v3 as integer endtype Type Mesh VertexList as Vertex[] TriangleList as Triangle[] endtype global MeshID as Mesh type _vector x# y# z# polygon // 1 = yes - 0 = no vindex nindex tindex u# v# endtype type _object v as integer[] // the actual vertex on the mesh which need to save so can use SetMeshMemblockVertexPosition commands for example at a later time vertex as _vector[] // eg v 1.276477 0.200934 -0.387665 normals as _vector[] // eg vn vn -0.5346 0.3304 -0.7779 faces as _vector[] // eg f 5//9 21//9 29//9 textures as _vector[] // eg vt 0.500 1 [0] polygon as integer // 1=Yes , 0 = No endtype global objectmesh as _object[10] // upto 10 objects per app type _meshmemblockvertexes id vfrom vto endtype global meshmemblockvertexes as _meshmemblockvertexes[] // this will store the true vertex positions on a meshmemblock type _farworlds objID x# y# z# endtype global farworlds as _farworlds[] // ************************************************* // ** END OF - Mesh Memblock Types - please dont upset these variables // ************************************************* // setup perlin data and map //initialiseperlin() global objects as integer[] global size=16 global wsize=0 coned=LoadImage("\media\cone.png") loadobjects() global objs as integer[4] /* size=4000 maxobjects=0 for meshes = 0 to 4 for a=1 to size/2 y=random(5,20) if random(1,100)>0 then InstanceMeshObject(meshes,maxobjects,random2(-size,size),y,random2(-size,size),random(1,5),y,random(1,5),MakeColor(0,0,0)) inc maxobjects next if meshes=0 then objs[meshes]=CreateObjectFromMeshWithUVTexturing(meshid, fubarpksD) if meshes=1 then objs[meshes]=CreateObjectFromMeshWithUVTexturing(meshid, cubed) if meshes=2 then objs[meshes]=CreateObjectFromMeshWithUVTexturing(meshid, treeD) if meshes=3 then objs[meshes]=CreateObjectFromMeshWithUVTexturing(meshid, icoD) if meshes=4 then objs[meshes]=CreateObjectFromMeshWithUVTexturing(meshid, ConeD) emptymesh() next */ CreateMeshObjectConeInvertedWithTexture(500,50,1000,1) object=CreateObjectFromMeshWithUVTexturing(meshid, ConeD) objectmesh.length=-1 //road = CreateObjectPlane(200000,200000) //SetObjectColor(road,40,43,42,255) //SetObjectRotation(road, 90,0,0) //SetObjectPosition(road,getobjectx(road),-500,getobjecty(road)) setupskyandfog() //SetAmbientColor(255,255,255) SetCameraRange(1,0.1,10000) setupcamera() bouncey#=0 : bounceamount#=0 : bounce=1 angle#=0 do movecamerawithmouse() if GetRawKeyState(87) then inc cameray#,.2 if GetRawKeyState(83) then dec cameray#,.2 // if cameray#<4 then cameray#=4 SetCameraPosition(1,camerax#,cameray#,cameraz#) print("FPS " + str(ScreenFPS()) + " - Last Key" + str(GetRawLastKey())) print("W and D to go up or down for the minute") //print("Memblock Size " + str(GetMemblockSize(objs[0]))) print("Buildings on the mesh " + str(maxobjects)) Sync() loop function moveobjectYonmesh(mesh,id, y#) for i=meshmemblockvertexes[id].vfrom to meshmemblockvertexes[id].vto SetMeshMemblockVertexPosition(memblock,i,GetMeshMemblockVertexX(memblock,i),GetMeshMemblockVertexY(memblock,i)+y#,GetMeshMemblockVertexZ(memblock,i)) next endfunction function moveobjectXonmesh(mesh,id, x#) for i=meshmemblockvertexes[id].vfrom to meshmemblockvertexes[id].vto SetMeshMemblockVertexPosition(memblock,i,GetMeshMemblockVertexX(memblock,i)+x#,GetMeshMemblockVertexY(memblock,i),GetMeshMemblockVertexZ(memblock,i)) next endfunction function moveobjectZonmesh(mesh,id, z#) for i=meshmemblockvertexes[id].vfrom to meshmemblockvertexes[id].vto SetMeshMemblockVertexPosition(memblock,i,GetMeshMemblockVertexX(memblock,i),GetMeshMemblockVertexY(memblock,i),GetMeshMemblockVertexZ(memblock,i)+z#) next endfunction function initialiseperlin() // Setup perlin noise and load texture stuff NoiseInit() mapimage = generateperlinimage() // mapsprite=CreateSprite(mapimage) //SetSpriteScale(mapsprite,.5,.5) endfunction function setupprogressbar(min,max,value) endfunction function buildfarworld( object, size, sizex, sizez,alpha) fw as _farworlds for x = -sizex to sizex y=0 for z=-sizez to sizez // dont duplicate the chunk we on if x<>0 or z<>0 fw.x#=random2(-30,30) * size fw.y#=0 fw.z#=random2(-30,30) * size fw.objID = InstanceObject(object) SetObjectPosition(fw.objID, fw.x#, fw.y#, fw.z#) SetObjectTransparency(fw.objID,1) SetObjectScreenCulling(fw.objID,1) SetObjectColor(fw.objID,255,255,255,alpha) farworlds.insert(fw) endif next next endfunction function GetObjectInFront(obj, cam) x1# = GetCameraX(cam) y1# = GetCameraY(cam) z1# = GetCameraZ(cam) dx# = GetObjectX(obj) - x1# dy# = GetObjectY(obj) - y1# dz# = GetObjectZ(obj) - z1# d# = sqrt(dx#*dx# + dy#*dy# + dz#*dz#) ux1# = dx#/d# uy1# = dy#/d# uz1# = dz#/d# d# = 3 MoveCameraLocalZ(cam, d#) dx# = GetCameraX(cam) - x1# dy# = GetCameraY(cam) - y1# dz# = GetCameraZ(cam) - z1# MoveCameraLocalZ(cam, -d#) ux2# = dx#/d# uy2# = dy#/d# uz2# = dz#/d# res# = ux1# * ux2# + uy1# * uy2# + uz1# * uz2# angle# = acos(res#) inFront = 0 ////////CHANGE THIS//////////// if angle# < 20 then inFront = 1 endfunction inFront function cull_objs_behind_camera() for a=0 to farworlds.length v = GetObjectInFront( farworlds[a].objID, 1 ) if v = 0 then SetObjectVisible(farworlds[a].objID,0) if v = 1 then SetObjectVisible(farworlds[a].objID,1) next endfunction function buildworld(sizex, sizey, sizez, px,pz) c=0 for x=-sizex to sizex inc px,2 if px>perlinw then px=0 for y=-sizey to sizey for z=-sizez to sizez inc pz if pz>perlinh then pz=0 print (" X - " + str(px) + " " + str(perlinw)) print(" Y - " + str(pz)) sync() //sleep(100) if random(0,10)>=0 // 0 - cube // y#=255.0 * (noise2d(abs(x+sizex)*px/120.0,abs(z+sizey)*pz/120.0)) / 13 //y=0 y#=perlinmap[px,pz,0].level InstanceMeshObject(0,c , x*2, y# * 2,z*2, 5,1,1, MakeColor( perlinmap[x+sizex+1,z+sizez+1,0].r, perlinmap[x+sizex+1,z+sizez+1,0].g,perlinmap[x+sizex+1,z+sizez+1,0].b)) inc c endif next next next maxobjects=c-1 object = CreateObjectFromMeshWithColor(meshid) // empties the mesh array - no9t required anymore now built emptymesh() endfunction object function loadobjects() // 0 cube, 1 - tree // LoadObjectIntoMesh(0,"\media\fubarpk.obj", "cube.png",0,1) // 1= saves the V/VN/VTs for been able// to instance it // LoadObjectIntoMesh(1,"\media\cube.obj", "",0,1) // 1= saves the V/VN/VTs for been able to instance it // LoadObjectIntoMesh(2,"\media\tree.obj", "",0,1) // 1= saves the V/VN/VTs for been able to instance it // LoadObjectIntoMesh(3,"\media\tree.obj", "",0,1) // 1= saves the V/VN/VTs for been able to instance it LoadObjectIntoMesh(0,"\media\cone.obj", "",0,1) // 1= saves the V/VN/VTs for been able to instance it endfunction function setupcamera() camerax#=0 cameray#=4 cameraz#=0 startx#=screenwidth/2 starty#=screenheight/2 SetRawMousePosition(startx#,starty#) endfunction function setupskyandfog() // setup a skybox SetSunActive(1) SetSkyBoxHorizonSize(4.1,4) SetSkyBoxHorizonColor(90,132,150)//nice horizon blue SetSkyBoxSkyColor(0,122,193)//thunder horison thunderblue SetSkyBoxVisible(1) SetFogColor(155,155,155) SetFogRange(1000,2000) SetFogMode(0) SetCameraRange(1,0.1,90000) endfunction function RemoveVertices(id,mesh,vertexfrom,vertextto) for i=vertexfrom to vertextto SetMemblockFloat(mesh,72+i*36,0) SetMemblockFloat(mesh,76+i*36,0) SetMemblockFloat(mesh,80+i*36,0) SetMemblockFloat(mesh,84+i*36,0) SetMemblockFloat(mesh,88+i*36,0) SetMemblockFloat(mesh,92+i*36,0) SetMemblockFloat(mesh,96+i*36,0) SetMemblockFloat(mesh,100+i*36,0) SetMemblockInt(mesh,104+i*36,0) //maybe one day or year in 2019 lol next SetObjectMeshFromMemblock(id,1,memblock) endfunction // Delete an object from a mesh // ID = object to delete // mesh = is the main meshmemblock that deletes from function deletemeshobject(id, mesh, m ref as Mesh) for i=meshmemblockvertexes[id].vfrom to meshmemblockvertexes[id].vto SetMemblockFloat(memblock,72+i*36,0) SetMemblockFloat(memblock,76+i*36,0) SetMemblockFloat(memblock,80+i*36,0) SetMemblockFloat(memblock,84+i*36,0) SetMemblockFloat(memblock,88+i*36,0) SetMemblockFloat(memblock,92+i*36,0) SetMemblockFloat(memblock,96+i*36,0) SetMemblockFloat(memblock,100+i*36,0) SetMemblockInt(memblock,104+i*36,0) //maybe one day or year in 2019 lol next SetObjectMeshFromMemblock(mesh,1,memblock) endfunction function Debug() endfunction function movecamerawithmouse() fDiffX# = (GetPointerX() - startx#)/4.0 fDiffY# = (GetPointerY() - starty#)/4.0 newX# = angx# + fDiffY# // if ( newX# > 360 ) then newX# = 360 // if ( newX# < -360 ) then newX# = -360 // if we keep hold of the left mouse button then rotate the view otherwise the camera stays put // so can concentrate on adding/removing blocks at that positon SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 ) endfunction // ************************************************* // ** Mesh Memblock Function // ************************************************* // Instance a loaded object - requires to "save" the data when load an object for this to work function InstanceMeshObject(id, ObjID, x#, y#, z#, scalex#,scaley#,scalez#, color) mv as _meshmemblockvertexes mv.id = ObjID mv.vfrom = vertexcount indices=0 if objectmesh[id].polygon=0 for a=0 to objectmesh[id].faces.length // calculate the normals nnx#=objectmesh[id].normals[objectmesh[id].faces[a].nindex].x# nny#=objectmesh[id].normals[objectmesh[id].faces[a].nindex].y# nnz#=objectmesh[id].normals[objectmesh[id].faces[a].nindex].z# * -1 length# = sqrt((nnx# * nnx#) + (nny# * nny#) + (nnz# * nnz#)) if length#>31 length#=1/length# else nny#=1 length#=1 endif nx# = nnx# * length# ny# = nny# * length# nz# = nnz# * length# // apply the polygon referencing indexes from the OBJect // does the object have a texture assigned if objectmesh[id].faces[a].tindex <> -1 // yes AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# * scalez# ,nx#,ny#,nz#, objectmesh[id].textures[objectmesh[id].faces[a].tindex].u# ,objectmesh[id].textures[objectmesh[id].faces[a].tindex].v#,Color) else // no AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# * scalez# ,nx#,ny#,nz#, 0,0,Color) endif inc indices,1 // add the next vertex position so we know which vertexs to change later when using setmeshmemblockvertexposition etc next else //polygon // polygon construction for a=0 to objectmesh[id].faces.length step 4 //calculate the normals //sleep(10000) nnx#=objectmesh[id].normals[objectmesh[id].faces[a].nindex].x# nny#=objectmesh[id].normals[objectmesh[id].faces[a].nindex].y# nnz#=objectmesh[id].normals[objectmesh[id].faces[a].nindex].z# * -1 length# = sqrt((nnx# * nnx#) + (nny# * nny#) + (nnz# * nnz#)) if length#>31 length#=1/length# else nny#=1 length#=1 endif nx# = nnx# * length# ny# = nny# * length# nz# = nnz# * length# // apply the polygon referencing indexes from the OBJect // does the object have a texture assigned if objectmesh[id].faces[a].tindex <> -1 // yes AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# * scalez# ,nx#,ny#,nz#, objectmesh[id].textures[objectmesh[id].faces[a].tindex].u# ,objectmesh[id].textures[objectmesh[id].faces[a].tindex].v#,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].z# * scalez# ,nx#,ny#,nz#, objectmesh[id].textures[objectmesh[id].faces[a+1].tindex].u# ,objectmesh[id].textures[objectmesh[id].faces[a+1].tindex].v#,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].z# * scalez# ,nx#,ny#,nz#, objectmesh[id].textures[objectmesh[id].faces[a+2].tindex].u# ,objectmesh[id].textures[objectmesh[id].faces[a+2].tindex].v#,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].z# * scalez# ,nx#,ny#,nz#, objectmesh[id].textures[objectmesh[id].faces[a+2].tindex].u# ,objectmesh[id].textures[objectmesh[id].faces[a+2].tindex].v#,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].z# * scalez# ,nx#,ny#,nz#, objectmesh[id].textures[objectmesh[id].faces[a+3].tindex].u# ,objectmesh[id].textures[objectmesh[id].faces[a+3].tindex].v#,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# * scalez# ,nx#,ny#,nz#, objectmesh[id].textures[objectmesh[id].faces[a].tindex].u# ,objectmesh[id].textures[objectmesh[id].faces[a].tindex].v#,color) else // no AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# * scalez# ,nx#,ny#,nz#, 1,1 ,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].z# * scalez# ,nx#,ny#,nz#,1,0,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].z# * scalez# ,nx#,ny#,nz#,0,0,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].z# * scalez# ,nx#,ny#,nz#, 0,0,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].z# * scalez# ,nx#,ny#,nz#, 0,1,color) AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x# * scalex#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y# * scaley#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# * scalez# ,nx#,ny#,nz#, 1,1,color) endif // add the next 4 vertex position so we know which vertexs to change later when using setmeshmemblockvertexposition etc // we need to add 4 of these cause its a polygon structure // inc vertexcount,1 inc indices,6 next endif mv.vto = vertexcount + indices-1 meshmemblockvertexes.insert(mv) inc vertexcount,indices endfunction // LoadObjectIntoMeshfunction // filename$ - What is the model name // debug - 0 to not have any - 1 to have all the info displayed // save - 0 to not save any Vs/VNs/VTs/Fs in global memory or 1 to keep those in memory to change at a later time in the app if so wish function LoadObjectIntoMesh(id, filename$, material$, debug, save) v as _vector // create an empty type so can inert data // with face elements these are index references of the above array indexes // // f v1 v2 v3 // This will be the indexes of the Vertex 1 2 and 3 in the vertex array // f v1/vt1 v2/vt2 v3/vt3 // This one has texture / UV assigned to the object and the first is the index in the vertex array and the 2nd is the texture array // f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 // This one has texture / UV assigned and Normals to the object and the first is the index in the vertex array and the 2nd is the texture array and the index in normals arra // // The f data is normally at the end of the OBJ file, so // What we would have to do first is grab the V into the Vertex array // then the VNs into the Normal array // then the VTs into the texture array // then use the F(aces) data to pick out which vertex to work with the AddVertex command // firstly empty the mesh for a new object to be loaded objectmesh[id].vertex.length=-1 objectmesh[id].normals.length=-1 objectmesh[id].faces.length=-1 objectmesh[id].textures.length=-1 f = OpenToRead(filename$) vindex=0 while not FileEOF(f) line$=ReadLine(f) if (mid(line$,1,2) = "v ") line$=mid(line$,3,len(line$)) v.x# = ValFloat(GetStringToken(line$," ",1)) v.y#= ValFloat(GetStringToken(line$," ",2)) v.z#= ValFloat(GetStringToken(line$," ",3)) * -1 objectmesh[id].vertex.insert(v) endif if (mid(line$,1,3) = "vn ") line$=mid(line$,4,len(line$)) v.x# = ValFloat(GetStringToken(line$," ",1)) v.y#= ValFloat(GetStringToken(line$," ",2)) v.z#= ValFloat(GetStringToken(line$," ",3)) * -1 objectmesh[id].normals.insert(v) endif if (mid(line$,1,3) = "vt ") line$=mid(line$,4,len(line$)) v.u# = ValFloat(GetStringToken(line$," ",1)) v.v#= ValFloat(GetStringToken(line$," ",2)) objectmesh[id].textures.insert(v) endif if (mid(line$,1,2) = "f ") line$=mid(line$,3,len(line$)) face1$ = GetStringToken(line$," ",1) face2$ = GetStringToken(line$," ",2) face3$ = GetStringToken(line$," ",3) face4$ = GetStringToken(line$," ",4) // eg constucted F 1//1 14//1 13//1 = Vertex // Normal VertexIndex//NormalIndex VertexIndex//NormalIndex // eg constucted F 1//1 14//1 13//1 8//1 = Polygon construction // Normal VertexIndex//NormalIndex VertexIndex//NormalIndex v.vindex = ValFloat(GetStringToken(face1$,"//",1))-1 v.tindex = ValFloat(GetStringToken(face1$,"//",2))-1 v.nindex = ValFloat(GetStringToken(face1$,"//",3))-1 if v.nindex = -1 v.nindex = v.tindex v.tindex = -1 endif objectmesh[id].faces.insert(v) print(v.vindex) print(v.tindex) print(v.nindex) print(face1$) //sync() //sleep(3000) v.vindex = ValFloat(GetStringToken(face2$,"//",1))-1 v.tindex = ValFloat(GetStringToken(face2$,"//",2))-1 v.nindex = ValFloat(GetStringToken(face2$,"//",3))-1 if v.nindex = -1 v.nindex = v.tindex v.tindex = -1 endif objectmesh[id].faces.insert(v) print(v.vindex) print(v.tindex) print(v.nindex) print(face2$) //sync() //sleep(1000) // Y# // Z# v.vindex = ValFloat(GetStringToken(face3$,"//",1))-1 v.tindex = ValFloat(GetStringToken(face3$,"//",2))-1 v.nindex = ValFloat(GetStringToken(face3$,"//",3))-1 if v.nindex = -1 v.nindex = v.tindex v.tindex = -1 endif objectmesh[id].faces.insert(v) print(v.vindex) print(v.tindex) print(v.nindex) print(face3$) //sync() //sleep(1000) // 4 faces = polygon so needs a polygon - 4 vertices command rather than a addvertex (3 points) // a polygon will require 6xvertices. 1st/2nd/3rd points is indeed makes the first triangle // then the other 3 needs to be - 2 x shared vertices from the 2 of the previous and an extra one making the // final outcome of 4 vertices polygon object if len(face4$)>1 v.vindex = ValFloat(GetStringToken(face4$,"//",1))-1 v.tindex = ValFloat(GetStringToken(face4$,"//",2))-1 v.nindex = ValFloat(GetStringToken(face4$,"//",3))-1 if v.nindex = -1 v.nindex = v.tindex v.tindex = -1 endif objectmesh[id].faces.insert(v) print(v.vindex) print(v.tindex) print(v.nindex) print(face4$) //sync() //sleep(1000) objectmesh[id].polygon=1 else objectmesh[id].polygon=0 endif endif endwhile if debug=1 print(objectmesh[id].Vertex.length) for a=0 to objectmesh[id].vertex.length print("V " + str(objectmesh[id].vertex[a].x#) + " " + str(objectmesh[id].vertex[a].y#) + " " + str(objectmesh[id].vertex[a].z#)) next sync() sleep(2000) print(objectmesh[id].Normals.length) for a=0 to objectmesh[id].normals.length print("VN " + str(objectmesh[id].normals[a].x#) + " " + str(objectmesh[id].normals[a].y#) + " " + str(objectmesh[id].normals[a].z#)) next sync() sleep(2000) print(objectmesh[id].Faces.length) for a=0 to objectmesh[id].faces.length print("F " + str(objectmesh[id].faces[a].x#) + " " + str(objectmesh[id].faces[a].y#) + " " + str(objectmesh[id].faces[a].z#)) next sync() sleep(2000) endif if debug=1 sync() sleep(1000) endif if save=0 objectmesh[id].vertex.length=-1 objectmesh[id].normals.length=-1 objectmesh[id].faces.length=-1 objectmesh[id].textures.length=-1 endif CloseFile(f) endfunction // X#,Y#,Z# location of where you want it // First vetex always in centre 0 of x,y,z // X2# is the 2nd vertex // X3# is the 3rd // X4# is the 4th function createMeshObjectTriangleChunk(x#,y#,z#,x2#,y2#,z2#,x3#,y3#,z3#, x4#,y4#,z4#) Color=MakeColor(255,255,255) // bottom AddVertex(MeshID, x#, y#, z# , 0 ,1, 0, .5,.5,Color) AddVertex(MeshID, x4#, y4#, z4# , 0 ,1, 0, 0, 1,Color) AddVertex(MeshID, x2#, y2#, z2# , 0 ,1, 0, 0, 0,Color) AddVertex(MeshID, x2#, y2#, z2# , 0 ,1, 0, .5,.5,Color) AddVertex(MeshID, x4#, y4#, z4# , 0 ,1, 0, 0, 1,Color) AddVertex(MeshID, x3#, y3#, z3# , 0 ,1, 0, 0, 0,Color) AddVertex(MeshID, x#, y#, z# , 0 ,1, 0, .5,.5,Color) AddVertex(MeshID, x3#, y3#, z3# , 0 ,1, 0, 0, 0,Color) AddVertex(MeshID, x4#, y4#, z4# , 0 ,1, 0, 0, 1,Color) AddVertex(MeshID, x#, y#, z# , 0 ,1, 0, .5,.5,Color) AddVertex(MeshID, x2#, y2#, z2# , 0 ,1, 0, 0, 0,Color) AddVertex(MeshID, x3#, y3#, z3# , 0 ,1, 0, 0, 1,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() endfunction // X#,Y#,Z# location of where you want it // First vetex always in centre 0 of x,y,z // X2# is the 2nd vertex // X3# is the 3rd function createMeshObjectTriangleBlock(x#,y#,z#,x2#,z2#,x3#,z3#,height#) Color=MakeColor(255,255,255) // bottom AddVertex(MeshID, x#, y#, z# , 0 ,1, 0, .5,.5,Color) AddVertex(MeshID, x3#, y#, z3# , 0 ,1, 0, 0, 0,Color) AddVertex(MeshID, x2#, y#, z2# , 0 ,1, 0, 0, 1,Color) // top AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, .5, .5,Color) AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, 0, 0,Color) AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, 0, 1,Color) // side 1 AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 0, 1,Color) AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, 1, 0,Color) AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, 0, 0,Color) AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 0,1,Color) AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 1,1,Color) AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, 1,0,Color) // side 2 AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 0,1,Color) AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, 1,0,Color) AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, 0,0,Color) AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 0,1,Color) AddVertex(MeshID, x3#, y#, z3# , 0 ,1,0, 1,1,Color) AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, 1,0,Color) // side 3 AddVertex(MeshID, x3#, y#, z3# , 0 ,1,0, 0,1,Color) AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, 1,0,Color) AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, 0,0,Color) AddVertex(MeshID, x3#, y#, z3# , 0 ,1,0, 0,1,Color) AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 1,1,Color) AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, 1,0,Color) // AddVertex(MeshID, x#, y#+height#, z3# , 0 ,1,0, .5,.5,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() endfunction function createmeshobjectlighthouse(x#, y#, z#, basewidth#, height#) CreateMeshObjectConeWithTexture(height#,50,basewidth#,0) endfunction function emptymesh() MeshID.VertexList.Length=-1 MeshID.TriangleList.Length=-1 endfunction Function CreateMeshObjectPlayWithTexture_Shatter(x#,y#,z#,width#,depth#) color=MakeColor(random(0,255),random(0,255),random(0,255)) pos#=8 // location of the shatter point AddVertex(MeshID, x#-width#/2 , y#+depth#/2-depth#/2 ,z# , 0 ,1,0, 0,0.5,Color) AddVertex(MeshID, x#+(width#/2)-depth#/pos# , y#+(depth#/2)-depth#/pos# ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#-width#/2 , y#+depth#/2 ,z# , 0 ,1,0, 0,0,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() AddVertex(MeshID, x#-width#/2 , y#+depth#/2 ,z# , 0 ,1,0, 0,0,Color) AddVertex(MeshID, x#+(width#/2)-depth#/pos# , y#+(depth#/2)-depth#/pos# ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#-width#/2+(depth#/2) , y#+depth#/2 ,z# , 0 ,1,0, .5,0,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() AddVertex(MeshID, x#-width#/2+(depth#/2) , y#+depth#/2 ,z# , 0 ,1,0, .5,0,Color) AddVertex(MeshID, x#+(width#/2)-depth#/pos# , y#+(depth#/2)-depth#/pos# ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#+width#/2 , y#+depth#/2 ,z# , 0 ,1,0, 1,0,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() AddVertex(MeshID, x#+width#/2 , y#+depth#/2 ,z# , 0 ,1,0, 1,0,Color) AddVertex(MeshID, x#+(width#/2)-depth#/pos# , y#+(depth#/2)-depth#/pos# ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#+width#/2 , y#+depth#/2-depth#/2 ,z# , 0 ,1,0, 1,.5,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() AddVertex(MeshID, x#+width#/2 , y#+depth#/2-depth#/2 ,z# , 0 ,1,0, 1,.5,Color) AddVertex(MeshID, x#+(width#/2)-depth#/pos# , y#+(depth#/2)-depth#/pos# ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#+width#/2 , y#-depth#/2 ,z# , 0 ,1,0, 1,1,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() AddVertex(MeshID, x#+width#/2 , y#-depth#/2 ,z# , 0 ,1,0, 1,1,Color) AddVertex(MeshID, x#+(width#/2)-depth#/pos# , y#+(depth#/2)-depth#/pos# ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#+width#/2-depth#/2 , y#-depth#/2 ,z# , 0 ,1,0, .5,1,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() AddVertex(MeshID, x#+width#/2-depth#/2 , y#-depth#/2 ,z#, 0 ,1,0, .5,1,Color) AddVertex(MeshID, x#+(width#/2)-depth#/pos# , y#+(depth#/2)-depth#/pos# ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#-width#/2 , y#-depth#/2 ,z#, 0 ,1,0, 0,1,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() AddVertex(MeshID, x#-width#/2 , y#-depth#/2 ,z# , 0 ,1,0, 0,1,Color) AddVertex(MeshID, x#+(width#/2)-depth#/pos# , y#+(depth#/2)-depth#/pos# ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#-width#/2 , y#+depth#/2-depth#/2 ,z# , 0 ,1,0, 0,.5,Color) peices.insert(CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)) emptymesh() endfunction function splitmesh(splitamount#) length=meshid.VertexList.length for a=0 to 5 randomvertex = a oldx# = MeshID.VertexList[randomvertex].x = MeshID.VertexList[randomvertex].x oldy# = MeshID.VertexList[randomvertex].y = MeshID.VertexList[randomvertex].y oldz# = MeshID.VertexList[randomvertex].z = MeshID.VertexList[randomvertex].z randomsplit#=random2(1,splitamount#)/100.0 MeshID.VertexList[randomvertex].x = MeshID.VertexList[randomvertex].x+randomsplit# randomsplit#=random2(1,splitamount#)/100.0 MeshID.VertexList[randomvertex].y = MeshID.VertexList[randomvertex].y-randomsplit# randomsplit#=random2(1,splitamount#)/100.0 MeshID.VertexList[randomvertex].z = MeshID.VertexList[randomvertex].z+randomsplit# // endif next deleteobject(object) object = CreateObjectFromMeshWithUVTexturing(MeshID,CubeD) endfunction function createMeshObjectPlaneWithTexture(x#,y#,z#,width#,depth#) color=MakeColor(255,255,255) AddVertex(MeshID, x#-width#/2 , y# ,z#+depth#/2 , 0 ,1,0, 0,0,Color) AddVertex(MeshID, x#-width#/2 , y# ,z#-depth#/2 , 0 ,1,0, 0,1,Color) AddVertex(MeshID, x#+width#/2 , y# ,z#+depth#/2 , 0 ,1,0, 1,0,Color) AddVertex(MeshID, x#+width#/2 , y# ,z#+depth#/2 , 0 ,1,0, 1,0,Color) AddVertex(MeshID, x#-width#/2 , y# ,z#-depth#/2 , 0 ,1,0, 0,1,Color) AddVertex(MeshID, x#+width#/2 , y# ,z#-depth#/2 , 0 ,1,0, 1,1,Color) endfunction function createMeshObjectCylinderWithTexture(x#, y#, z#,height#, baseradius#, topradius#,segments#, top, bottom, color) if (segments#<3) then segments#=3 if (baseradius#<0) then baseradius#=-baseradius# radius#=baseradius#/2.0 SegX# = 2*PI# /segments# SegU# = 1.0 / segments# if top=1 for i=0 to segments# nxt = i+1 if ( nxt >= segments# ) then nxt = 0 AddVertex(MeshID, x# , y#+height#/2.0 ,z# , 0 ,1,0, .5,.5,Color) AddVertex(MeshID, x#+Sinrad(-SegX#*i) * (radius#-topradius#) , y#+height#/2.0 ,z#+CosRad(-SegX#*i) * (radius#-topradius#) , 0 ,1,0, SinRad(-SegX#*i)/2.0+.5,CosRad(SegX#*i)/2.0+.5,Color) AddVertex(MeshID, x#+Sinrad(-SegX#*nxt) * (radius#-topradius#) , y#+height#/2.0 ,z#+CosRad(-SegX#*nxt) * (radius#-topradius#) , 0 ,1,0, SinRad(-SegX#*(i+1))/2.0+.5,CosRad(SegX#*(i+1))/2.0+.5,Color) next endif for i=0 to segments# nxt = i+1 if ( nxt >= segments# ) then nxt = 0 AddVertex(MeshID, x#+SinRad(-SegX#*i) * (radius#-topradius#) , y#+height#/2.0 ,z#+CosRad(-SegX#*i) * (radius#-topradius#), SinRad (-SegX#*i) ,0,CosRad(-SegX#*i), SegU#*i,0,Color) AddVertex(MeshID, x#+Sinrad(-SegX#*i) * (radius#+0) , y#-height#/2.0 ,z#+CosRad(-SegX#*i) * (radius#-0) , SinRad(-SegX#*i) ,0,CosRad(-SegX#*i), SegU#*i,1,Color) AddVertex(MeshID, x#+Sinrad(-SegX#*nxt) * (radius#+0) , y#-height#/2.0 ,z#+CosRad(-SegX#*nxt) * (radius#-0) , SinRad(-SegX#*nxt) ,0,CosRad(-SegX#*nxt), SegU#*(i+1),1,Color) AddVertex(MeshID, x#+SinRad(-SegX#*i) * (radius#-topradius#) , y#+height#/2.0 ,z#+CosRad(-SegX#*i) * (radius#-topradius#), SinRad (-SegX#*i) ,0,CosRad(-SegX#*i), SegU#*i,0,Color) AddVertex(MeshID, x#+Sinrad(-SegX#*nxt) * (radius#-0) , y#-height#/2.0 ,z#+CosRad(-SegX#*nxt) * (radius#-0) , SinRad(-SegX#*nxt) ,0,CosRad(-SegX#*nxt), SegU#*(i+1),1,Color) AddVertex(MeshID, x#+Sinrad(-SegX#*nxt) * (radius#-topradius#) , y#+height#/2.0 ,z#+CosRad(-SegX#*nxt) * (radius#-topradius#) , SinRad(-SegX#*nxt) ,0,CosRad(-SegX#*nxt), SegU#*(i+1),0,Color) next if bottom=1 for i=0 to segments# nxt = i+1 if ( nxt >= segments# ) then nxt = 0 AddVertex(MeshID, x#+Sinrad(-SegX#*i) * radius# , y#-height#/2.0 ,z#+CosRad(-SegX#*i) * radius# , 0 ,-1,0, SinRad(-SegX#*i)/2.0+.5,CosRad(SegX#*i)/2.0+.5,Color) AddVertex(MeshID, x# , y#-height#/2.0 ,z# , 0 ,-1,0, .5,.5,Color) AddVertex(MeshID, x#+Sinrad(-SegX#*nxt) * radius# , y#-height#/2.0 ,z#+CosRad(-SegX#*nxt) * radius# , 0 ,-1,0, SinRad(-SegX#*(i+1))/2.0+.5,CosRad(SegX#*(i+1))/2.0+.5,Color) next endif endfunction function CreateMeshObjectConeWithTexture(height#, segments#, Radius#, Bottom) color=MakeColor(255,255,255) // doesnt use color but the AddVertex requires it SegX# = 2 * PI# / segments# for i = 0 to segments# nxt = i+1 if (nxt >= segments#) then nxt=0 AddVertex(MeshID, 0 , height# ,0 , 0,1,0, .5,.5,Color) AddVertex(MeshID, SinRad(-SegX#*i)*radius# ,-height# ,CosRad(-SegX#*i) * radius#, sinrad( -SegX#*i),abs(radius#)/height#,cosRad(-SegX#*i),SinRad( -SegX# * i ) /2.0 +.5, CosRad(-SegX# * i)/2.0 + .5,Color) AddVertex(MeshID, SinRad(-SegX#*nxt)*radius# ,-height# ,CosRad(-SegX#*nxt) * radius#, SinRad(-SegX#*nxt),abs(radius#)/height#,CosRad(-SegX# * nxt),SinRad(-SegX# * (i+1) )/2.0 + .5, CosRad(-SegX#*(i+1)) /2.0+.5,Color) next if bottom=1 for i = 0 to segments# nxt = i+1 if (nxt >= segments#) then nxt=0 AddVertex(MeshID, SinRad(-SegX#*i)*radius# ,-height#/2.0 ,CosRad(-SegX#*i) * radius#, 0,-height#,0,SinRad( -SegX#*i) /2.0+.5,CosRad(-SegX#*i)/2.0+.5,Color) AddVertex(MeshID, 0 , -height#/2.0 ,0 , 0,-height#,0, .5,.5,Color) AddVertex(MeshID, SinRad(-SegX#*nxt)*radius# ,-height#/2.0 ,CosRad(-SegX#*nxt) * radius#, 0,-height#,0,SinRad(-SegX#*(i+1))/2.0+.5,CosRad(-SegX#*(i+1))/2.0+.5,Color) next endif endfunction MeshID function CreateMeshObjectConeInvertedWithTexture(height#, segments#, Radius#, Bottom) color=MakeColor(255,255,255) // doesnt use color but the AddVertex requires it SegX# = 2 * PI# / segments# for i = 0 to segments# nxt = i+1 if (nxt >= segments#) then nxt=0 AddVertex(MeshID, 0 , height# ,0 , 0,1,0, .5,.5,Color) AddVertex(MeshID, SinRad(-SegX#*nxt)*radius# ,-height# ,CosRad(-SegX#*nxt) * radius#, SinRad(-SegX#*nxt),abs(radius#)/height#,CosRad(-SegX# * nxt),SinRad(-SegX# * (i+1) )/2.0 + .5, CosRad(-SegX#*(i+1)) /2.0+.5,Color) AddVertex(MeshID, SinRad(-SegX#*i)*radius# ,-height# ,CosRad(-SegX#*i) * radius#, sinrad( -SegX#*i),abs(radius#)/height#,cosRad(-SegX#*i),SinRad( -SegX# * i ) /2.0 +.5, CosRad(-SegX# * i)/2.0 + .5,Color) next if bottom=1 for i = 0 to segments# nxt = i+1 if (nxt >= segments#) then nxt=0 AddVertex(MeshID, SinRad(-SegX#*i)*radius# ,-height#/2.0 ,CosRad(-SegX#*i) * radius#, 0,-height#,0,SinRad( -SegX#*i) /2.0+.5,CosRad(-SegX#*i)/2.0+.5,Color) AddVertex(MeshID, SinRad(-SegX#*nxt)*radius# ,-height#/2.0 ,CosRad(-SegX#*nxt) * radius#, 0,-height#,0,SinRad(-SegX#*(i+1))/2.0+.5,CosRad(-SegX#*(i+1))/2.0+.5,Color) AddVertex(MeshID, 0 , -height#/2.0 ,0 , 0,-height#,0, .5,.5,Color) next endif endfunction MeshID // creates a full cube with all the same texture all way round it function CreateMeshObjectBoxWithTexture(X#, Y#, Z#, Width#, Height#, Depth#) Color= MakeColor(255,255,255) // This doesnt use color but AddVertex requires it //Front Face AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2), 0,1,0, 0,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2), 0,1,0, 1,0,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2)+height# ,(Z#-depth#/2), 0,1,0, 0,0,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2), 0,1,0, 0,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2) ,(Z#-depth#/2), 0,1,0, 1,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2), 0,1,0, 1,0,Color) // Left AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2) , 0,1,0, 1,1,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2)+height# ,(Z#-depth#/2) , 0,1,0, 1,0,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2)+depth# , 0,1,0, 0,1,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2)+height# ,(Z#-depth#/2) , 0,1,0, 1,0,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2)+height# ,(Z#-depth#/2)+depth# , 0,1,0, 0,0,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2)+depth# , 0,1,0, 0,1,Color) // Right AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2) ,(Z#-depth#/2) , 0,1,0 , 0,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2) ,(Z#-depth#/2)+depth# , 0,1,0 , 1,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2) , 0,1,0 , 0,0,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2) , 0,1,0 , 0,0,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2) ,(Z#-depth#/2)+depth#, 0,1,0 , 1,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2)+depth# , 0,1,0 , 1,0,Color) //back AddVertex(MeshID, (X#-width#/2) ,(y# -height#/2) ,(Z#-depth#/2)+depth#, 0,1,0, 1,1,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2)+height# ,(Z#-depth#/2)+depth#, 0,1,0, 1,0,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2)+depth#, 0,1,0, 0,0,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2)+depth#, 0,1,0, 1,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2)+depth#, 0,1,0, 0,0,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2) ,(Z#-depth#/2)+depth#, 0,1,0, 0,1,Color) // top AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2)+height# ,(Z#-depth#/2) , 0,1,0, 0,0,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2) , 0,1,0, 0,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2)+depth# , 0,1,0, 1,1,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2)+height# ,(Z#-depth#/2) , 0,1,0, 0,0,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2)+height# ,(Z#-depth#/2)+depth# , 0,1,0, 1,1,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2)+height# ,(Z#-depth#/2)+depth# , 0,1,0, 1,0,Color) //bottom AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2) , 0,1,0, 0,1,Color) AddVertex(MeshID, (X#-width#/2)+width# ,(y#-height#/2) ,(Z#-depth#/2)+depth# , 0,1,0, 1,0,Color) AddVertex(MeshID, (X#+width#/2) ,(y#-height#/2) ,(Z#-depth#/2) , 0,1,0, 0,0,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2) , 0,1,0, 0,1,Color) AddVertex(MeshID, (X#-width#/2) ,(y#-height#/2) ,(Z#-depth#/2)+depth# , 0,1,0, 1,1,Color) AddVertex(MeshID, (X#+width#/2) ,(y#-height#/2) ,(Z#-depth#/2)+depth# , 0,1,0, 1,0,Color) endfunction MeshID // This uses an Atlas tilemap image function addcube(meshID ref as mesh, cubesize#, tilenumberx, tilenumbery, normx#,normy#,normz#,x#,y#,z#) // calculate the UVs - YIKES here we go cubex#=((tilenumberx-1) * .5) + tilenumberx // cubey#=(tilenumbery * 0.5)+ 0.5 maxx# = ((100/15.00)/100) * cubex# // the 15.00 is the amount of textures left to right in the Atlas image minx# = (maxx#-(100/15.00)/100) // the 15.00 is the amount of textures left to right in the Atlas image halfx# = (maxx#/2 + minx# / 2) bottommaxx# = ((100/15.00)/100) * (cubex#+.5) // the 15.00 is the amount of textures left to right in the Atlas image bottomminx# = (bottommaxx#-((100/15.00)/100)) // the 15.00 is the amount of textures left to right in the Atlas image bottomhalfx# = (bottommaxx#/2 + bottomminx# / 2) maxy# = ((100/11.00)/100) * cubey# // the 11.00 is the amount of textures top to bottom in the Atlas image miny# = (maxy#-(100/11.00)/100) // the 11.00 is the amount of textures top to bottom in the Atlas image halfy# = (maxy#/2 + miny# / 2) // create the cube AddVertex(meshID,x# ,y#,z# ,0,1,0, maxx#,halfy#,MakeColor(255,0,0)) AddVertex(meshID,x#,y#+cubesize#,z# ,0,1,0, maxx#,miny#,MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#,z# ,0,1,0, halfx#,halfy#,MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z# ,0,1,0, halfx#,halfy#,MakeColor(255,0,0)) AddVertex(meshID,x# ,y#+cubesize#,z# ,0,1,0, maxx#,miny#,MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#+cubesize#,z# ,0,1,0, halfx#,miny#,MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#+cubesize#,z# ,0,1,0 ,maxx# ,miny#, MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#+cubesize#,z#+-cubesize# ,0,1,0 ,halfx#,miny#,MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z# ,0,1,0 ,maxx#,halfy#, MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z# ,0,1,0 ,maxx# ,halfy#, MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#+cubesize#,z#+-cubesize# ,0,1,0 ,halfx# ,miny#,MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z#+-cubesize# ,0,1,0 ,halfx# ,halfy#, MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z#+-cubesize# ,0,1,0 ,bottommaxx#,miny# , MakeColor(255,0,0)) AddVertex(meshID,x# ,y# ,z# ,0,1,0 ,bottomhalfx#,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z# ,0,1,0 ,bottommaxx#,halfy#, MakeColor(255,0,0)) AddVertex(meshID,x# ,y# ,z# ,0,1,0 ,bottomhalfx#,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z#+-cubesize# ,0,1,0 ,bottommaxx#,miny# , MakeColor(255,0,0)) AddVertex(meshID,x# ,y# ,z#+-cubesize# ,0,1,0 ,bottomhalfx# ,miny# , MakeColor(255,0,0)) AddVertex(meshID,x# ,y# ,z#+-cubesize# ,0,1,0 ,halfx# ,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z#+-cubesize# ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x# ,y#+cubesize#,z#+-cubesize# ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#+cubesize#,z#+-cubesize# ,0,1,0 ,maxx#,miny# , MakeColor(255,0,0)) AddVertex(meshID,x# ,y#+cubesize#,z#+-cubesize# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y# ,z#+-cubesize# ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x#,y# ,z#+-cubesize# ,0,1,0 ,maxx# ,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x#,y#+cubesize# ,z# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0)) AddVertex(meshID,x#,y# ,z# ,0,1,0 ,halfx#,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x#,y#+cubesize# ,z# ,0,1,0 ,halfx# ,miny# , MakeColor(255,0,0)) AddVertex(meshID,x#,y# ,z#+-cubesize# ,0,1,0 ,maxx# , halfy# , MakeColor(255,0,0)) AddVertex(meshID,x#,y#+cubesize# ,z#+-cubesize# ,0,1,0 ,maxx# , miny# , MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#+cubesize# ,z#+-cubesize# ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#+cubesize# ,z# ,0,1,0 ,minx#,miny#, MakeColor(255,0,0)) AddVertex(meshID,x# ,y#+cubesize# ,z# ,0,1,0 ,minx#,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x# ,y#+cubesize# ,z#+-cubesize# ,0,1,0 ,halfx# ,halfy# , MakeColor(255,0,0)) AddVertex(meshID,x#+cubesize#,y#+cubesize# ,z#+-cubesize# ,0,1,0 ,halfx#,miny# , MakeColor(255,0,0)) AddVertex(meshID,x# ,y#+cubesize# ,z# ,0,1,0 ,minx#,halfy# , MakeColor(255,0,0)) 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, color 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.color = color m.VertexList.Insert(vert) endfunction Function AddTriangle(m ref as Mesh, v1 as integer, v2 as integer, v3 as integer) t as Triangle t.v1 = v1 t.v2 = v2 t.v3 = v3 m.TriangleList.Insert(t) endfunction Function CreateObjectFromMeshWithColor(m ref as mesh) VertexCount = m.VertexList.Length + 1 IndexCount = (m.TriangleList.Length + 1) * 2 IndexOffset = 72 + VertexCount*36 memblock = CreateMemblock(IndexOffset+IndexCount*4) SetMemblockInt(memblock,0,VertexCount) SetMemblockInt(memblock,4,IndexCount) SetMemblockInt(Memblock,8,4) SetMemblockInt(memblock,12,36) // no color - 36 if color SetmemblockInt(memblock,16,72) SetMemblockInt(memblock,20,IndexOffset) SetMemblockInt(memblock,24,0x0c000300) SetMemblockString(Memblock,28,"position") SetMemblockInt(memblock,40,0x08000300) SetMemblockString(memblock,44,"normal") SetMemblockInt(memblock,52,0x04000200) SetMemblockString(memblock,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 SetMemblockFloat(memblock,72+i*36,m.VertexList[i].x) SetMemblockFloat(memblock,76+i*36,m.VertexList[i].y) SetMemblockFloat(memblock,80+i*36,m.VertexList[i].z) SetMemblockFloat(memblock,84+i*36,m.VertexList[i].nx) SetMemblockFloat(memblock,88+i*36,m.VertexList[i].ny) SetMemblockFloat(memblock,92+i*36,m.VertexList[i].nz) SetMemblockFloat(memblock,96+i*36,m.VertexList[i].u) SetMemblockFloat(memblock,100+i*36,m.VertexList[i].v) SetMemblockInt(memblock,104+i*36,m.VertexList[i].color) //maybe one day or year in 2019 lol next /* for i = 0 to m.TriangleList.Length SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1) SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2) SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3) next */ id = CreateObjectFromMeshMemblock(memblock) // DeleteMemblock(memblock) endfunction id Function CreateObjectFromMeshWithUVTexturing(m ref as mesh, texture) DeleteMemblock(memblock) VertexCount = m.VertexList.Length + 1 IndexCount = (m.TriangleList.Length + 1) * 2 IndexOffset = 60 + VertexCount*36 memblock = CreateMemblock(IndexOffset+IndexCount*4) SetMemblockInt(memblock,0,VertexCount) SetMemblockInt(memblock,4,IndexCount) SetMemblockInt(Memblock,8,3) SetMemblockInt(memblock,12,32) // no color - 36 if color SetmemblockInt(memblock,16,60) SetMemblockInt(memblock,20,IndexOffset) SetMemblockInt(memblock,24,0x0c000300) SetMemblockString(Memblock,28,"position") SetMemblockInt(memblock,40,0x08000300) SetMemblockString(memblock,44,"normal") SetMemblockInt(memblock,52,0x04000200) SetMemblockString(memblock,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 SetMemblockFloat(memblock,60+i*32,m.VertexList[i].x) SetMemblockFloat(memblock,64+i*32,m.VertexList[i].y) SetMemblockFloat(memblock,68+i*32,m.VertexList[i].z) SetMemblockFloat(memblock,72+i*32,m.VertexList[i].nx) SetMemblockFloat(memblock,76+i*32,m.VertexList[i].ny) SetMemblockFloat(memblock,80+i*32,m.VertexList[i].nz) SetMemblockFloat(memblock,84+i*32,m.VertexList[i].u) SetMemblockFloat(memblock,88+i*32,m.VertexList[i].v) //SetMemblockInt(memblock,104+i*36,m.VertexList[i].color) //maybe one day or year in 2019 lol next // for i = 0 to m.TriangleList.Length // SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1) // SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2) // SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3) // next DeleteObject(id) id = CreateObjectFromMeshMemblock(memblock) SetObjectImage(id,texture,0) // if mode=1 // creates the world or it creates for other small things - like explosion blocks // we need to keep the world chunk in memory so we can keep updating the vertices meshmemory = memblock // endif // DeleteMemblock(memblock) endfunction id //////////////////////////////////////////////////////////////////////////////////// /// /// Perlin Noise functions /// //////////////////////////////////////////////////////////////////////////////////// #constant PN3DF2 = 0.5*(sqrt(3.0)-1.0) #constant PN3DG2 = (3.0-sqrt(3.0))/6.0 Type sPNVECTOR x as float y as float z as float endtype Global PNHash as integer[512] Global PNGrad3 as sPNVECTOR[256] Function NoiseInit() Local n as integer, rn as integer For n=0 To 255 PNHash[n] = n Next n For n=0 To 255 rn=Random(0, 255) PNHash.swap(n,rn) Next n For n=0 To 255 PNHash[256 + n] = PNHash[n] Next n PNHash[511] = PNHash[0] For n=0 To 15 PNGrad3[n * 16 + 0].x = 1 : PNGrad3[n * 16 + 0].y = 1 : PNGrad3[n * 16 + 0].z = 0 PNGrad3[n * 16 + 1].x = -1 : PNGrad3[n * 16 + 1].y = 1 : PNGrad3[n * 16 + 1].z = 0 PNGrad3[n * 16 + 2].x = 1 : PNGrad3[n * 16 + 2].y = -1 : PNGrad3[n * 16 + 2].z = 0 PNGrad3[n * 16 + 3].x = -1 : PNGrad3[n * 16 + 3].y = -1 : PNGrad3[n * 16 + 3].z = 0 PNGrad3[n * 16 + 4].x = 1 : PNGrad3[n * 16 + 4].y = 0 : PNGrad3[n * 16 + 4].z = 1 PNGrad3[n * 16 + 5].x = -1 : PNGrad3[n * 16 + 5].y = 0 : PNGrad3[n * 16 + 5].z = 1 PNGrad3[n * 16 + 6].x = 1 : PNGrad3[n * 16 + 6].y = 0 : PNGrad3[n * 16 + 6].z = -1 PNGrad3[n * 16 + 7].x = -1 : PNGrad3[n * 16 + 7].y = 0 : PNGrad3[n * 16 + 7].z = -1 PNGrad3[n * 16 + 8].x = 0 : PNGrad3[n * 16 + 8].y = 1 : PNGrad3[n * 16 + 8].z = 1 PNGrad3[n * 16 + 9].x = 0 : PNGrad3[n * 16 + 9].y = -1 : PNGrad3[n * 16 + 9].z = 1 PNGrad3[n * 16 + 10].x = 0 : PNGrad3[n * 16 + 10].y = 1 : PNGrad3[n * 16 + 10].z = -1 PNGrad3[n * 16 + 11].x = 0 : PNGrad3[n * 16 + 11].y = -1 : PNGrad3[n * 16 + 11].z = -1 PNGrad3[n * 16 + 12].x = 1 : PNGrad3[n * 16 + 12].y = 1 : PNGrad3[n * 16 + 12].z = 0 PNGrad3[n * 16 + 13].x = -1 : PNGrad3[n * 16 + 13].y = 1 : PNGrad3[n * 16 + 13].z = 0 PNGrad3[n * 16 + 14].x = 0 : PNGrad3[n * 16 + 14].y = -1 : PNGrad3[n * 16 + 14].z = 1 PNGrad3[n * 16 + 15].x = 0 : PNGrad3[n * 16 + 15].y = -1 : PNGrad3[n * 16 + 15].z = -1 Next n endfunction function Noise2D(xin as float, yin as float) local n0 as float, n1 as float, n2 as float, s as float, t as float, x0 as float, y0 as float, xs as float, ys as float local i as integer, j as integer, i1 as integer, j1 as integer, i2 as integer, j2 as integer, gi0 as integer, gi1 as integer, gi2 as integer local x1 as float, y1 as float, x2 as float, y2 as float, x3 as float, y3 as float, t0 as float, t1 as float, t2 as float s = (xin + yin) * PN3DF2 xs = xin + s i = floor(xs) ys = yin + s j = floor(ys) t = (i + j) * PN3DG2 x0 = xin - (i - t) y0 = yin - (j - t) if x0>y0 i1=1 j1=0 else i1=0 j1=1 endif x1 = x0 - i1 + PN3DG2 y1 = y0 - j1 + PN3DG2 x2 = x0 - 1.0 + 2.0 * PN3DG2 y2 = y0 - 1.0 + 2.0 * PN3DG2 i = i && 255 j = j && 255 gi0 = PNHash[i + PNHash[j]] && 15 gi1 = PNHash[i + i1 + PNHash[j + j1]] && 15 gi2 = PNHash[i + 1 + PNHash[j+ 1]] && 15 t0 = 0.5 - x0*x0-y0*y0 if t0<0 n0 = 0.0 else t0 = t0 * t0 n0 = t0 * t0 * (PNGrad3[gi0].x * x0 + PNGrad3[gi0].y * y0) endif t1 = 0.5 - x1*x1-y1*y1 if t1<0 n1 = 0.0 else t1 = t1 * t1 n1 = t1 * t1 * (PNGrad3[gi1].x * x1 + PNGrad3[gi1].y * y1) endif t2 = 0.5 - x2*x2-y2*y2 if t2<0 n2 = 0.0 else t2 = t2 * t2 n2 = t2 * t2 * (PNGrad3[gi2].x * x2 + PNGrad3[gi2].y * y2) endif endfunction perlinheight * (n0 + n1 + n2) function generateperlinimage() // Generate image from memblock size = perlinw * perlinh * 4 + 12 mem = CreateMemblock(size) SetMemblockInt(mem,0,perlinw) SetMemblockInt(mem,4,perlinh) SetMemblockInt(mem,8,32) offset as integer = 12 a as float, b as float a = 5.0 b = 2.0 for y = 0 to perlinh - 1 for x = 0 to perlinw - 1 a = a + 0.0001 b = b + 0.002 // Try out these two noise methods //noise = 255.0*Noise2D(x/10.0,y/10.0) noise = abs(255.0*noise2d(x/100.0,y/100.0)) // print(noise) // sync() // noise = abs(noise) perlinmap[x,y,0].noise=noise perlinmap[x,y,0].x = x perlinmap[x,y,0].y = y //clouds if noise>255 perlinmap[x,y,0].r = noise perlinmap[x,y,0].g = noise perlinmap[x,y,0].b = noise perlinmap[x,y,0].texture = 6 // snow perlinmap[x,y,0].level = 5 SetMemblockByte(mem, offset, noise) SetMemblockByte(mem, offset+1, noise) SetMemblockByte(mem, offset+2, noise) SetMemblockByte(mem, offset+3, 255) endif //greenary if noise>100 and noise<=255 perlinmap[x,y,0].r = 0 perlinmap[x,y,0].g = noise perlinmap[x,y,0].b = 0 perlinmap[x,y,0].texture = 0 // grass perlinmap[x,y,0].level = 4 // grass SetMemblockByte(mem, offset, 0) SetMemblockByte(mem, offset+1, noise) SetMemblockByte(mem, offset+2, 0) SetMemblockByte(mem, offset+3, 255) endif //sand if noise>50 and noise<=100 perlinmap[x,y,0].r = noise perlinmap[x,y,0].g = noise perlinmap[x,y,0].b = 0 perlinmap[x,y,0].texture = 5 // sand perlinmap[x,y,0].level = 3 SetMemblockByte(mem, offset, noise) SetMemblockByte(mem, offset+1, noise) SetMemblockByte(mem, offset+2, 0) SetMemblockByte(mem, offset+3, 255) endif // water if noise>25 and noise<=50 perlinmap[x,y,0].r = 0 perlinmap[x,y,0].g = noise perlinmap[x,y,0].b = noise perlinmap[x,y,0].texture = 4 // lightwater perlinmap[x,y,0].level = 2 SetMemblockByte(mem, offset, 0) SetMemblockByte(mem, offset+1, 0) SetMemblockByte(mem, offset+2, noise) SetMemblockByte(mem, offset+3, 255) endif if noise<=25 perlinmap[x,y,0].r = 0 perlinmap[x,y,0].g = 0 perlinmap[x,y,0].b = noise perlinmap[x,y,0].texture = 3 // deep water perlinmap[x,y,0].level = 1 // deep water SetMemblockByte(mem, offset, 0) SetMemblockByte(mem, offset+1, noise) SetMemblockByte(mem, offset+2, noise) SetMemblockByte(mem, offset+3, 255) endif perlinmap[x,y,0].level=noise/40 // height - the higher value then less (lower) - the lower value is higher if perlinmap[x,y,0].level<1 then perlinmap[x,y,0].level=1 offset = offset + 4 next next mapspriteimage = CreateImageFromMemblock(mem) mapsprite=CreateImageFromMemblock(mem) endfunction mapsprite /*createMeshObjectTriangleBlock( 0, 0, 0, 10, -10, 10, 0,10) createMeshObjectTriangleBlock( 0, 0, 0, 10, 0, 10, 10,10) createMeshObjectTriangleBlock( 0, 0, 0, 10, 10, 0, 10,10) createMeshObjectTriangleBlock( 0, 0, 0, 0, 10, -10, 10,10) createMeshObjectTriangleBlock( 0, 0, 0, -10, 10, -10, 0,10) createMeshObjectTriangleBlock( 0, 0, 0, -10, 0, -10, -10,10) createMeshObjectTriangleBlock( 0, 0, 0, -10, -10, 0, -10,10) /*createMeshObjectTriangleBlock( 0, 0, 0, -size#/2,-size#/2, size#/2, -size#/2 ,size#) createMeshObjectTriangleBlock( 0, 0, 0, size#/2,-size#/2, size#/2, size#/2 ,size#) createMeshObjectTriangleBlock( 0, 0, 0, size#/2, size#/2, -size#/2, size#/2 ,size#) */ //createMeshObjectTriangleBlock(10, 0, -10, 10, 0, 0, 0 , 10) //CreateMeshObjectPlayWithTexture_Shatter(0,0,0,100,100) //SetObjectPosition(faces[0],0,0,0) // front //SetObjectRotation(faces[1],90,0,0) // top //SetObjectPosition(faces[2],0,0,0) //createmeshobjectlighthouse(0,0,0,20,10) //function createMeshObjectCylinderWithTexture(x#, y#, z#,height#, baseradius#, topradius#,segments#, top, bottom, color) //lighgthouse //createMeshObjectCylinderWithTexture(0,0,0,30,10,3,10,1,0,MakeColor(255,255,255)) //goblet /*createMeshObjectTriangleChunk( 0, 0, 0, -20, 20, 0, 0, 20, 0, 0,20,-20) createMeshObjectTriangleChunk( 0, 0, 0, 20, 20, 0, 0, 20, -20, 0,20,0) // Cube full of 24 segments // first layer createMeshObjectTriangleChunk( 0, 0, 0, -size#, size# , 0, 0, size#, size# , 0,size#,0) createMeshObjectTriangleChunk( 0, 0, 0, size#, size# , 0, 0, size#, 0 , 0,size#,size#) createMeshObjectTriangleChunk( 0, 0, 0, size#, size# , 0, size#, 0, size# , size#,0,0) createMeshObjectTriangleChunk( 0, 0, 0, size#, -size# , 0, size#, 0, 0 , size#,0,size#) createMeshObjectTriangleChunk( 0, 0, 0, size#, -size# , 0, 0, -size#, size# , 0,-size#,0) createMeshObjectTriangleChunk( 0, 0, 0, -size#, -size# , 0, 0, -size#, 0 , 0,-size#,size#) createMeshObjectTriangleChunk( 0, 0, 0, -size#, -size# , 0, -size#,0, size# , -size#,0,0) createMeshObjectTriangleChunk( 0, 0, 0, -size#, 0 , 0, -size#,0, size# , -size#,size#,0) // 2nd later createMeshObjectTriangleChunk( 0, -size#, size#, -size#, -size#, 0, -size#,-size#, size#, -size#, 0, size#) createMeshObjectTriangleChunk( 0, -size#, size#, size#, -size#, 0, size#, 0, size# ,size#,-size#, size#) createMeshObjectTriangleChunk( 0, size#, size#, size#, size#, 0, size#, size#, size# ,size#, 0, size#) createMeshObjectTriangleChunk( 0, size#, size#, -size#, size#, 0, -size#, 0, size#, -size#, size#, size#) // 3rd later createMeshObjectTriangleChunk( 0, size#, size#, -size#, size#, size#, -size#, 0, size#, -size#,size#,size#*2) createMeshObjectTriangleChunk( 0, size#, size#, size#, size#, size#, size# , size#,size#*2, size#,0, size# ) createMeshObjectTriangleChunk( 0, -size#, size#, size#, -size#, size#, size# , 0, size#, size#,-size#, size#*2 ) createMeshObjectTriangleChunk( 0, -size#, size#, -size#, -size#, size#, -size#, -size#,size#*2, -size#,0,size#) // final layer createMeshObjectTriangleChunk( 0, 0, size#*2, -size#,size#, size#*2, 0, size#, size#*2, 0,size#,size#) createMeshObjectTriangleChunk( 0, 0, size#*2, size#, size#, size#*2, 0, size#, size#, 0,size#,size#*2) createMeshObjectTriangleChunk( 0, 0, size#*2, size#, size#, size#*2, size#, 0, size#*2, size#,0,size#) createMeshObjectTriangleChunk( 0, 0, size#*2, size#, -size#, size#*2, size#, 0, size#, size#,0,size#*2) createMeshObjectTriangleChunk( 0, 0, size#*2, size#, -size#, size#*2, 0, -size#, size#*2, 0,-size#,size#) createMeshObjectTriangleChunk( 0, 0, size#*2, -size#,-size#, size#*2, 0, -size#, size#, 0,-size#,size#*2) createMeshObjectTriangleChunk( 0, 0, size#*2, -size#,-size#, size#*2, -size#,0, size#*2, -size#,0,size#) createMeshObjectTriangleChunk( 0, 0, size#*2, -size#,-size#, size#*2, -size#,0, size#*2, -size#,0,size#) createMeshObjectTriangleChunk( 0, 0, size#*2, -size#, 0, size#*2, -size#,size#, size#*2, -size#,0,size#) */ // Cube from blender //LoadObjectIntoMesh(1,"\media\ico.obj", 0,1) // 1= saves the V/VN/VTs for been able to instance it // Torus from blender //LoadObjectIntoMesh(2,"\media\torus.obj", 0,1) // 1= saves the V/VN/VTs for been able to instance it // andother object from blender //LoadObjectIntoMesh(3,"\media\test.obj", 0,1) // 1= saves the V/VN/VTs for been able to instance it /*j=0 for i=-30 to 30 // for j=-5 to 5 for k=-30 to 30 // random place an object which was loaded just before InstanceMeshObject(0, i*f2,j,k*2, MakeColor(0,random(100,200),0)) rand=random(1,10) if rand=1 then InstanceMeshObject(1, i*2,2,k*2, MakeColor(random(0,255),random(0,255),random(0,255))) if rand=2 then InstanceMeshObject(2, i*2,2,k*2, MakeColor(random(0,255),random(0,255),random(0,255))) next //next next function bworld() total=((wsize*2)+1) * ((wsize*2)+1) a=0 px#=0:pz#=size for x=-wsize to wsize pz#=0 for y=0 to 0 for z=-wsize to wsize for xx=-size to size inc px#,1 //if px>perlinw then px=0 // dec pz#,size for yy=0 to 0 for zz=-size to size inc pz#,.001 // if pz>perlinh then pz=0 if random(0,10)>=0 //yy#=perlinmap[px,pz,0].level // yy#= 255.0 * round(noise2d(px#,pz#)) yy#=random2(-1,1) InstanceMeshObject(0,0 , xx*2, yy#,zz*2, 1 ,MakeColor(0,random(100,200),0)) endif // print(px) // print(pz) // sync() // sleep(1) next next next objs[a]=CreateObjectFromMeshWithColor(meshid) emptymesh() // SetObjectScale(objs[a],x * 5, 1, z * 5) SetObjectPosition(objs[a],x * (size) * 4, y * (size), z * (size) * 4) inc a next next next maxobjects=a-1 endfunction maxobjects */