Created
November 2, 2019 21:18
-
-
Save RH2/890be5871b80af398996898b8ae901bd to your computer and use it in GitHub Desktop.
(first attempt, not fully functional)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pointArray = npoints(0); | |
int processedPoints[]={}; | |
int edgeList[]; //ds: ai,at,bi,bt,ci,ct.... | |
int faceList[]; //ds: aa,ab,ba,bb.... | |
float edgeAngles[]; | |
vector edgeMid[]; | |
int pass; | |
//go through all points that have not been processed already | |
for(int i = 0 ; i<pointArray;i++){ | |
int thispoint = i; | |
int found = find(processedPoints,thispoint); | |
if(found<0){ | |
int ns[] = neighbours(0,thispoint); | |
//create filtered neightbour list that excludes processed points. | |
int ns2[]; | |
foreach(int neigh; ns){ | |
if(find(processedPoints,neigh)>-1){ | |
push(ns2,neigh); | |
} | |
} | |
foreach(int fn; ns2){ | |
//create list of edges | |
push(edgeList,thispoint); | |
push(edgeList,fn); | |
} | |
push(processedPoints,thispoint); | |
} | |
} | |
//for each edge, there should be two adjacent faces. | |
for(int e=0; e<len(edgeList);e=e+2){ | |
int p1 = edgeList[e]; | |
int p2 = edgeList[e+1]; | |
int faces1[] = pointprims(0,p1); | |
int faces2[] = pointprims(0,p2); | |
//now we find the two faces that exist in both sets. | |
int overlapFaces[]; | |
foreach(int face1; faces1){ | |
//try to find it in faces2 | |
if(find(faces2,face1)){push(overlapFaces, face1);} | |
} | |
//write the frist two elements of overlapFaces to the facelist | |
push(faceList,overlapFaces[0]); | |
push(faceList,overlapFaces[1]); | |
} | |
//printf("processedPoints: %f\\n",processedPoints); | |
//now we have the edges and the faces. Now it's time to calculate the edge angles. | |
for(int f=0;f<len(faceList);f=f+2){ | |
vector a = point(0,"P",edgeList[f]); | |
vector b = point(0,"P",edgeList[f+1]); | |
vector c = lerp(a,b,0.5); | |
int f1 = faceList[f]; | |
int f2 = faceList[f+1]; | |
vector pnorm1 = normalize(prim_normal(0, f1, 0.5, 0.5)); | |
vector pnorm2 = normalize(prim_normal(0, f2, 0.5, 0.5)); | |
float dot = dot(pnorm1,pnorm2); | |
printf("dot: %f\\n",dot); | |
float angle = acos(dot)*180/3.14159264; | |
push(edgeAngles,angle); | |
push(edgeMid, c); | |
int aVerts[]= pointvertices(0,edgeList[f]); | |
int bVerts[]= pointvertices(0,edgeList[f+1]); | |
int f1verts[] = primvertices(0,f1); | |
int f2verts[] = primvertices(0,f2); | |
//highly inefficient* | |
//first we find a and b verts in face 1. | |
int v1,v2,v3,v4; //create two points because edge could be split. | |
foreach(int aVert;aVerts){ | |
if(find(f1verts,aVert)>-1){//if we find a result, we write and escape. | |
v1= aVert; | |
} | |
} | |
foreach(int bVert;bVerts){ | |
if(find(f1verts,bVert)>-1){//if we find a result, we write and escape. | |
v2= bVert; | |
} | |
} | |
foreach(int aVert;aVerts){ | |
if(find(f2verts,aVert)>-1){//if we find a result, we write and escape. | |
v3= aVert; | |
} | |
} | |
foreach(int bVert;bVerts){ | |
if(find(f2verts,bVert)>-1){//if we find a result, we write and escape. | |
v4= bVert; | |
} | |
} | |
//find midpoint uv angle | |
vector uv1,uv2,uv3,uv4,uvMid1,uvMid2; | |
uv1 = vertex(0,"uv",v1); | |
uv2 = vertex(0,"uv",v2); | |
uv3 = vertex(0,"uv",v3); | |
uv4 = vertex(0,"uv",v4); | |
uvMid1 = lerp(uv1,uv2,0.5); | |
uvMid2 = lerp(uv3,uv4,0.5); | |
//create a point with a position, uv, and angle attribute. | |
int newpoint = addpoint(0,c); | |
int pass2 = setpointattrib(0,"angle",newpoint,angle,"set"); | |
int pline1 = addprim(0,"polyline"); | |
int newVertex1 = addvertex(0,pline1,newpoint); | |
pass = setvertexattrib(0,"uv",-1,newVertex1,uvMid1,"set"); | |
int newpoint2 = addpoint(0,c); | |
int pass3 = setpointattrib(0,"angle",newpoint2,angle,"set"); | |
int pline2 = addprim(0,"polyline"); | |
int newVertex2 = addvertex(0,pline2,newpoint2); | |
pass = setvertexattrib(0,"uv",-1, newVertex2,uvMid2,"set"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment