Forum > modo > SDK, Scripting & Macros > Viewport Shade Type Cycler

Topic - Viewport Shade Type Cycler

 
atanguay
rating: signal 0  


21 posts
Hey all...I wrote a VERY simple viewport shading type cycler today that I thought I'd share in case someone could use it or improve it. It runs through wireframe, shaded, gooch (or the wax shader I substituted), and reflection mapped.

I've mapped this to the Zero on my keypad so that I can quickly zip through these modes. Here is the code:

#!perl
#ANDYs SHADING MODE CYCLER
#v0.1
#This script allows me to cycle through the shading modes
#available in a viewport...wire, shaded, gooch, and reflection

my $shade = lxq("query view3dservice view.shade ? first");

if($shade == 0)

lxout("Shading Type is 0 or wire");
lx("viewport.3dView shade:shade");
}

if($shade == 3)

lxout("Shading Type is 3 or smooth shaded");
lx("view3d.shadingStyle shd1");
}

if($shade == 7)

lxout("Shading Type is 7 or gooch shaded");
lx("viewport.3dView shade:shd3");
}

if($shade == 9)

lxout("Shading Type is 9 or reflection");
lx("viewport.3dView shade:wire");
}





I couldn't find a Case statement in Perl...I'm thinking there still might not be one. So I did it this way. I know it's dirty and terrible, but for now it works. If someone has a better way to do it, I am completely listening.



9/23/2009 - 4:10 PM
[ Quote ]
Robert Lechl
rating: signal 0  

munich
2086 posts
Nice. That saves one key on my shortcut list. Thanks!
9/23/2009 - 4:52 PM
[ Quote ]

Mountain View, California
406 posts
Andy, thanks for sharing your script.

Here's the equivalent script in Python:


#python
#CycleShadeMode.py

def WireToSmoothShaded():
    lx.out("Wire to Smooth Shaded.")
    lx.eval("view3d.shadingStyle shade")

def SmoothShadedToGooch():
    lx.out("Smooth Shaded to Gooch.")
    lx.eval("view3d.shadingStyle shd1")

def GoochToReflection():
    lx.out("Gooch to Reflection.")
    lx.eval("view3d.shadingStyle shd3")

def ReflectionToWire():
    lx.out("Reflection to Wire.")
    lx.eval("view3d.shadingStyle wire")

def ToWire():
    lx.out("Wire.")
    lx.eval("view3d.shadingStyle wire")

cycles = {
    0: WireToSmoothShaded,
    3: SmoothShadedToGooch,
    7: GoochToReflection,
    9: ReflectionToWire
    }

mode = lx.eval("query view3dservice view.shade ? first")

cycles.get (mode, ToWire)()

Twitter: modoCOLLADA
SourceForge: http://colladamodo.sourceforge.net

9/23/2009 - 6:09 PM
[ Quote ]
Gim Dong joo
rating: signal 0  

South Korea
171 posts
Hi,

Here is another script.
You can easily edit the shading type cycle.


#python

shade = ('wire', 'sket', 'vmap', 'shade', 'tex', 'texmode', 'advgl', 'shd1', 'shd2', 'shd3')
cycle = (0, 3, 7, 9)

curr = shade.index(lx.eval('view3d.shadingStyle ?'))
if curr in cycle:
    next = cycle[(cycle.index(curr) + 1) % len(cycle)]
else:
    next = cycle[0]
    
lx.out('%s to %s' %(shade[curr], shade[next]))
lx.eval('view3d.shadingStyle %s' %next)


9/26/2009 - 4:53 AM
[ Quote ]
Robert Lechl
rating: signal 0  

munich
2086 posts
Anybody know how to do this with cycle for background shading type and wireframe overlay? I can't find the correct query command.
9/26/2009 - 6:23 AM
[ Quote ]
Robert Lechl
rating: signal 0  

munich
2086 posts
got it!

Here two scripts for background shading and wireframe overlay (and yes I just copied atanguay):

#!perl
#Roberts BACKGROUND SHADING MODE CYCLER

my $shade = lxq("query view3dservice view.bgmode ? first");

if($shade == 0)
{
lxout("Shading Type is 0 or wire");
lx("view3d.bgLayerDisplay flat");
}

if($shade == 1)
{
lxout("Shading Type is 1 or flat");
lx("view3d.bgLayerDisplay active");
}


if($shade == 2)
{
lxout("Shading Type is 2 or active");
lx("view3d.bgLayerDisplay wire");
}

-------------

#!perl
#Roberts WIREFRAME OBERLAY CYCLER

my $shade = lxq("query view3dservice view.wire ? first");

if($shade == 0)
{
lxout("Shading Type is 0 or none");
lx("view3d.wireframeOverlay uniform");
}

if($shade == 1)
{
lxout("Shading Type is 1 or uniform");
lx("view3d.wireframeOverlay colored");
}


if($shade == 2)
{
lxout("Shading Type is 2 or colored");
lx("view3d.wireframeOverlay none");
}

Message edited by Robert Lechl on 9/26/2009 - 7:01 AM

9/26/2009 - 7:00 AM
[ Quote ]
 
Search
Topic Subscriptions
Forum Preferences
Forum Help
Search the Forums
Advanced Search
modo Training Materials

New for modo 401
Backpack Modeling

New for modo 401
Human Eye

HDRE Urban Kit

HDRE Landscape Kit

Studio Lighting & Illumination Kit

Product Auto Presets

Splash Kit

Subdivision Modeling

modo 401 Spotlight

Real World modo

Shader Tree Essentials

modo 401 Courseware

Rotary Aircraft Engine

Architectural Interior Rendering Series (Intermediate)

Architectural Modeling Series (Intermediate)

Rapid Prototyping Training Series (Intermediate)

Concept Car Training Series (Intermediate)

Cartoon Kid Training Series (Intermediate)

The Alley - Real-Time Asset and Level Creation (Intermediate)

modo is a registered trademark of Luxology LLC., in the USA and/or other countries.
All products or brand names mentioned are trademarks or registered trademarks of their respective holders.