Intro to RWX Modeling
Example Scripts
page 5


The next six examples show how you can use the graphics primitives commands to create vertices for you, which you can then use as the basis for creating entirely different shapes. In the case, we will create an L-shaped hollow tube, starting out with only a few discs to create the basic shape for us.

First, we create two discs to the left of center, one of them slightly rotated.around the Z axis.

rw-tube1.rwx

modelbegin
clumpbegin

addhint editable

materialmode double # make poly's two-sided for now, so we can see them better

surface .5 .5 0

# these two lines create a sphere at coordinates 0,0,0 as a visual reference;
# we will remove them before converting the file with rwxmod
color 1 0 0
sphere .05 4

transformbegin
color 0 0 1
translate -2 0 0 # move disc to the left of center
disc 0 1.5 12 # disc has 1.5 radius, 12 sides
transformend

color 0 1 0 # give this disc a different color so we can tell them apart later

rotate 0 0 1 -22.5 # rotate this disc around the Z axis slightly

translate -2 0 0 # also move this disc left of center;
                 # to get the proper rotation, we had to rotate first,
                 # then move to the left

disc 0 1.5 12

clumpend
modelend



After opening and saving the file with RWXMod, and adding number comments to the vertices with FixRWX, we get this. If you look at this model in wireframe mode, you will notice that RWXMod turned the disc primitives into discs composed of 12 triangles or wedges each. If you look at the triangle commands below, you will also notice that each of the 12 triangles in each disc, includes the vertex in the center of the disc. (Vertex 1 for the first disc; vertex 14 for the second disc.)

rw-tube2.rwx

modelbegin
transformbegin
identity
jointtransformbegin
identityjoint
clumpbegin
color 0.000000 0.000000 0.000000
surface 0.000000 0.000000 0.000000
opacity 1.000000
lightsampling facet
geometrysampling solid
texturemodes lit
materialmodes null
texture null
 
addhint editable

# first disc
vertex -2.0000  0.0000  0.0000  # 1
vertex -0.5000  0.0000  0.0000  # 2
vertex -0.7009  0.0000 -0.7500  # 3
vertex -1.2500  0.0000 -1.2990  # 4
vertex -2.0000  0.0000 -1.5000  # 5
vertex -2.7500  0.0000 -1.2990  # 6
vertex -3.2990  0.0000 -0.7500  # 7
vertex -3.5000  0.0000  0.0000  # 8
vertex -3.2990  0.0000  0.7500  # 9
vertex -2.7500  0.0000  1.2990  # 10
vertex -2.0000  0.0000  1.5000  # 11
vertex -1.2500  0.0000  1.2990  # 12
vertex -0.7009  0.0000  0.7500  # 13

# second disc
vertex -1.8477  0.7653  0.0000  # 14
vertex -0.4619  0.1913  0.0000  # 15
vertex -0.6476  0.2682 -0.7500  # 16
vertex -1.1548  0.4783 -1.2990  # 17
vertex -1.8477  0.7653 -1.5000  # 18
vertex -2.5406  1.0523 -1.2990  # 19
vertex -3.0479  1.2624 -0.7500  # 20
vertex -3.2335  1.3393  0.0000  # 21
vertex -3.0479  1.2624  0.7500  # 22
vertex -2.5406  1.0523  1.2990  # 23
vertex -1.8477  0.7653  1.5000  # 24
vertex -1.1548  0.4783  1.2990  # 25
vertex -0.6476  0.2682  0.7500  # 26

# first (bottom) disc 
color 0.000000 0.000000 0.968750
ambient 0.500000
diffuse 0.500000
addmaterialmode double
triangle 1 2 3  # note how all the triangles share the central vertex "1"
triangle 1 3 4
triangle 1 4 5
triangle 1 5 6
triangle 1 6 7
triangle 1 7 8
triangle 1 8 9
triangle 1 9 10
triangle 1 10 11
triangle 1 11 12
triangle 1 12 13
triangle 1 13 2

# second (upper) disc:
color 0.000000 0.984375 0.000000
triangle 14 15 16 # note how all the triangles share the central vertex "14"
triangle 14 16 17
triangle 14 17 18
triangle 14 18 19
triangle 14 19 20
triangle 14 20 21
triangle 14 21 22
triangle 14 22 23
triangle 14 23 24
triangle 14 24 25
triangle 14 25 26
triangle 14 26 15
clumpend
jointtransformend
transformend
modelend



For our purposes, it will be better to change each of these 12-triangle discs into a single 12-sided polygon instead. To do so, we need to remove the vertex in the center of the disc and “reconnect” the 12 remaining vertices in a circle to form the single polygon.

(Actually the polygons will only be temporary; the vertices are what we are really interested in. But changing the two 12-triangle discs into polygons will help illustrate the process.)

So, here we’ve removed the center vertex from each disc (previously vertices 1 and 14) and renumbered the remaining vertices. Then we’ve removed all the triangle commands and substituted two polygon commands that result in equivalent-appearing discs. If you look at this model in wireframe mode, you can see the difference between it and rw-tube2.rwx. Otherwise, there is no difference in appearance.

rw-tube3.rwx

modelbegin
clumpbegin
 
addhint editable

# first disc
vertex -0.5000  0.0000  0.0000    # 1
vertex -0.7009  0.0000 -0.7500    # 2
vertex -1.2500  0.0000 -1.2990    # 3
vertex -2.0000  0.0000 -1.5000    # 4
vertex -2.7500  0.0000 -1.2990    # 5
vertex -3.2990  0.0000 -0.7500    # 6
vertex -3.5000  0.0000  0.0000    # 7
vertex -3.2990  0.0000  0.7500    # 8
vertex -2.7500  0.0000  1.2990    # 9
vertex -2.0000  0.0000  1.5000    # 10
vertex -1.2500  0.0000  1.2990    # 11
vertex -0.7009  0.0000  0.7500    # 12

# second disc
vertex -0.4619  0.1913  0.0000    # 13
vertex -0.6476  0.2682 -0.7500    # 14
vertex -1.1548  0.4783 -1.2990    # 15
vertex -1.8477  0.7653 -1.5000    # 16
vertex -2.5406  1.0523 -1.2990    # 17
vertex -3.0479  1.2624 -0.7500    # 18
vertex -3.2335  1.3393  0.0000    # 19
vertex -3.0479  1.2624  0.7500    # 20
vertex -2.5406  1.0523  1.2990    # 21
vertex -1.8477  0.7653  1.5000    # 22
vertex -1.1548  0.4783  1.2990    # 23
vertex -0.6476  0.2682  0.7500    # 24

materialmode double
surface .5 .5 0

color 0 0 1
polygon 12 1 2 3 4 5 6 7 8 9 10 11 12
 
color 0 1 0
polygon 12 13 14 15 16 17 18 19 20 21 22 23 24
 
clumpend
modelend



Now comes the fun part. :P We create a short tube section by connecting the equivalent vertices of each disc together to form quads. Look at the following model in wireframe mode to see how the vertices of each disc are connected to the other disc. Yes, it does take a little thought to figure out what vertices to use to make the quads, but there is a definite pattern, as you can see below. If you don’t have a 3d modeling program, this method is much simpler than graph paper, which is the only other alternative. :)

rw-tube4.rwx

modelbegin
clumpbegin

addhint editable

vertex -0.5000  0.0000  0.0000    # 1
vertex -0.7009  0.0000 -0.7500    # 2
vertex -1.2500  0.0000 -1.2990    # 3
vertex -2.0000  0.0000 -1.5000    # 4
vertex -2.7500  0.0000 -1.2990    # 5
vertex -3.2990  0.0000 -0.7500    # 6
vertex -3.5000  0.0000  0.0000    # 7
vertex -3.2990  0.0000  0.7500    # 8
vertex -2.7500  0.0000  1.2990    # 9
vertex -2.0000  0.0000  1.5000    # 10
vertex -1.2500  0.0000  1.2990    # 11
vertex -0.7009  0.0000  0.7500    # 12
vertex -0.4619  0.1913  0.0000    # 13
vertex -0.6476  0.2682 -0.7500    # 14
vertex -1.1548  0.4783 -1.2990    # 15
vertex -1.8477  0.7653 -1.5000    # 16
vertex -2.5406  1.0523 -1.2990    # 17
vertex -3.0479  1.2624 -0.7500    # 18
vertex -3.2335  1.3393  0.0000    # 19
vertex -3.0479  1.2624  0.7500    # 20
vertex -2.5406  1.0523  1.2990    # 21
vertex -1.8477  0.7653  1.5000    # 22
vertex -1.1548  0.4783  1.2990    # 23
vertex -0.6476  0.2682  0.7500    # 24

surface .5 .2 .8
lightsampling vertex
materialmode double

#color 0 0 1
#polygon 12 1 2 3 4 5 6 7 8 9 10 11 12

#color 0 1 0
#polygon 12 13 14 15 16 17 18 19 20 21 22 23 24

color .5 .6875 .875
opacity 0.500000

# each quad is made from 2 vertices on the lower disc
# and two vertices on the upper disc; if you have trouble
# visualizing this, try temporarily removing all but one
# of the quads below, to see what a single part looks like

quad 1 2 14 13
quad 2 3 15 14
quad 3 4 16 15
quad 4 5 17 16
quad 5 6 18 17
quad 6 7 19 18
quad 7 8 20 19
quad 8 9 21 20
quad 9 10 22 21
quad 10 11 23 22
quad 11 12 24 23
quad 12 1 13 24

clumpend
modelend



So far though we only have a short section of tube. Now we need to make the rest of the it. We could make more discs and connect them as we did above, but it’s much simpler to just duplicate the section we’ve already made. So, we turn the above tube section into a prototype, and simply duplicate it four times, rotating it 22.5 degrees each time to result in a 90 degree bend.

rw-tube5.rwx

modelbegin

protobegin section # "section" is the name we're giving this prototype

addhint editable

vertex -0.5000  0.0000  0.0000    # 1
vertex -0.7009  0.0000 -0.7500    # 2
vertex -1.2500  0.0000 -1.2990    # 3
vertex -2.0000  0.0000 -1.5000    # 4
vertex -2.7500  0.0000 -1.2990    # 5
vertex -3.2990  0.0000 -0.7500    # 6
vertex -3.5000  0.0000  0.0000    # 7
vertex -3.2990  0.0000  0.7500    # 8
vertex -2.7500  0.0000  1.2990    # 9
vertex -2.0000  0.0000  1.5000    # 10
vertex -1.2500  0.0000  1.2990    # 11
vertex -0.7009  0.0000  0.7500    # 12
vertex -0.4619  0.1913  0.0000    # 13
vertex -0.6476  0.2682 -0.7500    # 14
vertex -1.1548  0.4783 -1.2990    # 15
vertex -1.8477  0.7653 -1.5000    # 16
vertex -2.5406  1.0523 -1.2990    # 17
vertex -3.0479  1.2624 -0.7500    # 18
vertex -3.2335  1.3393  0.0000    # 19
vertex -3.0479  1.2624  0.7500    # 20
vertex -2.5406  1.0523  1.2990    # 21
vertex -1.8477  0.7653  1.5000    # 22
vertex -1.1548  0.4783  1.2990    # 23
vertex -0.6476  0.2682  0.7500    # 24

surface .5 .2 .8
lightsampling vertex
materialmode double

#color 0 0 1
#polygon 12 1 2 3 4 5 6 7 8 9 10 11 12

#color 0 1 0
#polygon 12 13 14 15 16 17 18 19 20 21 22 23 24

color .5 .6875 .875
opacity 0.500000

quad 1 2 14 13
quad 2 3 15 14
quad 3 4 16 15
quad 4 5 17 16
quad 5 6 18 17
quad 6 7 19 18
quad 7 8 20 19
quad 8 9 21 20
quad 9 10 22 21
quad 10 11 23 22
quad 11 12 24 23
quad 12 1 13 24

protoend

# now the actual clump begins:
clumpbegin

protoinstance section # each "protoinstance" draws the prototype we defined
rotate 0 0 1 22.5
protoinstance section
rotate 0 0 1 22.5
protoinstance section
rotate 0 0 1 22.5
protoinstance section

clumpend
modelend



There are still a few shortcomings to our 90-degree bend tube, however. First off, you can see where the sections join, and we’d rather that the model had a smooth surface. Secondly, the whole thing will end up with more than 64 vertices (24 vertices in the prototype, times 4 instances = 96 vertices), which means it will be solid right through the bounding box...avatars won’t be able to scamper through it the way we want. :)

So, we run it through RWXMod once more, incidentally losing the nice, neat prototyping but reducing the number of total vertices by using the “Clean Vertices” option under the Edit menu. What Clean Vertices does is to find any vertices that have the sample coordinates, and combine them into one. You might not always want to do that—consider rw-cube3.rwx in which each quad needs its own vertices in order to have a separate texture—but in this case it’s just what we need to reduce the number of vertices and smooth out the model.

In this step we have also created an interior surface for the tube by simply copying the quads that make up the outer surface and reversing their order. (We could instead keep “materialmode double,” but IMHO the two-surface version will look better in the final result, with a transparent object like this.) FixRWX can be used with the "/f" switch to flip polygons around...but since you don’t want to flip all the quads in this model, you should cut and paste them into a temp file, let FixRWX flip them, then cut and paste the result back again as a separate group for the inside surface.

And finally I also used RWXMod in this step to rescale the tube, since I goofed initially and made it much too large. I wanted it to be 3m wide, not 30m (!) so I scaled it to 10% of the original size.

rw-tube6.rwx

modelbegin
clumpbegin
 
addhint editable

# using the "orient" option in the rwxmod edit menu puts the model at proper
# ground level, but also resulted in the tube not being aligned properly,
# so we can use the rotate command to put it back again
rotate 0 0 1 22.5

vertex  0.1345  0.3233  0.0000  # 1
vertex  0.1144  0.3233 -0.0750  # 2
vertex  0.0595  0.3233 -0.1299  # 3
vertex -0.0154  0.3233 -0.1500  # 4
vertex -0.0904  0.3233 -0.1299  # 5
vertex -0.1453  0.3233 -0.0750  # 6
vertex -0.1654  0.3233  0.0000  # 7
vertex -0.1453  0.3233  0.0750  # 8
vertex -0.0904  0.3233  0.1299  # 9
vertex -0.0154  0.3233  0.1500  # 10
vertex  0.0595  0.3233  0.1299  # 11
vertex  0.1144  0.3233  0.0750  # 12
vertex  0.1383  0.3424  0.0000  # 13
vertex  0.1198  0.3501 -0.0750  # 14
vertex  0.0690  0.3711 -0.1299  # 15
vertex -0.0002  0.3998 -0.1500  # 16
vertex -0.0694  0.4285 -0.1299  # 17
vertex -0.1202  0.4495 -0.0750  # 18
vertex -0.1387  0.4572  0.0000  # 19
vertex -0.1202  0.4495  0.0750  # 20
vertex -0.0694  0.4285  0.1299  # 21
vertex -0.0002  0.3998  0.1500  # 22
vertex  0.0690  0.3711  0.1299  # 23
vertex  0.1198  0.3501  0.0750  # 24
vertex  0.1383  0.3042  0.0000  # 25
vertex  0.1198  0.2965 -0.0750  # 26
vertex  0.0690  0.2755 -0.1299  # 27
vertex -0.0002  0.2468 -0.1500  # 28
vertex -0.0695  0.2181 -0.1299  # 29
vertex -0.1202  0.1971 -0.0750  # 30
vertex -0.1387  0.1894  0.0000  # 31
vertex -0.1202  0.1971  0.0750  # 32
vertex -0.0695  0.2181  0.1299  # 33
vertex -0.0002  0.2468  0.1500  # 34
vertex  0.0690  0.2755  0.1299  # 35
vertex  0.1198  0.2965  0.0750  # 36
vertex  0.1492  0.2880  0.0000  # 37
vertex  0.1350  0.2737 -0.0750  # 38
vertex  0.0961  0.2349 -0.1299  # 39
vertex  0.0431  0.1819 -0.1500  # 40
vertex -0.0098  0.1289 -0.1299  # 41
vertex -0.0487  0.0900 -0.0750  # 42
vertex -0.0629  0.0758  0.0000  # 43
vertex -0.0487  0.0900  0.0750  # 44
vertex -0.0098  0.1289  0.1299  # 45
vertex  0.0431  0.1819  0.1500  # 46
vertex  0.0961  0.2349  0.1299  # 47
vertex  0.1350  0.2737  0.0750  # 48
vertex  0.1654  0.2771  0.0000  # 49
vertex  0.1577  0.2586 -0.0750  # 50
vertex  0.1367  0.2078 -0.1299  # 51
vertex  0.1080  0.1385 -0.1500  # 52
vertex  0.0793  0.0692 -0.1299  # 53
vertex  0.0583  0.0185 -0.0750  # 54
vertex  0.0506  0.0000  0.0000  # 55
vertex  0.0583  0.0185  0.0750  # 56
vertex  0.0793  0.0692  0.1299  # 57
vertex  0.1080  0.1385  0.1500  # 58
vertex  0.1367  0.2078  0.1299  # 59
vertex  0.1577  0.2586  0.0750  # 60
 
color .5 .6875 .875
surface .5 .2 .8
opacity .5
lightsampling vertex
 
quad 1 2 14 13
quad 12 1 13 24
quad 25 26 2 1
quad 36 25 1 12
quad 2 3 15 14
quad 26 27 3 2
quad 3 4 16 15
quad 27 28 4 3
quad 4 5 17 16
quad 28 29 5 4
quad 5 6 18 17
quad 29 30 6 5
quad 6 7 19 18
quad 30 31 7 6
quad 7 8 20 19
quad 8 9 21 20
quad 32 33 9 8
quad 31 32 8 7
quad 9 10 22 21
quad 33 34 10 9
quad 10 11 23 22
quad 34 35 11 10
quad 11 12 24 23
quad 35 36 12 11
quad 37 38 26 25
quad 48 37 25 36
quad 38 39 27 26
quad 39 40 28 27
quad 40 41 29 28
quad 41 42 30 29
quad 42 43 31 30
quad 43 44 32 31
quad 44 45 33 32
quad 46 47 35 34
quad 45 46 34 33
quad 47 48 36 35
quad 49 50 38 37
quad 60 49 37 48
quad 50 51 39 38
quad 51 52 40 39
quad 52 53 41 40
quad 53 54 42 41
quad 54 55 43 42
quad 56 57 45 44
quad 55 56 44 43
quad 57 58 46 45
quad 58 59 47 46
quad 59 60 48 47
 
# inside surface
# this section was made by coping the quads above into a temp file, then
# running fixrwx on the temp file to flip the order of the vertices
# listed here for each quad; then the result was pasted in below

quad 13 14 2 1
quad 24 13 1 12
quad 1 2 26 25
quad 12 1 25 36
quad 14 15 3 2
quad 2 3 27 26
quad 15 16 4 3
quad 3 4 28 27
quad 16 17 5 4
quad 4 5 29 28
quad 17 18 6 5
quad 5 6 30 29
quad 18 19 7 6
quad 6 7 31 30
quad 19 20 8 7
quad 20 21 9 8
quad 8 9 33 32
quad 7 8 32 31
quad 21 22 10 9
quad 9 10 34 33
quad 22 23 11 10
quad 10 11 35 34
quad 23 24 12 11
quad 11 12 36 35
quad 25 26 38 37
quad 36 25 37 48
quad 26 27 39 38
quad 27 28 40 39
quad 28 29 41 40
quad 29 30 42 41
quad 30 31 43 42
quad 31 32 44 43
quad 32 33 45 44
quad 34 35 47 46
quad 33 34 46 45
quad 35 36 48 47
quad 37 38 50 49
quad 48 37 49 60
quad 38 39 51 50
quad 39 40 52 51
quad 40 41 53 52
quad 41 42 54 53
quad 42 43 55 54
quad 44 45 57 56
quad 43 44 56 55
quad 45 46 58 57
quad 46 47 59 58
quad 47 48 60 59
 
clumpend
modelend


 More Examples