home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2005 May / PC för Alla 0505.iso / fullversioner / realsoft3d / data1.cab / Scripting / scripts / js / myclasses / toolbars / myexport.js < prev    next >
Encoding:
Text File  |  2005-04-04  |  3.4 KB  |  118 lines

  1.  
  2. //
  3. // Description:
  4. //      Export camera animation to a file. Also demonstrates how to use r3File class to
  5. //      enumerate the contents of a layer 
  6. //
  7. // Super class:
  8. //      myclasses/toolbars/toolbar.js
  9. //
  10. // Constructor:
  11. //      toolbar = new myExportTools();
  12. //
  13. // Attributes:
  14. //      --
  15. //
  16. // Methods:
  17. //      --
  18. //
  19.  
  20. include("myclasses/toolbars/mytoolbar.js"); // our super class
  21.  
  22. include("real/layer/r3prilay.js");      // geometric layer
  23. include("real/layer/r3animtr.js");      // animator
  24. include("oops/r3file.js");              // file
  25.  
  26. // support these geometric objects
  27. include("real/objects/r3sphere.js");
  28. include("real/objects/r3camera.js");
  29.  
  30.  
  31. // This callback function is called for each geometric object
  32.  
  33. function myExportHook(r3obj, frame)
  34. {
  35.     // call low level API to fetch the class ID of the object
  36.     iClid = R3Get(r3obj, R3RA_ClassID, R3TID_INTEGER, 0); 
  37.  
  38.     if (iClid == R3CLID_CAMERA) {
  39.  
  40.         camera = new r3Camera();
  41.         camera.r3Attach(r3obj);
  42.         
  43.         // fetch position, rotation and viewing angle
  44.         pPos = camera.GetPosition();
  45.         pRot = camera.GetQuaternion();
  46.         fAngle = camera.GetAngle();
  47.         
  48.         // write them out 
  49.         this.myFile.PUTS("at time " + frame + "f c.rotation = quat " + pRot.x + " " + pRot.y + " " + pRot.z + " " + pRot.w + "\n");
  50.         this.myFile.PUTS("at time " + frame + "f c.position = [" + pPos.x + "," + pPos.y + "," + pPos.z + "]\n");
  51.         this.myFile.PUTS("at time " + frame + "f c.fov = " + fAngle / (2*Math.PI) * 360.0 + "\n");
  52.  
  53.         delete camera;
  54.     }
  55.     return TRUE;
  56. }
  57.  
  58. function myExportGeometrics(button, event, value)
  59. {
  60.     // create R3D file object
  61.     myFile = new r3File(R3FIA_FileName, "js.out",
  62.                         R3FIA_Mode, "wa");
  63.     myExportHook.myFile = myFile;
  64.     
  65.     animator = new r3Animator();
  66.     animator.r3Attach(Get("CurrentProject.Animator"));
  67.  
  68.     iFrames = animator.GetFrames();
  69.  
  70.     myFile.PUTS("-- REALViZ MatchMover exported file\n");
  71.     myFile.PUTS("-- (c) REALViZ 1998\n");
  72.     myFile.PUTS("-- Export tag: $Revision: 1.6 $\n");
  73.     myFile.PUTS("-- Realsoft 3D : scale: 1\n\n");
  74.     myFile.PUTS("-- Creation date : ....\n\n");
  75.     myFile.PUTS("animationRange = interval 0f " + iFrames + "f\n\n");
  76.     myFile.PUTS("-- The camera and its keyframes\n");
  77.     myFile.PUTS("animate on (\n");
  78.     myFile.PUTS("c = freecamera name:\"camera11\"\n\n");
  79.  
  80.     do {
  81.         iCurr = animator.GetCurrentFrame();
  82.         
  83.         // enumerate all geometric objects to 'myExportHook()'
  84.         button.layer.LOCKSHARED(0);
  85.         button.layer.ENUMOBJECTS([R3RA_Hook, myExportHook, R3RA_HookData, iCurr]);
  86.         button.layer.RELEASE(0);
  87.  
  88.         animator.NEXTFRAME();
  89.     } while(iCurr < iFrames-1);
  90.     
  91.     myFile.PUTS(")\n");
  92.     
  93.     // close file
  94.     myExportHook.myFile = 0;
  95.     myFile.r3Detach();
  96.  
  97.     print("Camera animation written to 'js.out' file");
  98. }
  99.  
  100. function myExportTools(orientation)
  101. {
  102.     if(arguments.length == 0)
  103.         return;
  104.  
  105.     // create interface to geometric objects layer
  106.     primLayer = new r3Primlayer();
  107.     primLayer.r3Attach(Get("CurrentProject.Geometrics"));
  108.  
  109.     // call super class constructor
  110.     this.base = myToolBar; 
  111.     this.base("Export", orientation, primLayer);
  112.  
  113.     // add tool buttons
  114.     this.AddTool("Export Geometrics", myExportGeometrics);
  115. }
  116.  
  117. myExportTools.prototype=new myToolBar;
  118.