###################################################### ######## ANImate Marilyn Monroe & 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:/") ### sys.path.append("P:/WWW/mori21/DM2/") 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.Command("cplane w t enter", 0) dm.PointRadius(displayModeX=0, rad=3, styl=3) dm.printDisplay(0) rs.EnableRedraw(0) ### not used here: def makeFigure( pnts=[], crv_degree=1, pos=[30.0, 0,0], divis=64, show=1, delIt=1, crv_name="singt", obj_color=[0,200,0]): coords = [ rs.VectorAdd(cor, pos) for cor in pnts ] crvID = rs.AddCurve(coords, crv_degree) rs.ObjectColor( crvID, obj_color ) rs.ObjectName( crvID, crv_name ) coords = rs.DivideCurve( crvID, divis, show ) if delIt: rs.DeleteObject( crvID ) return coords ### USAge #coords_1 = makeFigure( pnts=pnts_singt, crv_degree=deg, pos=[50.0, 10.0,0], divis=anz, show=showPts, delIt=delIt, crv_name="MM_singt", obj_color=[0,200,0]) #coords_2 = makeFigure( pnts=pnts_wind, crv_degree=deg, pos=[00.0, 10.0,0], divis=anz, show=showPts, delIt=delIt, crv_name="MM_wind", obj_color=[210,0,120]) def setCrvStartPoint( crvID="xxx", set2point=[0,0,0] ): crvID = rs.GetObject("sel Crv:", filter=0, preselect=0, select=1, custom_filter=None, subobjects=False) set2point = rs.GetPointCoordinates(message="Select point", preselect=0)[0] if not rs.IsCurveClosed(crvID): print "!!! curve ist not closed" return param=rs.CurveClosestPoint(crvID, set2point) rs.CurveSeam(crvID,param) ### tst print rs.CurveStartPoint(crvID), "\n", rs.EvaluateCurve(crvID,param) return rs.CurveStartPoint(crvID) ### USAge / tst ### setCrvStartPoint( ) ### old: #setCrvStartPoint( "4444c0c9-9046-49b9-b2ad-368c5a61b83f", [2145.759,649.485,228.098] ) #setCrvStartPoint( "c55be39a-2484-4251-99ec-9359de807a44", [2790.027,649.485,411.627] ) #MM #rs.AddPoint(setCrvStartPoint( "05df7669-d708-4c6b-9f64-788086024ac1", [6.809,1.728,4.808] )) #rs.AddPoint(setCrvStartPoint( "6070313a-fdc5-4005-accc-0f67757c4917", [10.931,1.918,4.717] )) #rs.AddPoint(setCrvStartPoint( "8dcac52f-b68a-434e-95e7-6f789eef11e5", [15.053,3.167,4.750] )) anz = 16*16 showPts = 0 deg = 1 delIt = 0 if 1 : MMs = rs.ObjectsByName("MM_*", 0) allCoords = [] print "len(MMs)", len(MMs) for i in range( len(MMs) ): nam = "MM_"+str(i) crv = rs.ObjectsByName(nam)[0] print nam, crv coords = rs.CurvePoints( crv ) if len(coords) != anz: rs.RebuildCurve(crv, degree=1, point_count=anz-1) coords = rs.CurvePoints( MM ) print "***", rs.ObjectName(MM), "rebuilt" #print len(coords) allCoords.append( coords ) #dm.exportCoordLists(list2export=allCoords, exportedListName='allCoords', path="P:/WWW/mori21/DM2/", fileName='MM_coords') ###################### #import MM_coords ### #reload(MM_coords) #allMMCoords = MM_coords.allCoords ###################### allMMCoords = allCoords+allCoords #random.shuffle( allMMCoords ) #allMMCoords.append( allMMCoords[0] ) dm.newEmptyLayer("TST") #dm.setCameraTarget( [3041.31517563, -2800.26096912, 607.17679033], [-502.90614144, -445.42106446, -343.98856543], lens=50.0, rota=0, upVec=[-0.18169718703862137,0.12072264915897345,0.9759160692407373] ) # ... danke, andi ! for coords in allMMCoords: pass #random.shuffle(coords) #rs.AddCurve( coords ) anzMMs = len(allMMCoords) if 0: ### PATH coords = [ [random.uniform(-20,20)+20, 5*i+10, 0] for i in range(5) ] #coords = rs #coords.append( coords[0]) dm.newEmptyLayer("path", [200,0,0]) path = rs.AddCurve( coords ) rs.ObjectName( path, "MMpath") #anzMMs -= (rs.IsCurveClosed(path)) posPts = rs.DivideCurve(path, anzMMs-1, 1) path = rs.ObjectsByName("MMpath")[0] posPts = rs.DivideCurve(path, anzMMs-1, 0) if 1: #anzMMs -= rs.IsCurveClosed(path) for i in range(anzMMs-0): ### fuer jede MM pass MMpos = posPts[i] coords = allMMCoords[i] #rs.AddCurve( coords ) param = rs.CurveClosestPoint(path, MMpos) tang = dm.vecCurvePerpXY(path, param) ## eigentlich normal auf crv #tang = rs.CurveTangent(path, param) #rs.AddLine( MMpos, rs.VectorAdd(MMpos, tang)) ang = rs.VectorAngle( tang, [0,1,0] ) ang = rs.Angle( MMpos, rs.VectorAdd(MMpos, tang) )[0] #print ang coords = [ rs.VectorRotate(cor, ang, [0,0,1]) for cor in coords ] movVec = rs.VectorSubtract(MMpos, coords[0]) ### crvStart von MM coords = [ rs.VectorAdd(cor, movVec) for cor in coords ] #crv = rs.AddCurve( coords, 1 ) ### rs.RotateObject(crv, MMpos, ang, [0,0,1]) allMMCoords[i] = coords if 0: #anzMMs -= rs.IsCurveClosed(path) for i in range(anzMMs-0): ### fuer jede MM pass MMpos = posPts[i] coords = allMMCoords[i] allMMCoords[i] = coords print "len(allMMCoords)", len(allMMCoords) #allMMCoords.reverse() if 1: dm.newEmptyLayer("ANIfiguren", [0,100,100]) frames = anzMMs*25*1 ### 25 = 1sec animation aniCoords = [] if 1: ### just test lenx = len(allMMCoords[0]) #lenx = 1 for i in range(0, lenx): coords = [] for MMCoords in allMMCoords: coords.append( MMCoords[i] ) crv = rs.AddInterpCurve(coords, degree=3, knotstyle=0, start_tangent=None, end_tangent=None) #crv = rs.AddCurve(coords, degree=3) aniCoords.append( rs.DivideCurve(crv, frames, 0) ) rs.DeleteObjects( crv ) #dm.zA() rs.CurrentView("Perspective") #frames = 25 dm.getCameraTarget() camPath = rs.ObjectsByName("camPath")[0] tarPath = rs.ObjectsByName("MMpath")[0] camPts = rs.DivideCurve( camPath, frames, 0) tarPts = rs.DivideCurve( tarPath, frames, 0) dm.setCameraTarget( [91.08577528, -97.94447192, 32.57776566], [40.65009302, 37.67826349, -88.40866703], lens=20.0, rota=0, upVec=[0,0,1] ) # ... danke, andi ! if 0: #### tst ! for f in range(frames): dm.esc() cam = camPts[f] tar = tarPts[f] dm.setCameraTarget( camPts[f], tar, lens=50.0, rota=0, upVec=[0,0,1] ) # ... danke, andi ! rs.Redraw() rs.Sleep(500) if 1: rs.ViewDisplayMode(rs.CurrentView(), "rendered") path = "L:/animatzi/TU_tstX/" if not os.path.exists(path): os.makedirs(path) captureIt = 1 keepFrames = 3 framNumber = 0 dm.newEmptyLayer("aniMMs", [00,220,220]) anz = len(aniCoords[0]) print "anz coords pro MM", anz lensX = 20 ### ziel am ende zoom = 20 deltaZoom = (lensX - 20)/frames intervall = 10 for f in range(0, frames+1, intervall): dm.esc() coords = [] #rs.DeleteObjects( rs.ObjectsByName("MMX")[0:5] ) if len(rs.ObjectsByName("MMX")) > keepFrames: rs.DeleteObjects( rs.ObjectsByName("MMX")[-1:] ) for posCoords in aniCoords: coords.append(posCoords[f]) crv = rs.AddCurve( coords, 1 ) rs.ObjectName( crv, "MMX") rs.Redraw() crvs = rs.ObjectsByName("MMX") lensX += deltaZoom*intervall dm.setCameraTarget( camPts[f], tarPts[f], lens=lensX, rota=0, upVec=[0,0,1] ) # ... danke, andi ! if captureIt: nam = dm.makeName(name='MM', 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 crvs.reverse() for crv in crvs[0:-1]: rs.DeleteObject(crv) rs.Redraw() if captureIt: nam = dm.makeName(name='MM', 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 0: allCoords = aniCoords[:] captureIt = 0 keepFrames = 15 framesProFigur = 25*1 path = "L:/animatzi/TU_tst/" if not os.path.exists(path): os.makedirs(path) fac = 1/framesProFigur #allCoords = [] for i in range(0, len(allCoords)-1): framNumber = 0 coords_A = allCoords[i][:] coords_B = allCoords[i+1][:] #rs.AddLine( coords_A[0], coords_B[0] ) for fram in range(0, framesProFigur+1): coords = [ dm.pntInbetween( coords_A[j], coords_B[j], fac*framNumber ) for j in range(anz) ] ### anz = points pro figur frameCrvs = rs.ObjectsByName("frameCrv") if len(frameCrvs) == keepFrames: rs.DeleteObjects(frameCrvs[-1:]) coords.append(coords[0]) crv = rs.AddCurve(coords, deg) rs.ObjectName(crv, "frameCrv") rs.Redraw() nam = dm.makeName("TU", frameNumber=framNumber+i*framesProFigur, anzahl=4, format='jpg') if captureIt: rs.Command("-viewCaptureToFile Width=960 Height=540 Scale=2 DrawCPlaneAxes=No TransparentBackground=No "+path+nam+" ", 0) framNumber +=1 print nam dm.esc() rs.LayerVisible("Default", 1) rs.CurrentLayer("Default") dm.printDisplay(1) #print round(48/11, 2) #print 48 - round(48/11, 2) #print (48 - round(48/11, 2)) + round(48/11, 2)