PDA

View Full Version : Shading selected objects in a colour


CarlCampbell
04-14-2008, 05:17 PM
Greetings!

I'm working as Junior Animator on a next-gen videogame using Unreal Engine 3. I've noticed that Unreal Ed has an interesting behaviour on how it displays selected objects in viewports; it shades them in a transparent purple hue.
No selection brackets, no wireframe overlay, just a colourful semi-transparent shading. I kind of like this way of displaying selected objects and I was wondering if anyone knew of a script that could be used to achieve this effect or if anyone could point me in the proper direction as to how to get this working in Max.

Cheers!

ZeBoxx2
04-14-2008, 07:01 PM
I don't think you can easily get rid of the selection brackets by script - I know you can disable them in the viewports themselves through the viewport display options.

As for the visual change... you could use a selectionSetChanged callback to keep track of selection changes and either...
A. Toggle the "see-through" node property. This is a transparent grey, rather than a transparent magenta.
B. Store the object's original material, replace with the transparent magenta material; when de-selected, restore the object's original material.

CarlCampbell
04-15-2008, 09:15 AM
Thanks for the tips. Selection brackets really aren't bothering me right now. More specifically, what UnrealEd does is colour the selected object's texture in a purple hue, meaning to say it retains it's original texture and/or mapping and shades it; you can still see the texture, it's as if you added a coloured layer on top with 50% opacity.

I really have no idea about MAXscripting at all but I'll check out the callback function and see what I can find out...

Cheers!

zortech
04-15-2008, 04:07 PM
Sry for ruining your learning effect but I have had some time, so I put something together. This adds a transparent, purple material to the selected objects...if you want to keep the texture you'd rather edit the current material than assining a new one. Maybe not the best approach, but it works somehow :D


(
callbacks.removeScripts id:#U3Selection --// unregister the callback
local aPrevSelection = #() --// array containing previous selection
local aPrevMaterials = #() --// array containing previous selection's materials

local mSelMaterial = standard() --// create a new standard material
mSelMaterial.opacity = 40 --// opacity value
mSelMaterial.diffuse = (color 90 10 120) --// diffuse & ambient color

global fnU3Selection = function fnU3Selection =
(
if aPrevSelection != undefined and aPrevMaterials != undefined do
(
for i = 1 to aPrevSelection.count do
(
if aPrevMaterials[i] == undefined then (
aPrevSelection[i].material = noMaterial()
)
else (
aPrevSelection[i].material = aPrevMaterials[i] --// reassign old materials
)
)
)

aPrevSelection = selection as array --// create a copy of the current selection

for i = 1 to aPrevSelection.count do
(
aPrevMaterials[i] = aPrevSelection[i].material --// store the old material
aPrevSelection[i].material = mSelMaterial --// assign the transparent material
)
)
callbacks.addScript #selectionSetChanged "fnU3Selection()" id:#U3Selection
)

CarlCampbell
04-15-2008, 04:32 PM
Thanks zortech! I'm getting a message when running the script:

"Call needs funciont or class, got: undefined"

Take into account that I'm using MAXscript>New Script then pasting the code and evaluating. What is is that I'm doing wrong?

Cheers!

zortech
04-15-2008, 04:54 PM
Ah shit, my bad.

I have edited the code so it should work now. The function is now in a global scope. xD

Edit: if you're assining a new material to the selected object, when deselecting it, the material will be overwritten with the previous material...kinda stupid.

CarlCampbell
04-15-2008, 05:30 PM
Wow! That's pretty impressive indeed! Are you sure there's no possible way to preserve the object's current texture and shade it in purple? What I mean is that the texture stays visible, only tinted like I mentioned in my first post.

Cheers for real!

zortech
04-15-2008, 07:05 PM
I've tried to find a way to edit the material in a way that it appears purple, but the only thing I got was an ugly selfillumination material and memory leaks caused by to many material copies xD So here's a different approach, probably not very fast, as it clones the actual mesh...but the closest thing to the u3 selection type. (I guess)

(
callbacks.removeScripts id:#U3Selection --// unregister the callback
local aPrevSelection = #() --// array containing previous selection
local objShadeMesh = #() --// array containing cloned objects
local mSelMaterial = standard()
mSelMaterial.opacity = 50
mSelMaterial.diffuse = (color 150 10 200)
mSelMaterial.selfIllumColor = (color 150 10 200)
mSelMaterial.useSelfIllumColor = true

global fnU3Selection = function fnU3Selection =
(
if objShadeMesh != undefined and objShadeMesh.count > 0 do
(
for o in objShadeMesh do try (delete o) catch()
objShadeMesh = #()
)

aPrevSelection = for o in selection where superClassOf o == GeometryClass collect o

for i = 1 to aPrevSelection.count do
(
objShadeMesh[i] = reference aPrevSelection[i]
addModifier objShadeMesh[i] (push Push_Value:1.5) --// increase the push value if necessary
objShadeMesh[i].material = mSelMaterial
)
)
callbacks.addScript #selectionSetChanged "fnU3Selection()" id:#U3Selection
)

CarlCampbell
04-15-2008, 08:05 PM
Works great with push set to 0.001 :D

The only shame is that it doesn't work once you throw in some animation (or move the object around for that matter). Ah well, it will come in handy somehow though. Thank-you VERY much for your efforts!

Cheers!

zortech
04-15-2008, 08:33 PM
Hehe well whatever works for you! I have edited the code so the new mesh is linked to the base mesh, this should do the trick for animated objects.

Yay you are welcome, it was fun to do something different. :)

labbejason
04-15-2008, 09:10 PM
That's very cool! Some things I noticed off the bat though is that it conflicts while trying to create new objects. Also if you modify the mesh, like changing the radius of a sphere, the 'selection' object won't update. I also just got it to crash while reselecting the object over and over.

One thing I messed around with was making the selection object an instance, so when you change the mesh, it'll move along with it. Again, cool stuff!

zortech
04-15-2008, 09:30 PM
Thank you Jason! Great input, though a reference would fit better, as when instancing the base mesh, it will also get the push modifier applied to it.

I have changed the key word within the code.

You're right about the object creation, as well as the re-selecting thing...also pressing undo doesn't work quite well. Hm I'm gonna add an On Off button xD

CarlCampbell
04-15-2008, 09:32 PM
Hm I'm gonna add an On Off button xD

If it were possible to bind that to a keyboard shortcut, this script of yours will DEFINITELY be going in my startup folder!

Cheers!

zortech
04-15-2008, 10:00 PM
Edit: fixed reselecting bug by freezing the reference node

No problem. This is some kind of a workaround, but I have no idea how I can quickly do it solid. (The On/Off button solution)

Well its kinda bitchy to make one single toggle macro, because with a max version older than 2009 there's no function to easily check if a callback is currently active. Like the "Searching for Callbacks.." thread shows.

Change the category's name if you like. It's just that my name is "Max" :D

macroScript u3SelectionOn category:"max'sScripts" tooltip:"Activate u3Selection"
(
callbacks.removeScripts id:#U3Selection --// unregister the callback
local aPrevSelection = #() --// array containing previous selection
local objShadeMesh = #() --// array containing cloned objects
local mSelMaterial = standard()
mSelMaterial.opacity = 50
mSelMaterial.diffuse = (color 150 10 200)
mSelMaterial.selfIllumColor = (color 150 10 200)
mSelMaterial.useSelfIllumColor = true

global fnU3Selection = function fnU3Selection =
(
if objShadeMesh != undefined and objShadeMesh.count > 0 do
(
for o in objShadeMesh do try (delete o) catch()
objShadeMesh = #()
)

aPrevSelection = for o in selection where superClassOf o == GeometryClass collect o

for i = 1 to aPrevSelection.count do
(
objShadeMesh[i] = reference aPrevSelection[i]
addModifier objShadeMesh[i] (push Push_Value:1.5) --// increase the push value if necessary
objShadeMesh[i].material = mSelMaterial
objShadeMesh[i].parent = aPrevSelection[i]
objShadeMesh[i].showFrozenInGray = off
freeze objShadeMesh[i]
)
)
callbacks.addScript #selectionSetChanged "fnU3Selection()" id:#U3Selection
)

macroScript u3SelectionOff category:"max'sScripts" tooltip:"Deactivate u3Selection"
(
callbacks.removeScripts id:#U3Selection --// unregister the callback
)


No need to put this into your startup folder. Just as before open and run it once and the functions "Activate / Deactivate..." will be added to the appropriate category within the customize menu.

CGTalk Moderation
04-15-2008, 10:00 PM
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.