Calculating Normals Speed Tips

BlitzMax Forums/BlitzMax Programming/Calculating Normals Speed Tips

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

If all else fails, try this. Use it myself on a p2-350 without any slow down on bigger meshes.

	Local VCon:Double[ vIndex +3];
				
				While Index<vIndex
					
					Norms[Index]=0
					Index:+1
				
				Wend
				
				Index = 0
				
				While Index<TIndex
							
					V0 = Tris[ Index ] 
					V1 = Tris[ Index +1 ] 
					V2 = Tris[ Index +2 ] 
					
					Vec1.Set3D( Verts[ V0*3],Verts[ V0*3+1],Verts[ V0*3+2] )
					Vec2.Set3D( Verts[ V1*3],Verts[ V1*3+1],Verts[ V1*3+2] )
					Vec3.Set3D( Verts[ V2*3],Verts[ V2*3+1],Verts[ v2*3+2] )
					
					VecB1.CoPlaner( Vec1,Vec2 )
					VecB2.CoPlaner( Vec1,Vec3 )
			
					Norm.DotProduct3D( VecB1,VecB2 ) 
					Norm.Normalize()
					
					TNorms[ Index ] = Norm.Vec[0]
					TNorms[ Index+1 ] = Norm.Vec[1]
					TNorms[ Index+2 ] = Norm.Vec[2]
					
					VCon[V0]:+1
					VCon[V1]:+1
					VCon[V2]:+1
					
					Norms[ V0*3]:+Norm.Vec[0]
					Norms[ V0*3+1]:+Norm.Vec[1]
					Norms[ V0*3+2]:+Norm.Vec[2]
					
					Norms[ V1*3]:+Norm.Vec[0]
					Norms[ V1*3+1]:+Norm.Vec[1]
					Norms[ V1*3+2]:+Norm.Vec[2]
					
					
					Norms[ V2*3]:+Norm.Vec[0]
					Norms[ V2*3+1]:+Norm.Vec[1]
					Norms[ V2*3+2]:+Norm.Vec[2]
					
												
					Index:+3
					
				Wend
				
				Index=0
				Local CIndex:Int
								
				While Index<vIndex
					
					If VCon[Index] = 0 VCon[Index]=0.0001
					
					Norm.Set3D( Norms[Index]/VCon[CIndex],Norms[Index+1]/VCon[CIndex],Norms[Index+2]/Vcon[CIndex])
					Norm.Normalize()
					Norms[Index]=Norm.X()
					norms[Index+1]=Norm.Y()
					Norms[Index+2]=Norm.Z()
										
					CIndex:+1	
					Index:+3
				
				Wend
					
				
			


Rename the maths funcs to whichever you're using, all standard ops.