Intro to RWX Modeling
Example Scripts
page 4


Some more examples of pulling and pushing vertices around. Start with a cylinder (and two discs for the ends).
rw-skew1.rwx

modelbegin
clumpbegin

lightsampling vertex
surface .5 .5 0
color .5 .7 .6

cylinder 1 .1 .1 12
disc 1 .1 12
disc 0 -.1 12

clumpend
modelend



Convert to vertices and polygons with RWXMod.

rw-skew1.rwx

modelbegin
clumpbegin

addhint editable

vertex   0.1000  0.0000  0.0000
vertex   0.1000  1.0000  0.0000
vertex   0.0866  0.0000 -0.0500
vertex   0.0866  1.0000 -0.0500
vertex   0.0499  0.0000 -0.0866
vertex   0.0499  1.0000 -0.0866
vertex   0.0000  0.0000 -0.1000
vertex   0.0000  1.0000 -0.1000
vertex  -0.0500  0.0000 -0.0866
vertex  -0.0500  1.0000 -0.0866
vertex  -0.0866  0.0000 -0.0499
vertex  -0.0866  1.0001 -0.0499
vertex  -0.1000  0.0000  0.0000
vertex  -0.1000  1.0001  0.0000
vertex  -0.0866  0.0000  0.0500
vertex  -0.0866  1.0001  0.0500
vertex  -0.0499  0.0000  0.0866
vertex  -0.0499  1.0001  0.0866
vertex   0.0000  0.0000  0.1000
vertex   0.0000  1.0002  0.1000
vertex   0.0500  0.0000  0.0866
vertex   0.0500  1.0002  0.0866
vertex   0.0866  0.0000  0.0499
vertex   0.0866  1.0002  0.0499
vertex   0.0000  1.0000  0.0000
vertex  -0.0866  1.0000 -0.0499
vertex  -0.1000  1.0000  0.0000
vertex  -0.0866  1.0000  0.0500
vertex  -0.0499  1.0000  0.0866
vertex   0.0000  1.0000  0.1000
vertex   0.0500  1.0000  0.0866
vertex   0.0866  1.0000  0.0499
vertex   0.0000  0.0000  0.0000
vertex  -0.0866  0.0000 -0.0500
vertex  -0.0499  0.0000 -0.0866
vertex   0.0500  0.0000 -0.0866
vertex   0.0866  0.0000 -0.0499
vertex   0.0866  0.0000  0.0500
vertex   0.0499  0.0000  0.0866
vertex  -0.0500  0.0000  0.0866
vertex  -0.0866  0.0000  0.0499

color 0.500000 0.687500 0.593750
ambient 0.500000
diffuse 0.500000
lightsampling vertex
triangle 25 2 4
triangle 25 4 6
triangle 25 6 8
triangle 25 8 10
triangle 25 10 26
triangle 25 26 27
triangle 25 27 28
triangle 25 28 29
triangle 25 29 30
triangle 25 30 31
triangle 25 31 32
triangle 25 32 2
triangle 33 13 34
triangle 33 34 35
triangle 33 35 7
triangle 33 7 36
triangle 33 36 37
triangle 33 37 1
triangle 33 1 38
triangle 33 38 39
triangle 33 39 19
triangle 33 19 40
triangle 33 40 41
triangle 33 41 13
quad 23 1 2 24
quad 21 23 24 22
quad 19 21 22 20
quad 17 19 20 18
quad 15 17 18 16
quad 13 15 16 14
quad 11 13 14 12
quad 9 11 12 10
quad 7 9 10 8
quad 5 7 8 6
quad 3 5 6 4
quad 1 3 4 2

clumpend
modelend



Before we can go on to rw-skew3.rwx, we have to do some very special adjustments. Obviously, it would be much easier to play with moving pieces of the model around if the vertices were ordered more conveniently; for instance, from the top to the bottom of the model. In other cases we might want to have vertices sorted from left to right, or from near to far, etc.  Unfortunately we can’t just sort the vertex lines around because the vertex numbers used in the polygon commands (e.g. “quad 1 2 3 4”) refer to the position of the lines with the vertex commands. So, if we sort the vertices, we also have to change the numbers in the polygon commands.

This sounds like an awful task to do by hand! Someday I plan to add this feature to FixRWX, but for now, if you have a spreadsheet program, you can use that. (Thanks to DerekH for the inspiration to use Excel on RWX files!) Here’s an example on how you would do that using Microsoft Excel. (Yes, it is a pain, but better than no method at all.)
 
Start Excel, and open the RWX file. The Text Import Wizard will start. Choose Delimited for the file type.


 

  • Make Space one of the delimiters.
  • Use General coulmn data format.

    Create two columns of consecutive numbers to the right of the vertex commands...

    Select the columns containing the vertices and only the left column of numbers.

    Sort the selected area by the appropriate column (Data menu, /Sort option in Excel) . In this case we want to sort by height, so we use the middle (y) column, which is column C in the spreadsheet. We choose Descending so the vertices will end up sorted from top to bottom (highest to lowest).

    Now, select the two columns of numbers to the right of the vertices. The left of the two columns will have been scrambled by the sort, but the right column will still be in consecutive order.

    Now the block we just named will act as a translation table, converting old vertex numbers into new.

    Page down and go to a cell that’s a few columns to the right of the first triangle command. Then enter a VLOOKUP formula into that cell, as shown:

    For the lookup value, enter the cell with the first vertex number in it. For table, enter the name of the table we created, and for column index put 2, range lookup 0. (Click the fx button to get the dialog below.)

    Now copy that formula so it fills four columns (to account for quads as well as triangles). Careful you don’t overwrite any lines below!

    Just delete the “#NA” from the cells where it appears. Now, (and this is IMPORTANT!), convert the formulas to values in all those cells by selecting them all, choosing “Edit/Copy” from the menu, then “Edit/Paste Special,” and Values.

    After that, you can drag the new columns over to the left to replace the old columns.

    I wish I could say we were done. :) But now we have to sort the polygons too, or the whole routine won’t be of much use. Create a column to the right of the triangle commands, with a formula that averages the vertex numbers to the left of it, in the triangle and quad commands.Convert the column to values. Then sort the whole thing using that column as a key.

    Finally, save the file as Text (under another name is probably a good idea).


     
    The model should now look the same as before in RWXMod, but the vertices and polygons will be sorted.



    rw-skew3.rwx

    modelbegin
    clumpbegin

    addhint editable

    transformbegin

    translate .5 0 0
    scale 1 1 2

    vertex  0.0000  1.0002  0.1000  # 1
    vertex  0.0500  1.0002  0.0866  # 2
    vertex  0.0866  1.0002  0.0499  # 3
    vertex -0.0866  1.0001 -0.0499  # 4
    vertex -0.1000  1.0001  0.0000  # 5
    vertex -0.0866  1.0001  0.0500  # 6
    vertex -0.0499  1.0001  0.0866  # 7
    vertex  0.1000  1.0000  0.0000  # 8
    vertex  0.0866  1.0000 -0.0500  # 9
    vertex  0.0499  1.0000 -0.0866  # 10
    vertex  0.0000  1.0000 -0.1000  # 11
    vertex -0.0500  1.0000 -0.0866  # 12
    vertex  0.0000  1.0000  0.0000  # 13
    vertex -0.0866  1.0000 -0.0499  # 14
    vertex -0.1000  1.0000  0.0000  # 15
    vertex -0.0866  1.0000  0.0500  # 16
    vertex -0.0499  1.0000  0.0866  # 17
    vertex  0.0000  1.0000  0.1000  # 18
    vertex  0.0500  1.0000  0.0866  # 19
    vertex  0.0866  1.0000  0.0499  # 20

    transformend

    vertex  0.1000  0.0000  0.0000  # 21
    vertex  0.0866  0.0000 -0.0500  # 22
    vertex  0.0499  0.0000 -0.0866  # 23
    vertex  0.0000  0.0000 -0.1000  # 24
    vertex -0.0500  0.0000 -0.0866  # 25
    vertex -0.0866  0.0000 -0.0499  # 26
    vertex -0.1000  0.0000  0.0000  # 27
    vertex -0.0866  0.0000  0.0500  # 28
    vertex -0.0499  0.0000  0.0866  # 29
    vertex  0.0000  0.0000  0.1000  # 30
    vertex  0.0500  0.0000  0.0866  # 31
    vertex  0.0866  0.0000  0.0499  # 32
    vertex  0.0000  0.0000  0.0000  # 33
    vertex -0.0866  0.0000 -0.0500  # 34
    vertex -0.0499  0.0000 -0.0866  # 35
    vertex  0.0500  0.0000 -0.0866  # 36
    vertex  0.0866  0.0000 -0.0499  # 37
    vertex  0.0866  0.0000  0.0500  # 38
    vertex  0.0499  0.0000  0.0866  # 39
    vertex -0.0500  0.0000  0.0866  # 40
    vertex -0.0866  0.0000  0.0499  # 41

    color   0.5 0.6875  0.59375
    ambient 0.5
    diffuse 0.5
    lightsampling   vertex
    triangle    13  8   9
    triangle    13  9   10
    triangle    13  10  11
    triangle    13  11  12
    triangle    13  12  14
    triangle    13  14  15
    triangle    13  15  16
    triangle    13  16  17
    triangle    13  17  18
    triangle    13  18  19
    triangle    13  19  20
    triangle    13  20  8
    triangle    33  27  34
    triangle    33  34  35
    triangle    33  35  24
    triangle    33  24  36
    triangle    33  36  37
    triangle    33  37  21
    triangle    33  21  38
    triangle    33  38  39
    triangle    33  39  30
    triangle    33  30  40
    triangle    33  40  41
    triangle    33  41  27
    quad    32  21  8   3
    quad    31  32  3   2
    quad    30  31  2   1
    quad    29  30  1   7
    quad    28  29  7   6
    quad    27  28  6   5
    quad    26  27  5   4
    quad    25  26  4   12
    quad    24  25  12  11
    quad    23  24  11  10
    quad    22  23  10  9
    quad    21  22  9   8

    clumpend
    modelend


     More Examples