#!/bin/ksh ## ## SCRIPT NAME: stl2vrml1_admesh_ivview_bygui ## ## in $FEDIR/scripts ## where FEDIR=/apps/nns_com/fea ############################################################################# ## PURPOSE: A converter of STL files (binary or ASCII) to VRML-1 files ## --- with a dynamic view of the resulting VRML-1 file, via use of ## the SGI 'ivview' utility. ## ## 1) Uses the public 'ADMesh' program, its STL-to-VRML1 file translator ## option, to create a VRML-1 '.vrml1' file from an STL ## (stereolithography) file. ## See 'ADMesh' help info, below and in the site 'stltools' toolchest. ## ## 2) Uses the SGI-supplied Inventor viewer program, '/usr/sbin/ivview', ## to show the VRML-1 data as a shaded (or wire) image. ## ## This utility prompts for a fully-qualified STL input filename -- using ## a Tcl-Tk GUI interface for file navigation-and-selection. ## ##-------- ## This script is mainly meant to provide a way to convert STL files to VRML1 ## files --- in an easy-to-use way (mostly mouse-clicks), and with a 3D ## dynamic viewer. ############################################################################# ## CALLED BY: 'stltools' script in $FEDIR/scripts ## actually, by 'stltools.chestdef' in $FEDIR/scripts ## ## which is called by ## '3d_tools' script in $FEDIR/scripts ## actually, by '3d_tools.chestdef' in $FEDIR/scripts ## ## which is called by ## 'handytools' script in $FEDIR/scripts ## actually, by 'handytools.chestdef' in $FEDIR/scripts ## and some other 3D toolchests. ## ## A Site SGI toolchest-drawer path: ## ## SGI Toolchest -> ## HandyTools -> ## 3D AuxTools -> ## STL ... toolchest (NNS-SGI) -> ## (Binary or Ascii) STL-to-VRML-1 Converter (via ADMesh) ############################################################################# ## MAINTENANCE HISTORY: ## Written by: Blaise Montandon 14jul2004 Based on the script ## 'stl2dxf2iv_admesh_ivview_bygui' ## in $FEDIR/scripts ## ## Updated by: Blaise Montandon 02aug2004 Add (undocumented) '-t' title parm ## to 'ivview' call. ############################################################################# ############################################################################# ## Setup to allow running outside of the nnsFEAmenu system. ############################################################################# if test "$FEDIR" = "" then FEDIR="/apps/nns_com/fea" fi # . $FEDIR/scripts/clearnns ############################################################################# ## SAVE 'this hostname' for host-checks and form titles. ############################################################################# THISHOST=`hostname` SGI_SERVER="engprd00" VIZ_SERVER="engvis00" VIEWER_3D="ivview" ######################################################################## ## Popup a message via 'xconfirm' --- a sample to use in case this ## utility is de-activated for a period --- or to provide an ## informational message via 'xconfirm' rather than 'confirm.tk', which ## follows. ######################################################################## ## ## xconfirm -c -B DISMISS \ ## -header "NNS STL file to VRML-1 Translator-Viewer - Warning" \ ## -t " STL-to-VRML-1 File Translator-Viewer:" \ ## -t " " \ ## -t " This STL-to-VRML-1 utility, based on translating an STL file to a" \ ## -t " '.vrml1' file and then dynamically viewing the '.vrml1' file" \ ## -t " using the SGI 'ivview' viewer, is UNAVAILABLE AT THIS TIME." \ ## -t " " \ ## -t " This utility is based on using the public 'ADMesh'" \ ## -t " utility program and on using the SGI-supplied 'ivview'" \ ## -t " utility to create and view a VRML-1 file from an STL" \ ## -t " 3D-geometry (triangles) file." \ ## -t "" \ ## -t " The 'temp.vrml1' file is put in local directory, /local/scratch/$USER," \ ## -t " if possible, to keep down network traffic and give a little faster" \ ## -t " startup of large image files. (Alternative: user's home directory) " \ ## -t "Exiting." \ ## -icon warning > /dev/null ## ## exit ## ######################################################################## ######################################################################### ## INFORM THE USER ABOUT HOW THIS UTILITY WORKS --- ## via a pop-up message window (a foreground process) ## that can be dismissed when the user is ready to continue. ######################################################################### CONFIRM_TITLE="STL-to-VRML-1 File Translator-Viewer" export CONFIRM_TITLE CONFIRM_TEXT="\ STL-to-VRML-1 File Translator-Viewer: This STL-to-VRML-1 3D-data-file Translator-Viewer utility 1) translates an STL 3D-geometry (triangles) file (binary or ASCII) to a '.vrml1' file, in VRML-1 (pre-1997, pre-VRML-2) format, then 2) uses the SGI-supplied 'ivview' viewer, to view a shaded or wireframe image of the tesselated (triangulated) model in the '.vrml1' file. -------------------------------- Additonal info about steps 1 & 2: 1) The public 'ADMesh' STL utility program is used to create a VRML-1 '.vrml1' file from an STL (STereo-Lithography) file (binary or ASCII) --- using appropriate options to get a 'direct' translation rather than an 'automatic fixes' translation. 2) The SGI 'ivview' utility has 'thumb-wheels' to allow for quick zoom and rotation of the triangulated data of the VRML-1 file. Or you can spin the model with a quick drag of the mouse. Reference: man ivview Use MB3 (mouse button 3) to choose WIREFRAME DrawStyle from a POPUP MENU. You can use 'Options, Edit Background color...' to quickly change the background from BLACK to GRAY or WHITE or magenta or other colors. MB1 = rotate (trackball). MB2 = Panning. Click on '?' button for more help. It generally takes 2 to 12 seconds to translate and show a small to medium sized STL file. --------------- SELECTING FILES: A file-selector GUI is used to present a list of STL files, for example in a $FEDIR/demos_stl directory. OR, you may find it better to paste a full filename into the 'File Selection:' entry field --- FROM a directory name and relative-filename (or a full-filename) in ANOTHER WINDOW. --------------- SOME ADVANTAGES: This multi-program utility requires NO licenses for use of the 'ADMesh' and 'ivview' programs. If you used a CAD program and its associated translators & viewers, you would ordinarily use some licenses for a considerable period of time. Another advantage, compared to full-featured CAD programs, is that 'ADMesh' and 'ivview' are 'light-weight' (quick to run or startup). And 'ivview' is a very easy-to-use and easy-to-learn viewer, with an amazing amount of nice features in a small package. ------------ OUTPUT FILES: The 'temp.vrml1' file is put in a local directory, /local/scratch/$USER, if possible. (Alternative: user's home directory.) The local files keep down network traffic and give faster file I/O when creating or processing these files. Furthermore, the local files help avoid accumulation of files in server directories. You can copy-rename 'temp.vrml1' if you need to save it for a while. ----------- QUICK START for '$VIEWER_3D': Reference: man $VIEWER_3D ----------- The SGI '$VIEWER_3D' utility has 'thumb-wheels' to allow for quick zoom and rotation of the Inventor file 'polygon-ated' model data. Or you can spin the model with a quick drag of the mouse. MB1 = rotate ; MB2 = pan ; Ctl-MB2 = zoom --- You can use 'Options, Edit Background color...' to quickly change the background from BLACK to WHITE or GRAY or MAGENTA or other colors. --- FOR WIREFRAME DISPLAYS, you can use MouseButton3 on the graphics area, to get a popup menu. Then use the 'Draw Style' option to set the Draw mode to 'hidden line' and, for huge models, set the Move mode to 'bounding box (no depth)'. --- You can use the 'Preferences..' option of the MB3-popup menu to turn on 'Show point of rotation axes' --- so that it is clearer where the rotation is centered. (Increase the size of the axes to about 100 pixels, with the wheel.) If the model is not where you want it with respect to the center of rotation, you can move the model, with MB2 and Ctl-MB2. --- The popup menu 'Preferences...' option provides a dialog box that includes a check-button for 'clipping planes'. --- YOU: If you have suggestions for improvement of this utility, please inform NN SGI Visualization Applications Support --- like the author of this utility, Blaise Montandon at 0-2301. To continue, click the 'Proceed' button." export CONFIRM_TEXT CONFIRM_GEOM="+080+080" CONFIRM_MINSIZE="150 100" export CONFIRM_GEOM CONFIRM_MINSIZE # CONFIRM_COLOR="plum2" # CONFIRM_COLOR="#EEAEEE" # CONFIRM_COLOR="#CC99CC" # CONFIRM_COLOR="#996699" # CONFIRM_COLOR="#AA77AA" CONFIRM_COLOR="#C090C0" export CONFIRM_COLOR # REPLY=`$FEDIR/tkGUIs/confirm.tk PROCEED CANCEL` REPLY=`$FEDIR/tkGUIs/confirm_scroll.tk PROCEED CANCEL` if test "$REPLY" = "CANCEL" then exit fi ######################################################################### ## SET var LOCDIR to /local/scratch/$USER --- if possible --- ## otherwise to $HOME. Used below to hold temporary files, like ## the 'temp.vrml1' VRML-1 file for viewing. ######################################################################### . $FEDIR/scripts/set_localuserdir ######################################################################### ## INITIALIZE a directory-navigator/file-selector, for the user ## to specify the input file. ######################################################################### FILSEL_MSG="\ PASTE a binary or ASCII STL FULL-FILENAME IN THE 'File Selection' FIELD -OR- click the FILTER button & SELECT an STL FILE from the file listbox. Then click 'OK' to 1) translate the STL file to a '.vrml1' file, then 2) *VIEW* the '.vrml1' file WITH 'ivview'. -OR- click 'Cancel' to exit. Some STL files are in directories like ${SGI_SERVER}: $FEDIR/demos_stl ${SGI_SERVER}: $FEDIR/3d_tools/cyberware_3Dtools.dir/HUMANmodels ${VIZ_SERVER}: /division/VIZADM_DEVELOPMENT/Sample_data/ ${VIZ_SERVER}: /division/VIZADM_DEVELOPMENT/SESSION_WKG/viz/projects/NASACAVE/.../ Or perhaps your binary or ASCII STL files in ${THISHOST}: /local/scratch/$USER/ ${SGI_SERVER}: /data/subs/cae/$USER/ ${SGI_SERVER}: $HOME/ " FILSEL_NUMLINES="17" ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/BEM-NNSPMC-data/yard/emals/product/5004/grey/ ## ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/BEM-NNSPMC-data/yard/island76/fuchsia_ax ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/BEM-NNSPMC-data/yard/island76/green_ax/ ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/BEM-NNSPMC-data/yard/island76/peach_ax/ ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/BEM-NNSPMC-data/yard/island76/teal_ax/ ## ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/viz/projects/NASACAVE/hpcdemo/magenta_ax/ ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/viz/projects/NASACAVE/hpcdemo/maroon_ax/ ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/viz/projects/NASACAVE/hpcdemo/pink_ax/ ## /division/VIZADM_DEVELOPMENT/SESSION_WKG/viz/projects/NASACAVE/hpcdemo/purple/ ####################### ## SET FILE DIR & MASK. ####################### ## FOR TESTING: # FILSEL_MASK="$FEDIR/3d_tools/cyberware_3Dtools.dir/HUMANmodels/*.s*" # FILSEL_MASK="$FEDIR/demos_stl/*" # FILSEL_MASK="$FEDIR/3d_tools/cyberware_3Dtools.dir/HUMANmodels/*.s*" FILSEL_MASK="$FEDIR/demos_stl/*.s*" # FILSEL_MASK="/division/VIZADM_DEVELOPMENT/Sample_data/*.s*" # FILSEL_MASK="/division/VIZADM_DEVELOPMENT/SESSION_WKG/viz/projects/NASACAVE/hpcdemo/purple/*.s*" DIRTEMP=`dirname "$FILSEL_MASK"` if test ! -d $DIRTEMP then FILSEL_MASK="$HOME/*.s*" fi export FILSEL_MASK FILSEL_MSG FILSEL_NUMLINES # FILTER_AT_STARTUP=YES # export FILTER_AT_STARTUP ######################################################################## ######################################################################## ## START OF PROMPTING LOOP, FOR FILE SELECTION. ######################################################################## ######################################################################## # while true while : do ######################################################################## ## GET NAME OF USER-SELECTED STL FILE. ######################################################################## FILEIN=`$FEDIR/tkGUIs/file_select_gui_ver2.tk` if test "${FILEIN}" = "" then # continue # break exit fi ######################################################################### ## CHECK THAT THE FILE IS NOT ASCII. ## IF ASCII, return to the file selector. ######################################################################### # # STL_CHECK=`file $FILEIN | grep "ascii text"` # # if test ! "$STL_CHECK" = "" # then # # xconfirm -c -header "'STL File Fixer-Viewer - Warning" -B DISMISS \ # -t "The file" \ # -t " $FILEIN" \ # -t "is not a 'text' file. " \ # -t " " \ # -t "The ADMesh utility program & translator" \ # -t "can create an ASCII STL (SLA) file from a binary STL file." \ # -t "" \ # -t "Proceed or exit (Cancel)." \ # -icon warning > /dev/null # # ## -t "Exiting." \ # ## -icon warning > /dev/null # ## # ## exit # # ######################################################################## # ## RETURN TO FILE-SELECTION PROMPT. # ######################################################################## # # CURDIRNAME=`dirname "$FILEIN"` # # FILSEL_MASK="${CURDIRNAME}/*.s*" # FILSEL_MASK="${CURDIRNAME}/*" # export FILSEL_MASK # # # FILTER_AT_STARTUP=NO # # export FILTER_AT_STARTUP # # continue # # fi # ## END OF if test ! "$STL_CHECK" = "" ######################################################################### ## CHECK THAT THE STL FILE IS NOT SO BIG THAT 'ADMesh' will have a problem ## translating it (exceeding in-memory-array-sizes or whatever) into a ## big VRML-1 file. ######################################################################### STL_BYTES=`ls -l $FILEIN | awk '{print $5}'` STL_MEG=`echo "scale = 6; $STL_BYTES / 1000000" | bc -l` STLBIG_BYTES=2500000 if test $STL_BYTES -gt $STLBIG_BYTES then GO_YN=`xconfirm -c -header "STL FILE SIZE - Warning" \ -b Proceed -B Exit \ -t "The file" \ -t " $FILEIN" \ -t "is big ($STL_MEG Megabytes). It is so big that 'ADMesh' MAY" \ -t "consume a lot of memory translating the STL file into the" \ -t "'.vrml1' file." \ -t "" \ -t "Exit --- OR PROCEED (at the risk of EXCEEDING VIRTUAL MEMORY" \ -t "ON HOST $THISHOST, if it is memory-limited)." \ -icon warning` if test "$GO_YN" = "Exit" then exit fi fi ## END OF if test $STL_BYTES -gt $STLBIG_BYTES ######################################################################### ## TRANSLATE the STL file to a VRML-1 file --- ## using the 'ADMesh' utility program. ## Some 'ADMesh' help info follows. ######################################################################### ## ## $ admesh-0.95-irix5.3.bin --help GIVES: ## ## ADMesh version 0.95 ## Copyright (C) 1995, 1996 Anthony D. Martin ## Usage: admesh-0.95-irix5.3.bin [OPTION]... file ## ## --x-rotate=angle Rotate CCW about x-axis by angle degrees ## --y-rotate=angle Rotate CCW about y-axis by angle degrees ## --z-rotate=angle Rotate CCW about z-axis by angle degrees ## --xy-mirror Mirror about the xy plane ## --yz-mirror Mirror about the yz plane ## --xz-mirror Mirror about the xz plane ## --scale=factor Scale the file by factor (multiply by factor) ## --translate=x,y,z Translate the file to x, y, and z ## --merge=name Merge file called name with input file ## ## -e, --exact Only check for perfectly matched edges ## -n, --nearby Find and connect nearby facets. Correct bad facets ## ## -t, --tolerance=tol Initial tolerance to use for nearby check = tol ## -i, --iterations=i Number of iterations for nearby check = i ## -m, --increment=inc Amount to increment tolerance after iteration=inc ## ## -u, --remove-unconnected Remove facets that have 0 neighbors ## -f, --fill-holes Add facets to fill holes ## -d, --normal-directions Check and fix direction of normals(ie cw, ccw) ## --reverse-all Reverse the directions of all facets and normals ## -v, --normal-values Check and fix normal values ## ## -c, --no-check Don't do any check on input file ## -b, --write-binary-stl=name Output a binary STL file called name ## -a, --write-ascii-stl=name Output an ascii STL file called name ## --write-off=name Output a Geomview OFF format file called name ## --write-dxf=name Output a DXF format file called name ## --write-vrml=name Output a VRML format file called name ## --help Display this help and exit ## --version Output version information and exit ## ## The functions are executed in the same order as the options shown here. ## So check here to find what happens if, for example, --translate and --merge ## options are specified together. The order of the options specified on the ## command line is not important. ## ## Invoking ADMesh ## =============== ## ## ADMesh is executed as follows: ## admesh [OPTION]... file ## ## By default, ADMesh performs all of the mesh checking and repairing options ## on the input file. This means that it checks exact, nearby, ## remove-unconnected, fill-holes, normal-directions, and normal-values. ## ## The file type (ASCII or binary) is automatically detected. The input file is ## not modified unless it is specified by the --write option. ## ## If the following command line was input: ## admesh sphere.stl ## The file sphere.stl would be opened and read, it would be checked and fixed ## if necessary, and the results of processing would be printed out. The ## results would not be saved. ## ## The default value for tolerance is the length of the shortest edge of the ## mesh. The default number of iterations is 2, and the default increment is ## 0.01% of the diameter of a sphere that encloses the entire mesh. ## ## ** If any of the options --exact, --nearby, --remove-unconnected, --fill-holes, ## ** --normal-directions, --reverse-all, --normal-values, or --no-check are ## ** given, then no other checks besides that one will be done unless they are ## ** specified or unless they are required by ADMesh before the specified check ## ** can be done. ## ## For example the following command line: ## admesh --remove-unconnected sphere.stl ## would first do an exact check because it is required, and then the ## unconnected facets would be removed. The results would be printed and no ## other checks would be done. ## ## Examples ## ======== ## ## To perform all checks except for nearby, the following command line would be ## used: ## admesh --exact --remove-unconnected --fill-holes \ ## --normal-directions --normal-values sphere.stl ## ## Actually, since the exact check is required by ADMesh before ## remove-unconnected, and remove-unconnected is required before --fill-holes, ## the above command line could be shortened as follows with the same results: ## admesh --fill-holes --normal-directions --normal-values sphere.stl ## ## And again the same results could be achieved using the short options: ## admesh -fudev sphere.stl ## or ## admesh -fdv sphere.stl ## ## The following command lines do the same thing: ## admesh sphere.stl ## admesh -fundev sphere.stl ## admesh -f -u -n -d -e -v sphere.stl ## since the -fundev options are implied by default. To eliminate one of the ## checks, just remove the letter of the check to eliminate from the "word" ## 'fundev'. ######################################################################### OUTFILE_VRML1="${LOCDIR}/temp.vrml1" rm -f $OUTFILE_VRML1 /usr/sbin/xwsh -bg midnightblue -fg white \ -title 'ADMesh_msgs (Wait .... until ADMesh is done. To kill it or TO PROCEED, Close Me.)' \ -hold -icontitle 'ADMesh_msgs' \ -geom 80x38+620+350 \ -e /apps/nns_com/fea/3d_tools/stlb2stla.dir/admesh-0.95-irix5.3.bin \ --exact \ --write-vrml=$OUTFILE_VRML1 $FILEIN VRML1_BYTES=`ls -l $OUTFILE_VRML1 | awk '{print $5}'` VRML1_MEG=`echo "scale = 6; $VRML1_BYTES / 1000000" | bc -l` ######################################################################### ## VIEW the VRML-1 file with 'ivview'. ######################################################################### # VIEW_MODE=`xconfirm -c \ # -header "'ivview' of '.vrml1' file from STL file" \ # -B Examiner -b Walk \ # -t "SELECT AN 'ivview' VIEW MODE:" \ # -t "" \ # -t "'Examiner' (virtual trackball) or 'Walk' ?" \ # -t "" \ # -t "Use the '?' button in 'ivview' to see navigation details of the" \ # -t "'Examiner' mode versus the 'Walk' mode --- as well as for two other" \ # -t "modes ( 'Fly' and 'Plane' ) that are not implemented in 'ivview'." \ # -icon question` CONFIRM_TITLE="'ivview' of '.vrml1' file from STL file" export CONFIRM_TITLE CONFIRM_TEXT="\ SELECT AN 'ivview' VIEW MODE: 1) 'Examiner' (virtual trackball) OR 2) 'Walk' ----------------------------------------------------------------------- The size of the '.vrml1' file $OUTFILE_VRML1 is $VRML1_MEG Megabytes. The size of the STL file $FILEIN is $STL_MEG Megabytes. ----------------------------------------------------------------------- Use the '?' button in 'ivview' to see navigation details of the 'Examiner' mode versus the 'Walk' mode --- as well as info for two other modes ( 'Fly' and 'Plane' ) that are not implemented in 'ivview'." export CONFIRM_TEXT CONFIRM_GEOM="+080+080" CONFIRM_MINSIZE="150 100" export CONFIRM_GEOM CONFIRM_MINSIZE # CONFIRM_COLOR="plum2" # CONFIRM_COLOR="#EEAEEE" # CONFIRM_COLOR="#CC99CC" # CONFIRM_COLOR="#996699" # CONFIRM_COLOR="#AA77AA" # CONFIRM_COLOR="#C090C0" CONFIRM_COLOR="#F0C0F0" export CONFIRM_COLOR VIEW_MODE=`$FEDIR/tkGUIs/confirm.tk Examiner Walk Exit` # VIEW_MODE=`$FEDIR/tkGUIs/confirm_scroll.tk Examiner Walk Exit` if test "$VIEW_MODE" = "Exit" then exit fi VIEW_PARM="" if test "$VIEW_MODE" = "Walk" then VIEW_PARM="-w" fi ## FOR TESTING: # set -x # # ivview $VIEW_PARM $OUTFILE_VRML1 & # ivview $VIEW_PARM $OUTFILE_VRML1 # ivview -t "iv of $FILEIN" $VIEW_PARM $OUTFILE_VRML1 & ivview -t "iv of $FILEIN" $VIEW_PARM $OUTFILE_VRML1 ## FOR TESTING: # set - ######################################################################## ## RETURN TO FILE-SELECTION PROMPT. ######################################################################## CURDIRNAME=`dirname "$FILEIN"` # FILSEL_MASK="${CURDIRNAME}/*.s*" FILSEL_MASK="${CURDIRNAME}/*" export FILSEL_MASK FILSEL_MSG="\ PASTE *ANOTHER* STL FILENAME ... or click FILTER and select a file, binary or ASCII. Then click 'OK' to 1) translate to the STL file to a VRML-1 '.vrml1' file, then 2) *VIEW* the '.vrml1' file WITH 'ivview'. -OR- Click 'Cancel' to exit. Some binary or ASCII STL files are in directories like ${SGI_SERVER}: $FEDIR/demos_stl ${SGI_SERVER}: $FEDIR/3d_tools/cyberware_3Dtools.dir/HUMANmodels ${VIZ_SERVER}: /division/VIZADM_DEVELOPMENT/Sample_data/ ${VIZ_SERVER}: /division/VIZADM_DEVELOPMENT/SESSION_WKG/viz/projects/NASACAVE/.../ " FILSEL_NUMLINES="10" # FILTER_AT_STARTUP=NO # export FILTER_AT_STARTUP done ######################################################################## ## END OF prompting loop, for file name. ########################################################################