Top Radius# = 57 creates the blades for the wind turbine
// Project: Mesh Objects
// Created: 2018-08-04
// show all errors
SetErrorMode(2)
#constant PI# = 3.14159265359
// set window properties
SetWindowTitle( "Mesh Objects" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // 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
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
global CubeD, Object, fall#, falltimer#, falling, pivot
CubeD =LoadImage("\media\cube.png")
//CreateMeshObjectBoxWithTexture(0,0,0,10,10,10)
global faces as integer[5]
global size#=30
global peices as integer[]
//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
falling=0
fall#=10
explode=0
SetCameraPosition(1,0,20,-50)
SetCameraRange(1,0.1,3000)
//SetObjectRotation(object,90,0,0)
pattern=0
do
if GetRawKeyPressed(32)
DeleteObject(object)
emptymesh()
createMeshObjectCylinderWithTexture(0,0,0,10,10,pattern,3,0,0,MakeColor(255,255,255))
object = CreateObjectFromMeshWithColor(meshid)
inc pattern
endif
Print ("Press Space for different shape")
print ("Top Radius# = " + str(pattern))
Print( ScreenFPS() )
Sync()
loop
function createmeshobjectlighthouse(x#, y#, z#, basewidth#, height#)
CreateMeshObjectConeWithTexture(height#,50,basewidth#,0)
endfunction
function emptymesh()
MeshID.VertexList.Length=-1
MeshID.TriangleList.Length=-1
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#,height#)
Color=MakeColor(255,255,255)
z3#=z2#
// bottom
AddVertex(MeshID, x#, y#, z# , 0 ,-1,0, 0,0.5,Color)
AddVertex(MeshID, x3#, y#, z3# , 0 ,-1,0, .5,.5,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,-1,0, .5,.5,Color)
// side 1
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
// side 2
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x3#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x3#, y#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x3#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
// side 3
AddVertex(MeshID, x3#, y#, z2# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x3#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x3#, y#, z2# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, .5,.5,Color)
// AddVertex(MeshID, x#, y#+height#, z3# , 0 ,1,0, .5,.5,Color)
// top
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, .5,.5,Color)
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,32) // 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
// SetMemblockFloat(memblock,104+i*36,m.VertexList[i].color) //maybe one day or year in 2019 lol
// 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
function fallingcode()
if GetRawKeyPressed(32)
falling=1
falltimer#=timer()
endif
if falling=1
rebuildcube()
endif
if timer()-falltimer#>3.0
// inc fall#,1
explode=1
endif
endfunction
function rebuildcube()
DeleteObject(pivot)
pivot = CreateObjectSphere(.01,.01,.01)
DeleteObject(faces[0])
DeleteObject(faces[1])
DeleteObject(faces[2])
DeleteObject(faces[3])
DeleteObject(faces[4])
DeleteObject(faces[5])
for a=0 to 5 // 5 faces for a cube
// this empties the mesh
MeshID.TriangleList.length=-1
MeshID.VertexList.length=-1
CreateMeshObjectPlayWithTexture_Shatter(0,0,0,size#,size#)
faces[a] = CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)
if a=1
SetObjectRotation(faces[a],90,0,0)
SetObjectPosition(faces[a],0,size#/2,size#/2)
endif
if a=2
SetObjectRotation(faces[a],270,0,0)
SetObjectPosition(faces[a],0,-size#/2,size#/2)
endif
if a=3
SetObjectRotation(faces[a],0,180,0)
SetObjectPosition(faces[a],0,0,size#)
endif
if a=4
SetObjectRotation(faces[a],0,270,0)
SetObjectPosition(faces[a],size#/2,0,size#/2)
endif
if a=5
SetObjectRotation(faces[a],0,90,0)
SetObjectPosition(faces[a],-size#/2,0,size#/2)
endif
FixObjectToObject(faces[a],pivot)
next
endfunction
EDIT - change the segments# too for other nice effects - say top radius#=50 and segments=30
// Project: Mesh Objects
// Created: 2018-08-04
// show all errors
SetErrorMode(2)
#constant PI# = 3.14159265359
// set window properties
SetWindowTitle( "Mesh Objects" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // 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
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
global CubeD, Object, fall#, falltimer#, falling, pivot
CubeD =LoadImage("\media\cube.png")
//CreateMeshObjectBoxWithTexture(0,0,0,10,10,10)
global faces as integer[5]
global size#=30
global peices as integer[]
//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
falling=0
fall#=10
explode=0
SetCameraPosition(1,0,20,-50)
SetCameraRange(1,0.1,3000)
//SetObjectRotation(object,90,0,0)
pattern=0
do
if GetRawKeyPressed(32)
DeleteObject(object)
emptymesh()
createMeshObjectCylinderWithTexture(0,0,0,10,10,50,30,0,0,MakeColor(255,255,255))
object = CreateObjectFromMeshWithColor(meshid)
inc pattern
endif
if GetObjectExists(object) then RotateObjectLocalY(object,.1)
Print ("Press Space for different shape")
print ("Top Radius# = " + str(pattern))
Print( ScreenFPS() )
Sync()
loop
function createmeshobjectlighthouse(x#, y#, z#, basewidth#, height#)
CreateMeshObjectConeWithTexture(height#,50,basewidth#,0)
endfunction
function emptymesh()
MeshID.VertexList.Length=-1
MeshID.TriangleList.Length=-1
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#,height#)
Color=MakeColor(255,255,255)
z3#=z2#
// bottom
AddVertex(MeshID, x#, y#, z# , 0 ,-1,0, 0,0.5,Color)
AddVertex(MeshID, x3#, y#, z3# , 0 ,-1,0, .5,.5,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,-1,0, .5,.5,Color)
// side 1
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
// side 2
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x3#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x2#, y#, z2# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x3#, y#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x3#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
// side 3
AddVertex(MeshID, x3#, y#, z2# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x3#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x3#, y#, z2# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x#, y#, z# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, .5,.5,Color)
// AddVertex(MeshID, x#, y#+height#, z3# , 0 ,1,0, .5,.5,Color)
// top
AddVertex(MeshID, x#, y#+height#, z# , 0 ,1,0, 0,0.5,Color)
AddVertex(MeshID, x2#, y#+height#, z2# , 0 ,1,0, .5,.5,Color)
AddVertex(MeshID, x3#, y#+height#, z3# , 0 ,1,0, .5,.5,Color)
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,32) // 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
// SetMemblockFloat(memblock,104+i*36,m.VertexList[i].color) //maybe one day or year in 2019 lol
// 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
function fallingcode()
if GetRawKeyPressed(32)
falling=1
falltimer#=timer()
endif
if falling=1
rebuildcube()
endif
if timer()-falltimer#>3.0
// inc fall#,1
explode=1
endif
endfunction
function rebuildcube()
DeleteObject(pivot)
pivot = CreateObjectSphere(.01,.01,.01)
DeleteObject(faces[0])
DeleteObject(faces[1])
DeleteObject(faces[2])
DeleteObject(faces[3])
DeleteObject(faces[4])
DeleteObject(faces[5])
for a=0 to 5 // 5 faces for a cube
// this empties the mesh
MeshID.TriangleList.length=-1
MeshID.VertexList.length=-1
CreateMeshObjectPlayWithTexture_Shatter(0,0,0,size#,size#)
faces[a] = CreateObjectFromMeshWithUVTexturing(MeshID,CubeD)
if a=1
SetObjectRotation(faces[a],90,0,0)
SetObjectPosition(faces[a],0,size#/2,size#/2)
endif
if a=2
SetObjectRotation(faces[a],270,0,0)
SetObjectPosition(faces[a],0,-size#/2,size#/2)
endif
if a=3
SetObjectRotation(faces[a],0,180,0)
SetObjectPosition(faces[a],0,0,size#)
endif
if a=4
SetObjectRotation(faces[a],0,270,0)
SetObjectPosition(faces[a],size#/2,0,size#/2)
endif
if a=5
SetObjectRotation(faces[a],0,90,0)
SetObjectPosition(faces[a],-size#/2,0,size#/2)
endif
FixObjectToObject(faces[a],pivot)
next
endfunction