Thursday, October 24, 2013

Creator Resource - Doors in SL

This tutorial is currently at Creator Resource - Doors in SL



You will need basic building skills to follow this tutorial, such as rezzing prims, texturing their faces and know what the root/child prims are. Knowledge about creating sculpt prims and/or mesh is not required to understand what the scripts will do. It's only advisable if you plan modelling your own sculpt/mesh doors :-)

TABLE OF CONTENTS


Introduction: What do we mean by "using doors" in our builds?


When building in SL, when we say that we want to make "a door", we're implying a little more. What we normally mean is that we want to build an object that will work as a door, this is, than apart of having the appearance of a door, it will open and close as a door would do.

Building the door in itself isn't complicated. The issues arise when we want to add our door the desired interactivity. Suddenly we may find that our whole build rotates, or that the door is rotating around the wrong axis, or moving around the wrong axis, or that the way the door rotates, is not how we would like it to be, and the fix has to be performed in the build rather than in the script.

For all those reasons, I've spent some time putting together all the information that I consider essential for builders, and that I hope will help you understanding what you're after when you want to add doors to your builds. It's important because you'll learn how your door should be designed, what kind of script to use and why.

Note: When we talk about doors, we don't refer to doors strictly. If you think about it, a drawer that opens and closes presents the same kind of issues: an object that should slide. A music box's lid that opens and closes, it's again the same case: it's an object, the lid, that should rotate in order to open and close. Like these two, I'm sure that you can think of many other objects and uses, and all of them fall within the same category: "doors". For all of them, the same principles explained here, apply :-)


Sliding doors


Simply put, a sliding door is a door we will expect moving, but not rotating. From a textured door to a mesh door, they don't have specific requirements. The kind of scripts used normally will let you decide which direction to follow, how far the door should move in that desired direction, and during how much time.


Sliding doors: How to build them


We're going to begin our study of sliding doors by completing a "little project" that consists of building a door that will be simply a box using textures from our "Library" folder.

Wait, I don't have a "Library" folder in my inventory...

If that's the case, follow the "Advanced: Show Debug Settings" menu, look for the "NoInventoryLibrary" setting, and set it to FALSE, as the picture shows:


Rez a box. Give it a name under the "General" tab. For example, name it "My Sliding Door Example".

Now position it at integer coordinates (without decimals), like the picture shows:


Resize it to, for example:
X = 1.75
Y = 0.25
Z = 3

Now, to texture, select the "front" and "back" faces, and apply to it the "door51" texture, which is under "Library: Textures: Textures by Marlin Studios". Then select the edges, and apply to it the "Brazillian rosewood" texture, which is under "Library: Textures: Wood".

If you want to have showing only one door on your box (since the texture is of a double door), change the settings of face #1 to the following:

Repeats Per Face
Horizontal (U): 0.5    [X] FLIP
Vertical (V):   1.0

Texture Offset
Horizontal (U): 0.25
Vertical (V):   0.0

and then the settings of the opposite side (face #3) to:

Repeats Per Face
Horizontal (U): 0.5
Vertical (V):   1.0

Texture Offset
Horizontal (U): 0.25
Vertical (V):   0.0

There's no need to modify the repeats and offsets of the edges, so we'll just leave them be with the defaults.

We have a door to slide! :-)


Sliding doors: What we should expect from a "sliding door script", what we should expect to edit in it


There are so many free full permissions scripts to move doors, that is impossible to cover each single variation and say what to change and where exactly. Instead of that, I've decided to talk about the general aspects that all of them cover, so you know what to look for exactly in your particular script, or even, to know if that specific script is of some use for you or not.

A "sliding door script" simply takes the following information into account:

  • How much time the door should be sliding
  • How many steps during that time
    • Few steps will make the motion to be less smooth, but it will cause less lag, for less calculations will be involved
    • Many steps will make the motion to be smoother, but it will cause more lag, for more calculations will be required
  • What axis to follow in the motion. Some force your door to a predefined axis (so you should build it a bit differently than explained: basically rotating and resizing in another way - the script should tell you this in the comments). In that case, they give an extra parameter for the direction the door should move (like "left" and "right").

This means that such a script will have at some place a section where you introduce the new values. Some of those scripts may require from you that you reset it if you change the initial position of the door. You should read all the comments in the script to be aware of that. If there are no comments, you may try to guess by looking if the script contains the text llGetPos(); at some place... but if the script has no comments, I'd rather suggest to look for another script with comments (comments in scripts are colored orange.)

This is important to know because, for example, if it's required to have the script reset manually, you should not give your customers a no modify object. When prims are no modify, we cannot manually reset the scripts they contain.

If what I've just said sounds like "huh?" to you, then I urge you to read this tutorial about the most basic of permissions in SL. What an user can or cannot do with modify/no modify objects is covered specifically in this section.

A simplified sliding door script would just:

Move the door from one initial position to an end position. The motion is almost instant (our viewer will give it some smoothness, over a short time that we do not control), but it has the advantage of not overloading the server with intermediate calculations. If we're having several linked pieces, this is recommended, for performance and lag reasons.

If we want our sliding door being composed of more than one prim (a door and a knob, for example), like it has been pointed before, check the "Linked doors. More than one door prim. What to do?" section at the end of this tutorial. Check it also if editing those values in a script is not your strong suit. A professional door system will save you a lot of headaches and script editing :-)


Rotating doors


In this case, first we have to consider is what we understand as "rotating doors". All prims in SL have the ability of rotating, and they all do taking as a pivot point the center of the prim. So whenever we rotate a prim, we are rotating it around its center.

This is telling us that a "rotating door" is a door that we want to see, well... rotating :-)

But actually, we mean a little more here.

Let's take a look at the following picture, which is basically, the door we designed for the sliding case, which now has a cylinder in the middle, along the Z axis, to make us think of a "pivot":


If we rotate the door around the Z axis, since it will do from its center, this is what will happen:


A script will always do that: if we tell a script "rotate this prim these and these degrees around these and these axes", the script will always apply that rotation making the prim to pivot around the center. It doesn't matter what we do, scripting wise. If we want that the door, instead of rotating that way, visibly (the key word here) rotating, for example, like in the picture:


What we have to do, and the picture is suggesting it... is to alter the prim! We'll cover this by talking how to achieve this with regular prims, sculpt prims and mesh. But before, a word or two about what a script would do exactly...


Rotating doors: What a script would do in this case?


If you've ever joined a scripting group, you likely have realized that barely anybody likes rotations. What is it that makes rotations so hated? It is because of the following facts, which you, as a builder, have to be aware of:

  • If a script rotates the root prim, it will normally rotate the whole build with it
  • If we want to rotate a child prim, we need to perform a calculation that not everybody understands

This is why builders often feel so confused when editing a script to rotate a door, often preferring to leave the doors unlinked. Even scripters have issues with them!

So if we have a basic "rotating door script", this is what we may expect from it: It will rotate the prim containing the script. If this prim is the root prim, everything else that is linked to the door, will also rotate with the door. That's why these simple scripts, when used, don't "like" when we link the door to the build. Because they normally aren't ready to perform the necessary calculations that are required in a linked build.

Are we then left with no other choice than unlinked doors when we want them rotating? Of course not. You may head to the "Linked doors. More than one door prim. What to do?" section and read about it. But whether you read that section or not, what follows is important: in the next three sections, we're explaining how to modify regular prims, sculpts and mesh, so when they are rotated by a script, visually, they will look as expected.


Rotating doors. Building the door: Regular prims


There are some ways of making a regular prim to have visible only half of it, so when it rotates, it does around the visible hinge. For this, we have to understand the following two properties:

  • Path Cut
  • Slice (Boxes and cylinders)

Path Cut

Path cut is a property that operates on the XY plane, around the Z axis of the prim. When we change the path cut property of a box, for example, like in the picture, we see that the prim is indeed "cut":


What we've said before, "operates on the XY plane, around the Z axis of the prim", means that we cannot decide around which axis we want to "cut" (path cut) the prim. It's always around the Z axis:


So if we want the path cut showing in another axis, what we have to do, always, is to rotate the prim:


finding a good angle so it begins to look like a door:


and modifying the path cut to finally have a door that visibly, will rotate around its hinge:


When you texture this, remember that the prim has been rotated, and cut. Don't expect that the door texture will look right at the first try :-)


We will need to rotate the texture:


If the texture isn't of a double door like this one, then we'll also have to change the repeats and offset it:


("door31", also in your "Library: Textures: Textures by Marlin Studios" folder)

This is the principle behind using path cut to get prims that visually will rotate around a hinge. More complex primitives, such as torus, tube and ring, may require from you to also tweak "Profile Cut" (a secondary cut type that these prims allow). When working with spheres, you may also want to check out the "Dimple" property, which is exclusive of spheres.

Slice (Boxes and cylinders)

Slice is a property that we can find in boxes and cylinders, that removes "slices" of the prim, either beginning by its bottom ("Slice Begin"):


or by its top ("Slice End"):


This slice happens only in the Z axis, so once again, if we need a different configuration, we will have to rotate the prim, taking into account also that this will affect too to the texturing.

All clear with regular prims?

Then now let's study how to design our sculpted doors, so they will rotate around their hinges :-)


Rotating doors. Building the door: Sculpt prims


The same idea explained for regular prims applies here: prims rotate around the center, so what we have to do is to make the VISUAL part of the sculpted prim (the door in this case) to occupy just HALF the bounding box. That will make the effect, when the sculpt prim rotates, that it visually does around the hinge:


The prim continues rotating around the center! What we've made here is altering the bounding box. If you don't know what the bounding box of a sculpt prim is, then please check out this tutorial, "Introduction to sculpt prims", which explains what this and other essential terms mean :-)

As we can see, when working with sculpt prims, the important is understanding how we're designing the bounding box: The relevant is that the hinge is in the middle of the bounding box. We have, of course, to make sure that the sculpting tool allows us to manipulate the bounding box if we want to create these doors! The discussion about the tools is also covered in the "Introduction to sculpt prims" class.

Click here to know how to do this using Prim Generator (link to the Prim Generator class)

Now, this is relevant to sculpt prims. The door shows a problem: unless we make it phantom, the part of the bounding box with no visible geometry could hit us if this door is open and we are in its way!

Specifically talking about sculpt prims, this leads us to the need of linking phantom and non phantom prims, having an adequate collision prim. Click here for a detailed, technical explanation about linking phantom and non phantom prims. It covers other relevant details as understanding how the Land Impact works, and why we shouldn't worry about using this method with sculpt prims.

But of course, if we make the sculpt door phantom, that means, when it's closed, users will be able to walk through! Working with sculpts, the solution consists in using one or more extra prims, completely transparent, that will not be phantom, and will have the physical boundaries we need. For example, with a door, we will need a transparent box, having the size of the visible part of the sculpt. And remember! If this is to be controlled by a script... the transparent box should be moved too! Otherwise, the user will stumble against an invisible part :-)

Fortunately, this last is better solved if using mesh. So if you're waiting to know how to proceed in order to make a mesh door... It's that time now! Let's study how to design our mesh doors, so they will rotate too around their hinges and have an adequate physical presence :-)


Rotating doors. Building the door: MESH


We've studied so far how the doors should be built either in prims or sculpted, should we want them to look natural when pivoting around their hinges. Now, how would we model a mesh door having the same feature?

The case of sculpt prims may suggest us that we should, somehow, "modify the bounding box" of the mesh object, so we can offset the door and have the hinge in the center of the bounding box.

I will explain how to make these doors in Blender, because it's the program I use, but I hope that the idea I will develop will be easy enough for a Maya or 3DS Max user to follow. The final step refers to uploading the mesh to SL and setting up the object inworld, so then again that's common regardless of the program used to model the door.

I don't know if there are other ways of achieving the same result. I was exploring this one when I tried to offset a mesh object so particles would emit from the point I wanted them, and it worked. This made me think that it would work with doors too. I tried the concept, and it worked indeed. So having found this one method that can be used, I didn't pursue any other way: that's why I don't know if there are other ways of getting to the same place. If you know of another way, I'd like to hear from it. (Also, I'm not claiming this is my innovative idea, only how I got on my own to this place.)

I'm explaining now the whole process of creating a mesh door that will rotate around its hinge, over a mesh gate I released for the store.

This is the gate in Blender, still having the supporting pillar visible:


You may notice that there's "something" to the left of the pillar. If I now hide the pillar (H key in Blender) and go to the front view (NUM KEY 1), when I select the gate, the outlines tell me that apart than the gate itself, there's a tiny extra to the left:


By changing the "Viewport Shading" to "Bounding Box":


what we see is that the "tiny little thing" is extending the bounding box of my mesh gate:


Going back to "Texture" as "Viewport Shading", and then going to the top view (NUM KEY 7), we see better that this "little thing" is a small triangle:


If you've worked a bit in Blender, you know that each object has a special point known as "pivot point". We can change this pivot point to wherever we want, and within Blender, that will make the object to rotate around the pivot point. I'm pretty sure that Maya/3DS Max have a similar concept.

We could think that just by changing the pivot point to where the hinge is, that would be enough. But it's not enough. When we upload our model to SL, SL will only acknowledge as pivot point the point that is in the center of the model's bounding box. So if we want to have a pivot exactly where we want, we have to modify our model within Blender, extending the bounding box as needed. And how do we extend it? Simply adding a little triangle to either the top or the bottom opposite corner. Only a vertex will not work: it has to be a triangle. Make it small if you will, but not too small that you'll run into issues when uploading (btw, should you run into issues when uploading, check this thread, where Gaia Clary shares what she's found out so far regarding upload errors and what to do to fix them.)

We're not done yet.

Now, we want to assign one separate material to the little triangle face. Why? So once in SL, we can texture it separately, and simply make it completely transparent, so the triangle will not show at all:


Then we have to make sure of applying rotation and scale (CTRL A for the menu showing below, then choose "Rotation & Scale"). That will change all the local references of size and rotation so they will coincide with the world (global) ones. In less technical terms, it's going to save you trouble :o)


How is it going to save you trouble? For example, if you have a different rotation than X = 0, Y = 0, Z = 0, and then start modeling the physical boundaries of the door, it could happen that, once in the mesh uploader, you see that the visible geometry and the physics don't coincide at all: don't continue and upload, because once you have the mesh inworld, the physics will continue not matching the visible geometry. Instead, go back to Blender, apply rotation and scale, and export your models again.

I'm mentioning "physics" more than once. Does this mean that apart than assigning a material for the extra triangle alone, there's yet more work to do? Right, there's still a bit more we have to do.

We also have to create a physics model for our gate. Since the expected is that we can't walk through the gate, just a box makes the role of gate when it comes to physics. And check out the little triangle! We have to add it too in our physics model! Otherwise, we are in the same case than before: the bounding box will not be the same once in SL :-)


So we make sure that the physics model and the visible geometry have the same size of the bounding box, we make sure that the physics "box" will match the boundaries of the gate, and we're ready to export both the geometry and the physics as separate .dae files, and upload the gate into SL.

NOTE: Remember that you can work in wireframe mode (Z key in Blender) and also make more than one layer visible at a time (select one layer, then hit SHIFT and click on to a second layer: both will be visible). So you may have your visible geometry in layer #1 (say), then the physics in layer #2, and make both layers visible by first clicking on the layer 1, then hold SHIFT, then click on the layer 2. Also, remember that the numbers under the "Dimensions" boxes are telling you the size of the bounding box. The door and the physics model, ideally, should have the same numbers there :-)

Next step is uploading the model to SL. So we proceed as usual, and load our geometry:


Then we go to the "Physics" tab and load our .dae containing the physics. We should see the physics "embracing" the geometry, and the little triangle extending the bounding box, at the opposite corner:


Just a bigger view to show it better:


So with this, we upload our door to SL... And we aren't done yet!

Two more details :-)

First: Make sure that you texture the little triangle it being totally transparent. I like to use the "*Default Transparent Texture" from the "Library" folder, under "Textures" here, apart than raising the Transparency amount to 100, for one reason: if your door uses a script that changes the transparency of all faces, that would unveil the little triangle too. So if the texture is transparent, you will not have to modify the script so the little triangle face is skipped.


Second: Under the "Features" tab, make sure of changing "Physics Type" to "Prim", or you will not be able of walking through the part of the bounding box with no visible geometry :-)


Now, finally, our mesh door is ready to pivot around its hinge! \o/


Linked doors. More than one door prim. What to do?


At this point, we know how to build doors (drawers, etc) that will slide, or that will rotate around a pivot (their hinge). Whether they're made of regular prims, sculpt prims or mesh, we now know all the tricks. We also know how very basic scripts will work in very simple cases. We also understand why if we drop a rotation script in the root of a build, the whole build is going to rotate, not the door!

A note from experience as a customer: customers will greatly appreciate that the doors are linked to the build. Even though I know how to move the door and the build all together to another place, it's always a hassle having to remember. Normally, I move the build, realize that the door hasn't moved, undo, select the door, move everything again... It's annoying. It's annoying to an advanced user. So now imagine how this is for a customer that has no idea about what to do if, when moving the house, the doors are left behind.

When we want to have doors linked to our build, or we need our doors being composed of more than one object, or both, we have always to evaluate pros and cons of all the possibilities. If you wish to use one script per door-prim, and have unlinked doors, because to you, it's essential that the rotation happens exactly during 3.84 seconds and not the interpolation the viewers perform for prim-motion, then I will not be the one telling you not to do so. But remember that every script you add, adds to server side lag.

If you don't mind that the motion is the interpolation performed by the viewer, and prefer having all of your doors linked to the build and controlled by ONE single, low lag, script, then you can head to Marketplace and check out my own professional door script, which you can find here, recently upgraded to V2, that performs all the basic functions you would expect from a door script (change position, rotation, size), and then, quite a lot more of extra functions (vehicles compatible, interface with other scripts, AVsitter/MLP compatible, special features to create Murphy beds...), helped by a very complete auxiliary configuration tool, that will simplify your work.

Whatever your choice is, let it be an informed one :-)

2 comments: