mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-24 01:48:44 +00:00
Add script to orient zone patches automatically
This commit is contained in:
parent
37bd76838e
commit
7327b5ee39
5 changed files with 272 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -84,6 +84,31 @@
|
|||
*> Copyright(c) 1994, All Rights Reserved.
|
||||
**********************************************************************/
|
||||
#include "stdafx.h"
|
||||
|
||||
#if MAX_VERSION_MAJOR >= 14
|
||||
# include <maxscript/maxscript.h>
|
||||
# include <maxscript/foundation/3dmath.h>
|
||||
# include <maxscript/foundation/numbers.h>
|
||||
# include <maxscript/maxwrapper/maxclasses.h>
|
||||
# include <maxscript/foundation/streams.h>
|
||||
# include <maxscript/foundation/mxstime.h>
|
||||
# include <maxscript/maxwrapper/mxsobjects.h>
|
||||
# include <maxscript/compiler/parser.h>
|
||||
# include <maxscript/macros/define_instantiation_functions.h>
|
||||
#else
|
||||
# include <MaxScrpt/maxscrpt.h>
|
||||
# include <MaxScrpt/3dmath.h>
|
||||
// Various MAX and MXS includes
|
||||
# include <MaxScrpt/Numbers.h>
|
||||
# include <MaxScrpt/MAXclses.h>
|
||||
# include <MaxScrpt/Streams.h>
|
||||
# include <MaxScrpt/MSTime.h>
|
||||
# include <MaxScrpt/MAXObj.h>
|
||||
# include <MaxScrpt/Parser.h>
|
||||
// define the new primitives using macros from SDK
|
||||
# include <MaxScrpt/definsfn.h>
|
||||
#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 <object to use>'
|
||||
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;
|
||||
}
|
|
@ -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!
|
||||
|
|
108
code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms
Normal file
108
code/nel/tools/3d/plugin_max/scripts/nel_orient_zones.ms
Normal file
|
@ -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
|
||||
)
|
||||
)
|
||||
)
|
Loading…
Reference in a new issue