static const char* const CLASS = "AddInputsSol"; static const char* const HELP = "Add all the inputs together dynamic by solHe"; // Standard plug-in include files. #include "DDImage/NoIop.h" #include "DDImage/Op.h" #include "DDImage/NukeWrapper.h" using namespace DD::Image; #include "DDImage/Row.h" #include "DDImage/Tile.h" #include "DDImage/Knobs.h" #include "DDImage/ViewerContext.h" #include <string.h> #include "stdlib.h" class AddInputsSol : public NoIop { int first_frame; int last_frame; int _numberKnobs,_numberNewKnobs; int _change_bool; char *knoblabel,*newknoblabel,*knobname_f,*newknobname_f,*knobname_l,*newknobname_l; int _inputsnewnum; char inputs_s[20]; char *inputs_c; char temp[20]; char temp_label[20]; int inputsnum; public: int minimum_inputs() const { return 1; } int maximum_inputs() const { return 100; } AddInputsSol(Node* node) : NoIop(node), first_frame(0), last_frame(99), _change_bool(0), knoblabel("Frame Range "), //newknoblabel("Frame Range"), knobname_f("fisrt_frame_"), //newknobname_f("fisrt_frame_"), knobname_l("last_frame_") //newknobname_l("last_frame_") { _inputsnewnum = inputs(); _numberKnobs = 2; _numberNewKnobs = _inputsnewnum * 2 - 2; int inputsnum = 0; } virtual void knobs(Knob_Callback); //virtual void anyInputHandles(ViewerContext*); static void addDynamicKnobs(void*, Knob_Callback); int* get_first_frame() { return &first_frame; } int* get_last_frame() { return &last_frame; } char* dynamicName_label(int); char* dynamicName_first(int); char* dynamicName_last(int); void get_real_inputs(); void knobs_replace(void* ); //refresh the set() of knobs. virtual int knob_changed(Knob* ); //used to get the state that if input number of arrow changed. //void _validate(bool); const char* Class() const { return CLASS; } const char* node_help() const { return HELP; } static const Iop::Description description; }; /* void AddInputsSol::_validate(bool for_real) { copy_info(); if(_inputsnum != _inputsnewnum) { _inputsnum = _inputsnewnum; knob("lastFrame")->set_value(_inputsnum); return; } input_changed(this->firstOp()); } */ void AddInputsSol::knobs(Knob_Callback f) { Int_knob(f, &first_frame, "fisrt_frame_1", "Frame Range 1"); //SetFlags(f, Knob::NO_ANIMATION); Int_knob(f, &last_frame, "last_frame_1", ""); //SetFlags(f, Knob::NO_ANIMATION); SetFlags(f,Knob::KNOB_CHANGED_ALWAYS); //split from here to indicate that the script after here is dynamic. if( !f.makeKnobs() ) { get_real_inputs(); } } //compare number of inputs arrows and number of knobs,return a state value. int AddInputsSol::knob_changed(Knob* k) { //caluculate the real sum of inputs() if( _numberKnobs != 2 * inputsnum | inputsnum != inputs() ) { //refresh the knob list _change_bool = 1; _numberNewKnobs = replace_knobs(knob("last_frame_1"), _numberNewKnobs, addDynamicKnobs, this->firstOp()); _numberKnobs = 2 + _numberNewKnobs; return 1; } else { //nothing happen. _change_bool = 0; _numberKnobs += 0; get_real_inputs(); return NoIop::knob_changed(k); } } void AddInputsSol::get_real_inputs() { int i; int inputsnum = 0; for (i = 1;i <= inputs();i++) { if( node_input(i,OUTPUT_OP) != NULL ) { inputsnum += 1; } } } void AddInputsSol::addDynamicKnobs(void* p,Knob_Callback f) { if( ( ( AddInputsSol* ) p ) -> _change_bool == 1 ) { //get the real number of inputs. ( ( AddInputsSol* ) p ) -> get_real_inputs(); //create knobs. int i,num; num = ( ( AddInputsSol* ) p ) -> inputsnum - 1; for ( i = 1; i <= ( ( AddInputsSol* ) p ) -> inputs() - 1; i++ ) { Int_knob(f, ((AddInputsSol*) p) -> get_first_frame(), ((AddInputsSol*) p) -> dynamicName_first(i+1), ((AddInputsSol*) p) -> dynamicName_label(i+1)); Int_knob(f, ((AddInputsSol*) p) -> get_last_frame(), ((AddInputsSol*) p) -> dynamicName_last(i+1), ""); } } } char* AddInputsSol::dynamicName_label(int i) { char* inputs_c = itoa(i,inputs_s,20); strcpy(temp_label,knoblabel); strcat(temp_label,inputs_c); char* newknoblabel = (LPSTR)temp_label; return newknoblabel; } char* AddInputsSol::dynamicName_first(int i) { char* inputs_c = itoa(i,inputs_s,100); //char temp[20]; strcpy(temp,knobname_f); strcat(temp,inputs_c); char* newknobname_f = (LPSTR)temp; return newknobname_f; } char* AddInputsSol::dynamicName_last(int i) { char* inputs_c = itoa(i,inputs_s,100); //char temp[20]; strcpy(temp,knobname_l); strcat(temp,inputs_c); char* newknobname_l = (LPSTR)temp; return newknobname_l; } /*! The Iop::Description is how NUKE knows what the name of the operator is, how to create one, and the menu item to show the user. The menu item may be 0 if you do not want the operator to be visible. */ static Iop* AddInputsCreate(Node* node) { return new AddInputsSol(node); } static Iop* build(Node* node) { return new NukeWrapper(new AddInputsSol(node)); } const Iop::Description AddInputsSol::description ( CLASS, "AddInputsSol", AddInputsCreate );
国内正经搞NDK开发的TD不多,相关研究文章也很少,我就放个自己写的源码做参考吧,写的很乱,希望能给看到这篇文章的人一点启发。