Friday, April 20, 2007

Better Mousetrap

The schedule board at Rockcliffe University, while it looked nice, I'm told it was quite horrible to actually use. It required all sorts of strange configuration via notecards, making the weekly schedule change a nightmare.

I thought there had to be a better way. So I made a similar board - by tapering a box and then mashing it flat, three different letters could be put on a single prim. But instead of arcane configuration, I set it up so you could simply drop a notecard on it, and the text of the notecard would be displayed on the schedule board. Not too bad!

But it was kind of hard to read, and I thought it might be nice if you could change the colors for each line (or groups of lines by day), and added in a #color command which wouldn't be printed, but would set every subsequent line to the specified color, until it was overridden by another #color command. (Shown to the right; click image for a larger view. Classes which had already taken place appear in dim characters.)

And yet I still wasn't satisfied. I was already planning a Web-based schedule database, so the teachers could go in and schedule their classes, which would then appear on the Web site's calendar - so why not also automatically update the board whenever the schedule changed, or a class was over?

This required delving into the XML-RPC functions - which was an interesting learning experience in its own right. But while I was doing that, someone on the Scripters of Second Life group mentioned offhandedly that you could get five letters onto a prim. Well, that sounded like a fun challenge - not to mention cutting the number of prims by 40% - so I set about trying to do so.

Here's a graphic showing the stages of making a 5-letter text segment:

First, we start with a prism. This is the fourth icon on the "Create" pane, between the pyramid and the cylinder. I've colored the front faces red and black just for reference.

Second, set the Taper X and Taper Y both to zero, to get rid of the point on the top and make the edges straight.

Third, set the Path Cut to B=0.2, E=0.8. This cuts a wedge out of the front of the prism, giving us the faces which I've colored green and white. Those particular values leave the red and black faces each taking up one-fifth of the prim's width.

Fourth, set the Hollow to 65. This cuts into the green and white faces, showing us the interior between them (colored blue.

Fifth, set the X size all the way down to 0.010, which flattens out the prim as much as possible.

And sixth, scale the prim so that it gives us a good height-to-width ratio for text. I scaled it to <0.010,0.964,0.250> so that the letter faces were the same size as the ones on my previous version.

Next came setting the texture offsets. If you just tried to put a texture on the faces, they'd look okay on the second and fourth faces, but stretched out somewhat on the first and fifth faces, and REALLY stretched (and backwards!) on the middle face.

So if we were just going to apply a texture with a single letter to each, we'd have to change the texture repeats and offsets. From left to right:

  1. Repeat 2.5 horizontal, 1 vertical; offset -0.25 horizontal, 0 vertical.
  2. Leave at the defaults (repeat 1 horizontal, 1 vertical; offset 0 horizontal, 0 vertical).
  3. Repeat 15.4 horizontal (flipped), 1 vertical; offset -0.2 horizontal, 0 vertical.
  4. Leave at the defaults.
  5. Repeat 2.5 horizontal, 1 vertical; offset 0.25 horizontal, 0 vertical.
With those settings, you would just need to swap the textures for each face in order to display a different letter. (I did it somewhat differently, though - I made a texture with the lower 128 ASCII characters arranged in a grid, which requires a bit more computation every time the letters change.)

I'm still writing the database portion of the system, but to test the XML-RPC communication, I wrote a quick script on my Web site to contact the board in-world, display the version and time, and then include the output of the Linux fortune program, adding #color commands as appropriate:

Now I just need to add in sequence numbers so that if the Web server doesn't receive a response to its communication, it can resend it, and the schedule board won't duplicate the information if it already received it but its response was lost. And then finish writing the database front-end, of course. But still, not bad for a couple days' work!


Ged Larsen said...

oh wow, that's really impressive, and sounds incredibly useful. nice work, yet again.

Maido said...

Very nice work indeed.
I did my experiments with xml rpc for a couple of days before real life came biting my back again, but the thing I noticed is the annoying channel change on long idle times.
Being the noob I am at finding out scripting informations I didn't find out yet when I should enforce a channel refresh / check to see if it's still open.
Initially a timer seemed the most reasonable thing to me, but it sounds soo lame :p
How did you solve it?

lallander said...

Just wanted to point out that they now have code to display 10 characters per prim. Should save you even more prims.

Johanna Hyacinth said...

maido: If your idle time is really long, then a timer is your best bet. I left mine for four days and it didn't invalidate the channel, so I'm not sure quite how long it'll take before the channel goes dead.

lallander: Yes, if I recall correctly, XYText does it by using multiple textures which comprise all the valid combinations of characters. By using only a single texture, it does require more prims - but once that texture's rezzed, all the characters are visible. So I guess it's a tradeoff between primmage, and the time it takes before you can read the whole sign.

Anonymous said...

Why won't I just put all 26 chars on a single texture and simply use a script to only display that part of the texture? Like in animated textures?

- Peter Stindberg

Johanna Hyacinth said...

Peter, that's essentially what I did (as I wrote: "I made a texture with the lower 128 ASCII characters arranged in a grid, which requires a bit more computation every time the letters change").