Simple (and Primitive) 3D Rendering Program
Posted: Mon Oct 17, 2022 11:28 pm
Quite some time ago I wrote a Javascript program to facilitate simple glider design. It had fields for several glider measurements, and it could use those fields to build and display a reasonably good looking result. You can find that program at https://ushawks.org/designer/.
While that program can do a reasonable job of rendering somewhat standard gliders, it was no match for some of the innovations recently appearing in the 5 foot packed topic. The program was too closely tailored for "traditional" hang gliders to handle so many novel ideas. As a result, I just finished a newer version that is very simple (primitive) but doesn't impose any restrictions on what can be designed. As with the other version, the design files could be fairly easily imported into other tools (like Blender) to produce more professional and appealing results.
The primary use case for this program is for sharing quick sketches of ideas using a fairly simple and freely available tool. The attached program (Frame_Designer_1.zip) is my first effort at making such a program. The zip file contains 4 files:
frame_designer.htm
header_bg.png
site_logo.png
board_bg.png
You should be able to unzip that zip file into any location on your computer and then double click on "frame_designer.htm" to open it in your web browser. The program will start up looking something like this:
You can click anywhere in the black display area and drag your mouse to rotate the glider in combined azimuth and elevation. If you just want to rotate it (in azimuth or in pitch) separately, you can click and drag the two red tabs to isolate the rotation around one of those two axes.
There are a number of buttons for quickly selecting a standard orthographic view (top, bottom, left, right, front, rear) as well as a "standard" oblique perspective. You can also show the 3D coordinate axes (X, Y, and Z drawn as red, green, and blue respectively). There's also a "Mirror X" button so you only have to build half of a symmetric model and the computer will mirror that half across the Y/Z plane. This is very useful since most gliders are symmetrical across that plane (this program uses the convention that the X axis extends out the right wing, the Y axis extends forward, and the Z axis points "up". There are also fields for specifying particular viewing angles and zoom values.
The actual design is done by specifying individual lines to be drawn in 3 dimensional space. Each line is specified by 2 end points, a line thickness, and a line color. That's it. These are grouped using the JSON array notation (with square brackets and commas between items). For example, the glider shown above was specified with this JSON description:
These fields are: [ x1,y1,z1, x2,y2,z2, thickness, "RRGGBB" ]
The commas are important and must be entered as shown between individual numbers and after the closing square bracket of each entry. All of the text on each line following the "//" is ignored by the program. That text is called a "comment field" and it's there to help people understand what all the numbers mean. The computer ignores the comments completely.
As shown, the first three numbers specify the first end point of each line segment in 3 dimensional space (x,y,z). The second three numbers specify the second end point of each line segment in 3 dimensional space (x,y,z). The seventh number is an integer line thickness for the line. Since the program is often used to draw tubes, the thickness can represent the thickness for each tube. The last value is a string of "RRGGBB" values which specify a color by combining different amounts of red (RR), green (GG), and blue (BB). The values for each of the three colors must be expressed in hexadecimal from 00 through FF inclusive. If you're not familiar with hexadecimal, just imagine that the letters A, B, C, D, E, and F are progressively larger versions of the 0 to 9 digits that you already know. So "FF" is the largest value and "00" is the smallest. The numbers "77" and "80" are about in the middle of that range. If you look at the example above, you'll notice that all of the values are either "00" or "FF" or "88". While you have much finer color resolution available, These "min", "max", and "medium" values will usually work just fine. For example, the color "red" would have the maximum value (FF) for the red (RR) part, and the minium (00) for the green (GG) and blue (BB) parts. So full red would be written as "FF0000". It turns out that the color "magenta' (bright purple or pink) is a full combination of red and blue. So magenta would be specified as "FF00FF" with no green. Similarly, yellow is made up of both red and green, so it would be specified as "FFFF00" (no blue). Note that the letter values (A,B,C,D,E,F) can also be entered in lower case (a,b,c,d,e,f).
The program comes with a few examples that you can use to get started. Here's the code for a simple green pyramid:
Here's an animation generated from that simple code:
If you observe that animation for a while, you may find yourself seeing it revolving both directions (clockwise and counter-clockwise from the top). That perception comes from the fact that the figure really is ambiguous because it lacks perspective, it lacks solid faces, and it lacks hidden line removal. However, even with those limitations, the program can be very helpful in understanding a 3 dimensional object that might otherwise be drawn in only 2 dimensions.
Mostly, this program is intended to help people better share their ideas with one another. If you have an idea for something that's hard to describe in words or difficult to express in static pictures, that idea might be a candidate for a simple model or animation. If so, the attached program could help you build one and share it with others here on the forum. Just build your model, copy the text from the "JSON" area, and post the JSON to the forum. Anyone who want's to see the animation or use it to build on can download it and work on it for a while and then post their own version to share again.
While that program can do a reasonable job of rendering somewhat standard gliders, it was no match for some of the innovations recently appearing in the 5 foot packed topic. The program was too closely tailored for "traditional" hang gliders to handle so many novel ideas. As a result, I just finished a newer version that is very simple (primitive) but doesn't impose any restrictions on what can be designed. As with the other version, the design files could be fairly easily imported into other tools (like Blender) to produce more professional and appealing results.
The primary use case for this program is for sharing quick sketches of ideas using a fairly simple and freely available tool. The attached program (Frame_Designer_1.zip) is my first effort at making such a program. The zip file contains 4 files:
frame_designer.htm
header_bg.png
site_logo.png
board_bg.png
You should be able to unzip that zip file into any location on your computer and then double click on "frame_designer.htm" to open it in your web browser. The program will start up looking something like this:
You can click anywhere in the black display area and drag your mouse to rotate the glider in combined azimuth and elevation. If you just want to rotate it (in azimuth or in pitch) separately, you can click and drag the two red tabs to isolate the rotation around one of those two axes.
There are a number of buttons for quickly selecting a standard orthographic view (top, bottom, left, right, front, rear) as well as a "standard" oblique perspective. You can also show the 3D coordinate axes (X, Y, and Z drawn as red, green, and blue respectively). There's also a "Mirror X" button so you only have to build half of a symmetric model and the computer will mirror that half across the Y/Z plane. This is very useful since most gliders are symmetrical across that plane (this program uses the convention that the X axis extends out the right wing, the Y axis extends forward, and the Z axis points "up". There are also fields for specifying particular viewing angles and zoom values.
The actual design is done by specifying individual lines to be drawn in 3 dimensional space. Each line is specified by 2 end points, a line thickness, and a line color. That's it. These are grouped using the JSON array notation (with square brackets and commas between items). For example, the glider shown above was specified with this JSON description:
[
[ 0, 5, 0, 0, -5, 0, 4, "FF00FF" ], // Keel
[ 0, 5, 0, 15, -3, 0.2, 6, "FFFF00" ], // Leading Edge
[ 0, 1, 0, 0, 0.9, 3, 6, "0000FF" ], // Kingpost
[ 0, 1.6, 0, 9, 0.2, 0.1, 6, "00FFFF" ], // Crossbar
[ 0, 1, 0, 1.6, 2, -3.5, 4, "FF0000" ], // Downtubes
[ 0, 2, -3.5, 1.6, 2, -3.5, 4, "FF0000" ], // Basetube (right half)
[ 0, 5, 0, 1.6, 2, -3.5, 1, "888888" ], // Nose Wire to BT
[ 0, -3, 0, 1.6, 2, -3.5, 1, "888888" ], // Rear Wire to BT
[ 9, 0.2, 0.1, 1.6, 2, -3.5, 1, "888888" ], // Side Wire to BT
[ 9, 0.2, 0.1, 0, 0.9, 3, 1, "888888" ], // Side Wire to KP
[ 0, 5, 0, 0, 0.9, 3, 1, "888888" ], // Nose Wire to KP
[ 0, -3, 0, 0, 0.9, 3, 1, "888888" ], // Rear Wire to KP
]
These fields are: [ x1,y1,z1, x2,y2,z2, thickness, "RRGGBB" ]
The commas are important and must be entered as shown between individual numbers and after the closing square bracket of each entry. All of the text on each line following the "//" is ignored by the program. That text is called a "comment field" and it's there to help people understand what all the numbers mean. The computer ignores the comments completely.
As shown, the first three numbers specify the first end point of each line segment in 3 dimensional space (x,y,z). The second three numbers specify the second end point of each line segment in 3 dimensional space (x,y,z). The seventh number is an integer line thickness for the line. Since the program is often used to draw tubes, the thickness can represent the thickness for each tube. The last value is a string of "RRGGBB" values which specify a color by combining different amounts of red (RR), green (GG), and blue (BB). The values for each of the three colors must be expressed in hexadecimal from 00 through FF inclusive. If you're not familiar with hexadecimal, just imagine that the letters A, B, C, D, E, and F are progressively larger versions of the 0 to 9 digits that you already know. So "FF" is the largest value and "00" is the smallest. The numbers "77" and "80" are about in the middle of that range. If you look at the example above, you'll notice that all of the values are either "00" or "FF" or "88". While you have much finer color resolution available, These "min", "max", and "medium" values will usually work just fine. For example, the color "red" would have the maximum value (FF) for the red (RR) part, and the minium (00) for the green (GG) and blue (BB) parts. So full red would be written as "FF0000". It turns out that the color "magenta' (bright purple or pink) is a full combination of red and blue. So magenta would be specified as "FF00FF" with no green. Similarly, yellow is made up of both red and green, so it would be specified as "FFFF00" (no blue). Note that the letter values (A,B,C,D,E,F) can also be entered in lower case (a,b,c,d,e,f).
The program comes with a few examples that you can use to get started. Here's the code for a simple green pyramid:
[
[ -5, -5, -5, 5, -5, -5, 1, "44ff44" ], // Base -X to +X
[ 5, -5, -5, 5, 5, -5, 1, "44ff44" ], // Base -Y to +Y
[ 5, 5, -5, -5, 5, -5, 1, "44ff44" ], // Base +X to -X
[ -5, 5, -5, -5, -5, -5, 1, "44ff44" ], // Base +Y to -Y
[ -5, -5, -5, 0, 0, 5, 1, "44ff44" ], // Base -X -Y to Top
[ 5, -5, -5, 0, 0, 5, 1, "44ff44" ], // Base +X -Y to Top
[ 5, 5, -5, 0, 0, 5, 1, "44ff44" ], // Base +X +Y to Top
[ -5, 5, -5, 0, 0, 5, 1, "44ff44" ], // Base -X +Y to Top
]
Here's an animation generated from that simple code:
If you observe that animation for a while, you may find yourself seeing it revolving both directions (clockwise and counter-clockwise from the top). That perception comes from the fact that the figure really is ambiguous because it lacks perspective, it lacks solid faces, and it lacks hidden line removal. However, even with those limitations, the program can be very helpful in understanding a 3 dimensional object that might otherwise be drawn in only 2 dimensions.
Mostly, this program is intended to help people better share their ideas with one another. If you have an idea for something that's hard to describe in words or difficult to express in static pictures, that idea might be a candidate for a simple model or animation. If so, the attached program could help you build one and share it with others here on the forum. Just build your model, copy the text from the "JSON" area, and post the JSON to the forum. Anyone who want's to see the animation or use it to build on can download it and work on it for a while and then post their own version to share again.