SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.


SM Forums / Maya Questions / Programming / combine multiple fixe camera in one animated camera

Programming MEL Scripts, Expressions & Programming Related Topics

Join the conversation. Reply to post
 
Thread Tools
20-09-2017, 12:51 AM   #1
balthou1703
Registered User
 
Join Date: Sep 2017
Posts: 3
combine multiple fixe camera in one animated camera
Hello everyone,

I have multiple camera from a FBX generated by agisoft photoscan. Each of them is named by the corresponding frame and have a key at the corresponding frame.
I would like combine all cameras in one animated camera using each animation key of original cameras.

How would you do that with MEL or Python?

Thank you per advance
  Reply with quote
20-09-2017, 09:27 PM   #2
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,518
It would simply be a case of selecting all the cameras and saving that list to a variable. Using a "for loop", you can cycle through the camera list and grab their position in 3D space and use those coordinates to set keyframes on the a new camera (which you can create beforehand or have the script do it that too)

So essentially...
Code:
///////////////////////////////
{
	// For this example I'm hardcoding the new camera's name as a pre-existing "camera1"
	// The new camera will have keyframes set in the order that you've selected the "old" cameras
	string $cameraList[] = `ls -sl`; 
	if(`size($cameraList)`>0){
	
		string $newCam = "camera1"; 
		float $camPosition[];
		float $camRotation[];
		string $keyableTrans[] = {".tx", ".ty", ".tz"};
		string $keyableRot[] = {".rx", ".ry", ".rz"};
		float $existingKeys[];

		for($cam in $cameraList){
		
			// Get the position, rotation and existing keys of camera
			$camPosition = `xform -query -translation $cam`;
			$camRotation = `xform -query -rotation $cam`;
			$existingKeys = `keyframe -q $cam`;
			
			// Apply that transformation info to new camera
			xform -translation $camPosition[0] $camPosition[1] $camPosition[2] $newCam;	
			xform -rotation $camRotation[0] $camRotation[1] $camRotation[2] $newCam;
			
			// Set a keyframe on new camera's translation and rotation channels
			// at the frame specified by the first keyframe found in old cam's $existingKeys
			for($transChannel in $keyableTrans){
			
				if(`getAttr -keyable ($newCam + $transChannel)` || `getAttr -channelBox ($newCam + $transChannel)`)
					setKeyframe -time $existingKeys[0] ($newCam + $transChannel);	
			}
			
			for($rotChannel in $keyableRot){	
			
				if(`getAttr -keyable ($newCam + $rotChannel)` || `getAttr -channelBox ($newCam + $rotChannel)`)
					setKeyframe -time $existingKeys[0] ($newCam + $rotChannel);	
			}

		}
	}
}
//////////////////////////////
Hope that helps!
__________________
- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
  Reply with quote
21-09-2017, 08:45 AM   #3
balthou1703
Registered User
 
Join Date: Sep 2017
Posts: 3
Thank you I'll try it tonight!
  Reply with quote
22-09-2017, 07:36 AM   #4
balthou1703
Registered User
 
Join Date: Sep 2017
Posts: 3
In fact it didn't work :S

I had a way to do it in another script language:

int $input = 1017;
int $output = 1104;
int $step =1;
string $newcam = "new_cam";
string $fcam = "cam_sequence"; // each camera has the frame number in suffixe
scalar n;

// We duplicate the first camera of the sequence and rename it

select( "replace","${fcam}_${input}" );
cp( "all", "select" );
set( "name", "${newcam}" );

// We get the global position from each camera and we place a key at the frame

for(n=$input;n<=$output;n=n+$step)
{
frame $n;
set "$newcam:global", get "${fcam}_${n}:global";
key "$newcam:all";
}

But I don't know how to write it in mel :/
  Reply with quote
22-09-2017, 06:20 PM   #5
Gen
Super Moderator
 
Gen's Avatar
 
Join Date: Dec 2006
Location: South FL
Posts: 3,518
It worked in this scene I made. You could use a regex with the match command to find the suffix and convert that to an int value to use in setting keyframes. I went with the first keyframe on the dummy camera since it was a sure shot without knowing the naming conventions (which also gives it the flexibility to work with any selection of transforms).

Made with Maya 2017
copyCamKeys_test_01
To reset and test for yourself, delete the keyframes on camera1, select cameras 2 through 14 then run the script.
__________________
- Genny
__________________
::|| My CG Blog ||::
::|| My Maya FAQ ||::
  Reply with quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
trouble opening maya scene jooleyinboots Maya Technical Issues 2 03-02-2014 09:11 PM
Problems Rendering Volume Lights in Mental Ray Connor Lee Lighting & Rendering 3 16-04-2013 02:43 PM
How can I combine the animations of multiple .dae files into one timeline? EvaXephon Animation 0 14-03-2012 07:34 AM
how to combine or merge multiple poly faces nowonder Maya Basics & Newbie Lounge 4 03-11-2005 10:35 PM
Combine and then merging multiple vertex/edges Protheus Maya Modeling 7 25-01-2005 12:23 AM