XSI PPG for Cpp

うーむ、イベントよくわかんのぅ

PPGEventContext使わない?
というわけで中途半端にうp


#define READONLY (siReadOnly | siPersistable)
#define ANIMATABLE (siAnimatable | siPersistable | siKeyable)

static Application app;
static Factory factory = app.GetFactory();

... 他省略 ...

XSIPLUGINCALLBACK CStatus hoge_Execute( CRef& in_ctxt )
{
 Context ctxt( in_ctxt );
 CValueArray args = ctxt.GetAttribute(L"Arguments");

 // 
 // TODO: Put your command implementation here.
 CustomProperty oPSet = factory.CreateObject(L"CustomProperty");
 oPSet.PutName(L"hoge");
 oSel = app.GetSelection().GetItem(0);
 app.LogMessage(oSel.GetAsText());

 Parameter oParam;
 Parameter txtParam;
 Parameter btnParam;
 oPSet.AddParameter(L"Instance", CValue::siString, READONLY, L"", L"", L"instance here.", txtParam);
 oPSet.AddParameter(L"Count", CValue::siInt2, ANIMATABLE, L"", L"", 0, oParam);
 oPSet.AddParameter(L"Position", CValue::siInt1, siPersistable, L"", L"", 0, btnParam);

 PPGLayout oLayout = oPSet.GetPPGLayout();

 oLayout.Clear();
 oLayout.AddGroup(L"Duplicate");
 oLayout.AddItem(L"Instance", L"Target");
 oLayout.AddItem(L"Count", 0);
 oLayout.EndGroup();

 CValueArray radio(6);
 radio[0] = L"Left"; radio[1] = 0;
 radio[2] = L"Center"; radio[3] = 1;
 radio[4] = L"Right"; radio[5] = 2;
 oLayout.AddGroup(L"Position");
 oLayout.AddEnumControl(L"Position", radio, L"Change", siControlRadio);
 oLayout.EndGroup();

 // Logic
 oLayout.PutLanguage(L"JScript");
 oLayout.PutLogic(L"LogMessage(\"test\");");

 CValueArray wParam(5);
 wParam[0] = oPSet;
 wParam[1] = L"Duplicate Item";
 wParam[2] = (LONG)siRecycle;
 wParam[3] = false;
 CValue retval;
 app.ExecuteCommand(L"InspectObj", wParam, retval);

 // 
 // Return a value by setting this attribute:
 ctxt.PutAttribute( L"ReturnValue", true );

 // Return CStatus::Fail if you want to raise a script error
 return CStatus::OK;
}

XSI JScript - Get FCurve

アニメートされたオブジェクトからFカーブを取得するだけのもの

オブジェクトが選択されてない場合、ピックさせるようにする処理を追加

var HogeFCurve = function() { this.init(); }

/////////////////////////////////////////////////////////
// initialize class
/////////////////////////////////////////////////////////
HogeFCurve.prototype.init = function() {
 this.oPSet = XSIFactory.CreateObject("CustomProperty");
 this.oPSet.Name = "Test FCurve Param";
 this.oSel = Application.Selection(0);
 this.oParam = this.oPSet.AddFCurveParameter("TestFCurve");
 this.oFc = this.oParam.Value;
 this.oKey = this.oFc.Keys;
 try {
  this._checkSelection();
  var fcx = this.oSel.posx.Source;
  var fcy = this.oSel.posy.Source;
  var fcz = this.oSel.posz.Source;
  
  var datax = this.GetFCurveFromSource(fcx);
  var datay = this.GetFCurveFromSource(fcy);
  var dataz = this.GetFCurveFromSource(fcz);
  
  this.oFc.SetKeys(datax);
  
  LogMessage("x = " + datax + ", y = " + datay + ", z = " + dataz);
  
  //this.printInfo(fcx);
  //this.printInfo(fcy);
  //this.printInfo(fcz);
 } catch(err) {
  LogMessage(err.message);
  return false;
 }
}

HogeFCurve.prototype._checkSelection = function() {
 if(ClassName(this.oSel) != "X3DObject") {
  var oPick = PickObject("Select Object");
  var oRet = oPick.Value("ButtonPressed");
  LogMessage("Result = " + oRet);
  if(oRet) this.oSel = oPick.Value("PickedElement");
 }
 if(!this.oSel.IsClassOf(siX3DObjectID)) throw "Select or Pick Object.";
}

/////////////////////////////////////////////////////////
// show PPG
/////////////////////////////////////////////////////////
HogeFCurve.prototype.show = function() {
 try {
  this._checkSelection();
  InspectObj(this.oPSet, null, "", siRecycle, false);
 } catch(err) {
  LogMessage(err.message);
 }
 return this;
}

/////////////////////////////////////////////////////////
// 
// @param in_fc Parameter - Source property of KinematicState
// @return Array - 
/////////////////////////////////////////////////////////
HogeFCurve.prototype.GetFCurveFromSource = function(in_fc) {
 if(ClassName(in_fc) != "FCurve") throw "You passed me an a(n) " + ClassName(in_fc) + "istead of an FCurve.";
 data = []
 fckeys = in_fc.Keys;
 for(var i = 0, j = 0, k = 1; i < fckeys.Count; ++i, j+=2, k+=2) {
  data[j] = fckeys(i).Time;
  data[k] = fckeys(i).Value;
 }
 return data;
}

HogeFCurve.prototype.printInfo = function(in_fc) {
 if(ClassName(in_fc) != "FCurve") throw "You passed me an a(n) " + ClassName(in_fc) + "istead of an FCurve.";
 LogMessage("FCurve for parameter:" + in_fc.Parent);
 LogMessage("Number of keys:" + in_fc.GetNumKeys());
 LogMessage("Is the FCurve begin editing? ..." + in_fc.IsEditing());
 
 data = []
 fckeys = in_fc.Keys;
 for(var i = 0; i < fckeys.Count; ++i) {
  data[i] = fckeys(i).Value;
  LogMessage("Key[" + i + "] set at frame " + fckeys(i).Time + " = " + fckeys(i).Value);
 }
 LogMessage("data = " + data)
}

/////////////////////////////////////////////////////////
// Get current frame of scene.
// @return Double - current frame number.
/////////////////////////////////////////////////////////
HogeFCurve.prototype.currentFrame = function() {
 var remote = Dictionary.GetObject("PlayControl");
 var cur = remote.Parameters("Current");
 return cur.Value;
}

HogeFCurve.prototype.play = function(in_start, in_loop) {
 var is_start = in_start || false;
 var is_loop = in_loop || false;
 if(is_start) PlayForwardsFromStart();
 else PlayForwards();
 if(is_loop) SetValue("PlayControl.Loop", true, null);
 else SetValue("PlayControl.Loop", false, null);
 return this;
}

new HogeFCurve().show().play();

Softimage 7 - ICE

追記:シーン開き直したらアニメーションが外れたw これはダメってか

回してみた

初期化のツリーはvimeo.comを参考にしました。