Pages

Wednesday, May 26, 2010

And now for something completely unrelated.....

I was asked about making sculpties in Blender. Well the fact of the matter is that it's a little bit of a pain to set up if you're doing it from scratch. So what I've done is I've taken care of the initial steps and saved the file, and that is available to everyone here: http://bitcracked.com/sl/sculpty.html Just download the file, unzip and open it.

I have it set up with the default cylinder. If you want more vertices just push A (hotkey to select all), go to edit mode, click editing (looks like a sqaure with dots at the corners) and click subdivide.


To export your sculpty map, follow these steps.
1. Move your mouse right over the line between the top and bottom window and choose "split area"

2. Click the little box at the bottom left of the new window you just created and select "UV/image editor"

3. Click on Image > new, and set the dimensions for 256x256. Then, push F10 to go to the render menu, and click the "bake" tab. In the right column, click "Textures", and then click the large "Bake" button. You will see your colored sculpt map appear in the right window.



4. Once the image has been baked, click on image again, choose Save As, and select where you want to save your image. At the bottom of the save screen make sure you select to save your image as a Targa file.

I know there are plugins and junk to make sculpties in blender, but if you don't feel like using those or they're giving you trouble, this can be an easier way to make them without plugins. Just make sure you don't save over your sculptstart.blend file :)

Also, I know that SL will trim down your image to be 128x128 (and 32x33 verts) when you use it as a sculpt map but I always like to start high res and then let it be trimmed down as needed.

Dave's Giant Database Insertion Tutorial

So, I've had a request to explain inserting data into an external database from SL. This is a pretty lengthy subject but to shorten it up for this post I'm going to assume a few things, such as:
  1. You have a web server and a place that this database/web script can go.
  2. You have a database and don't need help setting one up
  3. You have at least very basic knowledge of PHP and writing MySQL requests.
As a side note, everything on this page that is highlighted in orange is something that you will need to rename yourself.

That being said, let's get started. The first thing you will need is to set up your database and know what you are going to store. For this example let's say you want to insert the name of an avatar into a database whenever the object is touched, and keep a running tab of how many times they have touched it.

Assume you have a database called "SL" with a table called "stats". Stats has two columns, "name" and "number". Name will be the name of the avatar (for this example it would need to be set as unique). Number will represent the number of times the prim was clicked.

Now what we are going to do is set up our PHP script. What will happen is that every time the prim is clicked, it will send a request to this PHP script, which will then update the database. Here is an example of what the PHP script should look like for this example.

<?php
$db = mysql_connect("localhost", "db_username", "your_password") or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.')</script></html>");
mysql_select_db("SL",$db);

$name = $_GET['name']; //$_GET takes variables that are passed from the url (see the LSL example)
$usertable = "stats";

$update = "INSERT INTO $usertable SET name = '$name', number = 1 ON DUPLICATE KEY UPDATE number = number + 1";
$result = mysql_query($update);

?>

And now for the LSL script that will send the request to the PHP page:



string owner_name;
key owner_name_query;
default
{
    state_entry()
    {
       
    }


    touch_start(integer total_number)
    {
       owner_name_query = llRequestAgentData(llGetOwner(), DATA_NAME);
    }
     dataserver(key queryid, string data){
        if (owner_name_query == queryid){
            owner_name = data;
            llHTTPRequest("http://www.yoursite.com/yourphppage.php?name=" + owner_name, [], "");
        }
    }
}
 Let's take a look at the URL in the llHTTPRequest function. http://www.yoursite.com/yourphppage.php?name=" + owner_name. Remember the $_GET['name'] part of the PHP script? Well this is where that variable is taking data from. ?name= denotes a variable that can be passed to PHP using a URL. If you want to pass more variables, you can string them along with ampersands like this: ?name=Joe_Shmo&id=123456&status=living

Well I hope that is enough to get you started loading things into databases. Next time we can talk about how to get data back out of the database.

Sunday, May 23, 2010

Beacon

So Patti wanted a beacon for a radio tower she was making, and I came up with this script. It's a pretty simple script but there's a nifty trick in here I felt like I just *had* to blog about. Here is the beacon script.

float delay = 0.01;
float k = 0;
integer toggle = 0;
default
{
state_entry()
{
llSetTimerEvent(delay);
}
timer(){
if(toggle == 0){
llSetLinkPrimitiveParamsFast(LINK_SET, [25, ALL_SIDES, k]);
k += 0.03; //changing this will change how fast the blink is
if (k >= .5){
toggle = 1;
}
}
if(toggle == 1){
llSetLinkPrimitiveParamsFast(LINK_SET, [25, ALL_SIDES, k]);
k -= 0.03;
if (k <= 0.04){ toggle = 0; } } } }

The neat trick is using llSetLinkPrimitiveParamsFast instead of llSetPrimitiveParams. Check out the video to see why :) The one using llSetLinkPrimitiveParamsFast is on the left. Nice and smooth :)

Oh! The one thing to look out for: you have to be careful changing the speed, do some math and make sure it won't try setting the glow under 0 or over 1. Otherwise you get a super annoying script error D: