[Closed] How to write on this plugin for naming edges?
Utility name_edge
(
persistent global per_x
persistent global per_y
persistent global per_z
persistent global per_name
edittext name
pickbutton pick;
On pick picked it do
(
if selection.count == 0 then
messageBox "No edge selected"
edge = selection.selectedEdge
per_name = name
per_x = edge.x
per_y = edge.y
per_z = edge.z
)
)
My intention is this
The user enters the name of the edge in “name”, then
When the user picks an object, it tests if it is an edge, then if it is,
the plugin stores it in memory somewhere until the asset exporter exports this data out to a file.
My problems are:
- how do you determine if it is an edge?
- how do I store it away inside memory?
Any ideas?
Thanks
Jack
No persistent globals were harmed when writing this snippet:
try destroyDialog name_edge catch()
rollout name_edge "Name Edge"
(
struct edgeInfo (name, v1, v2, pos = (v1 + v2)/2)
local edges = #()
fn isPoly obj = isKindOf obj Editable_Poly
edittext name "Name: "
pickbutton pick "NONE" autoDisplay:true filter:isPoly
on pick picked it do
(
if name.text.count < 1 do
return messageBox "Edge name cannot be empty"
if pick.object == undefined do
return messageBox "No object selected"
if pick.object.selectedEdges.count != 1 do
return messageBox "Exactly one edge has to be selected"
local verts = polyop.getEdgeVerts pick.object pick.object.selectedEdges[1].index
append edges (edgeInfo name:name.text v1:(polyop.getVert pick.object verts[1]) v2:((polyop.getVert pick.object verts[2])))
)
)
createDialog name_edge
Take it as a starting point, study maxscript reference and always test your assumptions.
Could you give me some hints on how to go about exporting this information into a, say Direct3D (.x) file or (.obj) file?
Where does this information go/reside?
Thanks
Jack
Anyone sheds some lights on this? I’d like to export this variable with a maxscript or user plugin…
Update
I found this
http://forums.cgsociety.org/archive/index.php/t-1041168.html
But which functions do I call? And how do I call them?
Thanks
Jack
You want to write the exporter part in c++? Anyway, wouldn’t a custom format be a better choice for you? Or how do you import the information and what does it represent anyway?
Hello Swordslayer,
I am trying to use your script to name the edge and in turn, export it thru the SDK
please see my last post, I am seeing lights to this.
Please verify.
Thanks
Jack
How do I call this function?
Value*
globalVars_get_cf(Value** arg_list, int count)
{
// globalVars.get <global_name>
check_arg_count(globalVars.get, 1, count);
Value* glob_name = Name::intern(arg_list[0]->to_string());
GlobalThunk* t = (GlobalThunk*)globals->get(glob_name);
if (!t)
throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_NO_SUCH_GLOBAL), glob_name);
return t->eval();
}
There is a global variable called globalVars, or I will have to make one?
I believe I need to get a variable called edge_name, do I do this
MCHAR *name = globalVars.get(“edge_name”);
Can anyone verify this?
Thanks
Jack
As we are talking about naming each edge individually, the source data probably are not overly complex so you can do the whole thing using MAXScript. You still haven’t indicated what does the edge represent in the target format, a single object, part of a mesh geometry (if that’s the case, how would you like to include the names?) or what kind of import process does it go through.
I’d like to do something like this in my application
D3DXVECTOR3 xyz = mWarehouse->GetEdge("Dock_Leveler_Edge")->GetVector3();
mLorry->SetPos(xyz + D3DXVECTOR3(0, 0, rearMove * numrearMoves);
Hope this makes sense
I decided to do it the hard way because of copyright protection and ease of development. I am more keen on C++.
See below I have
Edge_Transform =
How do I get the transformation of an edge?
try destroyDialog name_edge catch()
rollout name_edge "Name Edge"
(
struct edgeInfo (name, v1, v2, pos = (v1 + v2)/2)
local edges = #()
fn isPoly obj = isKindOf obj Editable_Poly
persistent global Edge_Name
persistent global Edge_Transform
edittext name "Name: "
pickbutton pick "NONE" autoDisplay:true filter:isPoly
on pick picked it do
(
if name.text.count < 1 do
return messageBox "Edge name cannot be empty"
if pick.object == undefined do
return messageBox "No object selected"
if pick.object.selectedEdges.count != 1 do
return messageBox "Exactly one edge has to be selected"
local verts = polyop.getEdgeVerts pick.object pick.object.selectedEdges[1].index
append edges (edgeInfo name:name.text v1:(polyop.getVert pick.object verts[1]) v2:((polyop.getVert pick.object verts[2])))
Edge_Name = name;
Edge_Transform =
)
)
createDialog name_edge
cpp code
define_system_global("Edge_Name", get_Edge_Name, set_Edge_Name);
define_system_global("Edge_Transform", get_Edge_Point3,
set_Edge_Point3);
Value *Temp3;
void SetEdgePoint3(Point3 vec)
{
}
Value* get_Edge_Point3()
{
return Temp3;
}
Value* set_Edge_Point3(Value* val)
{
SetEdgePoint3(val->to_point3());
return val;
}
void SetEdgeName(MCHAR* name)
{
}
Value* get_Edge_Name()
{
return NULL;
}
Value* set_Edge_Name(Value* val)
{
SetEdgeName(val->to_string());
return val;
}
Obviously, Temp3 is a NULL which would cause problem here
Let me know
Thanks
Jack
Well, do as you want; anyway, Edge_Name = name; should definitely be Edge_Name = name.text and Edge_Transform = … well, that depends, what kind of input do you expect? As it’s Point3 value, it cannot be a transformation matrix, so it’s either edge direction vector or the middle point (or maybe starting point? it’s hard to guess it).
Hi there,
At first blush, yes, it is a Point3,
I tried
$.selectedEdge.position or pos, but it crashed.
Edges don’t have a position; you can do what I did in the snippet which is getting the position half-way between vertex1 and vertex2 of the edge or anything that suits your needs.
I am pretty sure I'd want to get 2 y-z coordinates, x can be discarded.
If I add the 2 vectors then divide it by two, I will get the mid-point of the edge,
But does it necessarily be the precomputed location of the lorries. The X position will be incorrect. How do you which axis is the major axis?
BTW, do you know my code snippet would work or not. Because you see the edge name and position are pointer to nothing, I just define them define_system_globals
to define those 2 functions (getter, setter), can the maxscript externally update those pointers?
Update
projx = abs(verts[1].pos.x – verts[2].pos.x)<< unknown property pos in 2
don’t know why it fails
local v1 = polyop.getVert pick.Object verts[1]
local v2 = polyop.getVert pick.Object verts[2]
Edge_Name = name
local proj = abs (v1.pos - v2.pos)
local Largest = 1
if (proj.y > proj.x) then
Largest = 2
if (proj.z > Largest) then
Largest = 3
if (Largest == 1) then
-- x is discarded
Edge_Point3.pos.x = 0
Edge_Point3.pos.y = projy
Edge_Point3.pos.z = projz
if (Largest == 2) then
-- y is discarded
Edge_Point3.pos.x = projx
Edge_Point3.pos.y = 0
Edge_Point3.pos.z = projz
if (Largest == 3) then
-- z is discarded
Edge_Point3.pos.x = projx
Edge_Point3.pos.y = projy
Edge_Point3.pos.z = 0
MessageBox (Edge_Point3)