View Full Version : Material ID / Object ID randomizer?
Hey guys im really a novice to maxscript
and it should be really simple to write some code for that purpose
but im not an expert for this stuff.
I need a little script in order to
randomize my objects MaterialId / ObjectID.
--
max select all
for i in selection do i.gbufferchannel = random 1 100"
--
Also i dont want that any object have the same MatId/ObjId number.
Any hints are appreciated.
NAIK
|
|
denisT
12-14-2009, 04:30 PM
Hey guys im really a novice to maxscript
and it should be really simple to write some code for that purpose
but im not an expert for this stuff.
I need a little script in order to
randomize my objects MaterialId / ObjectID.
--
max select all
for i in selection do i.gbufferchannel = random 1 100"
--
Also i dont want that any object have the same MatId/ObjId number.
Any hints are appreciated.
NAIK
material ID is face property. If you want to apply some material ID to all faces of an object you can use for example Material Modifier...
so the code might be
for id=1 to objects.count while id < 65536 do
(
obj = objects[id]
append ids id
addmodifier obj (MaterialModifier materialID:id)
)
-- or if want to use random
ids = #{1..65535} as array
for k=1 to objects.count while k < 65536 do
(
obj = objects[k]
id = ids[random 1 ids.count]
deleteitem ids id
addmodifier obj (MaterialModifier materialID:id)
obj.gbufferChannel id
)
denisT
12-14-2009, 04:39 PM
ObjID's confused me. I changed my answer...
hey mate,
what is Obj ID I have no idea. Every node in scene has a unique handle <node>.INode.handle (see Node Handles in MXS help),
right click any object in the scene.
Under the Rendering Control you got
the slot G-Buffer - Object ID.
cheers
NAIK
My little tiny code is workign fine so far.
But i need to implement some decent code
for checking if one Object Id has already been
given to an object.
So that every object has an unique Object ID.
For Render Elements ( Object ID ) as an example...
cheers
NAIK
Thanks for the code mate,
but its not working 100%...
i get this error message
-- Syntax error: at ), expected <factor>
-- In line: )
Also, i think it would be better just to randomize the
ObjID instead of adding a modifier for the MaterialID.
best regards
NAIK
denisT
12-14-2009, 04:57 PM
ids = #{}
needID = #()
for obj in objects do if (finditem ids (id = obj.gbufferChannel)) == 0 then append ids id else append needID obj
ids = (#{1..65535} - ids) as array
for k=1 to needID.count while k < (65536 - ids.count) do
(
obj = needID[k]
id = ids[1]
deleteitem ids 1
-- addmodifier obj (MaterialModifier materialID:id)
obj.gbufferChannel = id
)
denisT
12-14-2009, 05:00 PM
Thanks for the code mate,
but its not working 100%...
i get this error message
-- Syntax error: at ), expected <factor>
-- In line: )
Also, i think it would be better just to randomize the
ObjID instead of adding a modifier for the MaterialID.
best regards
NAIK
never mind. new version has to work
denisT
12-14-2009, 05:02 PM
Sorry mate,
when i copy your code to the Mascript window
and select all line and evaluate it
i get this
#{}
#()
OK
#(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...)
OK
OK
Seems cool, but when i select one object and check its Object Id its still
0 - and thats for all objects in the scene...
we have to check for ZERO id:
ids = #{}
needID = #()
for obj in objects do if (id = obj.gbufferChannel) == 0 or (finditem ids id) != 0 then append needID obj else append ids id
ids = (#{1..65535} - ids) as array
for k=1 to needID.count while k < (65536 - ids.count) do
(
obj = needID[k]
id = ids[1]
deleteitem ids 1
-- addmodifier obj (MaterialModifier materialID:id)
obj.gbufferChannel = id
)
denisT
12-14-2009, 05:05 PM
last version has to work ;) (i've misspelt couple times)
Sorry mate,
when i copy your code to the Maxscript window
and select all line and evaluate it
i get this
#{}
#()
OK
#(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...)
OK
OK
Seems cool, but when i select one object and check its Object Id its still
0 - and thats for all objects in the scene...
Also when i copy the code into the Maxscript Listener
i get again this error message
-- Syntax error: at ), expected <factor>
-- In line: )
Am i nuts?
denisT
12-14-2009, 05:09 PM
here is a clean version:
ids = #{}
needID = #()
for obj in objects do if (id = obj.gbufferChannel) == 0 or (finditem ids id) != 0 then append needID obj else append ids id
ids = (#{1..65535} - ids) as array
while ids.count > 0 and needID.count > 0 do
(
needID[1].gbufferChannel = ids[1]
deleteitem ids 1
deleteitem needID 1
)
denisT
12-14-2009, 05:21 PM
also it will be better to go though renderable objects only. for other objects rendering doesn't make any sense.
Holy moly....
thanks mate - works perfect.
One thing i have recognized is that although
we have now unique ObjIds
that some object got the same color
when rendering the objId render elements.
Seems that it does support only a few colors...
Thanks for dropping in Denis!
cheers NAIK
Track
12-15-2009, 08:25 AM
EffectsChannelSet (http://3d-kstudio.com/scripts/trackscripts/#EffectsChannelSet)
Script for management ID of materials and the objects, and also for the assign wirecolor of objects.
Also automated creation MultiMatteElement in Render Elements. (Vray only)
Update – Adds ability for randomize the material-id for selected objects.
EffectsChannel v1.3
-Adds ability for assign id for user choosen slot in Material Editor
-Adds ability for assign id Only for submaterials
-Adds ability for assign id Only for root materials
-Adds ability for assign id for All levels material
-Fixes issues with VrayMtlWrapper & Vray2SidedMtl
http://3d-kstudio.com/downloads/maxscripts/effectschannel.gif
EffectsChannelSet included in TrackScripts pack
Download page (http://3d-kstudio.com/download/)
awesome script mate...
I use Mental Ray but the other functions are really good!
Thanks for the link.
I really appreciate it.
cheers
NAIK
Polimeno
12-15-2009, 06:00 PM
what about these ?
Node Common Properties, Operators, and Methods
getRenderID <node>
Returns the RenderID of the node. A value of 65535 is returned if the scene has not yet been rendered, or the node is not renderable. The RenderIDs of the nodes are output to the NODE_RENDER_ID g-buffer channel by the renderer.
setRenderID <node> <integer>
Sets the RenderID of the node to the specified value. This value is not "sticky" - it is not saved with the scene, and it will be replaced by the renderer when the next render occurs.
*** EDIT ***
i found in MXS Help something that could be usefull :
<void>maxOps.colorById <DWORD>id <&color>color
color is Out parameter
Returns a specific color for each unique ID passed. The result is written to the Out parameter by reference. This method is used internally to generate colors representing Material and Object IDs in the respective RenderElements. Available in 3ds Max 8 and higher.
for i = 0 to 9 do
(
maxops.colorById i &theColor
format "ID:% Color:%\n" i theColor
)
Track
12-15-2009, 10:45 PM
awesome script mate...
I use Mental Ray but the other functions are really good!
Thanks for the link.
I really appreciate it.
cheers
NAIK
I added support for MatteRenderElement creation (Mental Ray RenderElement)
Hey guys sorry for the ultra late answer.
Track thanks for the new support.
Its very strange mate, but i seems that your script
is not able to distribute unique Object IDs to several
object.
Just create 10 sphere and select your script while pressing shift
for random distribution.
You can see that not every sphere is getting an unique Object ID.
Am i missing something??
cheers
NAIK
Track
01-12-2010, 09:38 AM
Just create 10 sphere and select your script while pressing shift
for random distribution.
You can see that not every sphere is getting an unique Object ID.
Hello Naik.
For solution In "Object Id Randomise" rollout set the "Start Id"=0 and "End Id"=50.
Press "Assign" button.
The difference between the start and end must be greater than the number of objects.
Sorry mate,
its not working for me.
Just create 10 spheres and run your script.
If i set the start to "0" and the end to "30"
i get doulbe distribution...
cheers
NAIK
Track
01-12-2010, 11:24 AM
You can set biggest difference or
download TrackScriptsPack with new version of EffectsChannel
http://3d-kstudio.com/scripts/
CGTalk Moderation
01-12-2010, 11:24 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.