//#messiahscript /////////////////////////////////////////////////////////////////////////////// // // modified by peksi // // boxcontrollerquad.msa // // by Taron 03/08/05 based on Lyle Milton's "boxcontrollermulti.msa" // copyright © 2005 pmG Worldwide, LLC // // Purpose: create a "box controller" that modifies 4 channels on an object. // // Notes: this script is a drag handle armature action. It modifies its // siblings & child offest positions. It's primary usage is in the // BoxController armature which is located in the content directory. // // modified by peksi // /////////////////////////////////////////////////////////////////////////////// #define SCRIPT_ACTION_DRAG 1 #define BOX_SIZE 100 #define BOX_HALF (BOX_SIZE/2) //The main handle action function============================================== int HandleAction(object obj1, int chan1, object obj2, int chan2, object obj3, int chan3, object obj4, int chan4, int update) { int handle; vecd3 pos; double x, y, tx, ty; handle = HandleActive(); pos = HandleOffset(handle); x = Clamp(GetVecEntry(pos, 0), -BOX_HALF, BOX_HALF); y = Clamp(GetVecEntry(pos, 1), -BOX_HALF, BOX_HALF); x = x/BOX_HALF; y = y/BOX_HALF; if (IsCurrentMode("Setup")) { SetSetupValue(obj1, chan1, 0 , 1); SetSetupValue(obj2, chan2, 0 , 1); SetSetupValue(obj3, chan3, 0 , 1); SetSetupValue(obj4, chan4, 0 , 1); if(x > 0) { SetSetupValue(obj1, chan1, x, 1); } if(x < 0) { SetSetupValue(obj2, chan2, abs(x), 1); } if(y > 0) { SetSetupValue(obj3, chan3, y, 1); } if(y < 0) { SetSetupValue(obj4, chan4, abs(y), 1); } } else { CreateChannelKey(obj1, NOW, chan1, 0 ); CreateChannelKey(obj2, NOW, chan2, 0 ); CreateChannelKey(obj3, NOW, chan3, 0 ); CreateChannelKey(obj4, NOW, chan4, 0 ); if(x > 0) { CreateChannelKey(obj1, NOW, chan1, x); } if(x < 0) { CreateChannelKey(obj2, NOW, chan2, abs(x)); } if(y > 0) { CreateChannelKey(obj3, NOW, chan3, y); } if(y < 0) { CreateChannelKey(obj4, NOW, chan4, abs(y)); } } UpdateFrame(); UpdateInterface(); return (1); } //The select handle function=============================================== int HandleSelect(object obj1, int chan1, object obj2, int chan2, object obj3, int chan3, object obj4, int chan4, int update) { int action, sib; string class_name; action = ActionActive(); class_name = ActionClass(action); ActionParamSet(action, "update", 1); sib = action; while(sib=ActionPrev(sib)) { if (ActionIsClass(sib, class_name)) ActionParamSet(sib, "update", 0); } sib = action; while(sib=ActionNext(sib)) { if (ActionIsClass(sib, class_name)) ActionParamSet(sib, "update", 0); } HandleUpdate(obj1, chan1, obj2, chan2, obj3, chan3, obj4, chan4, 1); return (1); } //The update handle function=============================================== int HandleUpdate(object obj1, int chan1, object obj2, int chan2, object obj3, int chan3, object obj4, int chan4, int update) { int handle; int child, prev; double x, y, posx, posy, tempA, tempB; float r, g, b; int stipple; double m1, m2, m3, m4; if (!update) return (1); handle = HandleActive(); m1 = motchan(obj1, chan1, NOW); m2 = motchan(obj2, chan2, NOW); m3 = motchan(obj3, chan3, NOW); m4 = motchan(obj4, chan4, NOW); //update marker,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, if(m1>0) posx = m1; if(m2>0) posx = -m2; if(m3>0) posy = m3; if(m4>0) posy = -m4; x = (posx * BOX_HALF); y = (posy * BOX_HALF); x = Clamp(x, -BOX_HALF, BOX_HALF); y = Clamp(y, -BOX_HALF, BOX_HALF); HandleOffsetVecSet(handle, x, y, 0); //update crosshair,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, if ((posy<-1)||(posy>1)||(posx<-1)||(posx>1)) { r = 1; g = 0; b = 0; } else { r = 0.94; g = 0.60; b = 0.5; } if (KeyChannelExists(obj1, NOW, chan1)||KeyChannelExists(obj2, NOW, chan2)|| KeyChannelExists(obj3, NOW, chan3)||KeyChannelExists(obj4, NOW, chan4)) { stipple = 0; r = 1; g = 1; b = 0; } else stipple = 10; child = HandleChild(handle); HandleOffsetVecSet(child, -BOX_HALF-x, 0, 0); //horizontal line - HandleColorVecSet(child, r, g, b); HandleLineStippleSet(child, stipple); child = HandleNext(child); HandleOffsetVecSet(child, BOX_HALF-x, 0, 0); //horizontal line + HandleColorVecSet(child, r, g, b); HandleLineStippleSet(child, stipple); HandleTextSet(child, str(posy)); child = HandleNext(child); HandleOffsetVecSet(child, 0, -BOX_HALF-y, 0); //vertical line - HandleColorVecSet(child, r, g, b); HandleLineStippleSet(child, stipple); child = HandleNext(child); HandleOffsetVecSet(child, 0, BOX_HALF-y, 0); //vertical line + HandleColorVecSet(child, r, g, b); HandleLineStippleSet(child, stipple); HandleTextSet(child, str(posx)); //update box edges,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, prev = HandlePrev(handle); HandleOffsetVecSet(prev, BOX_HALF, BOX_HALF, 0); //start (tr) child = HandleChild(prev); HandleOffsetVecSet(child, 0, -BOX_SIZE, 0); //right edge (br) child = HandleChild(child); HandleOffsetVecSet(child, -BOX_SIZE, 0, 0); //bottom edge (bl) child = HandleChild(child); HandleOffsetVecSet(child, 0, BOX_SIZE, 0); //left edge (tl) child = HandleChild(child); HandleOffsetVecSet(child, BOX_SIZE, 0, 0); //top edge (tr) return (1); }