SOS - Simple OBJect Shading ***Updated***(again - 6/14/05)

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

SOS - Simple OBJect Shading ***Updated***(again - 6/14/05)

Post by 7feet »

I wanted to be able to just drop some 3D OBJects(simple primitives or objects, free stuff off the web) into Moho on occasion and be able to add a little lighting to them (in Moho) without futzing around. So that's just what I did.
Image
Basically simple objects that came out of Wings with one single color material applied overall (okay, I cheated, I made a second material for the outlines on the crib section there - I bevelled all the edges a tiny bit and gave the bevel an "outline" material. Which by the way works really well with geometric objects in Moho). Run the script, tell it the point from which the light is coming from, the number of shades of each material, how subtle or harsh you want it to be, if you want the brightness punched up at the top for a highlight, and there you go.

It makes a "baked" copy of the layer that's selected. One of the cool things about that is that all the information about that 3D doojigger is now stored safely inside the .moho file. Don't have to worry where the .OBJ file went to.

There are 6 parameters you can set. The X, Y, and Z coordinates of the "light source". The number of shading levels, meaning if you have 20 shading levels then something directly facing the "light" will use shade 1, directly away shade 20. You can set the interval between the shades - a % value, each shade is X% darker than the last. And there's an "Added Brightness" parameter that lets you set how much you would like to add to the original material's brightness for the first shade.

A few tips.
-- Right now, the light direction relates only to where the imported object was from right when you imported it. It takes no account of things if you translated or rotated it around. I really, really tried to make it take the layers translations and rotations into account, but wierd things happend. I'll get it.
-- If you set the light point to 0,0,0, you don't get nothin'. so don't try and get funny. Also, you don't get shadows. Don't even ask.
-- After you run the script, you won't see much interesting until you hide the original 3D layer (if you hadn't move the original around, that is). They're right on top of each other, and that mucks up the works.
-- If you do something like apply it to a 10,000 polygon shape with 50 materials set for 150 shading levels, you are certainly going to get one bloated object, it may take a million years, and I make no guaratees whatsover that it won't make Moho die. That's all on you. Use some restraint.
-- I don't take textures into account at all. Haven't tried it with them, don't know what it'll do. But likely as not, since I don't copy the texture points, the texture will just vaporize.
--if you rerun the script on a copy you have already shaded, you will, each time, create and exponentially expanding set of probably useless materials. If you aren't happy with what you got, it's better to delete the shaded (copy) layer and start again. Believe me - while I was debugging I ended up with one of the cubes made from the "Cube" menu script with thousands and thousands of materials, and it wasn't pretty.
--if an object has no materials (like what you'll get from the "Torus" menu script) the script gives you a warning and exits. I'll probably set something up so you can apply some sort of default material if you want.

I must have crashed Moho 3 or 4 hundred times while I was writing this. Like one every minute or so for hours. Guess I'm one determined bonehead. Never tried to write any 3D stuff before. Anyone who want's to pick apart the code or suggest improvements, I'm all ears. Without furthur ado -

UPDATED - bugfix 6:40am GMT 4/21/2005
-- fixed a little bug where the base shade wasn't adjusted if you changed the brightness. Also put all of the stats in an info window instead of the Lua console.
-- just the SOS script, the Library is the same.

UPDATED - wierd Lua bug 5:00pm GMT 6/14/2005 v1.02
-- Lua let's you divide zero by zero, giving nonsense in some cases. All tuned up.
Simple OBJect Shading
put that somewhere in your Moho>Scripts>Menu directory


My handy dandy library
This needs to go in the Moho>Scripts>Utilities directory.

Next, I think I actually have a proper automated lipsync solution. Only for Windows, but as the auto phoneme detection part from an old Win95 program (freely available), it should work on any old kinda Win emulation.

bwWAAAHAhahahah...
Last edited by 7feet on Wed Jun 15, 2005 3:10 am, edited 3 times in total.
User avatar
Lost Marble
Site Admin
Posts: 2355
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Post by Lost Marble »

Wow, that's really cool! We really need to get all your scripts collected on a single page somewhere...
User avatar
jahnocli
Posts: 3471
Joined: Fri Oct 29, 2004 2:13 pm
Location: UK

Post by jahnocli »

Brian, you are a star!
You can't have everything. Where would you put it?
Toontoonz
Posts: 763
Joined: Fri Mar 25, 2005 9:28 pm

Post by Toontoonz »

Great Stuff!

I agree with the idea of having all the scripts on one page. It can be confusing which and what are the latest scripts and newest versions of each. (Please as a minimum list the name of the script, a short description (and long, if needed) as to what it does and why one needs it and the date of the most current version.)
Toontoonz
Posts: 763
Joined: Fri Mar 25, 2005 9:28 pm

Post by Toontoonz »

"Next, I think I actually have a proper automated lipsync solution."


That´s one I really look forward to trying out! :D
User avatar
jorgy
Posts: 779
Joined: Sun Sep 05, 2004 8:01 pm
Location: Colorado, USA

Post by jorgy »

Holy Crap!!

OMG!!!

That is f'n cool, dude!
User avatar
bupaje
Posts: 1175
Joined: Fri Nov 12, 2004 5:44 pm
Location: California
Contact:

Post by bupaje »

Wow, that's really cool! We really need to get all your scripts collected on a single page somewhere...
I may be able to help with this soon if you like. I have been setting up a CMS on my site the past few days. Tried a test account for the scripts but turned up two minor 'features' which I am waiting to have resolved.

I also don't know PHP so am waiting on some help to modify the downloads mod to add a short description and version info. Unless LM plans to host them here, or someone else wants to, then I should have this fixed in a few days and we can give it a test run.
User avatar
jorgy
Posts: 779
Joined: Sun Sep 05, 2004 8:01 pm
Location: Colorado, USA

Post by jorgy »

Brian,

How did you apply your one-color texture within wings? The way I've been doing it:

http://www.lostmarble.com/forum/viewtopic.php?t=1393


It seems rather awkward - is there an easier way?

Thanks,
jorgy
User avatar
bupaje
Posts: 1175
Joined: Fri Nov 12, 2004 5:44 pm
Location: California
Contact:

Post by bupaje »

By the way, blew me away Brian. Very awesomely cool.
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

Thanks all. Glad you dig it. Thought it was going to make my brain drip out my ears.

jorgy - It's not a texture. I just assign a material to the whole object, of the basic color you want, or you can apply separate materials to faces, or groups of faces as you please. Moho only recognizes the "Diffuse" color of the material at this points. So, a quicky how to - (and I'm going to be thorough here - jorgy, since you've played with the "huh?" UV mapping setup in Wings, this'll be cake)
Image
Make your model (we're talkin' in Wings 3D here) If you want to keep things real simple. Make a few duplicates of the default material (left click to select the default material in the Outliner window and then right click to make a few copies.
Image
Pick one of those materials, and right click on it. Choose "Edit Material". Since Moho only looks at the "Diffuse" color, click on that box and set up your material color. Repeat for as many materials (colors in Moho) as you feel like setting up.
Image
Select some faces (hopefully more appropriate than I just did). right click on the material that has the color you want, and choose "Apply to Selection".
Image
Do that as many times, for as many sets of faces and as many materials as you have the patience for. If, in my case, if you just wanted to make a chair, crib frame, or crappy boxy ol' couch you could drop in Moho, that might likely be exactly one. Here I got fancy (and utterly random).

Export what you've got from Wings3D as an .OBJ (if you find yourself looking for how to do it, look for the line in File>Export that says "Wavefront .obj"). Import that .OBJect into Moho. I ran the script using the defaults, rotated the layer around a little, and this is what I got -
Image
It's flat shading. Moho won't let me do anything else, and I had to trick it. It's pre-Tron, even. But for the kind of fairly basic geometric kind of shapes I wrote it for, it'll do the trick. If you want something to look really round, you could use a really high polygon shape, and a really high number of shades. But if you really need that, I think you are better off using textures.

Now, LM, if you would give access to texture assignment as well as just the texture points, I might be an idiot and try to write some sort of internal Moho-style 3D modeler. Rudimetary, y'know, but perhaps way useful for the folks who just don't wan't to learn a 3D program to be able to put a 3d sawhorse in their cartoon. Not trying to subvert the purpose, I'm all about the 2D, but it can make some things easier.

Also, this damn thing currently creates way more points than it should. I copies each face individually, and creates a whole new set of points for each one. So it ends up jamming 3 or 4 times as many points as needed into the resulting .moho file. If anyone wanted to look at it, prob'ly ain't hard, but I'm working diligently on the lipsync issue. Day or 2. Or, I'll either find a new job or sqeeze the 6 months back pay out of the old one(and have some outside fun). Doubt it's more than a few lines, I just can't look at it at the moment.

Should have the lipsyc bit done to test in a day or 2. It's parsing the phoneme info alright, just need to set up the breakdowns (pretty much full IPS). Figuring on the extended Preston Blair at the git.

bupaje - wouldn't mind a place to plant them all. As they pile up, I've been trying to think about how to version them so it's clear (Toontoonz - if you go to the top toolbar Help>About Scripts I always include version numbers when I update something, you can check them there). I had a page for all my script built, and then by hard drive decided to go belly up. Whipped out the magic wand and got it (almost)all back, but I can't find half my software, including most of the html stuff, and I don't feel up to doing it by hand. Gotta dig around in my piles of stuff s'more. I have updated versions of pretty much everything I've done. I'd like to have 'em on my own page, but if I can't get it done by the end of the week I'll just ship them over to you and LM and let youse guys sort it out.


ACK! sorry if you can't see this, I think the servers running through another "update cycle". If I'd gotten paid I'd have a proper server. Anyone got a reasonably entertaining job for me? Serious.
User avatar
b15fliptop
Posts: 167
Joined: Thu Mar 10, 2005 6:11 pm
Location: Parts Unknown

Post by b15fliptop »

Wow!! That is truly the coolest script ever! Nice job, Brian!
User avatar
jorgy
Posts: 779
Joined: Sun Sep 05, 2004 8:01 pm
Location: Colorado, USA

Post by jorgy »

7feet wrote:Thanks all. Glad you dig it. Thought it was going to make my brain drip out my ears.

jorgy - It's not a texture. I just assign a material to the whole object, of the basic color you want, or you can apply separate materials to faces, or groups of faces as you please. Moho only recognizes the "Diffuse" color of the material at this points. So, a quicky how to - (and I'm going to be thorough here - jorgy, since you've played with the "huh?" UV mapping setup in Wings, this'll be cake)
Thanks! I now understand the difference between a "material" and a "texture". Your script rocks!
User avatar
jorgy
Posts: 779
Joined: Sun Sep 05, 2004 8:01 pm
Location: Colorado, USA

I broke it.

Post by jorgy »

I created a model in wings3d that your script didn't like. The output is:

Number of Faces: 769 Number of initial materials 1
invalid type in variable assignment.
value is 'nil'; 'number' expected

If it's not because the model is too complicated, then I suspect it's because some surfaces are obscured.

The model is here:

http://65.98.71.13/moho/Submarine.wings

Thanks for a great script!

jorgy
User avatar
7feet
Posts: 840
Joined: Wed Aug 04, 2004 5:45 am
Location: L.I., New Yawk.
Contact:

Post by 7feet »

It wasn't the obscured surfaces (although something wierd is going on near the front of the sub causing a band around the body of the sub to render black). The main problem was what was sticking out of the tower thingy on the bottom of the sub. Which was a 5 point, 5 sided open polygon my script did not like at all. In Wings, I just couldn't delete it. I had to close it, triangulate it, delete the faces, and then do it again to make it all go away, then it'll shade (mostly). The other thing thats going on is there are a lot of 5 or more sided polygons. Moho understands 3 and 4 sided faces, and anything else can make it hiccup, not render faces, all sorts of fun stuff. In this case the easiest thing to do is to select all the faces, and then Tesselate>Quadrangulate them. That'll break up those pesky faces into something that won't scare Moho without doing a lot to all proper 3 and 4 sided faces you already have..

I also noticed that if you are adding brightness to the shading, it's not recalculating the original color to reflect that. I'll fix that in a minute.
User avatar
jorgy
Posts: 779
Joined: Sun Sep 05, 2004 8:01 pm
Location: Colorado, USA

Post by jorgy »

Okay, I'll try that out!

Thanks for the speedy reply.


p.s. I was trying to make a conning tower on the sub.
Post Reply