how does it extend mxs and whats wrong with
node.modifiers[1].enabled = false
?
was having trouble clearing the “Global Tracks” filter in TrackView so I wrote a couple of functions that use masks (ints) as opposed to Name values.
the set function argument is either 0 or 1 and the mask bits can be found in itreevw.h in the SDK
for example
will clear the global Tracks and any material tracks
i was playing this weekend with k-d trees, and i’m absolutely positive that kd2tree and kd3tree should be one of built-in classes.
as well as box3 and typed array.
using kd2tree i’ve written pretty well walking UV pack
i found that kd3tree works very well for most “find nearest” tasks
box3 is absolutely necessary class
typed array is the thing that contains only specified type item. it changes everything! if you know a type of an item the array doesn’t take any mxs memory.
i wrote for my mxs extension:
floatTab (includes indexes, integers)
point2Tab
point3Tab
point4Tab (very useful when you want to store both position and index)
matrix3Tab
in my framework the task:
find all vertices of mesh B which are contained by bounding box of node A in it’s local coordinate system
looks as:
vertTab = (point4tab $B transform:(inverse $A.transform)) * (box3 $A transform:#local)
-- it's a point4Tab (pos + index)
verts = convertto vertTab #bitarray -- returns only indecies of verts
Putting this particular example aside and ignoring the fact that it’s solvable in maxscript, I highly encourage you to get in the habit of not writing this type of multi-purpose code.
Each method should have one and only one purpose which should be easily inferrable from its name. Once we alter the purpose of a method using its parameters, things get hard to keep track of and debug.
You wouldn’t write something like this, would you?
void DoSomethingToNode(INode* node, BOOL hide, BOOL delete, BOOL convertToTeapot)
{ ... }
You can separate common parts of two methods to a separate private function, but your public API should be more along the lines of:
void DeleteNodeModifiers(INode* node);
void EnableNodeModifiers(INode* node, BOOL state);
or
void DeleteNodeModifiers(INode* node);
void EnableNodeModifiers(INode* node);
void DisableNodeModifiers(INode* node);
something not exposed to mxs as far as I’m aware, though it is available via scripting it requires several lines and differing version depending on the obj type
nice
here is slightly modified version:
def_visible_primitive(hasUVW, "hasUVW");
Value* hasUVW_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(hasUVW, 1, count);
if (is_node(arg_list[0]))
{
INode* node = arg_list[0]->to_node();
Object* obj = node->EvalWorldState(MAXScript_time()).obj;
if (is_number(key_arg(channel)))
{
return bool_result(obj->HasUVW(key_arg(channel)->to_int()));
}
else return bool_result(obj->HasUVW());
}
return &undefined;
}
covers a case if any channel has uvws
here is a CUI extension. the most interesting part is getting and setting rank (in short second-third-etc. row or column of dock panels, and changing an order of toolbar in toolbar panel)
/************************** ICUI Manager ***************************************/
void RedrawCUI(BOOL entireApp = TRUE)
{
GetCUIFrameMgr()->RecalcLayout(entireApp);
GetCUIFrameMgr()->DrawCUIWindows(); // not sure it's necessary
}
ICUIFrame* GetCUIFrame(int index)
{
return GetCUIFrameMgr()->GetICUIFrame(index);
}
ICUIFrame* GetCUIFrame(const wchar_t* name)
{
return GetCUIFrameMgr()->GetICUIFrame(name);
}
ICUIFrame* GetCUIFrame(Value* val)
{
if (is_string(val))
return (GetCUIFrame(val->to_string()));
if (is_number(val))
return (GetCUIFrame(val->to_int()-1));
return NULL;
}
def_struct_primitive(ICUI_recalcLayout, ICUI, "recalcLayout");
Value* ICUI_recalcLayout_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(recalcLayout, 0, count);
BOOL entireApp = key_arg_or_default(all, &true_value)->to_bool();
RedrawCUI(entireApp);
return &ok;
}
def_struct_primitive(ICUI_redraw, ICUI, "redraw");
Value* ICUI_redraw_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(redraw, 0, count);
BOOL buttons = key_arg_or_default(update, &false_value)->to_bool();
GetCUIFrameMgr()->DrawCUIWindows();
if (buttons) GetCUIFrameMgr()->SetMacroButtonStates(FALSE);
return &ok;
}
def_struct_primitive(ICUI_update, ICUI, "update");
Value* ICUI_update_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(redraw, 0, count);
BOOL windows = key_arg_or_default(redraw, &false_value)->to_bool();
if (windows) GetCUIFrameMgr()->DrawCUIWindows();
GetCUIFrameMgr()->SetMacroButtonStates(FALSE);
return &ok;
}
def_struct_primitive(ICUI_getCount, ICUI, "getCount");
Value* ICUI_getCount_cf(Value **arg_list, int count)
{
check_arg_count(getCount, 0, count);
return Integer::intern(GetCUIFrameMgr()->GetCount());
}
def_struct_primitive(ICUI_getFrameNames, ICUI, "getFrameNames");
Value* ICUI_getFrameNames_cf(Value **arg_list, int count)
{
check_arg_count(getFrameNames, 0, count);
int num = GetCUIFrameMgr()->GetCount();
Array* arr = new Array(0);
for (int k=0; k < num; k++)
{
ICUIFrame* cui = GetCUIFrameMgr()->GetICUIFrame(k);
arr->append(new String(cui->GetName()));
}
return arr;
}
def_struct_primitive(ICUI_getToolbars, ICUI, "getToolbars");
Value* ICUI_getToolbars_cf(Value **arg_list, int count)
{
check_arg_count(getToolbars, 0, count);
int num = GetCUIFrameMgr()->GetCount();
Array* arr = new Array(0);
for (int k=0; k < num; k++)
{
ICUIFrame* cui = GetCUIFrameMgr()->GetICUIFrame(k);
if (cui->GetContentType() == 1) arr->append(new String(cui->GetName()));
}
return arr;
}
def_struct_primitive(ICUI_getFrameName, ICUI, "getFrameName");
Value* ICUI_getFrameName_cf(Value **arg_list, int count)
{
check_arg_count(getFrameName, 1, count);
int num = GetCUIFrameMgr()->GetCount();
int index = arg_list[0]->to_int()-1;
if (index < 0 || index >= num) return &undefined;
return (new String(GetCUIFrameMgr()->GetICUIFrame(index)->GetName()));
}
def_struct_primitive(ICUI_getFrameIndex, ICUI, "getFrameIndex");
Value* ICUI_getFrameIndex_cf(Value **arg_list, int count)
{
check_arg_count(getFrameIndex, 1, count);
int num = GetCUIFrameMgr()->GetCount();
MSTR name = arg_list[0]->to_string();
for (int k=0; k < num; k++)
{
const wchar_t* n = GetCUIFrameMgr()->GetICUIFrame(k)->GetName();
if (::_wcsicmp(n, name) == 0)
{
return int_value(k+1);
}
}
return &undefined;
}
def_struct_primitive(ICUI_getFrameType, ICUI, "getFrameType");
Value* ICUI_getFrameType_cf(Value **arg_list, int count)
{
check_arg_count(getFrameType, 1, count);
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui)
{
return int_value(cui->GetContentType());
}
return &undefined;
}
/* shouldn't be used
def_struct_primitive(ICUI_setFrameType, ICUI, "setFrameType");
Value* ICUI_setFrameType_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(setFrameType, 2, count);
BOOL redraw = key_arg_or_default(redraw, &true_value)->to_bool();
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui)
{
cui->SetContentType(arg_list[1]->to_int());
if (redraw) RedrawCUI();
return int_value(cui->GetContentType());
}
return &undefined;
}
*/
def_struct_primitive(ICUI_isFrameFloating, ICUI, "isFrameFloating");
Value* ICUI_isFrameFloating_cf(Value **arg_list, int count)
{
check_arg_count(isFrameFloating, 1, count);
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui) return bool_value(cui->IsFloating());
return &undefined;
}
def_struct_primitive(ICUI_getFramePosition, ICUI, "getFramePosition");
Value* ICUI_getFramePosition_cf(Value **arg_list, int count)
{
check_arg_count(getFramePosition, 1, count);
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui) return int_value(cui->GetCurPosition());
return &undefined;
}
def_struct_primitive(ICUI_setFramePosition, ICUI, "setFramePosition");
Value* ICUI_setFramePosition_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(setFramePosition, 2, count);
BOOL redraw = key_arg_or_default(redraw, &true_value)->to_bool();
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui)
{
cui->SetCurPosition(arg_list[1]->to_int());
if (redraw) RedrawCUI();
return int_value(cui->GetCurPosition());
}
return &undefined;
}
def_struct_primitive(ICUI_getFramePosType, ICUI, "getFramePosType");
Value* ICUI_getFramePosType_cf(Value **arg_list, int count)
{
check_arg_count(getFramePosType, 1, count);
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui) return int_value(cui->GetPosType());
return &undefined;
}
def_struct_primitive(ICUI_setFramePosType, ICUI, "setFramePosType");
Value* ICUI_setFramePosType_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(setFramePosType, 2, count);
BOOL redraw = key_arg_or_default(redraw, &true_value)->to_bool();
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui)
{
cui->SetPosType(arg_list[1]->to_int());
if (redraw) RedrawCUI();
return int_value(cui->GetPosType());
}
return &undefined;
}
def_struct_primitive(ICUI_getFrameRank, ICUI, "getFrameRank");
Value* ICUI_getFrameRank_cf(Value **arg_list, int count)
{
check_arg_count(getFrameRank, 1, count);
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui) return new Point2Value(Point2(cui->GetPosRank(), cui->GetPosSubrank()));
return &undefined;
}
def_struct_primitive(ICUI_setFrameRank, ICUI, "setFrameRank");
Value* ICUI_setFrameRank_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(setFrameRank, 2, count);
BOOL redraw = key_arg_or_default(redraw, &true_value)->to_bool();
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui)
{
Point2 rank = arg_list[1]->to_point2();
cui->SetPosRank(int(rank.x), int(rank.y));
if (redraw) RedrawCUI();
return new Point2Value(Point2(cui->GetPosRank(), cui->GetPosSubrank()));
}
return &undefined;
}
def_struct_primitive(ICUI_isFrameHidden, ICUI, "isFrameHidden");
Value* ICUI_isFrameHidden_cf(Value **arg_list, int count)
{
check_arg_count(isFrameHidden, 1, count);
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui) return bool_value(cui->IsHidden());
return &undefined;
}
def_struct_primitive(ICUI_showFrame, ICUI, "showFrame");
Value* ICUI_showFrame_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(showFrame, 1, count);
BOOL redraw = key_arg_or_default(redraw, &true_value)->to_bool();
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui)
{
cui->Hide(FALSE);
if (redraw) RedrawCUI();
return bool_value(!cui->IsHidden());
}
return &undefined;
}
def_struct_primitive(ICUI_hideFrame, ICUI, "hideFrame");
Value* ICUI_hideFrame_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(hideFrame, 1, count);
BOOL redraw = key_arg_or_default(redraw, &true_value)->to_bool();
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui)
{
cui->Hide(TRUE);
if (redraw) RedrawCUI();
return bool_value(!cui->IsHidden());
}
return &undefined;
}
def_struct_primitive(ICUI_getFrameHWND, ICUI, "getFrameHWND");
Value* ICUI_getFrameHWND_cf(Value **arg_list, int count)
{
check_arg_count_with_keys(getFrameHWND, 1, count);
BOOL parent = key_arg_or_default(parent, &false_value)->to_bool();
ICUIFrame* cui = GetCUIFrame(arg_list[0]);
if (cui)
{
HWND hwnd = cui->GetContentHandle();
if (parent) hwnd = GetParent(hwnd);
return IntegerPtr::intern(INT_PTR(hwnd));
}
return &undefined;
}