Code: Select all
Camera Sequencer v0.03
History:
v0.01 03-02-2012
v0.02 (24-05-2012) now works with cameras which are children of a Model null.
v0.03 (30-05-2012) Works with cameras without interest nulls.
Creates a new camera which matches a list of cameras.
work in progress needs lots of error checking/trapping including!
Dan Lane 03-02-2012
*/
if ( findObj( "Camera_Sequencer" ) != false){
deleteObj("Camera_Sequencer");
}
//--------------------------------------
// UI Layout
//--------------------------------------
var oCustomProperty = ActiveSceneRoot.AddCustomProperty(
"Camera_Sequencer",
false ) ;
oCustomProperty.AddParameter( "camQueue", siString ) ;
oCustomProperty.AddParameter3( "Start", siDouble, 0,0,2000,false) ;
oCustomProperty.AddParameter3( "End", siDouble, 0,0,2000,false) ;
var oPPGLayout = oCustomProperty.PPGLayout ;
oPPGLayout.AddTab( "Chars" );
var updateButton = oPPGLayout.AddButton( "ADD_TO_LIST" , "Add Selected" ) ;
updateButton.SetAttribute( siUICX , 260 );
oPPGLayout.AddRow() ;
var removeButton = oPPGLayout.AddButton( "REMOVE_FROM_LIST" , "Remove Item" ) ;
removeButton.SetAttribute( siUICX , 130 );
var clearButton = oPPGLayout.AddButton( "CLEAR_LIST" , "Clear list" ) ;
clearButton.SetAttribute( siUICX , 130 );
oPPGLayout.EndRow() ;
oPPGLayout.AddGroup( "Camera Queue" , true , 1 ) ;
AddListBox( oPPGLayout, "camQueue" , 260 , false ) ;
oPPGLayout.EndGroup() ;
oPPGLayout.AddGroup( "Time Range", true, 1 ) ;
oPPGLayout.AddRow() ;
var startSlider = oPPGLayout.AddItem( "Start" , "Start:" ) ;
startSlider.SetAttribute( siUICX , 65 );
var endSlider = oPPGLayout.AddItem( "End" , "End:" ) ;
endSlider.SetAttribute( siUICX , 65 );
oPPGLayout.EndRow() ;
oPPGLayout.EndGroup() ;
var processButton = oPPGLayout.AddButton( "process" , "Process Queue" ) ;
processButton.SetAttribute( siUICX , 260 );
processButton.SetAttribute( siUICY , 35 );
oPPGLayout.Language = "JScript" ;
oPPGLayout.Logic = ADD_TO_LIST_OnClicked.toString() +
camQueue_OnChanged.toString() +
getItemIndex.toString() +
Start_OnChanged.toString() +
End_OnChanged.toString() +
process_OnClicked.toString() +
CLEAR_LIST_OnClicked.toString() +
REMOVE_FROM_LIST_OnClicked.toString() +
findObj.toString();
InspectObj( oCustomProperty, "", "Camera_Sequencer" , siLock );
//--------------------------------------
// Button Functions
//--------------------------------------
function REMOVE_FROM_LIST_OnClicked()
{
var itemIndex = getItemIndex();
logmessage("item index = " + itemIndex);
// get the entire list of items
var oLayout = PPG.PPGLayout ;
var oItem = oLayout.Item("camQueue");
var vbItems = new VBArray(oItem.UIItems);
var aItems = vbItems.toArray();
var newList = new Array();
for ( var i = 0 ; i < aItems.length ; i++ )
{
if(i != itemIndex && i != (itemIndex - 1)){
newList[newList.length] = aItems[i];
}
}// end i loop
oItem.UIItems = newList ;
PPG.Refresh() ;
}
function CLEAR_LIST_OnClicked()
{
// get current list
var oLayout = PPG.PPGLayout ;
var oItem = oLayout.Item("camQueue");
var aItems = new Array();
oItem.UIItems = aItems ;
PPG.Refresh() ;
}
function ADD_TO_LIST_OnClicked()
{
// get current list
var oLayout = PPG.PPGLayout ;
var oItem = oLayout.Item("camQueue");
var vbItems = new VBArray(oItem.UIItems);
var aItems = vbItems.toArray();
//var aItems = oItem.UIItems;
var notInList = true;
inName = selection(0).fullname;
if(notInList){
logmessage("Name not in list");
// add to the end of the list
var startTimeStr = "0";
var endTimeStr = "100";
// if this is not the first item
if(aItems.length != 0){
var lastString = aItems[aItems.length - 2];
var dashIndex = ( lastString.indexOf("-", 0 ));
startTimeStr = ( parseFloat(lastString.slice(dashIndex + 2 ,lastString.length)) + 1 );
endTimeStr = (parseFloat( lastString.slice(dashIndex + 2 ,lastString.length) ) + 100) ;
}
//20 chars
var blankString = " ";
var inLength = inName.length
if(blankString.length > inName.length){
}else{
}
var gapString = blankString.slice(inName.length ,blankString.length);
aItems[aItems.length] = (inName + gapString + "@ "+startTimeStr+" - " + endTimeStr) ;
aItems[aItems.length] = inName ;
}// end if notInList
oItem.UIItems = aItems ;
PPG.Refresh() ;
}// end function
function camQueue_OnChanged()
{
var itemIndex = getItemIndex();
//logmessage("item index = " + itemIndex);
// get the entire list of items
var oLayout = PPG.PPGLayout ;
var oItem = oLayout.Item("camQueue");
var vbItems = new VBArray(oItem.UIItems);
var aItems = vbItems.toArray();
var timesString = aItems[itemIndex - 1];
var atIndex = timesString.indexOf("@", 0 );
var useString = timesString.slice(atIndex , timesString.length);
// extract the times from the timeString
var spaceIndex = ( useString.indexOf(" ", 0 ));
//logmessage("space index " + spaceIndex);
var dashIndex = ( useString.indexOf("-", 0 ));
//logmessage("dash Index " + dashIndex);
var startTimeFloat = parseFloat(useString.slice(spaceIndex + 1 , dashIndex - 1)) ;
var endTimeFloat = parseFloat( useString.slice(dashIndex + 2 ,timesString.length) ) ;
//logmessage("startTimeFloat = " + startTimeFloat);
// set the sliders to these times
var startSlider = oLayout.Item("Start");
var endSlider = oLayout.Item("End");
PPG.Start.Value = startTimeFloat;
//startSlider.value = startTimeFloat;
PPG.End.Value = endTimeFloat;
}// end function
function Start_OnChanged(){
if(PPG.Start.Value > PPG.End.Value){
PPG.End.Value = PPG.Start.Value;
}
var itemIndex = getItemIndex();
logmessage( "itemIndex = "+ itemIndex);
var oLayout = PPG.PPGLayout ;
var oItem = oLayout.Item("camQueue");
var vbItems = new VBArray(oItem.UIItems);
var aItems = vbItems.toArray();
var timeString = aItems[itemIndex - 1];
logmessage("aItems[itemIndex - 1] = "+ aItems[itemIndex - 1]);
var atIndex = timeString.indexOf("@", 0 );
var useString = timeString.slice(0, atIndex + 1);
aItems[itemIndex - 1] = ( useString + " " + PPG.Start.Value +" - " + PPG.End.Value) ;
oItem.UIItems = aItems ;
PPG.Refresh() ;
}
function End_OnChanged(){
if(PPG.Start.Value > PPG.End.Value){
PPG.Start.Value = PPG.End.Value;
}
var itemIndex = getItemIndex();
//logmessage( "itemIndex = "+ itemIndex);
var oLayout = PPG.PPGLayout ;
var oItem = oLayout.Item("camQueue");
var vbItems = new VBArray(oItem.UIItems);
var aItems = vbItems.toArray();
var timeString = aItems[itemIndex - 1];
//logmessage("aItems[itemIndex - 1] = "+ aItems[itemIndex - 1]);
var atIndex = timeString.indexOf("@", 0 );
var useString = timeString.slice(0, atIndex + 1);
aItems[itemIndex - 1] = ( useString + " " + PPG.Start.Value +" - " + PPG.End.Value) ;
//aItems[aItems.length] = inName ;
oItem.UIItems = aItems ;
PPG.Refresh() ;
}
function getItemIndex(){
// find out which item is clicked
var clickedStr = PPG.Inspected(0).Parameters("camQueue").Value;
// get the entire list of items
var oLayout = PPG.PPGLayout ;
var oItem = oLayout.Item("camQueue");
var vbItems = new VBArray(oItem.UIItems);
var aItems = vbItems.toArray();
// find the clicked item in the entire list
var itemIndex = -1;
var counter = 0;
while(counter < aItems.length){
if( clickedStr == aItems[counter]){
itemIndex = counter;
counter = (aItems.length + 1);
}
counter ++ ;
}// end while loop
return(itemIndex);
}
function process_OnClicked()
{
var matchCam = findObj( "matchCam" ) ;
if (matchCam == false){
}else{
// use the camera
var o3DObjCamera = Dictionary.GetObject("matchCam");
var oPrimObjCameraInterest = o3DObjCamera.Interest;
deleteObj(o3DObjCamera.fullname);
//deleteObj(oPrimObjCameraInterest.fullname);
}
// create camera
rtn = SIGetPrimCamera( "Camera", "matchCam", "matchCamInterest" );
var o3DObjCamera = rtn.Value("3DObjCamera" );
var o3DObjCameraInterest = rtn.Value("3DObjCameraInterest" );
var oPrimObjCamera = rtn.Value( "PrimObjCamera" );
var oPrimObjCameraInterest = rtn.Value(" PrimObjCameraInterest" );
deleteObj(o3DObjCameraInterest.fullname);
var oLayout = PPG.PPGLayout ;
var oItem = oLayout.Item("camQueue");
var vbItems = new VBArray(oItem.UIItems);
var aItems = vbItems.toArray();
// generate the pose constraints
for ( var i = 0 ; i < aItems.length ; i += 2 )
{
//Use i
var timesString = aItems[i];
var nameValue = aItems[i + 1];
//logmessage("timeString " + timesString);
var atIndex = timesString.indexOf("@", 0 );
var useString = timesString.slice(atIndex , timesString.length);
// extract the times from the timeString
var spaceIndex = ( useString.indexOf(" ", 0 ));
//logmessage("space index " + spaceIndex);
var dashIndex = ( useString.indexOf("-", 0 ));
//logmessage("dash Index " + dashIndex);
var startTimeFloat = parseFloat(useString.slice(spaceIndex + 1 , dashIndex - 1)) ;
var endTimeFloat = parseFloat( useString.slice(dashIndex + 2 ,timesString.length) ) ;
// get the camera to match to
logmessage(nameValue);
var matchCamera = Dictionary.GetObject(nameValue);
// get some settings off the camerea
if(i == 0){
var camFormat = matchCamera.Parameters("std").Value;
o3DObjCamera.Parameters("std").Value = camFormat;
}
if( matchInt == null){
logmessage("Undefined");
}else{
logmessage("OK");
}
// get the interest to match to
var matchInt = matchCamera.Interest;
// add the constraints
var oConstaintCam = o3DObjCamera.Kinematics.AddConstraint( "Pose", matchCamera , false );
//var oConstaintInt = o3DObjCameraInterest.Kinematics.AddConstraint( "Pose", matchInt , false );
// key the active parameters
var activeParam = oConstaintCam.Parameters("active");
//var activeParamInt = oConstaintInt.Parameters("active");
if ( ClassName(activeParam.source) != "FCurve" ) {
activeParam.AddFCurve2();
}
//if ( ClassName(activeParamInt.source) != "FCurve" ) {
// activeParamInt.AddFCurve2();
// }
var activeCurveCamera = activeParam.Source;
//var activeCurveInt = activeParamInt.Source;
activeCurveCamera.AddKey( startTimeFloat - 1 , 0 ) ;
activeCurveCamera.AddKey( startTimeFloat , 1 ) ;
activeCurveCamera.AddKey( endTimeFloat + 1 , 0 ) ;
activeCurveCamera.AddKey( endTimeFloat , 1 ) ;
//activeCurveInt.AddKey( startTimeFloat - 1 , 0 ) ;
//activeCurveInt.AddKey( startTimeFloat , 1 ) ;
//activeCurveInt.AddKey( endTimeFloat + 1 , 0 ) ;
//activeCurveInt.AddKey( endTimeFloat , 1 ) ;
}// end i loop
// create the script op for the fov
var inFovParam = o3DObjCamera.Parameters( "fov" );
var code = " function myCns_Update( In_UpdateContext, Out ," ;
//InTimeWarp , InpreviewSpeed
var camNamesArray = new Array();
var counter = 0;
for ( var i = 0 ; i < aItems.length ; i += 2 )
{
if(i > 0){
camNamesArray[camNamesArray.length] = "Infov" + counter;
}else{
camNamesArray[camNamesArray.length] = "Infov";
}
counter ++;
};
var camNameString = camNamesArray.join(",");
code += camNameString ;
code += " ) \n" ;
code += " { \n";
code += " var current_frame = In_UpdateContext.operator.current_frame.value; \n " ;
var counter = 0;
for ( var i = 0 ; i < aItems.length ; i += 2 )
{
var timesString = aItems[i];
var nameValue = aItems[i + 1];
//logmessage("timeString " + timesString);
var atIndex = timesString.indexOf("@", 0 );
var useString = timesString.slice(atIndex , timesString.length);
// extract the times from the timeString
var spaceIndex = ( useString.indexOf(" ", 0 ));
//logmessage("space index " + spaceIndex);
var dashIndex = ( useString.indexOf("-", 0 ));
//logmessage("dash Index " + dashIndex);
var startTimeFloat = parseFloat(useString.slice(spaceIndex + 1 , dashIndex - 1)) ;
var endTimeFloat = parseFloat( useString.slice(dashIndex + 2 ,timesString.length) ) ;
if(i == 0){
code += "if(current_frame >= " + startTimeFloat + " && current_frame <= " + endTimeFloat + "){ \n" ;
}else{
code += "else if(current_frame >= " + startTimeFloat + " && current_frame <= " + endTimeFloat + "){ \n" ;
}
code += " var outValue = " + camNamesArray[counter] + ".Value ; \n";
code += " } " ;
counter ++ ;
}// end i loop
code += "\n Out.Value = outValue ; \n";
code += " } \n";
var op = XSIFactory.CreateScriptedOp( "myCns", code , "JScript" );
op.AddOutputPort( inFovParam , "");
for ( var i = 0 ; i < aItems.length ; i += 2 )
{
op.AddInputPort( aItems[i + 1] + ".camera.fov" );
}
var pdef = XSIFactory.CreateParamDef("current_Frame", siInt4, 0, siAnimatable, "", "", 1, -100000, 100000,0,1);
var current_Frame_param = op.AddParameter(pdef);
op.Connect();
SetExpr(op + ".current_frame","fc");
}// end function
function AddListBox( in_oLayout, in_Name , width , multi)
{
// Insert a ListBox into the layout
var oItem = in_oLayout.AddItem( in_Name, "", "ListBox" ) ;
oItem.SetAttribute( "CY", 175 ) ;
oItem.SetAttribute( "CX", width ) ;
oItem.SetAttribute( "NoLabel", true ) ;
//Note: Multi-selection list box control only applies to string parameter.
oItem.SetAttribute( siUIMultiSelectionListBox, multi ) ;
}
function findObj( inObj ) {
var oColl = new ActiveXObject("XSI.Collection");
oColl.items = inObj;
if (oColl.count > 0) {
return(oColl(0));
} else {
return(false);
}
}