###################################
### DM2_w24 # AGruber@tugraz.at ###
### hu_06 UN_headquaters  NYC   ### ######################################################
### paneling  / new dimensions  ### 87.5 x 22.0 meters (was lenY = 116.56 / lenX =  28.18)
################################### ######################################################


##############################
import rhinoscriptsyntax as rs
import random, time, sys   ###
sys.path.append("P:/")     ###
sys.path.append("P:/WWW/limafi/dm2")     ###
sys.path.append("D:/PY/")
import DM_lib as dm        ### reload( dm )
##############################      

rs.UnitSystem(4)                                        # km = 5, meters = 4, cm = 3 etc
rs.ShowGrid(None, 0)                                    # grid > 0 = off
rs.ShowGridAxes(None, 1)                                # y/y/z axen display > 0/1 = off/on
#rs.ViewDisplayMode(rs.CurrentView(), "wireframe")
rs.ViewDisplayMode(rs.CurrentView(), "rendered")
rs.Command("cplane w t enter", 0)						# cPlane World Top
dm.PointRadius(displayModeX=2, rad=3, styl=3)
dm.printDisplay(1)                                      # nomen est omen
rs.EnableRedraw(0)


dm.newEmptyLayer("PROJ", [220,40, 100] )

srf = rs.ObjectsByName("040_3")[0]
srf = rs.ObjectsByName("drape")[0]
coords = dm.getSurfacePoints( srf )
#rs.AddPoints( coords )

#random.shuffle( coords )
#coords = coords[0:10]
print len(coords)
print len(coords)**0.5
coordsX=[]
for i in range(0,201,1):
    for j in range(0,201,1):
        if i%10==0 and j%10==0:
            coordsX.append( coords[i+201*j] )

coords = [ coords[i] for i in range(1, len(coords), 2) ]
coords = [ coords[i] for i in range(3, len(coords), 2) ]
rs.AddPoints( coordsX )
print len(coordsX)
for cor in coordsX[0:100]:
    param = rs.SurfaceClosestPoint(srf, cor)
    pnt = rs.EvaluateSurface( srf,param[0], param[1])
    nVec = rs.SurfaceNormal( srf, param )
    nLin = rs.AddLine( pnt, rs.VectorAdd(pnt, rs.VectorScale(nVec, -120.0*1)) )
    planeX = rs.CurvePerpFrame( nLin, 0)
    circ = rs.AddCircle( planeX, 10.0*random.randint(1,2) )
    rs.ProjectCurveToSurface(circ, srf, nVec )
    #rs.DeleteObjects( [circ, nLin])