Explode script needed(for baking purposes)


#1

Basically what I need is script which groups lowpoly parts with their corresponding highpoly
parts and scatter all groups in the viewport for easy texture baking of normal and AO maps.
Right now I do that manually by linking lowpoly and highpoly pieces to different help objects and moving them around.

Here is a gif illustrating what I’m talking about:

Another idea, the guys from polycount.com had given is using “isolate selection” instead.Something like this:

1)group coresponding parts into different selection sets
based on naming conventions, for instance:

LP_ShoulderPart (the LowPoly object)
HP_ShoulderPart (HighPoly object)
ZB_ShoulderPart (HighPoly object imported from Zbrush)

…this should be grouped into one selection set called “ShoulderPart”

2)iterate a render to texture for every selection set in isolation mode

I have no experience in MaxScript,though. I’ll be happy if someone of you guys can help here :slight_smile:


#2
(
local parts = #("shoulder","elbow")
local suffix = #("_L","_H","_Z")
local thePart = undefined
local theCenter = [0,0,0] -- this is the center of the character
local proj = 20.0 -- the distance projected out

  for i = 1 to parts.count do
  (
   for n = 1 to suffix.count do
   (
   thePart = getNodeByName (parts[i] + suffix[n])
   
   if thePart != undefined do
   (
   thePart.pos = normalize (thePart.transform.pos - theCenter) * proj  + theCenter
   )
  )
 )
)

roughly something like this.


#3

@eek, thank you for the quick response :slight_smile:

It will be better if it works with any names of objects, not just a predifined ones. I always have different parts named differently depending on the concept.


#4

Could you explane me the code, especialy this line ,please


#5
normalize (thePart.transform.pos - theCenter)

Creates a normalized vector from the origin of the scene to the object position. This will be used as the direction vector.

* proj

Is the vector multiplier, it scales the vector length. Determining the end position in space.

+ theCenter

acts as an offset value.

-Johan


#6

:), I just got up and saw your post. Thanks!

Yes basically im just building a vector, from the center of the character its the only way i saw i could explode things from an origin - i.e head goes up, arms to the side etc etc.

For any object you could do this:

local parts = for o in objects collect (o)

Then thePart could be getNodeByName (parts[i].name + suffix[n])

#7

Hi, guys , here is a more detailed algorithm :

Method1: Explode baker:

Step a) Link LPs to their corresponding HPs:

  • must provide flexible options such as smart sorting of names
    (even if some of the names are miswritten the script tries to find
    their best match).

  • linking by relative distance and positions.Even if there is no naming
    conventions and organization in the scene, the scripts pairs objects together
    by their relative pivot position( I saw smth like this at scriptspot.com, called
    “DistanceLinker” or smth similar.) It’s not a perfect solution, can produce mistakes.

  • or the two methods could be combined together. First the script tries to
    group objects using naming convention and if miswritten object is present in
    the scene , groups it to the nearest object if there is any.

This way it will even cut down the render time of each map , because the groups(LPs + HPs) will be considered in the baking process one at a time, instead of loading all objects at once(like the case of the “explode” algorithm).

  • also option to link object by other criteries , like material IDs or
    smth is a plus.

Step b) A projection modifier is applied to all LPs(with predefined settings),
or it would be better if it preserves the settings avaible prior the linkage.
Notice that a link hierarchy can’t be created when a projection modifier is
applied to some of the objects, so the modifier should be removed prior the
linkage and applied back after.

Step c) Exploded all linked groups using a unique vector so there are no
overlapping groups of objects and there is enough space between them.

Step d) Render all required maps on one pass using RTT.

Step e) Revert the original position of the linked groups. That can be done by
simple animation.At frame 0 all pieces are together, at frame 1 they are exploded.

I have to mention that I have no MaxScript experience, and I was hoping someone in this community to give me a hand, everything from ideas to simple source code I could use for reference will be highly appreciated.


#8

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.