Script to Create Target Camera Relative to Object

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 06 June 2013   #1
Unhappy Script to Create Target Camera Relative to Object

Hello!

I'm working on a theater and its full of people. Each person, seated or standing, has a separate 'head' object. I'm going to need to quickly and easily check the views of any given person in the theater, so I'm trying to generate a script that will allow me to click on a head and generate a target camera at the head's pivot point that will point to 0,0,0. I've never seen a script that places objects/cameras relative to a pivot point before. Any help would be much appreciated!
 
Old 06 June 2013   #2
try(destroydialog SpectatorCameraDialog) catch()
rollout SpectatorCameraDialog "Spectator Camera" width:200
(
	local cameraname = "Spectator_Camera"
	fn getCamera = (cam = getnodebyname cameraname)
	fn goodHead node = (cam = getCamera()) == undefined or (node != cam and node != cam.target)
	
	edittext cameraname_tx "Name:" text:cameraname fieldwidth:150 align:#right offset:[9,0]
	button createcam_bt "Create Camera" width:192 align:#right offset:[9,4]
	pickbutton pickhead_bt "Align To Head Object" filter:goodHead width:192 align:#right offset:[9,0]
	
	on cameraname_tx changed text do 
	(
		if (cam = getCamera()) != undefined do cam.name = text
		cameraname = text
	)
	on createcam_bt pressed do if (cam = getCamera()) == undefined do undo "Create Camera" on
	(
		TargetCamera name:cameraname target:(TargetObject name:(cameraname + ".Target")) isselected:on
	)
	on pickhead_bt picked obj do if isvalidnode obj do undo "Align Camera" on
	(
		if (cam = getCamera()) == undefined do createcam_bt.pressed()
		cam.transform = obj.transform
		if cam.target != undefined do cam.target.pos = [0,0,0]
		cam.parent = obj
	)
)
createdialog SpectatorCameraDialog

hopefully i didn't forget anything...
 
Old 06 June 2013   #3
you don't need a camera for every head i think. you can use the only one and just change it's parent and location.
 
Old 06 June 2013   #4
Denis, this is fantastic!! Thank you so much. Actually I do need a camera for every head (well, not every one, just the ones I select.)

I'm going to have to render out about 80 or so different views, so that'll be far easier if all 80 of those cameras are set up. How would the script need to be modified so that every camera I create is a unique view? In fact, is there anyway to make the camera take on the name of the head object it aligns to?

Thanks again!
 
Old 06 June 2013   #5
Wow Denis this is amazing, thanks!

Actually I do need to to have many cameras at once from many different views-- about 80 or so, and they'll all need to be rendered out in one batch. Would it be possible to change the script so that when I click on an object, the camera takes on the name of it?

The heads all have names like Row 7 Seat 6, so to be able to scroll down my list of cameras and pick my views based on that would be fantastic! It would also help to keep the cameras in alphabetical order when I do my batch rendering. Thanks again for your help.
 
Old 06 June 2013   #6
Originally Posted by ibrews: Wow Denis this is amazing, thanks!

Actually I do need to to have many cameras at once from many different views-- about 80 or so, and they'll all need to be rendered out in one batch. Would it be possible to change the script so that when I click on an object, the camera takes on the name of it?

The heads all have names like Row 7 Seat 6, so to be able to scroll down my list of cameras and pick my views based on that would be fantastic! It would also help to keep the cameras in alphabetical order when I do my batch rendering. Thanks again for your help.

it's very easy to change the script to make it works the way you want. but much easier for user will be select all heads and make a camera for every one at once than pick an every head. do you want me to change the script this way?
 
Old 06 June 2013   #7
That would be glorious
 
Old 06 June 2013   #8
Originally Posted by ibrews: That would be glorious

i don't have max to try but hopefully it will work

 try(destroydialog SpectatorCameraDialog) catch()
 rollout SpectatorCameraDialog "Spectator Camera" width:200
 (
 	local cameraname = "Spectator_Camera"
 	
 	edittext cameraname_tx "Name:" text:cameraname fieldwidth:150 align:#right offset:[9,0]
 	button createcam_bt "Create Cameras" width:192 align:#right offset:[9,4]
 
 	
 	on cameraname_tx changed text do 
 	(
 		cameraname = text
 	)
 	on createcam_bt pressed do undo "Create Cameras" on
 	(
 		cams = for node in selection collect 
 		(
 			name = node.name + "_" + cameraname
 			c = TargetCamera name:name target:(TargetObject name:(name + ".Target")) transform:node.transform parent:node
 		)
 		select cams
 	)
 )
 createdialog SpectatorCameraDialog
 
 
Old 06 June 2013   #9
i don't check that a camera already exists with a head. so the script might generate dups...so there is no 'full proof' here
 
Old 06 June 2013   #10
Talking

This is absolutely perfect. You just saved my workweek Denis!
 
Old 06 June 2013   #11
Originally Posted by ibrews: This is absolutely perfect. You just saved my workweek Denis!

workweek... hmm... not less than 40h x $20 = $800 not bad for 10 lines of code learn max script!
 
Old 06 June 2013   #12
Definitely! With the time I'm saving I'll start right on some tutorials.

Last thing I'll be asking before I embark on learning all this stuff myself:

Is there any way to make the cameras be created (0,9",-5") from each pivot point (or something like that?)? I may have to simulate people's leaning, but the geometry itself wouldn't be changing.
 
Old 06 June 2013   #13
Originally Posted by ibrews: Definitely! With the time I'm saving I'll start right on some tutorials.

Last thing I'll be asking before I embark on learning all this stuff myself:

Is there any way to make the cameras be created (0,9",-5") from each pivot point (or something like that?)? I may have to simulate people's leaning, but the geometry itself wouldn't be changing.

try this (again... i don't have and max help now to check its working)

try(destroydialog SpectatorCameraDialog) catch()
rollout SpectatorCameraDialog "Spectator Camera" width:200
(
	local cameraname = "Spectator_Camera"
	
	edittext cameraname_tx "Name:" text:cameraname fieldwidth:150 align:#right offset:[9,0]
	button createcam_bt "Create Cameras" width:192 align:#right offset:[9,4]

	
	on cameraname_tx changed text do 
	(
		cameraname = text
	)
	on createcam_bt pressed do undo "Create Cameras" on
	(
		cams = for node in selection collect 
		(
			name = node.name + "_" + cameraname
			tm = (transmatrix [0, units.decodevalue "9''", units.decodevalue "-5''"])*node.transform
			c = TargetCamera name:name target:(TargetObject name:(name + ".Target")) transform:tm parent:node
		)
		select cams
	)
)
createdialog SpectatorCameraDialog


one more line... hmm... it makes my code cheaper... have it saved another more hours too?
 
Old 06 June 2013   #14
Ah! Never mind, I think I did it myself

Does this look okay?


try(destroydialog SpectatorCameraDialog) catch()
 rollout SpectatorCameraDialog "Spectator Camera" width:200
 (
 	local cameraname = "Spectator_Camera"
 	
 	edittext cameraname_tx "Name:" text:cameraname fieldwidth:150 align:#right offset:[9,0]
 	button createcam_bt "Create Cameras" width:192 align:#right offset:[9,4]
 
 	
 	on cameraname_tx changed text do 
 	(
 		cameraname = text
 	)
 	on createcam_bt pressed do undo "Create Cameras" on
 	(
 		cams = for node in selection collect 
 		(
 			name = node.name + "_" + cameraname
			c = TargetCamera name:name target:(TargetObject name:(name + ".Target")) lens:21.661 fov:79.4535 transform:node.transform parent:node
 		)
 		select cams
		move $ [0,50,600]
 	)
 )
 createdialog SpectatorCameraDialog
 
Old 06 June 2013   #15
Ah! Just saw your post Denis. When I evaluate yours, I get a Runtime Error: 'Unable to decode value: "9""

But near as I can tell, my method works with the simple 'move' line... or am I missing something?
 
Thread Closed share thread



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:24 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.