Integrating 3D models with photography
Interested in integrating your 3D work with the real world? This might help
# 1 20-09-2017 , 12:51 AM
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 user added image

# 2 20-09-2017 , 09:27 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
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 ||::
# 3 21-09-2017 , 08:45 AM
Registered User
Join Date: Sep 2017
Posts: 3
Thank you user added image I'll try it tonight!

# 4 22-09-2017 , 07:36 AM
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 :/

# 5 22-09-2017 , 06:20 PM
Gen's Avatar
Super Moderator
Join Date: Dec 2006
Location: South FL
Posts: 3,522
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 ||::
Posting Rules Forum 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

Similar Threads