Hi guys,
My poly removal code works. It shows the right places where the poly should be hidden. You should see a half sphere when you run it.
However, if I write vertices-1 or vertices-3 in the memblock it messes up.
Here is the code:
// poly removal system by Darkvee with the help of TheComet
sync on
sync rate 60
global sk as integer
type GameType
X as float
Y as float
Z as float
NX as float
NY as float
NZ as float
TU as float
TV as float
endtype
make object sphere 1,10
// 310 is how many polys the sphere is made up
// 310/2 should remove half of the sphere
for poly = 1 to 310/2
RemovePoly(1,poly)
next poly
position camera 0,0,-20
do
inc ang
xrotate object 1,ang
yrotate object 1,ang
zrotate object 1,ang
// press spacebar to create new cube object
CreateNew_Cube()
// dbp poly counter
text 10,10,"polys: "+str$(Statistic(1))
//my poly counter
// my poly counter doesn't detect the sphers polys
// however it detects other objects.
text 10,20,"myPolyCounter: "+str$(CountPolys(1))
sync
loop
end
function RemovePoly(obj,index)
// if object doesn't exist exit function
if object exist(obj)=0 then exitfunction
// get free mesh and memblock
freeMesh = find free mesh()
freeMem = find free memblock()
// make mesh from a object
make mesh from object freeMesh,obj
// delete object
delete object obj
// make a memblock from mesh
make memblock from mesh freeMem,freeMesh
// get vertexSize and number of vertices in memblock
vertexSize = memblock dword(freeMem,4)
numberOfVertices = memblock dword(freeMem,8)
local dim myArray(vertexSize*numberOfVertices) as GameType
// offset value to pick the right poly
num = index
// use the offset to remove the right only
if index = 1 then index = 0
if index > 1 then index = num+3
for x = 1 to 3
for c = index to (numberOfVertices/2)-1
// get memblock position
memBlockPos = 12 + c*vertexSize
// get vertex x,y,z
x# = memblock float(1,memBlockPos)
y# = memblock float (1,memBlockPos+4)
z# = memblock float(1,memBlockPos+8)
//get vertex normals x,y,z
nx# = memblock float(1,memBlockPos+12)
ny# = memblock float (1,memBlockPos+16)
nz# = memblock float(1,memBlockPos+20)
//get vertex texcoords u,v
u# = memblock float(1,memBlockPos+24)
v# = memblock float (1,memBlockPos+28)
// put vertex position in array
myArray(c).X = x#
myArray(c).Y = y#
myArray(c).Z = z#
// put vertex normals in array
myArray(c).NX = nx#
myArray(c).NY = ny#
myArray(c).NZ = nz#
// put vertex texcoords in array
myArray(c).TU = u#
myArray(c).TV = v#
// now shift vertex position we remove it
myArray(c).X = myArray(c+1).X
myArray(c).Y = myArray(c+1).Y
myArray(c).Z = myArray(c+1).Z
// now shift vertex normals we remove it
myArray(c).NX = myArray(c+1).NX
myArray(c).NY = myArray(c+1).NY
myArray(c).NZ = myArray(c+1).NZ
// now shift vertex texcoords we remove it
myArray(c).TU = myArray(c+1).TU
myArray(c).TV = myArray(c+1).TV
//write vertex position to memblock
write memblock float 1,memBlockPos,myArray(c).X
write memblock float 1,memBlockPos+4,myArray(c).Y
write memblock float 1,memBlockPos+8,myArray(c).Z
//write vertex normals to memblock
write memblock float 1,memBlockPos+12,myArray(c).NX
write memblock float 1,memBlockPos+16,myArray(c).NY
write memblock float 1,memBlockPos+20,myArray(c).NZ
//write vertex texcoords to memblock
write memblock float 1,memBlockPos+24,myArray(c).TU
write memblock float 1,memBlockPos+28,myArray(c).TV
next c
// increase index to remove 3 vertexes
inc index
next x
// if I don't write anything it works
// if I do write vertices-1 or vertices-3 messes up
write memblock dword freeMem,8,numberOfVertices
write memblock dword freeMem,4,vertexSize
// create mesh from memblock and create the object with poly removed
make mesh from memblock freeMesh,freeMem
make object obj,freeMesh,0
// delete memblock and mesh
delete memblock freeMem
delete mesh freeMem
endfunction
function CreateNew_Cube()
if spacekey()=1 and sk = 0
sk = 1
newObj = find free object()
make object cube newObj,10
else
if spacekey()=0
sk = 0
endif
endif
endfunction
function CountPolys(polyNum)
for i = 1 to polyNum
if object exist(i)=1
lock vertexdata for limb i,0,2
numberOfVertices = get vertexdata vertex count()
numberOfPolygons = get vertexdata index count()/3
unlock vertexdata
result = result + numberOfPolygons
inc polyNum
else
if object exist(i)=0
break
endif
endif
next i
endfunction result
Also I made my own poly counter. Mine poly counter doesn't even pick up the sphere from when I rebuilt it. However, if you press spacekey it will create a new cube and it shows my poly counter works.
You think you can help me fix this guys thanks
darkvee