Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Scripting prim eyes.. is this possible?

Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-24-2006 08:09
Hi all,

I'm fairly new to SL having just got back into after a long hiatis. I'm currently handcrafting my furry AV, and at this stage working on a set of prim eyes. The socket is a sphere, hollowed and cut (to make an eye slit), inside is a sphere (eyeball). The effect I'm trying to achieve is eyes that are extruded from the skull, rather than countersunk (think cookie monster, or elmo type eyes).

I would like to make the 'lid' blink and am unsure the best way to approach this. The only way I can see doing it is to have second 'socket' overlap the first with less of a cut (half way between the fully open on, and a closed one) and set to transparent. A third one would have to be added for achieve an closed eye effect, again transparent. The script would end up having to wait, then cycle between 'opened', 'partial', 'closed', 'partial', 'opened', pause changing the ones not needed at that instance to switch to transparent.

A couple questions, is this the best way to approach this or am I overlooking an easier way, favoring prims over texures?

Or, one other idea I had was having a bottom eye socket and a top eye socket, and have the top rotate on the horizontal axis to achieve a blinking effect.

Lastly, having two eyes, and needing them to blink at the same time for obvious reasons, is there an easy way to sync them or do I need to communicate with them to in effect say, 'blink now' from a hidden master prim?

Thanks for any assistance!

Cheers,

Teddy.
Amber Stonecutter
Bruxing Babe
Join date: 13 Sep 2005
Posts: 296
01-24-2006 08:16
A texture with transparency where the eye prims show through would work wouldn't it? Though I imagine that takes longer to load than the prim lids would. =)
_____________________
From: Torley

And like the old adage goes, "Like water under the bridge", implying what passes—this moment—will never come again.


Amber Stonecutter
Introvert Petunia
over 2 billion posts
Join date: 11 Sep 2004
Posts: 2,065
01-24-2006 08:20
Look up RacerX Gullwing who had created large, prim racing snails with prim eyes and blinking lids with lashes. They are pretty snazzy.
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-24-2006 08:25
Hehe, yeah, that's one of the reasons why I wanted to go prim instead of textures. It should be quicker to have a few solid color prims than waiting on textures.

From: Amber Stonecutter
A texture with transparency where the eye prims show through would work wouldn't it? Though I imagine that takes longer to load than the prim lids would. =)


Teddy.
RacerX Gullwing
Magic Rabbit
Join date: 18 Jun 2004
Posts: 371
01-24-2006 08:37
Yes I use prim eyelids 3 sets with a link message telling them what one to be on/off and set on a timer to blink every 15 secs or so Also have a hud so i can make stuff happen when i want including raising eyebrows by reshaping a prim. The snails eyes use 2 textures thet switch for blinking and the eyeball shere is hollow with the eyeball painted on the inside of the hollow sphere it makes them apear to follow you but need to be not overlapping anything.Also the eyelashes are two more prims activated when the blink texture kicks in.
_____________________
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
01-24-2006 08:42
I don't know much about designing eyes, but couldn't you use a cut sphere as your eyelid which could then be rotated via Rot or TargetOmega to cover or uncover the eye?
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-24-2006 08:49
All I can say is, WOW! You certainly went through alot of effort! :) For now I want to get blinking down.. winking and raised eyebrows would have to wait for a v2.0 upgrade. *laughs*

So your using the on/off concept (what I was referring to as transparent).. at least I know I'm at least on the right track.

From: RacerX Gullwing
Yes I use prim eyelids 3 sets with a link message telling them what one to be on/off and set on a timer to blink every 15 secs or so Also have a hud so i can make stuff happen when i want including raising eyebrows by reshaping a prim. The snails eyes use 2 textures thet switch for blinking and the eyeball shere is hollow with the eyeball painted on the inside of the hollow sphere it makes them apear to follow you but need to be not overlapping anything.Also the eyelashes are two more prims activated when the blink texture kicks in.


Thanks!

Teddy.
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-24-2006 08:50
That was my second idea in my original post, except using two cut prims, the top to rotate and meet the bottom one and in sense achieve an effect of a blink.

From: Yumi Murakami
I don't know much about designing eyes, but couldn't you use a cut sphere as your eyelid which could then be rotated via Rot or TargetOmega to cover or uncover the eye?
Upshaw Underhill
Techno-Hobbit
Join date: 13 Mar 2003
Posts: 293
01-24-2006 09:21
There is something similar to what you are describing in the Frog Prince AV by Xenon Linden, using textures and texture animation. no prim cutting, hollowing, etc. needed.
Two spheres, one with the eye texture, one with an alpha-ed eyelid texture that has 4 or 6 frames of blink, and even a random every X-Y seconds blinker script included :)

Check out your nearest Telehub... err *Info*hub for a copy (If it's not still in there drop me an IM I can drop you one.)

L8r,
UU
_____________________
Mystic Tokhes
Registered User
Join date: 20 Jan 2006
Posts: 1
01-25-2006 11:26
I'm not a scrpiter yet, but to me it would make sence to script the eyelid, make 2 sockets that take the same space and same position, but just script one to rotate, this should result in a much smoother blink, and a better transition. also it would alow for more control
just my spare 2 cents, let me know what you think :)
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-25-2006 11:56
From: Mystic Tokhes
I'm not a scrpiter yet, but to me it would make sence to script the eyelid, make 2 sockets that take the same space and same position, but just script one to rotate, this should result in a much smoother blink, and a better transition. also it would alow for more control
just my spare 2 cents, let me know what you think :)


Yep, the only logistics to consider is rotating +x degrees, and then back -x degrees. I'm not certain if it allows for relative degrees or if you need to use defined measurements. I'll play around and see what I can come up with. I'm suspicious that I could design one eyeball first, along with a master prim that would whisper to the eye(s) to blink on command on a timed interval. Commands could extend to 'blink', 'squint', 'wink', etc. Alot of possibilities, but I need to figure out the blink method first. I'll redesign the eye tonight to have an internal prim to function as an eyelid and see what kind of script I can come up with.

All the ideas have been very helpful.. thanks everyone!

*hint hint* if anyone has an idea on a basic script to use, I'd be happy to entertain one. :)
Thraxis Epsilon
Registered User
Join date: 31 Aug 2005
Posts: 211
01-25-2006 19:30
Why not just change the cut of the socket prim? No extra prims, no fancy texture tricks..
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-25-2006 19:43
I wasn't aware that you could programmatically change the cut size within the scripting language.

From: Thraxis Epsilon
Why not just change the cut of the socket prim? No extra prims, no fancy texture tricks..


On another note, I have a tenative script written, it works fine until I rotate the entire eye assembly to another direction that it fails miserably and doesn't return back to it's 'home' position.. *laughs*

Here's what I wrote:
CODE

// Eyeblinker script - listens on channel 22 for /blink

default
{
state_entry()
{
llListen(22, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string message)
{
if (message == "blink")
{
rotation blinkclosed = llEuler2Rot( <60 * DEG_TO_RAD, 0,0 > );
rotation new_rot = llGetRot() * blinkclosed;
llSetRot(new_rot);
rotation blinkopened = llEuler2Rot( <-60 * DEG_TO_RAD, 0, 0> );
new_rot = llGetRot() * blinkopened;
llSetRot(new_rot);
}
}

}


The idea is that the inner eyelid should rotate 60 degrees to close, and then -60 degrees to open again. And like I say, it works fine.. when the eye is pointing North.. but point it east and it goes all to heck (because the axis has changed).

Arg! I've been pulling my hair out for the last hour on this one, I have to find a better way to rotate it.
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-25-2006 20:24
Woo hoo! Success!

As it turns out, instead of using SetRot and GetRot I should have been using SetLocalRot and GetLocalRot. I now have blinky eyes on command. I just need a master prim to tell'em to blink unless I can find a better way to communicate it to each eye.

CODE

// Eyeblinker script - listens on channel 22 for /blink

default
{
state_entry()
{
llListen(22, "", llGetOwner(), "");
}

listen(integer channel, string name, key id, string message)
{
if (message == "blink")
{
rotation blinkclosed = llEuler2Rot( <60 * DEG_TO_RAD, 0,0 > );
rotation new_rot = llGetRot() * blinkclosed;
llSetRot(new_rot);
rotation blinkopened = llEuler2Rot( <-60 * DEG_TO_RAD, 0, 0> );
new_rot = llGetRot() * blinkopened;
llSetRot(new_rot);
}
}

}
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-26-2006 12:26
Ok, now that I have two eyes listening for the blink command (I'm going to rewrite the above code to use LinkMessages when I'm done instead of Say/Listen).. I need a way to set a master prim (one to control the blinking and instruct the eyes to blink) communicate the blink command in a randomly timed method.

Obviously I'm looking at using the timer, and would like to set the eyes to blink once anywhere between 5-10 (with random variations in between) seconds apart to make the blinking process completely automated.

I'm hoping this will work.

CODE

float fastblink = 5; // Five second intervals
float slowblink = 10; // Ten second intervals
float delay = 0; // randomized delay value

default
{
state_entry()
{
// set timer to random number between fastblink and slowblink values
delay = (llFrand(fastblink - slowblink) + fastblink); // generate random value
llSetTimerEvent(delay);

timer()
{
// Tell eyes to blink
llWhisper(22, "blink");

// Set the timer to a new random number
delay = (llFrand(fastblink - slowblink) + fastblink); // generate new random value
llSetTimerEvent(delay);
}
}
Amber Stonecutter
Bruxing Babe
Join date: 13 Sep 2005
Posts: 296
01-26-2006 17:32
Teddy, you get dorky-cool points if the master prim is a brain textured sphere that lives inside your head.

Ps: Glad it's working!
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-26-2006 17:51
*laughs* That would be funny. :)
Kintar Czukor
Registered User
Join date: 23 Jan 2006
Posts: 6
01-27-2006 09:09
From: Amber Stonecutter
Teddy, you get dorky-cool points if the master prim is a brain textured sphere that lives inside your head.


I do believe that's the single weirdest/coolest thing I've heard today. :eek: Thank you, Amber, I now know what the master remote for the doors and windows in my house is going to look like. :D
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-27-2006 09:24
Ran into another problem after assembling everything into an attachment..

The eyelid script tells the inner eyelid to rotate on a relative X axis based on the entire eyeball assembly. However, when the eyeballs and 'brain' are then linked as one attachment, the relative X axis shifts based what I'm assuming is to the midpoint of where the brain is.

Arg! More fun to solve.

It looks like I have to either have to have the eyes as a separate attachment from the 'brain', or come up with a different method to make the eyes blink.. or go with a alpha on/off with mutiple eyelids, thereby increasing the prim count.. something I'd rather not have to do if I can get away with it.
Thraxis Epsilon
Registered User
Join date: 31 Aug 2005
Posts: 211
01-27-2006 13:18
Here is the code I just did for using the single prim, change cut paramaters


BlinkBrain
CODE

float fastblink = 5.0; // Five second intervals
float slowblink = 10.0; // Ten second intervals
float delay = 0; // randomized delay value
integer blinkChannel = 22; // link channel to send blink commands on

default
{
state_entry()
{
// set timer to random number between fastblink and slowblink values
delay = llFrand(slowblink - fastblink) + fastblink; // generate random value
llSetTimerEvent(delay);
}

on_rez(integer num)
{
llResetScript();
}

timer()
{

// Tell eyes to blink
llMessageLinked(LINK_SET,blinkChannel,"",NULL_KEY);

// Set the timer to a new random number
delay = llFrand(slowblink - fastblink) + fastblink; // generate new random value
llSetTimerEvent(delay);
}
}



EyelidBlink
CODE

integer blinkChannel = 22;

blink()
{
llSetPrimitiveParams([PRIM_TYPE,PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT,<0.05,0.95,0.0>,0.85,<0.0,0.0,0.0>,<0.0,1.0,0.0>]);
llSleep(.25);
llSetPrimitiveParams([PRIM_TYPE,PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT,<0.0,1.0,0.0>,0.85,<0.0,0.0,0.0>,<0.0,1.0,0.0>]);
llSleep(.25);
llSetPrimitiveParams([PRIM_TYPE,PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT,<0.05,0.95,0.0>,0.85,<0.0,0.0,0.0>,<0.0,1.0,0.0>]);
llSleep(.25);
llSetPrimitiveParams([PRIM_TYPE,PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT,<0.1,0.9,0.0>,0.85,<0.0,0.0,0.0>,<0.0,1.0,0.0>]);
}

default
{
state_entry()
{
llSetPrimitiveParams([PRIM_TYPE,PRIM_TYPE_SPHERE,PRIM_HOLE_DEFAULT,<0.1,0.9,0.0>,0.85,<0.0,0.0,0.0>,<0.0,1.0,0.0>]);
}

on_rez(integer num)
{
llResetScript();
}

link_message(integer sender_num, integer num, string str, key id)
{
if(num == blinkChannel)
{
blink();
}
}

}


If you want a copy of my eyes / brain just send me an IM in the game and I'll send you a full permission copy. I got bored a bit an set my eyes to move when you blink as well.
Teddy Wishbringer
Snuggly Bear Cub
Join date: 28 Nov 2004
Posts: 208
01-27-2006 14:08
OMG!

I can't wait to get home from work and try this out now! I love it when someone finds a way to creatively do similar things. :) This should solve my rotational vector issues as well.

I see you cleaned up the brain code and used link messages too, all I can say is WOW. :D
Obsidian Stormwind
Second Life Resident
Join date: 13 Nov 2004
Posts: 16
Prim Eyes that blink? I've been doing that for months!
01-28-2006 06:30
Heyo. I have a few different coding techniques for making prim eyes blink, but the one in this video is the most complex. I have 7 prims for each "frame" of the eye blink animation. I have the main script in the head determine when the blinking starts, but then the eyelids send linkmessages to one another in a daisy chain telling the next frame when to go visible while making itself fully transparent.

http://kindragon.dragoncity.net/Prim_Eyes_Blink.avi

The quality of the video isn't the greatest, but it should still give a good example of how well the animation works.