From b7dbbcac5405a6cf92df284392a4e2433ca03e9d Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 3 Dec 2014 15:16:39 +0100 Subject: [PATCH] Add script to orient zone patches automatically --- .../plugin_max/nel_patch_converter/script.cpp | 30 +++++ .../3d/plugin_max/nel_patch_edit/editpat.h | 1 + .../tools/3d/plugin_max/nel_patch_edit/np.cpp | 89 +++++++++++++++ .../nel_patch_edit/np_epm_selection.cpp | 44 +++++++ .../3d/plugin_max/scripts/nel_orient_zones.ms | 108 ++++++++++++++++++ 5 files changed, 272 insertions(+) create mode 100644 code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms diff --git a/code/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp b/code/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp index 8acae94bd..80e715f21 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp +++ b/code/nel/tools/3d/plugin_max/nel_patch_converter/script.cpp @@ -338,6 +338,8 @@ get_selected_tile_cf(Value** arg_list, int count) if (tri->rpatch->tileSel[i]) array->append(Integer::intern(i+1)); } + if (os.obj != tri) + delete tri; } } @@ -383,6 +385,8 @@ get_selected_patch_cf(Value** arg_list, int count) if (tri->patch.patchSel[i]) array->append(Integer::intern(i+1)); } + if (os.obj != tri) + delete tri; } } @@ -428,6 +432,8 @@ get_selected_vertex_cf(Value** arg_list, int count) if (tri->patch.vertSel[i]) array->append(Integer::intern(i+1)); } + if (os.obj != tri) + delete tri; } } @@ -617,6 +623,8 @@ set_vertex_count_cf(Value** arg_list, int count) { nRet=tri->patch.numVerts; } + if (os.obj != tri) + delete tri; } return Integer::intern(nRet); @@ -655,6 +663,8 @@ set_vector_count_cf(Value** arg_list, int count) { nRet=tri->patch.numVecs; } + if (os.obj != tri) + delete tri; } return Integer::intern(nRet); @@ -702,6 +712,8 @@ set_vertex_pos_cf(Value** arg_list, int count) node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); ip->RedrawViews(ip->GetTime()); } + if (os.obj != tri) + delete tri; } } @@ -750,6 +762,8 @@ set_vector_pos_cf(Value** arg_list, int count) node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); ip->RedrawViews(ip->GetTime()); } + if (os.obj != tri) + delete tri; } } @@ -792,6 +806,8 @@ get_vertex_pos_cf(Value** arg_list, int count) { vRet=new Point3Value (tri->patch.verts[nVertex].p); } + if (os.obj != tri) + delete tri; } } @@ -834,6 +850,8 @@ get_vector_pos_cf(Value** arg_list, int count) { vRet=new Point3Value (tri->patch.vecs[nVertex].p); } + if (os.obj != tri) + delete tri; } } @@ -877,6 +895,8 @@ get_edge_vect1_cf(Value** arg_list, int count) { nVert=tri->patch.edges[nEdge].vec12; } + if (os.obj != tri) + delete tri; } } @@ -919,6 +939,8 @@ get_edge_vect2_cf(Value** arg_list, int count) { nVert=tri->patch.edges[nEdge].vec21; } + if (os.obj != tri) + delete tri; } } @@ -961,6 +983,8 @@ get_edge_vert1_cf(Value** arg_list, int count) { nVert=tri->patch.edges[nEdge].v1; } + if (os.obj != tri) + delete tri; } } @@ -1004,6 +1028,8 @@ get_edge_vert2_cf(Value** arg_list, int count) { nVert=tri->patch.edges[nEdge].v2; } + if (os.obj != tri) + delete tri; } } @@ -1050,6 +1076,8 @@ get_sel_edge_cf(Value** arg_list, int count) array->append(Integer::intern(i+1)); //array->data[j++]=; } + if (os.obj != tri) + delete tri; } } @@ -1158,6 +1186,8 @@ set_tile_steps_cf(Value** arg_list, int count) nTess=5; tri->rpatch->rTess.TileTesselLevel=nTess; tri->rpatch->InvalidateChannels (PART_ALL); + if (os.obj != tri) + delete tri; } if (bRet) { diff --git a/code/nel/tools/3d/plugin_max/nel_patch_edit/editpat.h b/code/nel/tools/3d/plugin_max/nel_patch_edit/editpat.h index d0bfd1773..ec8947571 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_edit/editpat.h +++ b/code/nel/tools/3d/plugin_max/nel_patch_edit/editpat.h @@ -755,6 +755,7 @@ class EditPatchMod : public Modifier, IPatchOps, IPatchSelect, ISubMtlAPI, Attac TCHAR *GetObjectName() { return GetString(IDS_TH_EDITPATCH); } void ActivateSubobjSel(int level, XFormModes& modes ); int NeedUseSubselButton() { return 0; } + void SelectSubPatch(int index); void SelectSubComponent( HitRecord *hitRec, BOOL selected, BOOL all, BOOL invert ); void ClearSelection(int selLevel); void SelectAll(int selLevel); diff --git a/code/nel/tools/3d/plugin_max/nel_patch_edit/np.cpp b/code/nel/tools/3d/plugin_max/nel_patch_edit/np.cpp index 7b1c9c644..133d0b4d6 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_edit/np.cpp +++ b/code/nel/tools/3d/plugin_max/nel_patch_edit/np.cpp @@ -84,6 +84,31 @@ *> Copyright(c) 1994, All Rights Reserved. **********************************************************************/ #include "stdafx.h" + +#if MAX_VERSION_MAJOR >= 14 +# include +# include +# include +# include +# include +# include +# include +# include +# include +#else +# include +# include +// Various MAX and MXS includes +# include +# include +# include +# include +# include +# include +// define the new primitives using macros from SDK +# include +#endif + #include "editpat.h" #include "../nel_patch_lib/vertex_neighborhood.h" @@ -855,3 +880,67 @@ void ResetVert (PatchMesh *patch) patch->computeInteriors(); patch->InvalidateGeomCache (); } + +def_visible_primitive(turn_patch, "RykolTurnPatch"); + +Value *turn_patch_cf (Value** arg_list, int count) +{ + // Make sure we have the correct number of arguments (2) + check_arg_count(RykolTurnPatch, 3, count); + + // Check to see if the arguments match up to what we expect + // We want to use 'TurnAllTexturesOn ' + type_check(arg_list[0], MAXNode, "RykolTurnPatch [Node] [Modifier] [Patch]"); + type_check(arg_list[1], MAXModifier, "RykolTurnPatch [Node] [Modifier] [Patch]"); + type_check(arg_list[2], Integer, "RykolTurnPatch [Node] [Modifier] [Patch]"); + + // Get a good interface pointer + Interface *ip = MAXScript_interface; + + // Get a INode pointer from the argument passed to us + INode *node = arg_list[0]->to_node(); + nlassert (node); + + // Get a Object pointer + ObjectState os = node->EvalWorldState(ip->GetTime()); + + // ok ? + bool bRet=false; + + if (os.obj) + { + // Get class id + if (os.obj->CanConvertToType(RYKOLPATCHOBJ_CLASS_ID)) + { + bRet = true; + RPO *tri = (RPO *)os.obj->ConvertToType(ip->GetTime(), RYKOLPATCHOBJ_CLASS_ID); + if (tri) + { + Modifier *mod = arg_list[1]->to_modifier(); + if (mod) + { + EditPatchMod *epmod = (EditPatchMod *)mod; + epmod->ClearSelection(EP_PATCH); + epmod->SelectSubPatch(arg_list[2]->to_int() - 1); + epmod->DoPatchTurn(true); + epmod->ClearSelection(EP_PATCH); + } + else + { + bRet = false; + } + } + // Note that the TriObject should only be deleted + // if the pointer to it is not equal to the object + // pointer that called ConvertToType() + if (os.obj != tri) + delete tri; + + // redraw and update + node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE); + ip->RedrawViews(ip->GetTime()); + } + } + + return bRet?&true_value:&false_value; +} \ No newline at end of file diff --git a/code/nel/tools/3d/plugin_max/nel_patch_edit/np_epm_selection.cpp b/code/nel/tools/3d/plugin_max/nel_patch_edit/np_epm_selection.cpp index 3814a2df9..0b15b63e7 100644 --- a/code/nel/tools/3d/plugin_max/nel_patch_edit/np_epm_selection.cpp +++ b/code/nel/tools/3d/plugin_max/nel_patch_edit/np_epm_selection.cpp @@ -236,6 +236,50 @@ void EditPatchMod::SetSelLevel(DWORD level) // ------------------------------------------------------------------------------------------------------------------------------------------------------ +void EditPatchMod::SelectSubPatch(int index) +{ + if (!ip) + return; + TimeValue t = ip->GetTime(); + + ip->ClearCurNamedSelSet(); + + ModContextList mcList; + INodeTab nodes; + ip->GetModContexts(mcList, nodes); + + for (int i = 0; i < mcList.Count(); i++) + { + EditPatchData *patchData =(EditPatchData*)mcList[i]->localData; + + if (!patchData) + return; + + RPatchMesh *rpatch; + PatchMesh *patch = patchData->TempData(this)->GetPatch(t, rpatch); + if (!patch) + return; + + patchData->BeginEdit(t); + if (theHold.Holding()) + theHold.Put(new PatchRestore(patchData, this, patch, rpatch, "SelectSubComponent")); + + patch->patchSel.Set(index); + + patchData->UpdateChanges(patch, rpatch, FALSE); + if (patchData->tempData) + { + patchData->tempData->Invalidate(PART_SELECT); + } + } + PatchSelChanged(); + + UpdateSelectDisplay(); + NotifyDependents(FOREVER, PART_SELECT, REFMSG_CHANGE); +} + +// ------------------------------------------------------------------------------------------------------------------------------------------------------ + // Select a subcomponent within our object(s). WARNING! Because the HitRecord list can // indicate any of the objects contained within the group of patches being edited, we need // to watch for control breaks in the patchData pointer within the HitRecord! diff --git a/code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms b/code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms new file mode 100644 index 000000000..fb5ba2862 --- /dev/null +++ b/code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms @@ -0,0 +1,108 @@ + +gc() +nodes = getCurrentSelection() +max select none +clearselection() + +undo off +( + for cnode in nodes do + ( + if (classof cnode) == Editable_Patch or (classof cnode) == RklPatch then + ( + print cnode.name + selectmore cnode + if (classof cnode) == Editable_Patch and (classof cnode) != RklPatch then + ( + modPanel.addModToSelection (NeL_Convert ()) ui:on + ) + modPanel.addModToSelection (NeL_Edit ()) ui:on + setCommandPanelTaskMode #modify + cmod = modpanel.getCurrentObject() + pcount = (GetRykolPatchCount cnode) + print pcount + for p = 1 to pcount do + ( + --print p + vbegin = (NeLGetPatchVertex cnode p 1) + vend = (NeLGetPatchVertex cnode p 2) + vref = (NeLGetPatchVertex cnode p 3) + begin = (GetRykolVertexPos cnode vbegin) + end = (GetRykolVertexPos cnode vend) + ref = (GetRykolVertexPos cnode vref) + normal = (cross (end - begin) (ref - begin)) + normal = (normalize normal) + + rotnormal = (normal * (rotateZMatrix -90)) + if (normal.z > 0.9) then + ( + -- print "x normal" + rotnormal = (normal * (rotateXMatrix -90)) + ) + -- print rotnormal + + -- print normal + -- print rotnormal + -- print begin + -- print end + dir = (normalize (end - begin)) + -- print dir + score1 = (dot dir rotnormal) + + RykolTurnPatch cnode cmod (p) + vbegin = (NeLGetPatchVertex cnode p 1) + vend = (NeLGetPatchVertex cnode p 2) + begin = (GetRykolVertexPos cnode vbegin) + end = (GetRykolVertexPos cnode vend) + dir = (normalize (end - begin)) + score2 = (dot dir rotnormal) + + RykolTurnPatch cnode cmod (p) + vbegin = (NeLGetPatchVertex cnode p 1) + vend = (NeLGetPatchVertex cnode p 2) + begin = (GetRykolVertexPos cnode vbegin) + end = (GetRykolVertexPos cnode vend) + dir = (normalize (end - begin)) + score3 = (dot dir rotnormal) + + RykolTurnPatch cnode cmod (p) + vbegin = (NeLGetPatchVertex cnode p 1) + vend = (NeLGetPatchVertex cnode p 2) + begin = (GetRykolVertexPos cnode vbegin) + end = (GetRykolVertexPos cnode vend) + dir = (normalize (end - begin)) + score4 = (dot dir rotnormal) + + -- print score1 + -- print score2 + -- print score3 + -- print score4 + + if (score1 > score2 and score1 > score3 and score1 > score4) then + ( + -- print "score 1" + RykolTurnPatch cnode cmod (p) + ) + else if (score2 > score3 and score2 > score4) then + ( + -- print "score 2" + RykolTurnPatch cnode cmod (p) + RykolTurnPatch cnode cmod (p) + ) + else if (score3 > score4) then + ( + -- print "score 3" + RykolTurnPatch cnode cmod (p) + RykolTurnPatch cnode cmod (p) + RykolTurnPatch cnode cmod (p) + ) + else + ( + -- print "score 4" + ) + ) + maxOps.CollapseNode cnode off + max select none + ) + ) +)