// normalBaker.ls // Fixed by Alexx - 22/04/2006 @version 2.3 @warnings @script modeler @name Normal Baker @define VMAP_NORM @'N','M','B','K'@ main { normals = nil; // used to visualize normals ppos = nil; pointNorm = <0,0,0>; normVal = @0,0,0@; selmode(USER); editbegin(); ttlPnts = pointcount(); if(!ttlPnts) { error("
You must have geometry to perform this operation"); return; } normMap = VMap(VMAP_NORM,"pnt_normals"); if(normMap.isNil()) normMap = VMap(VMAP_NORM,"pnt_normals",3) || error("Can't generate VMap!"); pointCnt = pointcount(); for(x = 1;x <= pointCnt;x++) { rawPolys = points[x].polygon(); polyCnt = size(rawPolys); normlst = array; for(y = 1;y <= polyCnt;y++) { workVal = polynormal(rawPolys[y]); normlst += string(workVal); } normlst.sortA(); normlst.reduce(); normlst.pack(); normlst.trunc(); normVal=<0,0,0>; foreach(n,normlst){ normVal += n.asVec(); } normVal /= sizeof(normlst); normMap.setValue(points[x],normVal); normals += normVal; ppos += pointinfo(points[x]); } editend(); // now, show the normals generated empty = lyrempty(); fg = lyrfg(); bg = lyrbg(); for(x = 1;x <= pointCnt;x++) { lyrsetfg(empty[2]); editbegin(); p[1] = addpoint(<0,0,0>); p[2] = addpoint(normals[x]); addpolygon(p); editend(); move(ppos[x]); cut(); lyrsetfg(empty[1]); paste(); } lyrsetbg(fg); }