###################################################### ######## Turnerinnen ######## ###################################################### ############################## import rhinoscriptsyntax as rs import random, time, sys, math, os ### #from itertools import combinations #from itertools import permutations import itertools sys.path.append("P:/") ### sys.path.append("L:/") ### import DM_lib as dm ### reload(dm) ############################## rs.UnitSystem(4) # meters = 4, cm = 3 etc rs.ShowGrid(None, 0) # grid > 0 = off rs.ShowGridAxes(None, 0) # y/y/z axen display > 0/1 = off/on rs.ViewDisplayMode(rs.CurrentView(), "wireframe") rs.ViewDisplayMode(rs.CurrentView(), "shaded") rs.ViewDisplayMode(rs.CurrentView(), "ghosted") #rs.ViewDisplayMode(rs.CurrentView(), "rendered") rs.Command("cplane w t enter", 0) dm.PointRadius(displayModeX=0, rad=3, styl=3) dm.printDisplay(0) rs.EnableRedraw(0) dm.getCameraTarget() rs.CurrentView("Perspective") #dm.setCameraTarget( [444.70508935, 720.3935626, 133.42980215], [758.16891279, 564.78380652, 77.99999999], lens=50.0, rota=0, upVec=[0,0,1] ) # ... danke, andi ! #dm.setCameraTarget( [558.01311908, 471.27381083, 53.35447051], [754.09088415, 554.90512141, 74.63080291], lens=60.0, rota=0, upVec=[0,0,1] ) # ... danke, andi ! dm.setCameraTarget( [407.15036525, 624.15873605, 94.92659064], [758.17525536, 564.78273367, 78.13639507], lens=50.0, rota=0, upVec=[0,0,1] ) # ... danke, andi ! ###_________________________________________# ### basic settings for grid to fit UN_slab # ### # floors = H = dm.H = 40 # default=40 / incl roof slabs = L = dm.L = 11 # default=11 depth = D = dm.D = 4 # default= 4 / division in building_depth floorHeight = fH = dm.fH = 4.0 # default= 4.0 / 4.0*(H-1) = 156 meters dm.UNerror = 0 # # ################ # get from DM_lib as dm: UnoGridCoords = dm.UnoGridCoords # get gridCoords L*D*H = 1760 UnoPanelCoords = dm.UnoPanelCoords # get panelCoords [frontPanels, backPanels, sidePanels, upSidePanels] / default arguments s.u. ################____________________________# dm.newEmptyLayer("Default",) dm.newEmptyLayer("ANIfiguren", [211,100,110]) dm.newEmptyLayer("UNO::setUp", [120,120,140]) ################ lengthVec = lVec = rs.VectorUnitize(rs.VectorSubtract( dm.getUnoCoord(0, 0, 0), dm.getUnoCoord(1, 0, 0) )) ## rs.AddPoint( dm.getUnoCoord(1, 0, 0) ) depthVec = dVec = rs.VectorUnitize(rs.VectorSubtract( dm.getUnoCoord(0, 1, 0), dm.getUnoCoord(0, 0, 0) )) ## rs.AddPoint( dm.getUnoCoord(0, 1, 0) ) ################ BigPanelCoords = dm.getUNpanelCoords(anzL=10*1, anzH=39, anzD=3, stepL=2, stepH=6, stepD=2) ### = all ~windows_panels UnoPanelCoords = dm.getUNpanelCoords(anzL=10*1, anzH=39, anzD=3, stepL=1, stepH=3, stepD=1) ### = standard ! if 1: ### SETUP >> dont' exec @ homework ! rs.AddCurve( [dm.getUnoCoord(0,0,0), dm.getUnoCoord(0,0,39), dm.getUnoCoord(10,0,39), dm.getUnoCoord(10,0,0), dm.getUnoCoord(10,3,0), dm.getUnoCoord(0,3,0), dm.getUnoCoord(0,3,39), dm.getUnoCoord(10,3,39)], 1) rs.ObjectColor(rs.AddLine( dm.getUnoCoord(0, 0, 0), dm.getUnoCoord(0, 1, 0) ), [222, 0, 0] ) rs.ObjectColor(rs.AddLine( dm.getUnoCoord(0, 0, 0), dm.getUnoCoord(1, 0, 0) ), [0, 222, 0] ) rs.ObjectColor(rs.AddLine( dm.getUnoCoord(0, 0, 0), dm.getUnoCoord(0, 0, 2) ), [0, 0, 222] ) rs.ObjectPrintWidth( rs.AllObjects()[0:4], 1.0 ) #rs.AddPoints( UnoGridCoords ) #rs.ZoomExtents() frontPanels = UnoPanelCoords[0] backPanels = UnoPanelCoords[1] sidePanels = UnoPanelCoords[2] upSidePanels = UnoPanelCoords[3] topPanels = UnoPanelCoords[5] allPanels = UnoPanelCoords[4] for panel in allPanels: coords = panel[:] random.shuffle(coords) if random.uniform(0,100)<30: #rs.AddCurve( coords[0:3], 1 ) rs.AddCurve( coords[0:4], 2 ) #rs.AddCurve( coords[0:4], 3 ) if 1: dm.setCameraTarget( [407.15036525, 624.15873605, 94.92659064], [758.17525536, 564.78273367, 78.13639507], lens=50.0, rota=0, upVec=[0,0,1] ) # ... danke, andi ! rs.ZoomExtents() rs.Command("-zoom Factor 0.995 enter", 0) # decrease zoom for better framing rs.Redraw() #_____________________________here you go: ############################ ########### prepare dancers: anzPointsPerDancer = 16*6 ### ~ anz points per dancer: def 1..16 deg = 1 ####### ############################################################ if 0 : ### export NEW coord lists .. falls dancers changed or added dm.newEmptyLayer("ANIfiguren", [222,10,10]) TUs = rs.ObjectsByName("TU_*", 0) allTUCoords = [] print "len(TUs) all", len(TUs) for i in range( len(TUs) ): nam = "TU_"+str(i) rs.ObjectName(TUs[i], "TU_"+str(i)) crv = rs.ObjectsByName(nam)[0] ###print nam, crv coords = rs.CurvePoints( crv ) if len(coords) < anzPointsPerDancer: rs.RebuildCurve(crv, degree=1, point_count=anzPointsPerDancer-1) ### -1 weil closed curve coords = rs.CurvePoints( crv ) print "***", rs.ObjectName(crv), "rebuilt" #print len(coords) allTUCoords.append( coords ) dm.exportCoordLists(list2export=allTUCoords, exportedListName='allTUCoords', path="P:/FINALE/sarahA/", fileName='TU_coords') ####################################### if 1: ### always import basic dancer coords ! ###################### import TU_coords ### reload(TU_coords) allTUCoords = TU_coords.allTUCoords ################################### if 1: dm.newEmptyLayer("turn_figuren", [200,10,10]) for i,coords in enumerate(allTUCoords): pass crv = rs.AddCurve( coords, 5 ) rs.RebuildCurve( crv, 1, anzPointsPerDancer) coords = rs.CurveEditPoints(crv) rs.ObjectName( crv, "TU_"+str(i)) allTUCoords[i] = coords rs.CurrentLayer("Default") rs.LayerVisible("turn_figuren", 0) dm.newEmptyLayer("aniTUs", [111,100,110]) dm.newEmptyLayer("path", [20,110,220]) ### PATH neu ############### #random.shuffle(allTUCoords) anzTUs = len(allTUCoords) if 1: ### neu rs.DeleteObjects(rs.ObjectsByName("keyFig*")) rs.Redraw() coords = [ [random.uniform(-20,20)+20, 5*i+10, 0] for i in range(anzTUs+(anzTUs 1 >> dancers outside slab rs.ObjectName( path, "TUpath") anzTUs -= (rs.IsCurveClosed(path)) #dm.zA() ############## ############## pathCrvDeg = 1 ### 1, 2, 3 metersPerFigure = 45 ### def 25 framesPerFigure = 5 ### def 25 ############## captureIt = 0 keepFrames = int(framesPerFigure*0.9) keepFigure =0 ### prozent / einzelne random frames - alle: 101% :) ############## ############## #################################### path = rs.ObjectsByName("TUpath")[0] #posPts = rs.DivideCurve(path, anzTUs-1, 1) lenx = rs.CurveLength( path ) anzTUs = int(lenx / metersPerFigure) ### meters print "lenx path", lenx, "/ metersPerFigure =", lenx/metersPerFigure, " >> anzTUrnerIns", anzTUs ################################################################################################# ######################### if 1: ### PLACE dancers on path rotatTUonPath = 5.0-pathCrvDeg ### if 0.0: no good split of pathCrvs / the bigger the better posPts = rs.DivideCurve(path, anzTUs-1, 0) anzTUs -= rs.IsCurveClosed(path) tmpCoords = [] for i in range(anzTUs): ### 4 each dancer pass TUpos = posPts[i] #coords = allTUCoords[i] ### coords of figure .. wo_auch_immer coords = random.choice(allTUCoords)#[i] ### coords of figure .. wo_auch_immer #rs.AddCurve(coords, 2) param = rs.CurveClosestPoint(path, TUpos) tang = dm.vecCurvePerpXY(path, param) ## eigentlich normal auf crv #ang = rs.VectorAngle( tang, [0,1,0] ) ## wenn figuren in xz_ebene !!! #ang = rs.VectorAngle( tang, dVec ) #print "ang", ang #ang = rs.Angle( TUpos, rs.VectorAdd(TUpos, tang) )[0] ### rotation + 90 >> parallel zu path rndAxe = [random.uniform(-0.3, -0.0),random.uniform(0.0, 0.3), 1] ang = 1.0 if rotatTUonPath > 0: ang = rotatTUonPath if i and i%2==0: ang *= -1 #coords = [ rs.VectorRotate(cor, ang, [random.uniform(0, 0.5),random.uniform(0, 0.5), 5]) for cor in coords ] ### .01 damit nicht figur // path .. wh splitten der aniCurve @ figuren coords = [ rs.VectorRotate(cor, ang, rndAxe ) for cor in coords ] ### .01 damit nicht figur // path .. wh splitten der aniCurve @ figuren movVec = rs.VectorSubtract(TUpos, coords[0]) ### crvStart von TU coords = [ rs.VectorAdd(cor, movVec) for cor in coords ] ### more randomize ! ### rndVec = dm.randVec(-5.9, -0.1) ###rndVec = rs.VectorScale(dVec, random.uniform(rotatTUonPath*-0.2, -0.1)) rndVec = rs.VectorScale(dVec, random.uniform(-1.0, -0.5)) coords = [ rs.VectorAdd(cor, rndVec) for cor in coords ] crv = rs.AddCurve( coords, 1 ) rs.ObjectName( crv, "keyFigure") srf = rs.AddPlanarSrf(crv) rs.ObjectName( srf, "keyFigure_srf") tmpCoords.append(coords) allTUCoords = [ tmpCoords[i] for i in range(anzTUs) ] print "len(allTUCoords) placed dancers =", len(allTUCoords), "coordLists @", len(posPts), "posPts" ################################################################################################## #rs.HideObject(path) ###################################### # calculate aniCoords inBtw keyFigures # allTUCoords.reverse() if 1: dm.newEmptyLayer("ANIfiguren", [111,100,110]) frames = (anzTUs-1)*framesPerFigure+1 ### 25 = 1sec animation aniCoords = [] #rs.CurrentView("Top") if 1: ### just test lenx = len(allTUCoords[0]) #lenx = 1 for i in range(0, lenx, 1): coords = [] for TUCoords in allTUCoords[0:anzTUs]: coords.append( TUCoords[i] ) ###rs.AddPoint( TUCoords[i] ) crv = rs.AddInterpCurve(coords, degree=pathCrvDeg, knotstyle=0) nam = "pathCrv_"+str(i) rs.ObjectName( crv, nam ) #crv = rs.AddCurve(coords, degree=1) #aniCoords.append( rs.DivideCurve(crv, frames, 0) ) if 0 and i > 1 and i 1 and i keepFrames: if random.randint(0,100)>keepFigure: rs.DeleteObjects( rs.ObjectsByName("TUX")[-1:] ) else: rs.ObjectName( rs.ObjectsByName("TUX")[-1:], "keepIt") for posCoords in aniCoords: coords.append(posCoords[f]) crv = rs.AddCurve( coords, 1 ) if not rs.IsCurveClosed(crv): print "!!! ani crv not closed >> brrrr.........." break rs.ObjectName( crv, "TUX") if captureIt or f%10==0: rs.Redraw() #rs.Sleep(100) crvs = rs.ObjectsByName("TUX") if captureIt: nam = dm.makeName(name='TU', frameNumber=framNumber, anzahl=4, format='jpg') rs.Command("-viewCaptureToFile Width=640 Height=360 Scale=2 DrawCPlaneAxes=No TransparentBackground=No "+path+nam+" ", 0) framNumber +=1 print nam if not crvs: print "!!! no ani crvs >> brrrr.........." crvs.reverse() if 1: for crv in crvs[0:]: ### -1 >> keep last frame dm.esc() if random.randint(0,100)>keepFigure: rs.DeleteObject(crv) rs.Redraw() if captureIt: nam = dm.makeName(name='TU', frameNumber=framNumber, anzahl=4, format='jpg') rs.Command("-viewCaptureToFile Width=640 Height=360 Scale=2 DrawCPlaneAxes=No TransparentBackground=No "+path+nam+" ", 0) framNumber +=1 #print f, nam, "von", frames rs.LayerVisible("Default", 1) rs.CurrentLayer("Default") #dm.printDisplay(1)