Mesh Triangle Reduction?

Blitz3D Forums/Blitz3D Programming/Mesh Triangle Reduction?

VIP3R(Posted 2004) [#1]
If I have a model mesh containing 2000 triangles, is it possible to reduce the amount of triangles used to 1000 triangles, giving the model a less smoothed look (like the opposite of sub-dividing).

I'm using Quill 3D but I can't find any function to do this, can anyone help?

Is it possible in Blitz3D to directly assign the maximum number of triangles used in a mesh automatically?


Beaker(Posted 2004) [#2]
There is a crude function to do this in your samples folder:
samples\birdie\lodmesh

It's written by the same person who wrote Quill, so I'm surprised that it doesn't have any.


jhocking(Posted 2004) [#3]
Polygon reduction is a tricky problem, and one without any really good solution. There are free tools available for that purpose, but their results aren't great. Also, most polygon reduction tools screw up texture mapping.

Best results generally require doing polygon reduction manually, by merging vertices/collapsing edges.


Zethrax(Posted 2004) [#4]
I haven't tried this tool, but if you check out the demo, it might be what you're looking for.

http://www.thegamecreators.com/?f=action3d

------


VIP3R(Posted 2004) [#5]
Thanks for the replies all, I'll take a look at the lod function and the demo.

It sounds like it would be best to design meshes using the lowest possible poly count, then sub-divide where necessary rather than design hi-poly meshes and then try poly reduction. That's ok for my own meshes, but trying to lower the poly count manually in other authors meshes looks like it will be a lot of work.

[EDIT]
The birdie lod demo is far too crude to be of any use, that is probably why it isn't used in Quill :(

But the Action3D demo looks promising, thanks again Axeman :)


Zethrax(Posted 2004) [#6]
Here's a free poly reduction tool I came across that might be worth a look.

http://www.paralelo.com.br/en/solucoes/tecnologia/progmesh/index.php


AntonyWells(Posted 2004) [#7]
Here's the first lod function I wrote for vivid. It works using a radial claw. Any verts within the claw of another vert is removed, and replaced with the original vert. This is repeated for every vert.

Then any triangles with more than 1 clashing vert(I.e repeat) are removed from the mesh. Result is it works on any
kind of mesh.

VBank=a bank containing your verts. I.e byte0=vertex0 x,byte4 =vertex0 y.
and the tri banks are simply indices to each vert.

The cool thing is you can re-use the original vert pool using this method.

Uv mapping like jhocking said though can get a little distorted with too much lod.
Function glGenLod(sdat.sdat,level=0,rad#=0.08,mathes=2)
	Local Vbank
	oBank=sdat\cVerts
	nTri=CreateBank( BankSize(sdat\cTris))
	;CopyBank(oBank,0,vBank,0,BankSize(sdat\cverts))
	Local vertSt[50000] ;Should have used banks for this.
	Local vertTo[50000]
	vertC=sdat\vc
	
;	DebugLog "Was "+vertC+" vertices"
	For v=0 To VertC-1
	
		If vertSt[v]=False
		x#=PeekFloat(obank,vo)
		y#=PeekFloat(oBank,vo+4)
		z#=PeekFloat(obank,vo+8)
		;DebugLog x+" >"+y+" z>"+z
		
		so=0
	;	DebugLog "==============Checking Vert>"+v+"----"
		For ov=0 To vertC-1
			
			tx#=PeekFloat(oBank,so)-x
			ty#=PeekFloat(oBank,so+4)-y
			tz#=PeekFloat(oBank,so+8)-z
		
			If Sqr(tx*tx+ty*ty+tz*tz)<rad ;see if it's within clipping range.
				If ov<>v ;make sure its not the same vert. quicker to check here.
					If vertSt[ov]=False
					vertSt[ov]=True
					vertTo[ov]=v
					;opti=opti+1	
				;	DebugLog "------------>"+ov
					oc=oc+1
				;	DebugLog x+" >"+y+" z>"+z
				;	DebugLog "2:"+PeekFloat(obank,so)+" >"+PeekFloat(obank,so+4)+" >"+PeekFloat(obank,so+8)
					EndIf
				Else
	;			DebugLog "nope"	
			;		DebugLog "----NOT MATCH-------->"+ov
			;		oc=oc+1
			;		DebugLog x+" >"+y+" z>"+z
			;		DebugLog "2:"+PeekFloat(obank,so)+" >"+PeekFloat(obank,so+4)+" >"+PeekFloat(obank,so+8)
	
				;s;o=so+12
				EndIf	
			Else
			;DebugLog "----NOT MATCH-------->"+ov
			;		oc=oc+1
			;		DebugLog x+" >"+y+" z>"+z
			;		DebugLog "2:"+PeekFloat(obank,so)+" >"+PeekFloat(obank,so+4)+" >"+PeekFloat(obank,so+8)

			EndIf
				so=so+12
		
		Next
		EndIf
		vo=vo+12
	Next
	;Now generate new TriList
	ctris=sdat\ctris
	nTri=CreateBank(BankSize(sdat\cTris))
	Local vI[5]
	For t=0 To sdat\tc-1
		For v=0 To 2
			vid=PeekInt(ctris,(t*12)+(v*4))
			
			If vid>49999 Stop
			If vertSt[vid]=True
				nVert=vertTo[vid]
			Else
				nVert=vid
			EndIf
			vI[v]=nVert
			PokeInt(nTri,texO+(v*4),nVert)
		Next
		did=1
		If vi[0]=vi[1] Or vi[0]=vi[2] Or vi[1]=vi[2]
	;	If vi[1]=vi[2]
			did=0
		;EndIf
		EndIf
		
		If did=1
			texO=texO+12
			tC=tC+1
		EndIf
		
	Next
	;sdat\vBufId[level]=vBank
;	sdat\lTris[level]=nTri
	
	glGenBuffersObj(1,vbank)
	glBindBufferObj( GL_ELEMENT_ARRAY_BUFFER_ARB,PeekInt(vbank,0))
	If sdat\glOptimise=0 sdat\glOptimise=glStatic
	glBufferDataObj(GL_ELEMENT_ARRAY_BUFFER_ARB,BankSize(sdat\cTris),Ntri,sdat\glOptimise)
	
	sdat\tBufId[level]=PeekInt(vbank,0)
	sdat\lTc[level]=tc
	
	FreeBank vbank
	;DebugLog "Now "+Str(vertC-opti)+" vertices"
	
	;DebugLog "saved "+oc+" verts
;	DebugLog "old Tris>"+sdat\tc
;	DebugLog "new Tri count>"+tc	
End Function