mesh vert/tri limit?

Blitz3D Forums/Blitz3D Programming/mesh vert/tri limit?

big10p(Posted 2004) [#1]
Hi

I know there's a 65536 vert and tri limit for each surface in a mesh but is there an overall limit for the entire mesh? I'm trying to stuff a load of stuff into a single mesh - creating a new surface when the current gets full - but get a MAV on RenderWorld when I hit some limit. If there is an overall vert limit per mesh, nayone know what it is?

Cheers!


fredborg(Posted 2004) [#2]
Hi,

Try this:
Graphics3D 640,480,0,2
SetBuffer BackBuffer()

mesh = CreateMesh()
surf = CreateSurface(mesh)

count  = 0

camera = CreateCamera()

Repeat

	v0 = AddVertex(surf,Rnd(-10,10),Rnd(-10,10),Rnd(100,1000))
	v1 = v0-1
	v2 = v0-2
	If v1<0 Then v1 = 0
	If v2<0 Then v2 = 0
	t = AddTriangle(surf,v0,v1,v2)

	If v0=>65535 Or t=>65535
		surf = CreateSurface(mesh)
		count = count + v0 + 1
	EndIf

	If (v0 Mod 1000) = 0
		RenderWorld
		Text 0,0,count+v0+1
		Flip False
	End If

Until KeyHit(1)
End
I get a memory access violation when I hit 61000 poly's...Strange!

But with this, it keeps on going:
Graphics3D 640,480,0,2
SetBuffer BackBuffer()

mesh = CreateMesh()
surf = CreateSurface(mesh)
PositionEntity mesh,0,0,100

count  = 0

camera = CreateCamera()

Repeat

	v0 = AddVertex(surf,Rnd(-10,10),Rnd(-10,10),Rnd(-10,10))
	v1 = v0-1
	v2 = v0-2
	If v1<0 Then v1 = 0
	If v2<0 Then v2 = 0
	t = AddTriangle(surf,v0,v1,v2)

	If v0=>32767 Or t=>32767
		surf = CreateSurface(mesh)
		count = count + v0 + 1
	EndIf

	If (v0 Mod 1000) = 0
		TurnEntity mesh,1,1,1
		RenderWorld
		Text 0,0,count+v0+1
		Flip False
	End If

Until KeyHit(1)
End
I think it uses signed shorts to store triangles, which means the limit is effectively 32768 tri's per surface. I don't know who signed the shorts though, and quite how you store triangles with signed shorts is still somewhat of a mystery to me.

Correct me if I'm wrong!


Floyd(Posted 2004) [#3]
61001 is the last value displayed.
But the debugger shows that v0 actually reached 62000.

I always thought the limit was 2^16. Looks like it is a little less.


fredborg(Posted 2004) [#4]
The limit is: 61223 for some obscure reason. No signed shorts then :)

Hmmm, no it isn't I think the limit is actually 32768. If you change the 'mod 1000' to 'mod 100' the MAV happens at a different triangle count...

This works always:
Graphics3D 640,480,0,2
SetBuffer BackBuffer()

mesh = CreateMesh()
surf = CreateSurface(mesh)
PositionEntity mesh,0,0,100

count  = 0

camera = CreateCamera()

Repeat

	While t<32768
		v0 = AddVertex(surf,Rnd(-10,10),Rnd(-10,10),Rnd(-10,10))
		v1 = v0-1
		v2 = v0-2
		If v1<0 Then v1 = 0
		If v2<0 Then v2 = 0
		t = AddTriangle(surf,v0,v1,v2)
	Wend

	surf = CreateSurface(mesh)
	count = count + t + 1
	t = 0

	TurnEntity mesh,1,1,1
	RenderWorld
	Text 0,0,count
	Flip False

Until KeyHit(1)
End



big10p(Posted 2004) [#5]
Wow, that was a quick response, Fredborg! ;)

I don't think signed shorts are being used to store triangles because the max I can get the surface triangle count up to is 61223 - 61224 gets a MAV. Then, I thought maybe the top couple of bits are being used as flags of somesort but 61223 in binary is 1110111100100111, so that idea's out.

This makes no sense to me - I wonder what's going on?


fredborg(Posted 2004) [#6]
Yeah, it's weird. If you change:
	If (v0 Mod 1000) = 0
to:
	If (v0 Mod 100) = 0
In the top code example. I get a MAV when it reaches 47201. If you change it to 'Mod 10' I get a crash at 53931, So I think it's just some weird thing that let's it go beyond 32768. Maybe not, but 32768 seems to be crash proof :)


big10p(Posted 2004) [#7]
Hmm, but if you change 32768 to 65534 in the new code (without the mod), everything seems OK. 65535 crashes! :/


fredborg(Posted 2004) [#8]
But obviously that can't be right as it crashes some of the previous examples :)


big10p(Posted 2004) [#9]
Oh yeah! I have the memory of a goldfish. :)


Floyd(Posted 2004) [#10]
If anyone is not confused enough:
Const MagicNumber = 43700  ; try 43600

SeedRnd MilliSecs()

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

mesh = CreateMesh()
surf = CreateSurface(mesh)

count  = 0

camera = CreateCamera()

Repeat

	v0 = AddVertex(surf,Rnd(-10,10),Rnd(-10,10),Rnd(100,1000))
	v1 = AddVertex(surf,Rnd(-10,10),Rnd(-10,10),Rnd(100,1000))
	v2 = AddVertex(surf,Rnd(-10,10),Rnd(-10,10),Rnd(100,1000))
	
	t = AddTriangle(surf,v0,v1,v2)

	If v0 > MagicNumber
		RenderWorld
		Text 0,0,"v0 = " + v0
		Text 0,20," t = " + t
		Flip False
	End If

Until KeyHit(1)
End

When I start rendering at 43700 the program dies immediately.
But starting from 43600 it goes all the way to 65406.


big10p(Posted 2004) [#11]
...and even more confusion:

Const MagicNumber = 43700  ; try 43600

SeedRnd MilliSecs()

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

mesh = CreateMesh()
surf = CreateSurface(mesh)

count  = 0

camera = CreateCamera()

foo# = .1 ; .1 causes crash but 1.0 or 1.1 dont!

Repeat

	v0 = AddVertex(surf,foo,1,1)
	v1 = AddVertex(surf,1,foo,1)
	v2 = AddVertex(surf,1,1,foo)
	
	t = AddTriangle(surf,v0,v1,v2)

	If v0 > MagicNumber
		RenderWorld
		Text 0,0,"v0 = " + v0
		Text 0,20," t = " + t
		Flip False
	End If

Until KeyHit(1)
End



The position the verts are placed at seems to make a difference. :/


jhocking(Posted 2004) [#12]
Whee! Up is down! Left is right! Night is day!


big10p(Posted 2004) [#13]
heh, never ceases to amaze me how the pure logic of computers often seems to be so illogical. :/