2011年12月26日 星期一

MAXscript : 新創同樣BoneList的Skin

從現有已加完Bones的Skin中,抓取Bone List到新的Skin中

--從已有的Skin中抓取骨骼的Name
bonesAry = for i in 1 to skinOps.getNumberBones $.skin collect skinOps.getBoneName $.skin i 0
--加入到新的Skin中

for i in 1 to boneAry.count do skinOps.addBone $.skin (getNodeByName boneAry[i]) 0

2011年12月4日 星期日

Maxscript : Writing Better and Faster Scripts


( Frequently Asked Questions in MAXscript help)

Disable Viewport Redraws when making changes to scene objects
You can use the with redraw off() context or a pair of disableSceneRedraw() and enableSceneRedraw() calls to speed up you code. The former method is the preferred one.

Disable Undo system when possible
ondo off( ... ) ; ondo on( ... ) ; with undo off
print (et-st) --print the resulting time
gc() --call Garbage Collection &endash; you will needed it!

Modify Panel can be slow - change to Create Panel when possible
In 3ds Max 7 and higher, you can also completely disable Modify Panel updates using the suspendEditing() and resumeEditing() methods

Only calculate once if possible
Try to avoid running the same calculation more than once, or interrogating the same value in the same node more than once.

Cache frequently used functions and objects
You can store frequently used functions and objects in user variables to faster access.

Pre-initialize arrays when final size is known
When adding elements to an array using the append method, a copy of the original array is being created in memory before the new array is created. When the size of an array is known before the array is actually used, it is a good practice to pre-initialize the array in memory by assigning the last element of the array to some temporary value. This will create an array of the desired size in memory and will let you simply assign values to any element of the array using indexed access without the memory overhead of the append method.

MyArray = #()

MyArray[100] = 0 --initialize a 100 elements array in memory
for i = 1 to 100 do MyArray[i] = random 1 100 --assign to predefined array


matchPattern is faster than findString
When searching for a substring inside a string, using the matchPattern() method is faster than using findString().
Executing the same method one million times on the same PC resulted in:
3.7 seconds execution time for matchPattern
5.9 seconds execution time for findString
5.0 seconds execution time for subString when comparing the first 3 characters.

Do not use return, break, exit or continue

Return, break, exit, continue and throw are implemented using C++ exception.
C++ exceptions are SLOW!

Use StringStream to build large strings
If building strings, use a StringStream value to accumulate the string and then convert to a string.

fn test5d =
(
 local ss = stringstream"",fmt ="%"
 for i = 1 to 100 do format fmt ito:ss
 ss as string
)

Using Bsearch For Fast Table Lookup
The bsearch() method available in 3ds Max 2009 and higher allows for very fast table lookup operations in sorted arrays.

2011年12月2日 星期五

Maxscript : Right-Handed to Left-Handed


正解!!Right to Left or Left to Right:by cmann

Let me try to explain it a little better. I need to export from Blender, in which the z axis is facing, to OpenGL where the y axis is facing up.
For every coordinate (x, y, z) it's simple, swap the y and z values: (x, z, y).
Because I have swapped the all of the y and z values any matrix that I use also needs to be flipped so that it has the same affect .
After a lot of searching I've eventually found a solution here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=537664
If your matrix looks like this:
{ rx, ry, rz, 0 }
{ ux, uy, uz, 0 }
{ lx, ly, lz, 0 }
{ px, py, pz, 1 }
To change it from left to right or right to left, flip it like this:
{ rx, rz, ry, 0 }
{ lx, lz, ly, 0 }
{ ux, uz, uy, 0 }
{ px, pz, py, 1 }