Your welcome
There is 5000 AppGameKit instance objects of them now - thank you Peben with his awesome framerate work!!
// Project: Mesh Objects
// Created: 2018-08-04
// TO DO - Save Primative Objects to OBJ so can model them in blender and such like
// 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#
// *************************************************
// ** 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
// *************************************************
// setup perlin data and map
//initialiseperlin()
//loadobjects()
fern = LoadObject("\media\fern.obj")
size=5000
for a=0 to size
fern = InstanceObject(fern)
SetObjectPosition(fern, random(-100,100),0,random(-100,100))
SetObjectColor(fern,0,random(100,200),0,255)
// InstanceMeshObject(1,1,random(-size,size),0 ,random(-size,size),3,3,3,MakeColor(0,random(100,200),0),1)
next
//object=CreateObjectFromMeshWithColor(meshid)
//emptymesh()
size=20
SetCameraPosition(1,50,20,3)
do
// RotateObjectLocaly(object,.01)
print (ScreenFPS())
Sync()
loop
function loadobjects()
LoadObjectIntoMesh(1,"\media\fern.obj", "",0,1) // 1= saves the V/VN/VTs for been able to instance it
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, inverted)
mv as _meshmemblockvertexes
mv.id = ObjID
mv.vfrom = vertexcount
indices=0
if objectmesh[id].polygon=0
for a=0 to objectmesh[id].faces.length-2 step 2
// 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)
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+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)
inc indices,2
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)
inc indices,1
endif
// 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
if inverted = 0
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
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+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+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].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+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)
endif
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)
//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)
//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)
//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(1)
objectmesh[id].polygon=1
else
sleep(1)
if len(face3$)>1
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)
else
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)
endif
if objectmesh[id].polygon<>1
objectmesh[id].polygon=0
endif
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
function emptymesh()
MeshID.VertexList.Length=-1
MeshID.TriangleList.Length=-1
endfunction
Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, 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