I have now imported texturing for the OBJ
// 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( 0, 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#
// *************************************************
// ** Mesh Memblock Types - please dont upset these variables
// *************************************************
global Cubed, VertexCount, MaxObjects, object, memblock
global peices as integer[]
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
// *************************************************
size=8
cubed=LoadImage("cube.png")
loadobjects()
InstanceMeshObject(0,0 , 0,0,0, 1 , MakeColor(0, random(100,200),0))
object = CreateObjectFromMeshWithUVTexturing(meshid,cubed)
/*object = buildworld(size,3,size)
// create a clone of the above creation -7 x 7 surround the players play area chunk but with alpha (cause we wouldnt want to suggest
// it is a clone
buildfarworld(object, size*2, 3,3,5)
ocean = CreateObjectPlane(10000,10000)
SetObjectColor(ocean,0,0,70,255)
SetObjectRotation(ocean, 90,0,0)
setupskyandfog()
setupcamera()
*/
do
RotateObjectLocalX(object,.05)
RotateObjectLocalY(object,.05)
RotateObjectLocalZ(object,.05)
// movecamerawithmouse()
print (maxobjects)
if GetRawKeyState (32) // delete and object
deletemeshobject(random(0,maxobjects),object,meshid)
endif
if GetRawKeyState(87) then inc cameray#,.1
if GetRawKeyState(83) then dec cameray#,.1
if cameray#<4 then cameray#=4
// SetCameraPosition(1,camerax#,cameray#,cameraz#)
// cull_objs_behind_camera()
// Debug stuff
print ("WASD to move camera up or down")
print ("Press Space to delete an object")
print("FPS " + str(ScreenFPS()) + " - Last Key" + str(GetRawLastKey()))
Sync()
loop
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)
c=0
for x=-sizex to sizex
for y=-sizey to sizey
for z=-sizez to sizez
if random(0,10)>5
// 0 - cube
InstanceMeshObject(0,c , x*2, y * 2,z*2, 1 , MakeColor(0, random(100,200),0))
inc c
endif
if y=sizey
// add tree on a cube
if random(0,100)>99
InstanceMeshObject(1,c , x*2, y+3,z*2, 1 , MakeColor(0, random(100,200),0))
inc c
endif
// add ico on a cube
if random(0,100)>99
InstanceMeshObject(2,c , x*2, y+3,z*2, 1 , MakeColor(random(0,255),random(0,255),random(0,255)))
inc c
endif
// add torus on a cube
if random(0,100)>99
InstanceMeshObject(3,c , x*2, y+3,z*2, 1 , MakeColor(random(0,255),random(0,255),random(0,255)))
inc c
endif
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(0,"\media\cube.obj", "",0,1) // 1= saves the V/VN/VTs for been able to instance it
// LoadObjectIntoMesh(1,"\media\tree.obj", "",0,1) // 1= saves the V/VN/VTs for been able to instance it
// LoadObjectIntoMesh(2,"\media\ico.obj", "",0,1) // 1= saves the V/VN/VTs for been able to instance it
// LoadObjectIntoMesh(3,"\media\torus.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(0,0,70)//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,10000)
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#, scale#, 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
AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x# * scale#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y# * scale#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# * scale# ,nx#,ny#,nz#, objectmesh[id].textures[objectmesh[id].faces[a].tindex].u# ,objectmesh[id].textures[objectmesh[id].faces[a].tindex].v#,Color)
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
AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# ,nx#,ny#,nz#, 0,0,color)
AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].x#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].y#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+1].vindex].z# ,nx#,ny#,nz#, 0,0,color)
AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].x#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].y#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].z# ,nx#,ny#,nz#, 0,0,color)
AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].x#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].y#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+2].vindex].z# ,nx#,ny#,nz#, 0,0,color)
AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].x#, y#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].y#, z#+objectmesh[id].vertex[objectmesh[id].faces[a+3].vindex].z# ,nx#,ny#,nz#, 0,0,color)
AddVertex(MeshID, x#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].x#, y#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].y#, z#+objectmesh[id].vertex[objectmesh[id].faces[a].vindex].z# ,nx#,ny#,nz#, 0,0,color)
// 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
// objectmesh.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
// 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
/*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
*/
Used your OBJ data as an example and testing
Let me know how you get on
I just used a bog standard image and doesnt look right - but your material that you used to create the object maybe just slightly "spriteysheet" style / organised better to acheive the best result
I shall now tidy code up a bit and apply the texture to polygon x 4 objects