1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| vector pos0 = point(0, "P", 0); vector uv0= point(0, "uv_transfered", 0); vector avgNormal = normalize(v@avgN); float anglesum = 0; vector center = getbbox_center(0) ; vector uvcenter = (0,0,0);
for(int i = 1; i < @numpt; i++){ uvcenter += point(0, "uv_transfered", i); } uvcenter /= (@numpt - 1); vector up = (0,1,0); up.y = 1; vector avgPlaneX = cross(up, avgNormal); vector avgPlaneY = cross(avgNormal, avgPlaneX); v@avgX = avgPlaneX; v@avgY = avgPlaneY;
for(int i = 1; i < @numpt; i++){ vector thispos = point(0, "P", i); vector thisuv = point(0, "uv_transfered", i); vector position_offset = (thispos - center); vector uv_offset = normalize(thisuv - uvcenter);
float position_offset_project_on_angN = dot(avgNormal, position_offset);
vector position_offset_project_on_angNPlane = position_offset - position_offset_project_on_angN * avgNormal; float onX = dot(avgPlaneX, position_offset_project_on_angNPlane); float onY = dot(avgPlaneY, position_offset_project_on_angNPlane); vector onAvgPlane = (0,0,0); onAvgPlane.x = onX; onAvgPlane.y = onY; //setpointattrib(0, "P", i, center + onX * avgPlaneX + onY * avgPlaneY);
float dot = dot(normalize(onAvgPlane), uv_offset); float angle = acos(dot); vector crossangle = cross(normalize(onAvgPlane), uv_offset); if(crossangle.z>0){ if(dot > 0){ angle = -angle; } else{ angle = 2*3.1416 - angle; } }
anglesum += angle; setpointattrib(0, "errorness", i, dot); //setpointattrib(0, "errorness", i, angle * 360 / (2 * 3.14159)); setpointattrib(0, "pos_offset", i, normalize(onAvgPlane)); setpointattrib(0, "uv_offset", i, uv_offset); //@errorness = dot(position_offset, uv_offset); }
anglesum /= (@numpt - 1); @anglesum = anglesum * 360 / (2 * 3.14159);
|