A python quiz [Solution: an animated projected shadow]

(Monster) #1

Hi all,

I had an idea for a problem that is discussed here for ages. I tried and it is amazing. Now I want to share it as I’m sure you would love it as I do. There is some potential to enhance it.

What it is?
These is a quiz for medium to advanced blender users.

What can you win?
Big eyes and more. Believe me it is worth.

What do you require?
-a working blend file with an animated armature (e.g. a walking person)
-to know how to apply a python script to an object
-to know how to change the color of an object

What do you have to do?
Follow tho below tutorial and answer this question:
What does it do?

Here is the tutorial:

  1. Select the mesh parented to the armature (e.g. the skin of the actor )
  2. Make a full copy of it <shift><d> (name it as you like, keep parenting)
  3. Move the centre of the new object to be at the bottom of the mesh but a little bit above the ground. Do not just move the object as this would distort the mesh. (Hint: leftclick the side/top/front view to move the 3D cursor in the right position/<F9> click “Centre Cursor” in the mesh panel)
  4. Make your new mesh black without texture (Hint: face select mode <f>/ select all <a>/ texture face panel: disable all except opaque/click ”Copy Draw Mode” /select black color/click “Set VertCol”/leave face select mode <f>)
  5. Open the text editor and open quiz.py from below
  6. Add property alpha as float to the logic <F4> of new object (default 23.0)
  7. Add property length as float to the logic <F4> of the new object (default 1.0)
  8. Add an always sensor (true pulse on)
  9. Add a python controller with script quiz.py connected to the always sensor
  10. Select a nice view to the armature
  11. SAVE
  12. Start the engine

quiz.py:

cont = GameLogic.getCurrentController()
own = cont.getOwner()
 
ori = own.getOrientation()
a = ori
 
from math import sin,cos
# here you need the properties alpha and length
sinA = sin( own.alpha/9 )*own.length
cosA = cos( own.alpha/9 )*own.length
 
a00 = ori[0][0]*sinA
a01 = ori[0][1]*sinA
a10 = ori[1][0]*cosA
a11 = ori[1][1]*cosA
 
a[0][0] = 1.0
a[0][1] = 0.0
a[0][2] = -a00-a10
 
a[1][0] = 0.0
a[1][1] = 1.0
a[1][2] = a10+a11
 
a[2][0] = 0.0
a[2][1] = 0.0
a[2][2] = 0.0
 
own.setOrientation(a)

If I did everything correct and you did everything correct you should now know what it is:) .

Who can answer the question?
[edit:]
We have 3 winners (I think).

Here is the solution for the others:an animated projection shadow for armature meshes on the XY-plane

0 Likes

(fireside) #2

Interesting idea, but looks like a lot of overhead if it’s what I think it is.

0 Likes

(honeycomb) #3

WOW, that’s really neat. It seems that get/setOrientation is a very powerful combination if you know how to apply it using a creative mind.

0 Likes

(marvo) #4

yeah thats really nice.

0 Likes

(Monster) #5

You can reduce overhead by making the copied mesh with less vertices as not all details might be needed.

0 Likes

(Shn275) #6

Yooo…That’s pretty damn impressive. Do you mind if I use this? I always wondered if this was possible.

0 Likes

(Monster) #7

It is free to use.

Be aware there are some downfalls when used with transparent materials. You can see if two faces are overlapping. A real shadow wouldn’t care as shadow is shadow. I currently have no solution on this except to use non-transparent material.

Monster

0 Likes

(James XVI) #8

Could you give us a test file?

0 Likes

(ChicOrtiz) #9

mmmm… Sadly it is not working here…:frowning:

Some questions:

a) about steps 6 and 7: what do you mean by default value? Does we need to change the property value to 23.0 and 1.0?

b) Stupid question: we need to add logic brics and properties to the new copied mesh. <<<Is it right?

c) Does we need to change something inside the python script?

d)Any camera view will work?

Thank you!

0 Likes

(POCHO) #10

very good monster , now I works in example blend but used ray and gethitPosition()

0 Likes

(ChicOrtiz) #11

about my own questions:

a) Yes.

b) Yes

c) No

d) Yes

MONSTER YOU ROCK!

I just typed one of the properties wrong.

Thats awesome! Congratulations!

Iam tring to make it work nice with GLSL scripts YAHOOOOOO! Monster is the best!.

0 Likes

(kirado) #12

hi monster… looks cool… could you share a blend or a screenshot… I don’t have any animated characters to test this out with yet…

0 Likes

(Monster) #13

Here it comes :yes: .


A mouse with sharp black realtime shadow.

And here with with an example configuration (the shadow mesh is selected):



Have fun

0 Likes

(kirado) #14

wow very impressive… so how does the maths work (theory)… as in how did you get the model on the XY plane and still have it controlled by the armmatures? In GLSL you can affect the scale of objects like this too… but I dunno if it would work with the amarture thing… would be cool to control the rotation based on the position of a light… maybe make the shadow stretch and shrink as well… could layer another lighter shadow on for a different light?

0 Likes

(ChicOrtiz) #15

Dude this script is the most coolest thing in 2007. (Since 2.43 release). :))

Here you will find a ytube video of Monster’s masterpiece (this script also works nice with blender materials and GLSL):

YOU TUBE VIDEO: http://www.youtube.com/watch?v=grB4Jl3G-tY

Monster you are a GENIOUS!

Thanks for this toy! It adds a lot of deep to character presentation.

Have you tested it with alpha maps?

0 Likes

(jessegp) #16

that is a nice models you’ve got there thorgal.

Monster, this thread didn’t get the love it deserved when you originally posted it.

0 Likes

(ChicOrtiz) #17

"that is a nice models you’ve got there thorgal.

Monster, this thread didn’t get the love it deserved when you originally posted it."

Hey Thankx! My .blend will be available for download soon. My droid is looking better now thanks to Monster. A character without shadow is like a character without soul. (have you read "Peter Schlemihls Wrundersame Geschichte/ The wonderfull history of Peter Schlemihls?):wink:

Are you talking serious that Monster posted this script before? That is unacceptable to me!

How could i lost this one?:o

0 Likes

(Monster) #18

Nice that you like it. Maybe nobody recogniced it as the thread was stated as a quiz. Not everybody wanted to go through this.

Belive it or not I can’t remember:o . It uses some sideeffects of matrix manipulation. The basics are this:

The “shear” was more a mistake as this was the result of a bug in another script. Basicly you can set the direction and length of the shadow with the a[0][2] and a[1][2] terms. For easier use, with alpha you can set the angle with length the size of the shear operation.

The easy part: The Z-axis of the shadow mesh is scaled to 0 (a[2][2] = 0.0 ). This lays the mesh down to the ground.

The shadow is parented to the armature so it would rotate with the armature. This is not really nice for a shadow, isn’t it? Therefore an inverse rotation is applied to a[0][2] and a[1][2] keeping the length and alpha values.

This is a parallel projection (like sunlight or a far spotlight). You should avoid lightsources on short distance like candles in the hand etc.).

0 Likes

(OTO) #19

Dear Monster
if Thorgal say that you’re a “GENIOUS”, I believe it, and, even maybe a genius! :slight_smile:
It’s true, it looks nice!!
No big “charge” in the FPS count?
I’ll try it as soon as I can
Bye and thank you

0 Likes

(ChicOrtiz) #20

:stuck_out_tongue: Thank you for the tip Oto! I will redo my comment:

Monster you are a GENIOS!

Better now? ; )

But, as you can see iam not…

This:

"The “shear” was more a mistake as this was the result of a bug in another script. Basicly you can set the direction and length of the shadow with the a[0][2] and a[1][2] terms. For easier use, with alpha you can set the angle with length the size of the shear operation.

The easy part: The Z-axis of the shadow mesh is scaled to 0 (a[2][2] = 0.0 ). This lays the mesh down to the ground.

The shadow is parented to the armature so it would rotate with the armature. This is not really nice for a shadow, isn’t it? Therefore an inverse rotation is applied to a[0][2] and a[1][2] keeping the length and alpha values."

Sounds like Greek to me. And iam not from Grece so its being a litle hard to understand what Monster are pointing out :o.

Does i understand it right?>>> Is it possible to change the alpha value via your script making use of vertex colors only? I don’t need a texture to make that?

Right now I iam tring to use a .TGA texture but it overlaps in 3D leading to different grey tones for my shadow :mad: even if i work just with the model silhouette that still happens because of animation and 3D. DARN!:mad:

Which value i need to to use to correct the rotation issue?

Hey Monster, sorry about the English and Math. During the classes i was playing videogames. :cool:

0 Likes