Cel-Shading in Blitz3D

Blitz3D Forums/Blitz3D Programming/Cel-Shading in Blitz3D

Not that I've really ever tried cel shading, but if you want to extude a tri in the direction it's facing, no matter what type of mesh it is, do this.

function extrude(mesh,extrude#=1)
local vp[3]
     for j=0 to countSurfaces(mesh)
          srf=getSurface(mesh,j)
          for k=0 to countTriangles(srf)-1
               v0=triangleVertex(srf,k,0)
               v1=trianglevertex(srf,k,1)
               v2=trianglevertex(Srf,k,2)
               triNrom(vertexX(srf,v0),vertexy(srf,v0),vertexz(srf,v0),vertexx(srf,v1),vertexy(srf,v1),vertexz(srf,v1),vertexz(srf,v2),vertexy(srf,v2),vertexnz(srf,v2))
               for v=0 to 2
                   vert=triangleVertex(srf,v)
                   vertexcoords srf,vertexX(srf,vert)+triNX*extrude,vertexY(srf,vert)+triNY*extrude,vertexZ(srf,vert)+triNZ*extrude
               next
          next
     next
endfunction

global triNX,triNY,triNZ
Function TriNorm(x1#, y1#, z1#, x2#, y2#, z2#, x3#, y3#, z3#)
    ux#= x1# - x2#
    uy#= y1# - y2#
    uz#= z1# - z2#
    vx#= x3# - x2#
    vy#= y3# - y2#
    vz#= z3# - z2#	
    nx#= (uy# * vz#) - (vy# * uz#)
    ny#= (uz# * vx#) - (vz# * ux#)  
    nz#= (ux# * vy#) - (vx# * uy#)
    nl#= Sqr((nx*nx) + (ny*ny) + (nz*nz))  
    If NormLen > 0
		nx = nx/NL 
            ny = ny/NL
            nz = nz/NL
	Else
		nx = 0 : ny = 0 : nz = 1
	EndIf
	TriNX = nx
	TriNY = ny
	TriNZ = nz
End Function


extrude =scale of extrud..err...extrudation..(cough). Go well below 1 or you'll just create one funky looking mesh.



(Not tested..so use at your own caution...;)