Adobe

[3D + JS] Layer 제어 Example

  • 04-25
  • 524 회
  • 0 건

 [member]sahoon[/member]

 

 

 

[hidden]


* Show layer 1

[code]layers.displayLayer(0); [/code]

* Show layer 2

[code]layers.displayLayer(1); [/code]

* Show layer 3

[code]layers.displayLayer(2); [/code]

* Show layer 4

[code]layers.displayLayer(3); [/code]

* Layers.js

[code]console.println( "* The Javascript 'Layers.js is now being read..." );

var layersMessages = false;

 

  //------------------------------------------------------------------------------

  // constructor for the Layer Object (used by the Layers Manager)

  //------------------------------------------------------------------------------

  function LayerObject()

   {

    //---------------------------------------------

    // public methods

    //---------------------------------------------

    this.setIndex       = function( i    ) { index = i;           }

    this.setValid       = function( v    ) { valid = v;           }

    this.getValid       = function(      ) { return valid;        }

    this.getNumMeshes   = function(      ) { return numMeshes;    }

    this.getMeshIndex   = function( p    ) { return meshIndex[p]; }

    this.setDisplaying  = function( d    ) { displaying = d;      }

    this.getDisplaying  = function(      ) { return displaying;   }

    this.addMeshByIndex = function( m    ) 

     { 

      meshIndex[ numMeshes ] = m;

      //if ( layersMessages ) console.println( "" );

      //if ( layersMessages ) console.println( "* adding mesh  " + meshIndex[ numMeshes ] + " to layer " + index );

      numMeshes ++;

     }

 

    //----------------------------------

    // private members

    //----------------------------------  

    var MAX_MESHES_PER_LAYER = 30;

    var index      = -1;

    var valid      = false;

    var displaying = false;

    var numMeshes  = 0;

    var meshIndex  = new Array( MAX_MESHES_PER_LAYER );

 

    for (p=0; p<MAX_MESHES_PER_LAYER; p++)

     {

      meshIndex[p] = -1;

     }

 

   } // -----------------------------------------------------------------------------

    // end of Layer Object constructor----------------------------------------------

   //------------------------------------------------------------------------------

 

  //------------------------------------------------------------------------------

  // constructor for the LayersManager Object 

  //------------------------------------------------------------------------------

  function LayersManagerObject()

   {

    //---------------------------------------------

    // public methods

    //---------------------------------------------

    this.addPartToLayer = function( partName, layerIndex )

     {

      if ( layersMessages ) console.println( "* request to add mesh '" + partName + "' to layer " + layerIndex );

 

      if ( layerIndex < MAX_LAYERS - 1 )

       {    

        var meshIndex = -1;

        var numMeshesInScene = scene.meshes.count;

        for (m=0; m<numMeshesInScene; m++)

         {

          var mesh = scene.meshes.getByIndex(m);

  

          if ( mesh.name == partName )

           {

            meshIndex = m;

           }

         }

 

        if ( meshIndex == -1 )

         {

          if ( layersMessages ) console.println( "* Oops - I cannot find a mesh named '" + partName + "' to add to layer " + layerIndex );

         }

        else 

         {

          if ( ! scene.meshes.getByIndex( meshIndex ).material )

           {

             if ( layersMessages ) console.println( "* Oops, mesh '" + partName + "' has no material!" );

           }

          else

           {

            layer[ layerIndex ].setValid( true       );

            layer[ layerIndex ].setIndex( layerIndex );

            layer[ layerIndex ].addMeshByIndex( meshIndex );

           }

         }

       }

      else 

       {

        if ( layersMessages ) console.println( "* Oops - you cannot add a mesh to layer " + layerIndex + ". The maximimum layer index is " + MAX_LAYERS - 1 );

       }

 

     }//-----------end of addPartToLayer public method -------------------------------------------

 

  //---------------------------------------------------------------------

  this.displayLayer = function( layerIndex )

   {

    if ( layer[ layerIndex ].getValid() )

     {

      if ( layersMessages ) console.println( " " );

      if ( layersMessages ) console.println( "* displaying the meshes of view layer " + layerIndex );

 

      //--------------------------------------------

      // first set all meshes to low opacity...

      //--------------------------------------------

      var numMeshesInScene = scene.meshes.count;

      for (m=0; m<numMeshesInScene; m++)

       {

        var mesh = scene.meshes.getByIndex(m);

        if ( mesh.material )

         {

          mesh.material.opacity = nonLayerOpacity;

         }

       }

 

      //---------------------------------------------------------

      // then... set opacity to max for the meshes in this layer

      //---------------------------------------------------------

      for (m=0; m<layer[ layerIndex ].getNumMeshes(); m++)

       {

        var meshIndex = layer[ layerIndex ].getMeshIndex(m);

 

        var mesh = scene.meshes.getByIndex( meshIndex );

        if ( mesh.material )

         {

          mesh.material.opacity = 1.0;

         }

       }

 

     }// if ( layer[ layerIndex ].getValid() )

    else

     {

      if ( layersMessages ) console.println( " " );

      if ( layersMessages ) console.println( "* Oops - you requested to display layer " + layerIndex + ", which was never specified." );

     }

 

   }//---------------------------------------------------------------------

  //---------------------------------------------------------------------

  this.setNonLayerOpacity = function( o )

   {

    nonLayerOpacity = o; 

   }//---------------------------------------------------------------------

    //---------------------------------------------------------------------

  this.getMaxLayers = function()

   {

    return MAX_LAYERS;

 

   }//---------------------------------------------------------------------

 

  //---------------------------------------------------------------------

  this.turnOffLayerViewing = function()

   {

    var numMeshesInScene = scene.meshes.count;

    for (m=0; m<numMeshesInScene; m++)

     {

      var mesh = scene.meshes.getByIndex(m);

      if ( mesh.material )

       {

        mesh.material.opacity = 1.0;

       }

     }

 

   }//---------------------------------------------------------------------

 

 

    //---------------------------------------------------------------------

    this.turnOnMessagesInTheConsole = function()

     {

      layersMessages = true;

 

     }//--------------------------------------------------------------------------

    

    //--------------------------------------------------------------------------

    this.turnOffMessagesInTheConsole = function()

     {

      layersMessages = false;

 

     }//--------------------------------------------------------------------------

  

    //----------------------------------

    // private members

    //----------------------------------  

    var MAX_LAYERS      = 10;

    var nonLayerOpacity = 0.2;

 

    //---------------------------------------------------------------------------

    // making an array of Layer Objects

    //---------------------------------------------------------------------------

    var layer = new Array( MAX_LAYERS );

    for (i=0; i<MAX_LAYERS; i++)

     {

      layer[i] = new LayerObject();

     }

 

   } // -----------------------------------------------------------------------------

    // end of LayersManager Object constructor----------------------------------------------

   //------------------------------------------------------------------------------

    //-------------------------------------------------------

  // Here is the public method in which a new Spinbject

  // is created, so that the calls can be made 

  //-------------------------------------------------------

  function createNewLayersManagerObject()

   {

    return new LayersManagerObject();

 

   }//---------------------------------

 

 

/*

  //---------------------------------------------------------------------

  // The following functions can be called by any PDF document 

  // that includes this file as part of its 3D Annotation JavaScript.

  // the rest of the code in this file (above) is private and can only 

  // be accessed via the layersManager. 

  //---------------------------------------------------------------------

 

  var layersManager = new LayersManagerObject();

 

  //---------------------------------------------------------------------

  function addPartToLayer( partName, layerIndex )

   {

    layersManager.addPartToLayer( partName, layerIndex );

   } 

 

  //------------------------------------------------------------------------------

  function setNonLayerOpacity( o )

   {

    layersManager.setNonLayerOpacity( o );

   }

 

  //------------------------------------------------------------------------------

  function turnOffLayerViewing()

   {

    layersManager.turnOffLayerViewing();

   }

 

  //---------------------------------------------------------------------

  function getMaxLayers()

   {

    return layersManager.getMaxLayers();

 

   }//---------------------------------------------------------------------

 

  //---------------------------------------------------------------------

  function displayLayer( layerIndex )

   {

    layersManager.displayLayer( layerIndex );

 

   }//---------------------------------------------------------------------

 

    //-------------------------------------------------------------------------------------------

    function turnOnLayersMessagesInTheConsole()

     {

      layersMessages = true;

 

     }//--------------------------------------------------------------------------

    

    //-------------------------------------------------------------------------------------------

    function turnOffLayersMessagesInTheConsole()

     {

      layersMessages = false;

 

     }//--------------------------------------------------------------------------

*/

 

console.println( "* OK, the Javascript 'Layers.js' was successfully read to the end." );

[/code]

 

자동등록방지 숫자를 순서대로 입력하세요.