ScriptSpot

Script

Randomize Elements

By Swordslayer · Credited author: Vojtech Cada · 2016-01-23

Version
0.03a
Version requirement
3ds Max 2016
Votes
19
Description

 Randomize elements the easy way. Slow as hell with complex models (500k poly and more).

Additional Info

Installation: Copy the .ms file to your scripts\startup folder or run as a script if you only want to try it out. The modifier will be available in the Modifier List.

Notes: If you want to exit the Generate loop, hold the Esc key. When using Show Once update option and switching to baseobject/different modifier in stack and back, you have to click the Update button once again to show the randomization. Exercise caution when using this for complex meshes.

Credits: The original getMeshElements function comes from Jorge Rodríguez (aka PolyTools3D).

Attachments

Tags: modifier, random, randomize, Elements

Comments (14)

This isn't working and showing and Runtime error.

camouflage98 · 2019-04-02

This isn't working and showing an error.

--Runtime error: Plugin redefinition: cannot change class ID. RandomizeElements.
this is the message.
Is there any way we can fix this?

.

Swordslayer · 2019-04-07

That means you already have some other plugin called RandomizeElements present (might be MCG). You can edit the very first line of this one to use a different class identifier.

THANK YOU!

camouflage98 · 2019-05-03

Yes you were right.
I've deleted the mcg randomize elements, it works great.
Thank you so much.

Thanks for sharing but can't work

joelauduo · 2016-01-25

can't work idont know why
please up .mse thank U

Old max version, maybe?

Swordslayer · 2016-01-25

Check the requirements, it only works with max 2016 and higher. The .mse is just an encrypted version of plaint-text .ms, that won't help you.

Thanks you for help~

joelauduo · 2016-01-26

Not old, 3dsmax2016 ext1 sp2

-- Error occurred during fileIn in "C:\Program Files\Autodesk\3ds Max 2016\scripts\startup\randomize_elements.ms"; line number: 144
>> MAXScript Auto-load Script Error - C:\Program Files\Autodesk\3ds Max 2016\scripts\startup\randomize_elements.ms Exception:
-- Syntax error: at ?, expected
-- In line: spinner spnPosY "? p <<
-- Error occurred during fileIn in "C:\Program Files\Autodesk\3ds Max 2016\scripts\Startup\randomize_elements.ms"; line number: 144
-- Error occurred in anonymous codeblock; filename: C:\Program Files\Autodesk\3ds Max 2016\scripts\Startup\randomize_elements.ms; position: 4744; line: 144
>> MAXScript FileIn Exception:
-- Syntax error: at ?, expected
-- In line: spinner spnPosY "? p <<

Thanks for the stack trace

Swordslayer · 2016-01-26

Bummer, I've used a non-standard +- character there and it gets merged with the closing " character :/ Re-upped the file saved in UTF-8, not sure if that can help. If not, open the file in script editor, notepad or other text editor and delete all the "±" (or use the attached randomizeElements_replaced.ms file where I've already done it).

Thanks for patience and hope you will find the modifier useful.

Attachments

pixamoon · 2016-05-11

Thanks for sharing +1 great tool

lightcube · 2016-01-23

Thanks for sharing Swordslayer. I made a scripted plugin identical to this last year but never released it because I couldn't figure out the right transformation calculation to get the element rotations to always rotated from the element centers. No need to finish it now.

PS. You are on a rampage lately with all these great shares. I think you are working on a Flawless Victory.

Swordslayer · 2016-01-23

My pleasure. Once you get the elements and their centers, the calculation itself is 'translate point from the center to the origin, scale it there, rotate it, move it back, offset it' (or swap the last two if you like) - see the getRandomTM function. For me the part that was always hard to make reasonably fast with complex meshes was getting the elements and that part of the script logic comes from Jorge Rodríguez.

Victory, hmm? Is there a competition? 😎 If only there was more time, outside of work I spend very little time with max and the time spent at work is all hard-surface modeling - you know what, have a look at what we do and spread the word, that way I might soon get paid better and work less 😉 
jk, but not really

lightcube · 2016-01-23

I peeked in and honestly the center code looks a lot like what I started with. Seems like I was having problems when the object was transformed in the scene. But I was using SimpleMod... which may have been part of my issue. I've got to start playing with the new goodies in 2016.

Swordslayer · 2016-01-23

Center code, like getting center? Sure, that part IS easy (well, there's not much to complicate it, accumulate all the positions, divide by vertex count, done), what is usually harder is getting all the mesh elements in an efficient manner. Didn't even try the obvious method getElementUsingFace -> getVertsUsingFace here because I've been bitten by it quite a few times before. The memory usage with big meshes is huge (and I mean really huge... and I have in mind meshes around the mark of 1M polygons and let's say 20k elements). The method I was talking about comes from this thread at cgtalk.

If you have some time to spare, you could try comparing speed and memory consumption of both methods and post the results - now that would be interesting, having never benchmarked it inside a modifier, I might be wrong here.

Btw. out of curiosity, what method did you use to get the object mesh in the simpleMod? And did you have any sort of caching in place? If you don't mind attaching the file, I'd like to have a look, otherwise I'll keep asking stupid questions :) I know you can save the mesh as #maxObject but I keep wondering if there's some clever way to save <vertexSelection> data that would be persistent across sessions. The mapped access makes it much faster to work with, i.e. <vertexSelection>.pos *= TM, boom, done, thousand verts transformed in one go with no overhead nor leaking.

lightcube · 2016-01-25

I'll share it with you tomorrow. I had some hacky caching to get it to work, yes :) But it was mostly OK except rotations odd in some occasions.