sidebar features
sidebar content

Go Back   Blender Artists Forums > General Forums > Python & Plugins

Closed Thread
 
Thread Tools
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Hi all, I'm very proud to show you my last creation: the camera sequencer.
Builded to work almost like the Blender sequencer. It let you sequence camera in each scene. Read the doc at the begining of the script for more info. It should be very easy to use.
This is a followup on a post I did here: http://www.elysiun.com/forum/viewtop...r=asc&start=14
And after looking back at it, no it wasn't easy for me in the end.

Code:
#!BPY """ Registration info for Blender menus: Name: 'Camera Sequencer' Blender: 237 Group: 'Animation' Tooltip: 'Let you sequence camera change' """ __author__ = "Gabriel Beloin (Gabio)" __url__ = ("blender", "elysiun") __version__ = "alpha 1" __bpydoc__ = """\ This script let you sequence camera changes in a graphic editor. Usage: a) When you first start the script, the editor will be empty. You will need to add cameras. By default the first camera added also have a strip added. b) When all your cameras are registered, you can then add strips where you want in the timeline. It get added where the cursor is. c) A strip is an area where a camera have priority(where it's active). The only real point is the begining, the lenght of it is calculated by finding the next strip's start. d) You can select a strip with LMB, move the viewport with MMB and bring the main menu with RMB. e) You can move a selection with GKEY, move at a given frame with JKEY, delete a selection with XKEY, select/deselect with AKEY. f) You can Save the sequence in the main menu, and also delete saved data. It's important because the linker will need to be able to read this information. So you need to save before trying. g) You can enable/disable the switching of camera in realtime. """ import Blender from Blender.BGL import * #from Blender import Draw from Blender.Draw import * #from Blender import Object from Blender.Object import * from Blender import Registry from Blender import Scene #Global :) g = {} #Global dict for space handling g["h"] = 0 # the position of the viewport. can be in [0-18000] viewport will slide horizontal. g["zoom"] = 1 #zoom ratio. can be [1-10] this mean 1 pixel = 1 frame diplayed. g["xoldval"] = 0 #tracking the mouse mouvment. updated at each mousemouve. g["lmbpress"] = False #define the status of the lmb, if it's press or not. updated at each draw. g["mmbpress"] = False #define the status of the mmb, if it's press or not. updated at each draw. g["selection"] = [] #nothing is selected for now, This is a list of node g["grab"] = False #define status of grabmode cam = [] #cam #{} #["name"] #["node"] : (list of node, starting of strips.) dict = Blender.Registry.GetKey("cam_seq") if dict: sc = Scene.getCurrent() try: cam = dict[sc.name] except: cam = [] def draw(): global g, cam #Draw backgroud as gray glClearColor(.6,.6,.6,1) # define color used to clear buffers glClear(GL_COLOR_BUFFER_BIT) #Draw grid for I in range(Blender.Get("staframe"),Blender.Get("endframe"),100/g["zoom"]): #for vertical line glBegin(GL_LINES) glColor3i(0,0,0) glVertex2i(g["h"]+I,0) glVertex2i(g["h"]+I,100) glEnd() glRasterPos2i(g["h"]+I,5) glColor3i(1,1,1) Text(str(I)) #Draw the upper boundline glBegin(GL_LINES) glVertex2i(g["h"],100) glVertex2i(g["h"]+(Blender.Get("endframe")-Blender.Get("staframe"))*g["zoom"],100) glEnd() #draw the cursor at curent frame glColor3i(1,1,1) glLineWidth(2) glBegin(GL_LINES) x = (Blender.Get("curframe")*g["zoom"]) glVertex2i(g["h"]+x,0) glVertex2i(g["h"]+x,120) glEnd() glRasterPos2i(g["h"]+x,120) glColor3i(1,1,1) Text(str(x)) #strip if len(cam): index = 0 for c in cam: for n in c["node"]: end = getnextnode(n) Button(c["name"],n+10,g["h"]+n,20,(end-n),50,c["name"]) glColor3i(1,1,1) glRasterPos2i(g["h"]+n,80) Text(str(n)) for s in g["selection"]: if s == n: glColor3f(.5,1,.5) glBegin(GL_POLYGON) glVertex2i(g["h"]+n,10) glVertex2i(g["h"]+n,80) glVertex2i(g["h"]+end,80) glVertex2i(g["h"]+end,10) glEnd() Redraw(1) def getnextnode(cur): global cam busted = Blender.Get("endframe") for c in cam: for n in c["node"]: if ((n-cur) < (busted-cur)) and (n > cur): busted = n return busted def event(evt,val): global g, cam if evt == QKEY and not val: Exit() elif evt == MIDDLEMOUSE and val: #mouve viewport. g["mmbpress"] = True elif evt == LEFTMOUSE and val: #mouve selection g["lmbpress"] = True elif evt == MIDDLEMOUSE and not val: #mouve viewport off. g["mmbpress"] = False elif evt == LEFTMOUSE and not val: #mouve selection off. g["lmbpress"] = False if g["grab"] == True: g["grab"] = False elif evt == RIGHTMOUSE and not val: #main menu mainmenu() elif evt == AKEY and not val: #select all selection = [] for c in cam: for n in c["node"]: selection.append(n) if len(g["selection"]) == len(selection): g["selection"] = [] else: g["selection"] = selection elif evt == GKEY and not val and g["selection"]: g["grab"] = not g["grab"] elif evt == XKEY and not val: dellnode() elif evt == SPACEKEY and not val: addnode() elif evt == JKEY and not val: placenode() if g["lmbpress"] and evt == 4: Blender.Set("curframe",(Blender.Get("curframe") + (val - g["xoldval"]))) if g["mmbpress"] and evt == 4: g["h"] = g["h"] + (val - g["xoldval"]) if g["grab"] and evt == 4: grab(val - g["xoldval"]) if g["h"] > 0: g["h"] = 0 if g["h"] > Blender.Get("endframe"): g["h"] = Blender.Get("endframe") #should be at the end. if evt == 4: g["xoldval"] = val def bevent(evt): global cam, g node = evt-10 busted = False index = -1 for s in g["selection"]: index = index + 1 if s == node: del g["selection"][index] busted = True if busted == False: g["selection"].append(node) def addcam(): list = GetSelected() if not list: PupMenu("Error!%t|Select a camera") elif not list[0].getType() == "Camera": PupMenu("Error!%t|Select a camera") else: busted = False for I in cam: if list[0].name == I["name"]: busted = True if busted == True: PupMenu("Camera already added...") else: data = {} data["name"] = list[0].name data["node"] = [] if not cam: data["node"].append(1) elif isnodefree(Blender.Get("curframe")): data["node"].append(Blender.Get("curframe")) cam.append(data) def mainmenu(): global cam x = PupMenu("Main%t|Add selected camera...|Add Strip ( )|Delete selected strip (x)|Place selected strip (j)|Save sequence|Delete Save|Enable|Disable|Quit (Q)") if x == 1: addcam() elif x == 2: addnode() elif x == 3: dellnode() elif x == 4: placenode() elif x == 5: savework() elif x == 6: if PupMenu("Delete Save?%t|Yes|No") == 1: tmp = cam cam = [] savework() cam = tmp elif x == 7: plugscript() elif x == 8: unplugscript() elif x == 9: Exit() def addnode(): global cam if cam: if isnodefree(Blender.Get("curframe")): if not (Blender.Get("curframe") > Blender.Get("endframe")): text = "Available Camera:%t|" for I in cam: text = text + I["name"] + "|" text = text[:len(text)-1] c = PupMenu(text) if not ((c > len(cam)) or (c < 0)): cam[c-1]["node"].append(Blender.Get("curframe")) else: PupMenu("Error%t|Out of range") else: PupMenu("Error%t|No Camera added") def isnodefree(cur): global cam for c in cam: for n in c["node"]: if n == cur: return False return True def dellnode(): global cam, g if g["selection"]: if PupMenu("Delete?%t|Yes") == 1: for s in g["selection"]: icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == s: del cam[icam]["node"][inode] g["selection"] = [] def placenode(): global cam, g if (len(g["selection"]) == 1): ans = PupIntInput("Move to Frame:",Blender.Get("curframe"),0,Blender.Get("endframe")) icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == s: cam[icam]["node"][inode] = ans g["selection"][0] = ans else: PupMenu("Error!|Select one strip") def grab(ind): global cam, g isel = -1 for s in g["selection"]: isel = isel + 1 icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == s: ans = cam[icam]["node"][inode] + ind if ans < 1: ans = 1 elif ans > (Blender.Get("endframe") - 1): ans = (Blender.Get("endframe") - 1) if not isnodefree(ans): ans = ans + ind cam[icam]["node"][inode] = ans g["selection"][isel] = cam[icam]["node"][inode] def savework(): dict = {} sc = Scene.getCurrent() dict[sc.name] = cam Blender.Registry.SetKey("cam_seq",dict) def plugscript(): try: script = Blender.Text.Get("cam_seq_linker") except NameError: script = Blender.Text.New("cam_seq_linker") txt = """import Blender dict = Blender.Registry.GetKey("cam_seq") if dict: cam = dict[Blender.Scene.GetCurrent().name] for c in cam: for n in c["node"]: ###getnextnode() busted = Blender.Get("endframe") for cc in cam: for nn in cc["node"]: if ((nn-n) < (busted-n)) and (nn > n): busted = nn ### if n < Blender.Get("curframe") and busted > Blender.Get("curframe"): obj = Blender.Object.Get(c["name"]) sc = Blender.Scene.GetCurrent() sc.setCurrentCamera(obj) sc.update() """ script.write(txt) sc = Scene.GetCurrent() redraw_links = sc.getScriptLinks('FrameChanged') if not redraw_links or 'cam_seq_linker' not in redraw_links: sc.addScriptLink("cam_seq_linker", "FrameChanged") def unplugscript(): sc = Scene.GetCurrent() try: sc.clearScriptLinks(["cam_seq_linker"]) except: PupMenu("Error!%t|Functionnality no enabled") def check(): dict = Blender.Registry.GetKey("cam_seq") if dict: cam = dict["data"] for c in cam: for n in c["node"]: if n == Blender.Get("curframe"): obj = Blender.Object.Get(c["name"]) sc = Blender.Scene.GetCurrent() sc.SetCurrentCamera(obj) sc.update() Register(draw,event,bevent)
This is alpha version, a bit buggy and really not the best code-wise. Full of copy-paste and hack. Though it work.

If you have any idea for improvement...
For now I know that:
-Grab multiples strips can lead to a big problem if you move to limit. I just didn't though of a better way to block the move for the moment...
-Pupmenu of unplugscript() don't work Just didn't looked to fix yet. it's not important.
-Lotsa C&P of the same long loop of "for cam & for node", which could lead to slow down if a guy has the idea to work with 100 cameras having 100 nodes each... That's also no a problem for now...
-Some glColor call don't work... Really don't know why. Ho by the way this is my first succesfull opengl project.
-Functionality missing: Zooming the viewport. I already layed the base for that, just didn't coded it yet. Maybe glViewport could help me, I couldn't make it work. For now plan are to multiply all y adresse of drawing function by a factor, which would weight the code quit a bit.

(edit)mistake addon
............................................
Venez nous voir au Québec, on est pas sorteux!
#1   Old 19-Jul-05, 22:26   


jms's Avatar
jms jms is offline
Member
 
Join Date: Mar 2002
Location: PACA, France
Posts: 3,261
Not easy to understand at first sight but nice .
............................................
Ze French Group : ZOO-Blender | Starter Kit Blender (livre en français)
Daily updated Bpy API | Ze best french tutorials site.
#2   Old 19-Jul-05, 22:44   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Quote:
Originally Posted by jms
Not easy to understand at first sight but nice .
Is there something hard to understand in there at first sight? Apart the fact that you don't know that RMB open the main menu? Could there be some better hotkey?
............................................
Venez nous voir au Québec, on est pas sorteux!
#3   Old 20-Jul-05, 03:12   
tin2tin tin2tin is offline
Member
 
Join Date: May 2005
Posts: 102
Great stuff Gabio. Looking forward to test it!
Tin2tin
#4   Old 22-Jul-05, 19:14   
tin2tin tin2tin is offline
Member
 
Join Date: May 2005
Posts: 102
Just a few remarks.

When I add the second camera after moving the time indicator a second strip will be added - and this strip is non editable.

If I understand this concept correct, the user must first add all cameras, and then is able to add/edit strips?

On the first run I got a bit confused because adding the first and second cameras - added two strips - and I got stuck from there because I couldn't add more strips this way.

Maybe it will be more intuitive if adding cameras doesn't mean adding strips. Dunno if its possible to make the script automatically check and add all cameras on start up and/or adding a new strip.

Stupid question: How do I get the sequencer cam in the viewport?

Gotta work more with this - great stuff!

Tin2tin
#5   Old 26-Jul-05, 06:59   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Yes... why not, get all the camera at startup isn't a bad idea.
Sequencer cam in viewport? You mean "see result"? you need to save your work first, then enable it. I also though about doing a Save&enable button more logical and less problem for new user.
............................................
Venez nous voir au Québec, on est pas sorteux!
#6   Old 26-Jul-05, 12:35   
tin2tin tin2tin is offline
Member
 
Join Date: May 2005
Posts: 102
A few more things:

Adding a strip above frame 30(about the same length as the initial strip) gives me an out of range error.

Moving strips (j) gives me an error in line 291: global name 's' not defined.

One killer feature would be the ability to trim and seeing the in/out point changing in the viewport.

Instant preview(without saving) could be very nice.

I love the mouse button functions!

It's a bit complicated to figurout how to use the script a bit more explanation or a wink tut could be nice.

Tin2tin
#7   Old 26-Jul-05, 22:41   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Beta are like that
a popup "out of range" is done by me for you hehe..
You can't work outside the start-end bound of your animation... you shouldn't.
Changing in the viewport? Realtime. It's already done. just enter camera view, save&enable and drag the cursor. I had much fun testing it.

Will fix all that when I can
............................................
Venez nous voir au Québec, on est pas sorteux!
#8   Old 26-Jul-05, 23:50   
tin2tin tin2tin is offline
Member
 
Join Date: May 2005
Posts: 102
Quote:
One killer feature would be the ability to trim and seeing the in/out point changing in the viewport.
I mean moving the in/out point between two strips and moving the cursor automatically with the cut. So you can see the last frame of the first cut the moment you move it.

Wierdly strange to explain - does this make sense or should I make a drawing?

Tin2tin
#9   Old 27-Jul-05, 06:15   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
I'll pick "explain"
............................................
Venez nous voir au Québec, on est pas sorteux!
#10   Old 27-Jul-05, 12:25   
reaper reaper is offline
Member
 
Join Date: Jun 2004
Posts: 618
Just wanted to encourage you to keep moving on this script. I intend to use it for a different reason than you designed it, but it looks quite good. I have been looking for an easy way to render several views of a model from different cameras with differentlayers turned on/off. I can use your sequencer and set up an animation that may run only a few frames... 5-10. In each frame, I will have the proper layers turned off with a keyframe and I will select the proper camera with the sequencer. That way, I can end up with 5-10 high res stills of the image without sitting there and doing it all manually.

I think it should work but I am running into the same script issues reported earlier. Just wanted to pop in and let you know there was more interest.

Keep going!

reaper
#11   Old 27-Jul-05, 22:10   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Zooming will be usefull to you then
I'll see what i can do. I'm still not at home
............................................
Venez nous voir au Québec, on est pas sorteux!
#12   Old 28-Jul-05, 02:59   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Update! alpha 2.
Not time to implement zoom yet.
But fixed most if not all problem reported.
Mostly, The script is not limited anymore to startframe endframe.
Zoom not done yet. Also strips should show a tooltip of the name of the camera it represent, cause you don't always see the name... anyway it also doesn't work...

Here is a log:

#Alpha 2:
#-Removed the addcam() and hooks in the code. now cams are all there by default.
#-Fixed various drawing issues.
#-Added function addcams()
#-added hooks in the code to autosave
#-Added the shortcut CKEY to goto cursor.
#-Redid the menu to give less choice of saving start/stop... was too clutered.
#-Fixed error reported by tin2tin.
#-Removed check(), it was a copy of the linker string.
#-Upped Version number. This script is functionnal on 2.38
#-Update doc.
#-Todo: zooming still not worked out.


Code:
#!BPY """ Registration info for Blender menus: Name: 'Camera Sequencer' Blender: 238 Group: 'Animation' Tooltip: 'Let you sequence camera change' """ __author__ = "Gabriel Beloin (Gabio)" __url__ = ("blender", "elysiun") __version__ = "alpha 2" __bpydoc__ = """\ This script let you sequence camera changes in a graphic editor. Usage: a) When you start, all your cameras are registered. You can then add strips where you want in the timeline. It get added where the cursor is. b) A strip is an area where a camera have priority(where it's active). The only real point is the begining, the lenght of it is calculated by find the next strip's start. c) You can select a strip with LMB, move the viewport with MMB and bring the main menu with RMB. d) You can move a selection with GKEY, move at a given frame with JKEY, delete a selection with XKEY, select/deselect with AKEY, Move the viewport to the cursor with CKEY. e) You can Enable the switching using "enable" from the Main Menu. It's important because otherwise no effect will be appearent. You can also disable it via Main Menu. f) You can Reset data in Main Menu. This mean ereasing all cameras's strips and restarting to blank page. """ #History: #Alpha 2: #-Removed the addcam() and hooks in the code. now cams are all there by default. #-Fixed various drawing issues. #-Added function addcams() #-added hooks in the code to autosave #-Added the shortcut CKEY to goto cursor. #-Redid the menu to give less choice of saving start/stop... was too clutered. #-Fixed error reported by tin2tin. #-Removed check(), it was a copy of the linker string. #-Upped Version number. This script is functionnal on 2.38 #-Update doc. #-Todo: zooming still not worked out. #Alpha 1: #-Release of code asis. import Blender from Blender.BGL import * #from Blender import Draw from Blender.Draw import * #from Blender import Object from Blender.Object import * from Blender import Registry from Blender import Scene #Global :) g = {} #Global dict for space handling g["h"] = 0 # the position of the viewport. can be in [0-18000] viewport will slide horizontal. g["zoom"] = 1 #zoom ratio. can be [1-10] this mean 1 pixel = 1 frame diplayed. g["xoldval"] = 0 #tracking the mouse mouvment. updated at each mousemouve. g["lmbpress"] = False #define the status of the lmb, if it's press or not. updated at each draw. g["mmbpress"] = False #define the status of the mmb, if it's press or not. updated at each draw. g["selection"] = [] #nothing is selected for now, This is a list of node g["grab"] = False #define status of grabmode cam = [] #cam #{} #["name"] #["node"] : (list of node, starting of strips.) dict = Blender.Registry.GetKey("cam_seq") if dict: sc = Scene.getCurrent() try: cam = dict[sc.name] except: cam = [] def draw(): global g, cam #Draw backgroud as gray glClearColor(.6,.6,.6,1) # define color used to clear buffers glClear(GL_COLOR_BUFFER_BIT) #Draw grid for I in range(1,30000,100/g["zoom"]): #for vertical line glBegin(GL_LINES) glColor3i(0,0,0) glVertex2i(g["h"]+I,0) glVertex2i(g["h"]+I,100) glEnd() glRasterPos2i(g["h"]+I,5) glColor3i(1,1,1) Text(str(I)) #Draw the upper boundline glBegin(GL_LINES) glVertex2i(g["h"],100) glVertex2i(g["h"]+30000,100) glEnd() #draw the cursor at current frame glColor3i(1,1,1) glLineWidth(2) glBegin(GL_LINES) x = (Blender.Get("curframe")*g["zoom"]) glVertex2i(g["h"]+x,0) glVertex2i(g["h"]+x,120) glEnd() glRasterPos2i(g["h"]+x,120) glColor3i(1,1,1) Text(str(x)) #strip if len(cam): index = 0 for c in cam: for n in c["node"]: end = getnextnode(n) Button(c["name"],n+10,g["h"]+n,20,(end-n),50,c["name"]) glColor3i(1,1,1) glRasterPos2i(g["h"]+n,80) Text(str(n)) for s in g["selection"]: #selection if s == n: glColor3f(.5,1,.5) glBegin(GL_POLYGON) glVertex2i(g["h"]+n,10) glVertex2i(g["h"]+n,80) glVertex2i(g["h"]+end,80) glVertex2i(g["h"]+end,10) glEnd() Redraw(1) def getnextnode(cur): global cam busted = 30000 for c in cam: for n in c["node"]: if ((n-cur) < (busted-cur)) and (n > cur): busted = n return busted def event(evt,val): global g, cam if evt == QKEY and not val: Exit() elif evt == MIDDLEMOUSE and val: #mouve viewport. g["mmbpress"] = True elif evt == LEFTMOUSE and val: #mouve selection g["lmbpress"] = True elif evt == MIDDLEMOUSE and not val: #mouve viewport off. g["mmbpress"] = False elif evt == LEFTMOUSE and not val: #mouve selection off. g["lmbpress"] = False if g["grab"] == True: g["grab"] = False elif evt == RIGHTMOUSE and not val: #main menu mainmenu() elif evt == AKEY and not val: #select all selection = [] for c in cam: for n in c["node"]: selection.append(n) if len(g["selection"]) == len(selection): g["selection"] = [] else: g["selection"] = selection elif evt == GKEY and not val and g["selection"]: g["grab"] = not g["grab"] elif evt == XKEY and not val: dellnode() elif evt == SPACEKEY and not val: addnode() elif evt == JKEY and not val: placenode() elif evt == CKEY and not val: g["h"] = -Blender.Get("curframe")*g["zoom"] if g["lmbpress"] and evt == 4: Blender.Set("curframe",(Blender.Get("curframe") + (val - g["xoldval"]))) if g["mmbpress"] and evt == 4: g["h"] = g["h"] + (val - g["xoldval"]) if g["grab"] and evt == 4: grab(val - g["xoldval"]) if g["h"] > 0: g["h"] = 0 if g["h"] < -29999: g["h"] = -29999 #should be at the end. if evt == 4: g["xoldval"] = val def bevent(evt): global cam, g node = evt-10 busted = False index = -1 for s in g["selection"]: index = index + 1 if s == node: del g["selection"][index] busted = True if busted == False: g["selection"].append(node) savework() #automate, keep linker with fresh stuff. Because all action must pass here, #linker will be up to date. def addcams(): global cam list = Get() if not list: PupMenu("Error!%t|Add cameras to scene") Exit() else: for I in list: if I.getType() == "Camera": busted = False for x in cam: if I.name == x["name"]: busted = True if not busted: data = {} data["name"] = I.name data["node"] = [] cam.append(data) def mainmenu(): global cam x = PupMenu("Main%t|Add Strip ( )|Delete selected strip (x)|Place selected strip (j)|Reset|Enable|Disable|Quit (Q)") if x == 1: addnode() elif x == 2: dellnode() elif x == 3: placenode() elif x == 4: if PupMenu("Delete Save?%t|Yes|No") == 1: cam = [] savework() addcams() elif x == 5: savework() plugscript() elif x == 6: unplugscript() elif x == 7: Exit() def addnode(): global cam if isnodefree(Blender.Get("curframe")): text = "Available Camera:%t|" for I in cam: text = text + I["name"] + "|" text = text[:len(text)-1] c = PupMenu(text) if not ((c > len(cam)) or (c < 0)): cam[c-1]["node"].append(Blender.Get("curframe")) savework() def isnodefree(cur): global cam for c in cam: for n in c["node"]: if n == cur: return False return True def dellnode(): global cam, g if g["selection"]: if PupMenu("Delete?%t|Yes") == 1: for s in g["selection"]: icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == s: del cam[icam]["node"][inode] g["selection"] = [] savework() def placenode(): global cam, g if (len(g["selection"]) == 1): ans = PupIntInput("Move to Frame:",Blender.Get("curframe"),0,30000) icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == g["selection"][0]: cam[icam]["node"][inode] = ans g["selection"][0] = ans savework() else: PupMenu("Error!|Select one strip") def grab(ind): global cam, g isel = -1 for s in g["selection"]: isel = isel + 1 icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == s: ans = cam[icam]["node"][inode] + ind if ans < 1: ans = 1 elif ans > 29999: ans = 29999 if not isnodefree(ans): ans = ans + ind cam[icam]["node"][inode] = ans g["selection"][isel] = cam[icam]["node"][inode] savework() def savework(): dict = {} sc = Scene.getCurrent() dict[sc.name] = cam Blender.Registry.SetKey("cam_seq",dict) def plugscript(): try: script = Blender.Text.Get("cam_seq_linker") except NameError: script = Blender.Text.New("cam_seq_linker") txt = """import Blender dict = Blender.Registry.GetKey("cam_seq") if dict: cam = dict[Blender.Scene.GetCurrent().name] for c in cam: for n in c["node"]: ###getnextnode() busted = Blender.Get("endframe") for cc in cam: for nn in cc["node"]: if ((nn-n) < (busted-n)) and (nn > n): busted = nn ### if n < Blender.Get("curframe") and busted > Blender.Get("curframe"): obj = Blender.Object.Get(c["name"]) sc = Blender.Scene.GetCurrent() sc.setCurrentCamera(obj) sc.update() """ script.write(txt) sc = Scene.GetCurrent() redraw_links = sc.getScriptLinks('FrameChanged') if not redraw_links or 'cam_seq_linker' not in redraw_links: sc.addScriptLink("cam_seq_linker", "FrameChanged") def unplugscript(): sc = Scene.GetCurrent() try: sc.clearScriptLinks(["cam_seq_linker"]) except: PupMenu("Error!%t|Functionnality no enabled") addcams() Register(draw,event,bevent)
............................................
Venez nous voir au Québec, on est pas sorteux!
#13   Old 29-Jul-05, 19:58   
tin2tin tin2tin is offline
Member
 
Join Date: May 2005
Posts: 102
Great! Now adding more strips works perfectly!

And its very nice with the indication of frame and cut numbers.

Good idea with the ckey.

Maybe it's just stupid me, but using 'enable' doesn't show camera changes in my 3d view, is there anything else I need to do?

It's a bit difficult to work with frame 1-5 because they are too close to the side of the window.

Maybe its better to add the 'add camera' function to the 'add strip' function. I mean if the user adds more cameras or deletes them during the work - the script could check the current cameras before adding new strips.

The trim stuff I talked about earlier actually is in the gkey, but a nice addition could be moving the cursor with the cut automaticaly when in gkey mode - so the frame of the cut is visible in the 3dviewport as you move it.


Tin2tin
#14   Old 30-Jul-05, 07:58   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Quote:
Originally Posted by tin2tin
Great! Now adding more strips works perfectly!

And its very nice with the indication of frame and cut numbers.

Good idea with the ckey.

Maybe it's just stupid me, but using 'enable' doesn't show camera changes in my 3d view, is there anything else I need to do?

It's a bit difficult to work with frame 1-5 because they are too close to the side of the window.

Maybe its better to add the 'add camera' function to the 'add strip' function. I mean if the user adds more cameras or deletes them during the work - the script could check the current cameras before adding new strips.

The trim stuff I talked about earlier actually is in the gkey, but a nice addition could be moving the cursor with the cut automaticaly when in gkey mode - so the frame of the cut is visible in the 3dviewport as you move it.


Tin2tin
hey, pss.. you need to be in camera view you know, it's numpad 0...
............................................
Venez nous voir au Québec, on est pas sorteux!
#15   Old 30-Jul-05, 14:13   
tin2tin tin2tin is offline
Member
 
Join Date: May 2005
Posts: 102
Got it :-| - it works like a dream!

If you want to make it visible what strips are connected to the same cam, maybe one different color for each cam could be a way? (if its possible!?)

Tin2tin
#16   Old 30-Jul-05, 18:47   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Quote:
Originally Posted by tin2tin
Got it :-| - it works like a dream!

If you want to make it visible what strips are connected to the same cam, maybe one different color for each cam could be a way? (if its possible!?)

Tin2tin
Well for buttons it's not. I could draw a little square under... but it would mess with the selection square, which is green. And color isn't a good indicator of which camera it is actually.. maybe drawing the name of the actual camera following the cursor?
btw zoom is comming along nicely.
............................................
Venez nous voir au Québec, on est pas sorteux!
#17   Old 31-Jul-05, 04:26   
tin2tin tin2tin is offline
Member
 
Join Date: May 2005
Posts: 102
Quote:
And color isn't a good indicator of which camera it is actually..
I think Motionbuilder/Filmbox uses a color pr. cam. Drawing colors sounds like it will eat up some of the speed. Anyway drawing the name is a good idea and maybe selecting the current cam in the 3d view?

You properly thought of this one: but moving the cursor to the first frame of the next/prev cut with shortcut keys could be nice.

Is there a limitation of adding strips above frame say 250 - at least the strips added after this framenumber doesn't show in the 3d viewport?

Somehow it seems more logic to me to add the new strips to the left of the cursor instead of to the right of the cursor - is it just me?

Tin2tin
#18   Old 31-Jul-05, 06:21   
Gabio's Avatar
Gabio Gabio is offline
Moderator
 
Join Date: Nov 2003
Location: Canada - Québec - Sherbrooke
Posts: 2,195
Alpha 3 version.
Really, the zoom isn't the best piece of code I've done. Because of the conversion float -> int. In extrem zoom the sensitiveness can become null.
Though it all show ok.

#History:
#Alpha 3:
#-Fixed various boundary bugs.
#-Fixed Placenode stringpopup..
#-Added hooks in code to redraw just when needed.
#-fix for crash on outofbound move.(>0)
#-Zoom added.
#-Select all (AKEY) worked wrong way compared to blender UI. fixed.
#-Tooltip fixed.

Code:
#!BPY """ Registration info for Blender menus: Name: 'Camera Sequencer' Blender: 238 Group: 'Animation' Tooltip: 'Let you sequence camera change' """ __author__ = "Gabriel Beloin (Gabio)" __url__ = ("blender", "elysiun") __version__ = "alpha 3" __bpydoc__ = """\ This script let you sequence camera changes in a graphic editor. Usage: a) When you start, all your cameras are registered. You can then add strips where you want in the timeline. It get added where the cursor is. b) A strip is an area where a camera have priority(where it's active). The only real point is the begining, the lenght of it is calculated by find the next strip's start. c) You can select a strip with LMB, move the viewport with MMB and bring the main menu with RMB. d) You can move a selection with GKEY, move at a given frame with JKEY, delete a selection with XKEY, select/deselect with AKEY, Move the viewport to the cursor with CKEY. e) You can Enable the switching using "enable" from the Main Menu. It's important because otherwise no effect will be appearent. You can also disable it via Main Menu. f) You can Reset data in Main Menu. This mean ereasing all cameras's strips and restarting to blank page. """ #History: #Alpha 3: #-Fixed various boundary bugs. #-Fixed Placenode stringpopup.. #-Added hooks in code to redraw just when needed. #-fix for crash on outofbound move.(>0) #-Zoom added. #-Select all (AKEY) worked wrong way compared to blender UI. fixed. #-Tooltip fixed. #Alpha 2: #-Removed the addcam() and hooks in the code. now cams are all there by default. #-Fixed various drawing issues. #-Added function addcams() #-added hooks in the code to autosave #-Added the shortcut CKEY to goto cursor. #-Redid the menu to give less choice of saving start/stop... was too clutered. #-Fixed error reported by tin2tin. #-Removed check(), it was a copy of the linker string. #-Upped Version number. This script is functionnal on 2.38 #-Update doc. #-Todo: zooming still not worked out. #Alpha 1: #-Release of code asis. import Blender from Blender.BGL import * #from Blender import Draw from Blender.Draw import * #from Blender import Object from Blender.Object import * from Blender import Registry from Blender import Scene #Global :) g = {} #Global dict for space handling g["h"] = 0 # the position of the viewport. can be in [0-18000] viewport will slide horizontal. g["zoom"] = 1.0 #zoom ratio. can be [1-10] this mean 1 pixel = 1 frame diplayed. g["xoldval"] = 0 #tracking the mouse mouvment. updated at each mousemouve. g["lmbpress"] = False #define the status of the lmb, if it's press or not. updated at each draw. g["mmbpress"] = False #define the status of the mmb, if it's press or not. updated at each draw. g["selection"] = [] #nothing is selected for now, This is a list of node g["grab"] = False #define status of grabmode cam = [] #cam #{} #["name"] #["node"] : (list of node, starting of strips.) dict = Blender.Registry.GetKey("cam_seq") if dict: sc = Scene.getCurrent() try: cam = dict[sc.name] except: cam = [] def draw(): global g, cam #Draw backgroud as gray glClearColor(.6,.6,.6,1) # define color used to clear buffers glClear(GL_COLOR_BUFFER_BIT) #Draw grid for I in range(1,30000,100/g["zoom"]): #for vertical line glBegin(GL_LINES) glColor3i(0,0,0) glVertex2i(int(g["h"]+(g["zoom"]*I)),0) glVertex2i(int(g["h"]+(g["zoom"]*I)),100) glEnd() glRasterPos2i(int(g["h"]+(g["zoom"]*I)),5) glColor3i(1,1,1) Text(str(I)) #Draw the upper boundline glBegin(GL_LINES) glVertex2i(int(g["h"]*g["zoom"]),100) glVertex2i(int((g["h"]+30000)*g["zoom"]),100) glEnd() #draw the cursor at current frame glColor3i(1,1,1) glLineWidth(2) glBegin(GL_LINES) x = int(Blender.Get("curframe")*g["zoom"]) glVertex2i(g["h"]+x,0) glVertex2i(g["h"]+x,120) glEnd() glRasterPos2i(g["h"]+x,120) glColor3i(1,1,1) Text(str(int(x/g["zoom"]))) #strip if len(cam): index = 0 for c in cam: for n in c["node"]: end = getnextnode(n) if n < 0: #fix for crash on outofbound move. n = 0 Button(c["name"],n+10,int(g["h"]+(n*g["zoom"])),20,int((end-n)*g["zoom"]),50,c["name"]) print "end:", int((end-n)*g["zoom"]) glColor3i(1,1,1) glRasterPos2i(int(g["h"]+(n*g["zoom"])),80) Text(str(n)) for s in g["selection"]: #selection if s == n: glColor3f(.5,1,.5) glBegin(GL_POLYGON) glVertex2i(int(g["h"]+(n*g["zoom"])),10) glVertex2i(int(g["h"]+(n*g["zoom"])),80) glVertex2i(int(g["h"]+(end*g["zoom"])),80) glVertex2i(int(g["h"]+(end*g["zoom"])),10) glEnd() def getnextnode(cur): global cam busted = (30000/g["zoom"]) #taking care of drawing boundaries. for c in cam: for n in c["node"]: if ((n-cur) < (busted-cur)) and (n > cur): busted = n return busted def event(evt,val): global g, cam if evt == QKEY and not val: Exit() elif evt == MIDDLEMOUSE and val: #mouve viewport. g["mmbpress"] = True elif evt == LEFTMOUSE and val: #mouve selection g["lmbpress"] = True elif evt == MIDDLEMOUSE and not val: #mouve viewport off. g["mmbpress"] = False elif evt == LEFTMOUSE and not val: #mouve selection off. g["lmbpress"] = False if g["grab"] == True: g["grab"] = False elif evt == RIGHTMOUSE and not val: #main menu mainmenu() elif evt == 10: #zoom in: MOUSEWHEELUP g["zoom"] = g["zoom"] - .1 if g["zoom"] < .1: g["zoom"] = .1 Redraw() elif evt == 11: #zoom out: MOUSEWHEELDOWN g["zoom"] = g["zoom"] + .1 if g["zoom"] > 10: g["zoom"] = 10 Redraw() elif evt == AKEY and not val: #select all selection = [] if g["selection"]: g["selection"] = [] else: for c in cam: for n in c["node"]: g["selection"].append(n) Redraw() elif evt == GKEY and not val and g["selection"]: g["grab"] = not g["grab"] elif evt == XKEY and not val: dellnode() elif evt == SPACEKEY and not val: addnode() elif evt == JKEY and not val: placenode() elif evt == CKEY and not val: g["h"] = int(-Blender.Get("curframe")*g["zoom"]) Redraw() if g["lmbpress"] and evt == 4: Blender.Set("curframe",(Blender.Get("curframe") + int((val - g["xoldval"])/g["zoom"]))) Redraw() if g["mmbpress"] and evt == 4: g["h"] = g["h"] + (val - g["xoldval"]) Redraw() if g["grab"] and evt == 4: grab(int((val - g["xoldval"])/g["zoom"])) # ??? zoom raw data? Redraw() if g["h"] > 0: g["h"] = 0 if g["h"] < -29999: g["h"] = -29999 #should be at the end. if evt == 4: g["xoldval"] = val def bevent(evt): global cam, g node = evt-10 busted = False index = -1 for s in g["selection"]: index = index + 1 if s == node: del g["selection"][index] busted = True if busted == False: g["selection"].append(node) Redraw() savework() #automate, keep linker with fresh stuff. Because all action must pass here, #linker will be up to date. def addcams(): global cam list = Get() if not list: PupMenu("Error!%t|Add cameras to scene") Exit() else: for I in list: if I.getType() == "Camera": busted = False for x in cam: if I.name == x["name"]: busted = True if not busted: data = {} data["name"] = I.name data["node"] = [] cam.append(data) def mainmenu(): global cam x = PupMenu("Main%t|Add Strip ( )|Delete selected strip (x)|Place selected strip (j)|Reset|Enable|Disable|Quit (Q)") if x == 1: addnode() elif x == 2: dellnode() elif x == 3: placenode() elif x == 4: if PupMenu("Delete Save?%t|Yes|No") == 1: cam = [] savework() addcams() elif x == 5: savework() plugscript() elif x == 6: unplugscript() elif x == 7: Exit() def addnode(): global cam if isnodefree(Blender.Get("curframe")): text = "Available Camera:%t|" for I in cam: text = text + I["name"] + "|" text = text[:len(text)-1] c = PupMenu(text) if not ((c > len(cam)) or (c < 0)): cam[c-1]["node"].append(Blender.Get("curframe")) Redraw() savework() def isnodefree(cur): global cam for c in cam: for n in c["node"]: if n == cur: return False return True def dellnode(): global cam, g if g["selection"]: if PupMenu("Delete?%t|Yes") == 1: for s in g["selection"]: icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == s: del cam[icam]["node"][inode] g["selection"] = [] Redraw() savework() def placenode(): global cam, g if (len(g["selection"]) == 1): ans = PupIntInput("Move to Frame:",Blender.Get("curframe"),1,30000) if ans: icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == g["selection"][0]: cam[icam]["node"][inode] = ans g["selection"][0] = ans Redraw() savework() else: PupMenu("Error!|Select one strip") def grab(ind): global cam, g isel = -1 for s in g["selection"]: isel = isel + 1 icam = -1 for c in cam: icam = icam +1 inode = -1 for n in c["node"]: inode = inode +1 if n == s: ans = cam[icam]["node"][inode] + ind if ans < 1: ans = 1 elif ans > 29999: ans = 29999 if not isnodefree(ans): ans = ans + ind cam[icam]["node"][inode] = ans g["selection"][isel] = cam[icam]["node"][inode] savework() Redraw() def savework(): dict = {} sc = Scene.getCurrent() dict[sc.name] = cam Blender.Registry.SetKey("cam_seq",dict) def plugscript(): try: script = Blender.Text.Get("cam_seq_linker") except NameError: script = Blender.Text.New("cam_seq_linker") txt = """import Blender dict = Blender.Registry.GetKey("cam_seq") if dict: cam = dict[Blender.Scene.GetCurrent().name] for c in cam: for n in c["node"]: ###getnextnode() busted = Blender.Get("endframe") for cc in cam: for nn in cc["node"]: if ((nn-n) < (busted-n)) and (nn > n): busted = nn ### if n < Blender.Get("curframe") and busted > Blender.Get("curframe"): obj = Blender.Object.Get(c["name"]) sc = Blender.Scene.GetCurrent() sc.setCurrentCamera(obj) sc.update() """ script.write(txt) sc = Scene.GetCurrent() redraw_links = sc.getScriptLinks('FrameChanged') if not redraw_links or 'cam_seq_linker' not in redraw_links: sc.addScriptLink("cam_seq_linker", "FrameChanged") def unplugscript(): sc = Scene.GetCurrent() try: sc.clearScriptLinks(["cam_seq_linker"]) except: PupMenu("Error!%t|Functionnality no enabled") #uncomment for safemode start. #cam = [] #savework() addcams() Register(draw,event,bevent)
............................................
Venez nous voir au Québec, on est pas sorteux!
#19   Old 01-Aug-05, 16:36   
tin2tin tin2tin is offline
Member
 
Join Date: May 2005
Posts: 102
Just wanting to let you know that all the things you have been adressing works very well here too.
#20   Old 01-Aug-05, 21:40   
Closed Thread

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 11:20.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Logo and website design copyright © 2006 by froodee design bureau. All rights reserved.
Other Blender Sites
new icon Blender Homepage »
The official Blender homepage
new icon BlenderNation »
Fresh Blender News, Every Day
new icon Blenderart Magazine »
Blender articles, tutorials and images.
Blender Headlines
Featured Artwork
Short animation: Barrel by Phlopper
Woolly mammoth by sebastian_k
Photorealistic classic furniture by eMirage
Social BlenderArtists