@version 2.2 @warnings @script modeler main { // debug(); reqbegin("Align points to plane"); selmode(DIRECT); NumPoints = pointcount(); polysSelected = polycount(); if(polysSelected[1] == 0) { error("No polys selected"); } if(pntCnt == 0) { error("No points selected."); } // // Get POINTS selected // editbegin(); // Calculate Plane UNIT normal sumNormal = <0,0,0>; { p1 = pointinfo( points[1] ); p2 = pointinfo( points[2] ); p3 = pointinfo( points[3] ); v1 = p2 - p1; v2 = p3 - p1; normal = normalize(cross3d(v1, v2)); } aveNormal = normal; nx = aveNormal.x; ny = aveNormal.y; nz = aveNormal.z; // Point on the plane ox = p1.x; oy = p1.y; oz = p1.z; editend(); // // Now, select all the // selmode(USER); polysSelected = polycount(); if(polysSelected[1] <> 1) { error("One poly ONLY should be selected"); } //info("polysSelected[1] = ", polysSelected[1]); editbegin(); foreach(p, polygons) { polyID = polygons[p]; polyPointCount = polypointcount(polyID); polyInfo = polyinfo(polyID); //info( "Points changed = ", polyInfo.size() ); //info( "Points Total = ", polyPointCount); for(a = 2; a <= polyInfo.size(); a++) { pointPos = pointinfo(polyInfo[a]); projectedPointPos = pointPos; px = pointPos.x; py = pointPos.y; pz = pointPos.z; // (P-O).N // P is our point (px, py,pz) // O is a point on the plane (ox,oy,oz) // and N is a unit normal from the plane (nx,ny,nz) dx = px-ox; // Get distance vector dy = py-oy; dz = pz-oz; // do dot product (distancevector DOT Normal) distance = (nx*dx)+(ny*dy)+(nz*dz); dx = nx*distance; dy = ny*distance; dz = nz*distance; projectedPointPos = ; pointmove( polyInfo[a], projectedPointPos ); } } editend(); }