home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Raytracing / Raytracer / LW5VT09.LHA / Toaster / Arexx_examples / PlugIns / CurveToMotion.lwm < prev    next >
Encoding:
Text File  |  1996-06-10  |  13.0 KB  |  384 lines

  1. /* CMD: ½CurveToMotion                                                  */
  2. /* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
  3.     MacrosName = "CurveToMotion"
  4. /* Macro Type:                                                          */
  5. /* CREATES     * MOTIONS   * LAYER NEEDED * WARNING!     * REMEMBERS    */
  6. /* Description:                                                         */
  7.  
  8. Info1A = "!Curve To Motion ©             Information 1 of 2"
  9. Info1B = ""
  10. Info1C = "@This macro asks the user to create a curve, via "
  11. Info1D = "@the 'Sketch' button. It will then convert, and  "
  12. Info1E = "@save, the given curve into a motion file.       "
  13. Info1F = ""
  14. Info1G = "þ This macro will move to an empty layer. The   "
  15. Info1H = "  previously current layer will be in the BKG.  "
  16. Info1I = "¤ Any layers previously in the BKG will still be"
  17. Info1J = "  in the background.                            "
  18. Info1K = "þ Select 'Sketch' and draw a curve.             "
  19. Info1L = "¤ Then press RETURN or select 'Make'.           "
  20. Info1M = "þ A Menu will appear asking or saying if this   "
  21. Info1N = "  curve is acceptable to be saved.              "
  22.  
  23. Info2A = "!Curve To Motion ©             Information 2 of 2"
  24. Info2B = "@               Plug-Ins and Go! ©               "
  25. Info2C = "                           Hester and associates"
  26. Info2D = "                           13032 Copenhill Road "
  27. Info2E = "                           Dallas, Texas 75240  "
  28. Info2F = "@Special Thanks to:                              "
  29. Info2G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
  30. Info2H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
  31. Info2I = "Kevin DeRita    Greg Glaser     William S. Hawes"
  32. Info2J = "NewTek ©        Commodore ©     INOVAtronics ©  "
  33. Info2K = ""
  34. Info2L = "@This macro represents a lot of time & hard work."
  35. Info2M = "@Encourage people to create new ones and not kill"
  36. Info2N = "@that possibility by stealing those that are out."
  37.  
  38. /* -------------------------------------------------------------------- */
  39.                                      /* Start Error Detection (See End) */
  40. SIGNAL ON ERROR
  41. SIGNAL ON SYNTAX
  42.                                                    /* Address LightWave */
  43. VT3DLib = ADDLIB("LWModelerARexx.port",0)
  44. ADDRESS "LWModelerARexx.port"
  45.                                                /* Add Support Functions */
  46. SupportLib = "rexxsupport.library"
  47. IF POS(SupportLib , SHOW('L')) = 0 THEN
  48.     IF ~ADDLIB(SupportLib , 0 , -30 , 0) THEN DO
  49.         CALL Notify(1,"!Can't find "SupportLib)
  50.         CALL Exiting
  51.     END
  52.  
  53. /* -------------------------------------------------------------------- */
  54.  
  55. IF SHOW(CLIP,"Stage") = 0 THEN CALL SETCLIP("Stage","1")
  56. Stage = GETCLIP("Stage")
  57.  
  58. /* -------------------------------------------------------------------- */
  59. /* >>>>>>>>>>>>>> STAGE ONE <<<<<<<<<<<<<<< */
  60.  
  61. If Stage = 1 THEN DO
  62.  
  63.     CALL SETCLIP("Stage","2")
  64.  
  65.     PARSE SOURCE TempA TempB CurveToMotionMacro TempD TempE TempF
  66.  
  67.     ADDRESS COMMAND
  68.     "C:RUN C:RX "||CurveToMotionMacro
  69.     ADDRESS
  70.  
  71.     CALL Exiting
  72.  
  73. END
  74.  
  75. /* -------------------------------------------------------------------- */
  76. /* >>>>>>>>>>>>>> STAGE TWO <<<<<<<<<<<<<<< */
  77.  
  78. IF Stage = 2 THEN DO
  79.     CALL SETCLIP("Stage")
  80.  
  81. /* -------------------------------------------------------------------- */
  82.                                     /* Reading Global Macro Preferences */
  83.     BEHDefaultFilePath = "Sys:"
  84.     BEHSettingsSavedTo = "T:"
  85.     BEHSpeechAndSound = "1"
  86.  
  87.     IF (EXISTS("S:PlugInPrefs")) THEN DO
  88.         IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
  89.         IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
  90.         BEHDefaultFilePath = READLN(PlugInPrefs)
  91.         BEHSettingsSavedTo = READLN(PlugInPrefs)
  92.         BEHSpeechAndSound = READLN(PlugInPrefs)
  93.         CALL CLOSE PlugInPrefs
  94.     END
  95.  
  96. /* -------------------------------------------------------------------- */
  97.                                             /* Recalling Macro Settings */
  98.     ReqStart = "0"
  99.     ReqSpace = "1"
  100.     FilePath = "Motions"
  101.  
  102.     PrefsFileName = BEHSettingsSavedTo||MacrosName||".PLUG"
  103.  
  104.     IF (EXISTS(PrefsFileName)) THEN DO
  105.         IF (~OPEN(PrefsFile, PrefsFileName, 'R')) THEN BREAK
  106.         IF (READLN(PrefsFile) ~= MacrosName) THEN BREAK
  107.  
  108.         ReqStart = READLN(PrefsFile)
  109.         ReqSpace = READLN(PrefsFile)
  110.         FilePath = READLN(PrefsFile)
  111.  
  112.         CALL CLOSE PrefsFile
  113.     END
  114.  
  115. /* -------------------------------------------------------------------- */
  116.                                                    /* Empty Layer Setup */
  117.     CL = CurLayer()
  118.     BL = CurBLayer()
  119.     Empty = EmptyLayers()
  120.     IF (WORDS(Empty) < 1) THEN DO
  121.         CALL Notify(1,"!Sorry!","!Need an empty layer","for this operation.")
  122.         CALL Exiting
  123.     END
  124.     EL = WORD(Empty, 1)
  125.  
  126. /* -------------------------------------------------------------------- */
  127.                                               /* For Information Window */
  128.     BEHInfo = 1
  129.                       /* For Coming Back to Main Menu after Info Window */
  130.     DO WHILE BEHInfo
  131. /* -------------------------------------------------------------------- */
  132.                                                       /* User Interface */
  133.         CALL Req_Begin("Curve to Motion ©                by Brett Hester")
  134.  
  135.         CALL Req_AddControl("Draw a",'T',"curve on the current")
  136.         CALL Req_AddControl("empty layer",'T',"with the 'Sketch' tool...")
  137.         CALL Req_AddControl("",'T',"")
  138.         CALL Req_AddControl("NOTE: The curve",'T',"cannot have more than 19 points.")
  139.         ReqA = Req_AddControl("",'CH', "Information")
  140.  
  141.         CALL Req_SetVal(ReqA, 0)
  142.  
  143.         OKorCancel = Req_Post() ; IF OKorCancel = 0 THEN CALL Exiting
  144.  
  145.         BEHInfo = Req_GetVal(ReqA)
  146.  
  147.         CALL Req_End()
  148.  
  149.         IF BEHInfo = 1 THEN CALL InformationWindows
  150.     END
  151.  
  152. /* -------------------------------------------------------------------- */
  153.  
  154.     CALL SetLayer(EL)
  155.     CALL SetBLayer(CL BL)
  156.  
  157.     CALL Cut()            /* Clearing the buffer */
  158.  
  159.     OKorCancel = 1
  160.     DO WHILE OKorCancel = 1
  161.  
  162.         Box = BoundingBox()
  163.         PARSE var Box NumOfPnts X1 X2 Y1 Y2 Z1 Z2
  164.         IF NumOfPnts > 0 THEN DO
  165.             IF CurLayer() = EL THEN DO
  166.                 IF NumOfPnts = 1 THEN DO
  167.                     OKorCancel = Notify(2,"!Sorry!","Please, create the curve via the 'Sketch' tool.","","@þ OK     will allow you to draw another curve.","@þ CANCEL will exit this macro.                ")
  168.                     IF OKorCancel = 1 THEN CALL Cut()
  169.                     IF OKorCancel = 0 THEN CALL Exiting
  170.                 END
  171.                 IF NumOfPnts >= 20 THEN DO
  172.                     OKorCancel = Notify(2,"!Sorry!","The maximum number of points","along the curve must be less than 20.","","@þ OK     will allow you to draw another curve.","@þ CANCEL will exit this macro.                ")
  173.                     IF OKorCancel = 1 THEN CALL CUT()
  174.                     IF OKorCancel = 0 THEN CALL Exiting
  175.                 END
  176.                 IF NumOfPnts < 20 THEN DO
  177.                     YesOrNo = Notify(3,"!Continue?","Is the curve you created acceptable?","","@þ YES will continue towards saving a motion file.","@þ NO  will allow you to draw another curve.      ")
  178.                     IF YesOrNo = 1 THEN OKorCancel = 0
  179.                     IF YesOrNo = 0 THEN DO
  180.                         OKorCancel = 1
  181.                         CALL CUT()
  182.                     END
  183.                 END
  184.             END
  185.             IF CurLayer() ~= EL THEN DO
  186.                 OKorCancel = Notify(2,"!Sorry!","Please do not leave the empty layer.","","@þ OK will return you to the empty layer ","@  and allow you to draw another curve.  ","","@þ CANCEL will exit this macro.          ")
  187.                 IF OKorCancel = 1 THEN DO
  188.                     CALL SetLayer(EL)
  189.                     CALL SetBLayer(CL BL)
  190.                 END
  191.                 IF OKorCancel = 0 THEN CALL Exiting
  192.             END
  193.         END
  194.     END
  195.  
  196. /* -------------------------------------------------------------------- */
  197.                                               /* For Information Window */
  198.     BEHInfo = 1
  199.                       /* For Coming Back to Main Menu after Info Window */
  200.     DO WHILE BEHInfo = 1
  201.  
  202. /* -------------------------------------------------------------------- */
  203.                                                       /* User Interface */
  204.         CALL Req_Begin("Curve to Motion ©                by Brett Hester")
  205.  
  206.         CALL Req_AddControl("Key Frames = Total",'T',"Number of Points =" NumOfPnts)
  207.         ReqA = Req_AddControl("Starting Frame",'N',0)
  208.         ReqB = Req_AddControl("Frame Spacing",'N',0)
  209.         ReqC = Req_AddControl("",'CH', "Information")
  210.  
  211.         CALL Req_SetVal(ReqA, ReqStart)
  212.         CALL Req_SetVal(ReqB, ReqSpace)
  213.         CALL Req_SetVal(ReqC, 0)
  214.  
  215.         OKorCancel = Req_Post() ; IF OKorCancel = 0 THEN CALL Exiting
  216.  
  217.         ReqStart = Req_GetVal(ReqA)
  218.         ReqSpace = Req_GetVal(ReqB)
  219.         BEHInfo = Req_GetVal(ReqC)
  220.  
  221.         CALL Req_End()
  222.  
  223.         IF BEHInfo = 1 THEN CALL InformationWindows
  224.  
  225.         IF ReqStart < 0 THEN ReqStart = 0
  226.         ReqStart = TRUNC(ABS(ReqStart))
  227.         IF ReqSpace = 0 THEN ReqSpace = 1
  228.         ReqSpace = TRUNC(ABS(ReqSpace))
  229.  
  230.     END
  231.  
  232.     CALL FileRequester
  233.  
  234. /* -------------------------------------------------------------------- */
  235.                                                      /* Saving Settings */
  236.     IF (OPEN(PrefsFile, PrefsFileName, 'W')) THEN DO
  237.         CALL WRITELN(PrefsFile, MacrosName)
  238.  
  239.         CALL WRITELN(PrefsFile, ReqStart)
  240.         CALL WRITELN(PrefsFile, ReqSpace)
  241.         CALL WRITELN(PrefsFile, FilePath)
  242.  
  243.         CALL CLOSE PrefsFile
  244.     END
  245.  
  246. /* -------------------------------------------------------------------- */
  247.                                               /* Saving the Motion File */
  248.     NumberOfPoints = XFrm_Begin()
  249.  
  250.         IF OPEN(MotionFile,FileReq,'W') THEN DO
  251.             CALL WRITELN(MotionFile,"LWMO")
  252.             CALL WRITELN(MotionFile,"1") /* magic # */
  253.             CALL WRITELN(MotionFile,"9") /* Channels */
  254.             IF ReqStart = 0 THEN CALL WRITELN(MotionFile,NumberOfPoints)
  255.             IF ReqStart ~= 0 THEN CALL WRITELN(MotionFile,NumberOfPoints+1)
  256.         END
  257.         ELSE DO
  258.             CALL Notify(1,"!Sorry!","Unable to save motion file.")
  259.             CALL Exiting
  260.         END
  261.  
  262.         DO i = 1 to NumberOfPoints
  263.             PARSE value XFrm_GetPos(i) with X Y Z .
  264.  
  265.             IF i = 1 THEN Frame = ReqStart
  266.             IF i > 1 THEN Frame = Frame + ReqSpace
  267.  
  268.             IF i = 1 THEN DO
  269.                 IF ReqStart ~= 0 THEN DO
  270.                     CALL WRITELN(MotionFile,X Y Z "0.0 0.0 0.0 1.0 1.0 1.0")
  271.                     CALL WRITELN(MotionFile,"0 0 0.0 0.0 0.0")
  272.                 END
  273.             END
  274.  
  275.             CALL WRITELN(MotionFile,X Y Z "0.0 0.0 0.0 1.0 1.0 1.0")
  276.             CALL WRITELN(MotionFile,Frame "0 0.0 0.0 0.0")
  277.  
  278.         END
  279.     CALL XFrm_End
  280.     CALL CLOSE(MotFile)
  281.     CALL Notify(1,"!Curve to Motion ©","","@Motion file" FileReq "saved.","")
  282.     CALL Exiting
  283.  
  284. END
  285.  
  286. /* -------------------------------------------------------------------- */
  287.                                                       /* File Requester */
  288. FileRequester:
  289.  
  290.     FileReq = GetFileName("-- Save Motion Path --", FilePath)
  291.     IF FileReq = "(none)" THEN CALL Exiting
  292.                                        /* Extracting File Name and Path */
  293.     FileReqLength = LENGTH(FileReq)
  294.     FileDivider = LASTPOS("/",FileReq)
  295.     IF FileDivider = 0 THEN FileDivider = LASTPOS(":",FileReq)
  296.     FileNameLength = FileReqLength - FileDivider
  297.  
  298.     FilePath = STRIP(LEFT(FileReq, FileDivider),"T","/")
  299.     FileName = RIGHT(FileReq, FileNameLength)
  300.  
  301.     CALL VerifyFilename
  302.  
  303. RETURN
  304.  
  305. /* -------------------------------------------------------------------- */
  306.                                              /* Verifying the file name */
  307. VerifyFilename:
  308.  
  309.     IF EXISTS(FilePath) = 0 THEN DO
  310.         OKorCancel = Notify(3,"!Sorry!",'Directory "'||FilePath||'" not found.',"@Create NEW directory?")
  311.         IF OKorCancel = 1 THEN CALL MAKEDIR(FilePath)
  312.     END
  313.  
  314.     IF EXISTS(FileReq) = 1 THEN DO
  315.         DirOrFile = STATEF(FileReq)
  316.         PARSE var DirOrFile DirOrFile .
  317.         IF DirOrFile = "DIR" THEN DO
  318.             CALL Notify(1,"!Sorry!",'@"'||FileReq||'" is not a valid filename.')
  319.             CALL FileRequester
  320.         END
  321.         IF DirOrFile = "FILE" THEN DO
  322.             OKorCancel = Notify(3,"!Warning!","A file with that name already exists.",'@Overwrite "'||FileReq||'" ?')
  323.             IF OKorCancel = 0 THEN CALL FileRequester
  324.         END
  325.     END
  326.  
  327. RETURN
  328.  
  329. /* -------------------------------------------------------------------- */
  330.                                                               /* Ending */
  331. Exiting:
  332.  
  333.     IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  334.     EXIT
  335.  
  336. RETURN
  337.  
  338. /* -------------------------------------------------------------------- */
  339.                                                  /* Information Windows */
  340. InformationWindows:
  341.  
  342.     OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
  343.     IF OKorCancel = 1 THEN CALL Notify(1, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)
  344.  
  345. RETURN
  346.  
  347. /* -------------------------------------------------------------------- */
  348.                                                       /* Error Handling */
  349. SYNTAX:
  350. ERROR:
  351.  
  352.     ErrCode = RC
  353.     ErrLine = SIGL
  354.     ErrInfo = ERRORTEXT(ErrCode)
  355.  
  356.     Err1 = "!Sorry!"
  357.     Err2 = "An Error has been detected"
  358.     Err3 = "@þ Macro -            "
  359.     Err4 = "@þ Line Number -      "
  360.     Err5 = "@þ Error Code -       "
  361.     Err6 = "@þ Error Description -"
  362.     Err7 = "@¤ Please Inform -    "
  363.     Err8 = '  "Error Notice"     '
  364.     Err9 = "  13032 Copenhill Rd."
  365.     Err10 = "  Dallas, TX. 75240  "
  366.  
  367.     Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)
  368.  
  369. /* -------------------------------------------------------------------- */
  370.                                              /* Advanced Error Handling */
  371.     CALL SETCLIP("ErrorMacro",MacrosName)
  372.     CALL SETCLIP("ErrorLine",ErrLine)
  373.     CALL SETCLIP("ErrorCode",ErrCode)
  374.     CALL SETCLIP("ErrorDesc",ErrInfo)
  375.  
  376.     PARSE SOURCE TempA TempB ErrFile TempC TempD TempE
  377.  
  378.     CALL SETCLIP("ErrorFile",ErrFile)
  379.  
  380. /* -------------------------------------------------------------------- */
  381.  
  382.     IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  383.     EXIT
  384.