zzzz

Join us in Phaze Demesnes or follow us:

Home   Show All
Category: Contributor: Creator
Stairs Spiral_Starcase_generator  

Spiral_Starcase_generator

Generator

Drop this in the generator prim, along with the step, banister, and baluster.

Category: Stairs
By : Meyermagic Salome
Created: 2010-12-27 Edited: 2010-12-27
Worlds: Second Life + OpenSim

the Zip file

Download all files for Spiral_Starcase_generator
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Spiral_Starcase_generator_1.lsl
Get file # 2. Spiral_Starcase_generator_2.lsl
Get file # 3. Spiral_Starcase_generator_3.lsl
Get file # 4. Spiral_Starcase_generator_4.lsl
1 ////////////////////////////////
2 // Spiral Staircase Generator //
3 // By Meyermagic Salome //
4 ////////////////////////////////
5 // Staircase Configuration //
6 float wh = 2.5; //Height of one wave (in meters)
7 float wc = 4.0; //Full waves in staircase
8
9 float r_max = 10.0; //Radius maximum, (0.1 -> 10.0)
10 float r_min = 7.5; //Radius minimum, (0.1 -> 10.0)
11
12 integer landing = 5; //Number of non-rising stairs at top of staircase (not included in wc)
13
14 //Step Configuration
15 float s_h = 0.01; //Step height, (0.01 -> 0.99)
16 float s_s = 0.2; //Vertical stair spacing, (0.01 -> 10.00)
17
18 float l_max = 1.0; //Maximum stair length, (0.01 -> 10.00)
19 float l_min = 0.5; //Minimum stair length, (0.01 -> 10.00)
20
21 //Balustrade Configuration
22 float bal_d = 0.05; //Baluster diameter, (0.001 -> 1.000)
23 float bal_h = 0.5; //Height of baluster / height of banister, (0.01 -> 1.00)
24
25 float ban_d = 0.05; //Banister diameter, (0.001 -> 1.000)
26 float ban_h = 2.0; //Banister height, (0.01 -> 10.00)
27
28 // Functions //
29 string str_repeat(string src, integer count)
30 {
31 if(count > 0)
32 {
33 string output;
35 for(i = 0; i < count; i++)
36 {
37 output += src;
38 }
39 return output;
40 }
41 else
42 {
43 return "";
44 }
45 }
46
47 string pad_left(string str, string pad, integer len)//Left-pads string str to length len with character pas
48 {
49 return str_repeat(pad, len - llStringLength(str)) + str;
50 }
51 list segment(vector a, vector b)//Returns the parameters for a cylinder connecting points a and b
52 {//Based on http://lslwiki.net/lslwiki/wakka.php?wakka=LibraryBezierCurveDemo
53 vector mid = (a + b) / 2.0;
54 vector localZ = b - a;
55
56 float len = llVecMag(localZ);
57
58 localZ = localZ / len;
59
60 vector xAxis;
61
62 if(localZ.x < localZ.y)
63 {
64 xAxis = <1.0, 0.0, 0.0>;
65 }
66 else
67 {
68 xAxis= <0.0, 1.0, 0.0>;
69 }
70
71 vector localX = xAxis - (localZ * xAxis) * localZ;
72 localX = llVecNorm(localX);
73
74 rotation rot = llAxes2Rot(localX, localZ % localX, localZ);
75
76 return [len, mid, rot];
77 }
78
79 //Staircase-specific Functions
80 float wave(integer i)//Return i as portion of full wave (2PI)
81 {
82 return PI * (float)i * s_s / wh;
83 }
84 float radius(integer i)//Return the stair radius at step i
85 {
86 return llFabs(((llCos(wave(i)) + 1.0) * ((r_max - r_min) / 2)) + r_min);
87 }
88 float len(integer i)//Returns the length of stair at step i
89 {
90 return llFabs(((llCos(wave(i)) + 1.0) * ((l_max - l_min) / 2)) + l_min);
91 }
92 float rot(integer i)//Returns the rotation of stair at step i
93 {
94 return llAcos(1 - llPow(len(i), 2.0) / (2 * llPow(radius(i), 2)));
95 }
96
97 integer s_encode(integer i)
98 {
99 return (integer)("1" + pad_left((string)llRound(s_h * 100.0), "0", 2) + pad_left((string)llRound(radius(i) * 10.0), "0", 3) + pad_left((string)llRound(len(i) * 100.0), "0", 4));
100 }
101 integer p_encode(float h)
102 {
103 return (integer)("1" + pad_left((string)llRound(bal_d * 1000.0), "0", 4) + pad_left((string)llRound(h * 1000.0), "0", 5));
104 }
105 integer r_encode(float l)
106 {
107 return (integer)("1" + pad_left((string)llRound(ban_d * 1000.0), "0", 4) + pad_left((string)llRound(l * 1000.0), "0", 5));
108 }
109
110 default
111 {
112 touch_start(integer num_detected)
113 {
114 if(llDetectedKey(0) == llGetOwner())
115 {
116 integer i = 0;
117 float t = 0.0;
118
119 //Rez main rising steps
120 for(i = 0; i < (integer)(wc * wh / s_s); ++i)
121 {
122 llSetPos(llGetPos() + <0, 0, s_s>);//I'll have it do this every ~10m when I get around to it
123
124 float c_rot = rot(i);
125 float c_radius = radius(i);
126 float n_radius = radius(i + 1);
127 vector m_pos = llGetPos();
128
129 //Rez step
130 llRezObject("Step",
131 m_pos + <llCos(t + c_rot / 2.0) * c_radius / 2.0, llSin(t + c_rot / 2.0) * c_radius / 2.0, 0>,
133 llEuler2Rot(<PI_BY_TWO, t + c_rot / 2.0 + 4.7123889, 0>),
134 s_encode(i));
135
136 //Get balustrade data
137 list b_data = segment(m_pos + <llCos(t) * c_radius, llSin(t) * c_radius, ban_h + (s_h / 2.0)>,
138 m_pos + <llCos(t + c_rot) * n_radius, llSin(t + c_rot) * n_radius, ban_h + (s_h / 2.0) + s_s>);
139 if(i == (integer)(wc * wh / s_s) - 1)
140 {
141 b_data = segment(m_pos + <llCos(t) * c_radius, llSin(t) * c_radius, ban_h + (s_h / 2.0)>,
142 m_pos + <llCos(t + c_rot) * n_radius, llSin(t + c_rot) * n_radius, ban_h + (s_h / 2.0)>);
143 }
144 vector b_pos = llList2Vector(b_data, 1);
145
146 //Rez banister
147 llRezObject("Banister",
148 b_pos,
150 llList2Rot(b_data, 2),
151 r_encode(llList2Float(b_data, 0)));
152
153 //Rez baluster
154 llRezObject("Baluster",
155 <b_pos.x, b_pos.y, m_pos.z + ((b_pos.z - m_pos.z) / 2.0) + (s_h / 2.0)>,
158 p_encode((b_pos.z - m_pos.z) * bal_h));
159
160 //Increment rotation
161 t += rot(i);
162 }
163
164 //Rez non-rising steps
165 for(i = (integer)(wc * wh / s_s); i < (integer)(wc * wh / s_s) + landing; ++i)
166 {
167 float c_rot = rot(i);
168 float c_radius = radius(i);
169 float n_radius = radius(i + 1);
170 vector m_pos = llGetPos();
171
172 //Rez step
173 llRezObject("Step",
174 m_pos + <llCos(t + c_rot / 2.0) * c_radius / 2.0, llSin(t + c_rot / 2.0) * c_radius / 2.0, 0>,
176 llEuler2Rot(<PI_BY_TWO, t + c_rot / 2.0 + 4.7123889, 0>),
177 s_encode(i));
178
179 //Get balustrade data
180 list b_data = segment(m_pos + <llCos(t) * c_radius, llSin(t) * c_radius, ban_h + (s_h / 2.0)>,
181 m_pos + <llCos(t + c_rot) * n_radius, llSin(t + c_rot) * n_radius, ban_h + (s_h / 2.0)>);
182 vector b_pos = llList2Vector(b_data, 1);
183
184 //Rez banister
185 llRezObject("Banister",
186 b_pos,
188 llList2Rot(b_data, 2),
189 r_encode(llList2Float(b_data, 0)));
190
191 //Rez baluster
192 llRezObject("Baluster",
193 <b_pos.x, b_pos.y, m_pos.z + ((b_pos.z - m_pos.z) / 2.0) + (s_h / 2.0)>,
196 p_encode((b_pos.z - m_pos.z) * bal_h));
197
198 //Increment rotation
199 t += rot(i);
200 }
201 }
202 }
203 }

Spiral_Starcase_generator

Conf_Step

Drop this in a prim named "Step". (Box with x-taper 1.0 is recommended).

Category: Stairs
By : Meyermagic Salome
Created: 2010-12-27 Edited: 2010-12-27
Worlds: Second Life + OpenSim

1 default
2 {
4 {
5 if(s != 0)
6 {
8 float y = ((float)llGetSubString(d, 1, 2)) / 100.0;//Height
9 float z = ((float)llGetSubString(d, 3, 5)) / 10.0;//Radius
10 float x = ((float)llGetSubString(d, 6, 9)) / 100.0;//Length
11 llSetScale(<x, y, z>);
13 }
14 }
15 }

Spiral_Starcase_generator

Conf_Banister

Drop this in a cylinder named "Banister".

Category: Stairs
By : Meyermagic Salome
Created: 2010-12-27 Edited: 2010-12-27
Worlds: Second Life + OpenSim

1 default
2 {
4 {
5 if(s != 0)
6 {
8 float z = ((float)llGetSubString(d, 5, 9)) / 1000.0;//Length
9 float y = ((float)llGetSubString(d, 1, 4)) / 1000.0;//Diameter
10 float x = y;
11 llSetScale(<x, y, z>);
13 }
14 }
15 }

Spiral_Starcase_generator

Conf_Baluster

Drop this in a cylinder named "Baluster".

Category: Stairs
By : Meyermagic Salome
Created: 2010-12-27 Edited: 2010-12-27
Worlds: Second Life + OpenSim

1 default
2 {
4 {
5 if(s != 0)
6 {
8 float z = ((float)llGetSubString(d, 5, 9)) / 1000.0;//Height
9 float y = ((float)llGetSubString(d, 1, 4)) / 1000.0;//Diameter
10 float x = y;
11 llSetScale(<x, y, z>);
13 }
14 }
15 }