CGTalk > Software Specific Forums > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 06-12-2003, 09:38 PM   #1
Cyberdigitus
Challenging 3D
 
Cyberdigitus's Avatar
portfolio
Frederick Desimpel
Belgium
 
Join Date: Jun 2002
Posts: 213
how to get vertex id as integer ?

hi, i need the index of a selected vertex of an editpoly as an integer, to use it with setVert and getVert.

i tried this:

getvertselection gives a bitarray so i thought 'findItem polyop.getVertSelection $ 1' would give me the index, but finditem also needs the int i am looking for as an index, i thought it was an array with all selected verts.

??? how to do this, please help.

maybe i have to traverse the bitarray until i get to the selected one? or is there a better way?
 
Old 06-12-2003, 11:06 PM   #2
LFShade
smarter than I look
 
LFShade's Avatar
for sale or rent!
 
Join Date: Dec 2001
Posts: 964
findItem <some_array> <item_to_find>

You're passing a bitarray to findItem, which I'm not sure even works. But you don't even need findItem() to get what you're after here. If you're just want the index of a single selected vertex, try using $.selectedVerts[1].index, or (polyOp.getVertSelection $ as array)[1].


RH
__________________
Got Maxscript?
RHTools
 
Old 06-12-2003, 11:48 PM   #3
Cyberdigitus
Challenging 3D
 
Cyberdigitus's Avatar
portfolio
Frederick Desimpel
Belgium
 
Join Date: Jun 2002
Posts: 213
thanks for helping out

that seems to be what i need, but are you sure it returns an integer?

I'm working on a script that will help me model morph targets. say you model a smile on the left, and then you want to model that on the right on a new target object. It let's you copy the pos of a vetex then paste it on the coresponding vertex.

still have to manually select the verts and it only works with one at the time for now. i will need to build a list of relations to automate it)

anyway, i'm just starting out on maxscript and could use some help.

i think my reasoning and syntax is correct, but i still get a datatype error. what would be wrong?

the script:

--------------------------------------------------

------ morph target modeling helper ------
---------------------------------------------------

-- model one side of a morph target, and paste this pose to the other side of a new target
-- (get pos of a vert on one object and paste it to a vertex on another object with same vertlist - ie morph targets)

-- phase 1: manually select the coresponding vertex
-- phase 2: create a list of coresponding vertex id's -- for symmetrical objects! manually/automatically
-- phase 3: add functionality (batch, revert to original pos, 'ripple edit', ...)

---------------------------------------------------

-- phase 1 pseudo code : could be simplified if i can get the pos locally

-- (manually) select a vertex on the source object
-- get pos of the vertex [of source object]

-- adjust position relative to object position :

-- compute vert pos relative to pivot origin so we can mirror it (symmetrical aruond local Y axis)
-- the object that will be pasted to is in another place, could be offset in X Y or Z
-- compare and compute to get the new pos

-- (manually) select a - coresponding - vertex on the target object
-- set pos of the vertex [on target object]

------------------------------------------

global pos = undefined
global sourceObjPos = undefined
global targetObjPos = undefined
global symmetrical_flg = true

--functions--
-------------

function getID =
(
--local ID = (polyop.getVertSelection $ as array)[1]
local ID = $.selectedVerts[1].index
return ID
)

function copypos ID =
(
pos = polyOp.getVert $ ID - $.position
)

function pastepos ID =
(
if symmetrical_flg == true then polyOp.setVert $ ID ([-(pos.x), pos.y, pos.z] + $.position)
else polyOp.setVert $ ID pos + $.position
)

------
--UI--
------

rollout copypaste "copy/paste vertex" width:162 height:146
(
pickButton picksource "set source object" pos:[8,8] width:144 height:22
pickButton picktarget "set target object" pos:[8,32] width:143 height:22
checkbox chksym "symmetrcial" pos:[72,104] width:80 height:24 checked:true
button copy "get pos" pos:[8,72] width:56 height:27
button paste "set pos" pos:[8,104] width:56 height:27

on picksource picked obj do
(
sourceObjPos = obj.position
picksource.text = obj.name
)

on picktarget picked obj do
(
targetObjPos = obj.position
picktarget.text = obj.name
)

on copy pressed do
(
copypos getID
)

on paste pressed do
(
pastepos getID
)

on chksym changed arg do
(
symmetrical_flg = arg
)
)

myfloater = newRolloutFloater "Target modeler" 210 172

addRollout copypaste myfloater

---------------------------------------------------

Last edited by Cyberdigitus : 06-13-2003 at 12:10 AM.
 
Old 06-12-2003, 11:58 PM   #4
LFShade
smarter than I look
 
LFShade's Avatar
for sale or rent!
 
Join Date: Dec 2001
Posts: 964
I can't check that right now (no Max here); seems like both forms should return an integer, though. What are you getting?

[edit]--in other words, if you just select a vert and type (polyOp.getVertSelection $ as array)[1] in the listener, what is the result?--[/edit]

RH
__________________
Got Maxscript?
RHTools

Last edited by LFShade : 06-13-2003 at 12:00 AM.
 
Old 06-13-2003, 12:04 AM   #5
Cyberdigitus
Challenging 3D
 
Cyberdigitus's Avatar
portfolio
Frederick Desimpel
Belgium
 
Join Date: Jun 2002
Posts: 213
Wow that was fast!

how can i see what type it is?

i get this error: "unable to convert: getID() to integer" with both expressions, but it doesn't say what type it is. when i test it in the listener it seems to give a number but i dunno how to be sure.

Last edited by Cyberdigitus : 06-13-2003 at 12:12 AM.
 
Old 06-13-2003, 01:38 AM   #6
LFShade
smarter than I look
 
LFShade's Avatar
for sale or rent!
 
Join Date: Dec 2001
Posts: 964
I see the problem now. When you call a function with no arguments, you need to use parentheses to let it know you're calling the function rather than just listing its value. getID without parentheses doesn't call the function, it just returns getID(), which is obviously not an integer. Use getID() instead.

You may also want to modify your functions so that they take the object as an argument rather than working with '$' directly, and so that they do simple error checking. It's just good practice. So to redefine getID,

fn getID obj =
(
if classOf obj != Editable_Poly do return false
idx = (polyOp.getVertSelecion obj as array)[1]
if idx == undefined then return false
else return idx
)


Then, when you call it, do something like this:

id = getID $
if id != false do copypos $ id --with copypos() modded to take an object argument as well


That way, if the object happens to not be an EPoly, or no verts are selected, your script handles it gracefully and doesn't crash or give unpredictable results.

Good luck,
RH
__________________
Got Maxscript?
RHTools

Last edited by LFShade : 06-13-2003 at 01:42 AM.
 
Old 06-13-2003, 01:39 AM   #7
LFShade
smarter than I look
 
LFShade's Avatar
for sale or rent!
 
Join Date: Dec 2001
Posts: 964
Oh, and to see the type of an object or value (since you asked), use classOf <value>.


RH
__________________
Got Maxscript?
RHTools
 
Old 06-13-2003, 04:05 AM   #8
Cyberdigitus
Challenging 3D
 
Cyberdigitus's Avatar
portfolio
Frederick Desimpel
Belgium
 
Join Date: Jun 2002
Posts: 213
it works now, thanks for the great help!

here it is so far: script

so basically allows to do now is pasting vertex positions around, but from here i can build to it to [mirror]paste whole poses...

i'l keep you updated...
 
Old 06-13-2003, 04:15 AM   #9
Cyberdigitus
Challenging 3D
 
Cyberdigitus's Avatar
portfolio
Frederick Desimpel
Belgium
 
Join Date: Jun 2002
Posts: 213
oh, and thanks for pointing out some basic error checking stuff, leraned a lot from that and the script is more neat indeed with such stuff
 
Old 06-16-2003, 04:12 PM   #10
Cyberdigitus
Challenging 3D
 
Cyberdigitus's Avatar
portfolio
Frederick Desimpel
Belgium
 
Join Date: Jun 2002
Posts: 213
mirroring poses works !

just wanted to post an update: script

the script now let's you mirror a pose to another target. for use with morph target modeling.

first select the original - symmetrical!- model, then hit 'build vertex relations'.

then set source and target object where to - mirror -copy pose from/too.

thus you only have to model one side of your facial expressions.

for copying poses the axis checkbox doesn work yet, the model has to be symetrical in X (around XZ plane) and it's pivot centered. also the target copies should be laid out in this direction

WARNING: it's one of my first scripts, and now where finished yet, there little error checking and no undo yet. it's not very neat ui wise either. was just creating something that will help in production and learning some maxscript along the way.
 
Old 06-17-2003, 12:31 AM   #11
LFShade
smarter than I look
 
LFShade's Avatar
for sale or rent!
 
Join Date: Dec 2001
Posts: 964
Wow! Looks like you really took the ball and ran ran with it

I'll check this out tonight if I get a chance.


RH
__________________
Got Maxscript?
RHTools
 
Old 06-17-2003, 07:28 PM   #12
Cyberdigitus
Challenging 3D
 
Cyberdigitus's Avatar
portfolio
Frederick Desimpel
Belgium
 
Join Date: Jun 2002
Posts: 213
cool, please share your thoughts when you do.

i ill add in a feature to copy/paste multiple selected vertices. Also need to work on that undo. pretty odd that doesn't work by itself, it's just a series of commands right? but since i do a loop i will put the whole thing in one undo action after i learned how to do that. beyond that i would look if it is possible to do something like a 'ripple edit' ie when you do (positional) changes to the 'master' mesh, it will update in the targets, optionally keeping the offsets already made in them

but first need to clean it up a bit, my functions could be written better, some are even abundant, and i should think about a more structured error checking.

would it be worth a new thread once i gost so far? since no one else seems to notice this...

Last edited by Cyberdigitus : 06-17-2003 at 07:30 PM.
 
Old 07-02-2003, 09:34 AM   #13
gaggle
Quae?
Jon Lauridsen
Technical Artist
Denmark
 
Join Date: Mar 2002
Posts: 1,216
Holy crap this I have to check out.

[time passes]

Ah nice, very cool, it works nicely. And, might I add, it works with me just half-assing my way through the interface no less. Brilliant!

Certainly a useful script, and with further iterations to polish off the interface and clean up the code and whatever else you want to do, it should turn out very nicely. Nice work man.
 
Old 07-02-2003, 11:57 AM   #14
Cyberdigitus
Challenging 3D
 
Cyberdigitus's Avatar
portfolio
Frederick Desimpel
Belgium
 
Join Date: Jun 2002
Posts: 213
thanks ! It's my first effort at scripting something useful.
 
Old 07-31-2003, 10:45 PM   #15
RedFish
Lord of the posts
 
RedFish's Avatar
portfolio
Andrew Kincaid
Senior Modeler
Take 2 Firaxis
USA
 
Join Date: Jun 2003
Posts: 627
almost working

hey man this looks like a potentially great and powerful recourse, but I cannot get it to work for more than one vertice at a time. Is there anyway to make it work for multiple vertices?

Anyways thanks and keep up the good work.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:00 PM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.