Pages

Monday, January 18, 2010

Instantly Auto Edges


Instantly Auto Edges is a MaxScript that I just I published today. As usual I can share the link to the ScriptSpot post where you can read short description and usage notes, but... I would like to add some tips comments, which could be useful in writing other scripts, so...

First, I looked for a similar script and found 2 old that just loop through selected objects and performs auto edge, shortly - nothing special. Also I found a script by Pierre-Felix Breton. Interesting in the code is excluding instances optimization, which part come from Chris P. Johnson. But honestly, all code snippet looks like Chris job :) However. Well, even in this code, I saw many things that could be improved. As you will see yourself, I used mapped funcions. They are real magic, but the final awesome runtime speed result would be impossible without some tricks. So I wish to focus your attention at them.

First one is about collecting objects edges. Here needed all edges, and Max has easy ways to get faces but not edges. For example there no $MeshObject.NumEdges . Knowing that any face in mesh has 3 edges, Chris use loop from 1 to 3 end expression to collect all edges. This is slow. There is my way (using bitArray and ".numFaces" all is done in 1 command):

edgeList = #{1..(objs.numFaces * 3)}

Ok, Im add it to my mapped function and even this is enough optimization, i.e. my tests show that the script can operate almost 3 million edges per second ! But why not improve it if possible, right?

So the Second step is as Chris idea but in different method. Knowing that InstanceMgr.GetInstances output an array, it's clear so if the array keep only 1 item then the object has not instances (it's unique). Simple :) And if has more then we need just one of them, so here also not need separate commands. All what we need is to collect the 1st item only. Note: appendIfUnique function is also important! For more see inside the script code.

Well, the fast collecting instances deputy/delegate is not affect directly the final auto edges procedure, but I like it faster :) and as a said - this is a good trick for coding at all.

However, this step is also important because affects drastic scenes with many instances. If you have to say 100 instances - the script will proceed only 1, so it will end 100 times faster. In other words, even large scenes with many instances will end in no time !

My script you can find here.
Ok, that's all :)

Bigger/Smaller Comparisons

Well, it's about MaxScript comparision topic. I wonder why people continue to write custom funcions like this:
fn bigVal v1 v2 = if v1 > v2 then v1 else v2
fn smallVal v1 v2 = if v1 < v2 then v1 else v2

...provided that Max has great built functions amax() and amin().
Even more, they take more than 2 arguments and/or array.
-- Examples:
myMin1 = amin #(5,1,4,2,8)
myMin2 = amin 5 1 4 2 8 -- same as above
myMin1 == myMin2 --> true

In plain speed test both ((bigVal v1 v2) and (amax v1 v2), or (smallVal v1 v2) and (amin v1 v2)) has equal runtime. Well, even this is enough to skip writing of such functions, right? I know many people with a nice reputation in coding which still continue to do just that :) ... but not to digress from the topic... instead, let see the strong hand of those functions by simple test:
-- Let's fill an array with 100000 random integers
testArray = for i=1 to 100000 collect random 1 100

-- test 1
timeStart = timestamp()
amin testArray -- find min
amax testArray -- find max
timeEnd = timestamp()
t1 = (timeEnd - timeStart)

-- test 2
timeStart = timestamp()
sort testArray -- 1st need to sort the array
testArray[1] -- find min
testArray[testArray.count] -- find max
timeEnd = timestamp()
t2 = (timeEnd - timeStart)

format "Test 1 Time:\t\t% ms.\n" t1
format "Test 2 Time:\t\t% ms.\n" t2

-- result:
Test 1 Time: 0 ms.
Test 2 Time: 31 ms.

So, let's say, end of story here :)

Saturday, January 16, 2010

Extended Dummy with custom Mesh

Hi Dave, this post is specially for your question:
Can I extend a dummy object and replace the mesh and wirecolor of the Dummy object?

Yes, you can, using getDisplayMesh and createInstance just like its done in simpleObject geometry class plugins. In createInstance function you can supply needed propetries like wirecolor and etc.

I know a site with existing example code - Snipplr.com - it's a coders community where to get or upload code snippets and they have (not so rich but useful) MaxScript section. There is the link to the example extended Dummy helper with custom mesh:
http://snipplr.com/view/11904/scripted-helper-object-plugin/

3ds Max 2010 and stability

This is like to me more as defend lecture than ... :) well, there is a few hardware tips, but Ken Pimentel put accent on CERs (costumer error reports) system.

Friday, January 15, 2010

WireFence update


Some quick and simple update over my WireFence script today. Nothing special, yep :) but just in case you curious about how to open scripted utilities (from button or macros for example) - take a look at openUtility() function ;) and ...

if you like some of my scripts then please vote for them (at ScriptSpot) to have more incentive to share, thanks ! :D

Wednesday, January 13, 2010

DummyEx

DummyEx
May seem quite trivial to extend the Dummy, but this scripted plugin is useful in cases where scaling transform is undesirable (in rigging for example).

You can download DummyEx from here.

Monday, January 11, 2010

Select objects visible to camera

Select objects visible to camera is an interesting topic in Autodesk Area forum related to MaxScript.

Saturday, January 9, 2010

Transparent Alpha Channel


Mental ray tutorial by Ramy Hanna.