Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

LWSurfaceBlok.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: LWSurfaceBlok.cpp,v 1.4 2002/01/11 14:34:59 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/TeddyConfig.h"
00026 #if defined( TEDDY_INCLUDE_LW_SCENE )
00027 
00028 
00029 #include "Teddy/Imports/LWFile.h"
00030 #include "Teddy/Imports/LWLayer.h"
00031 #include "Teddy/Imports/LWModel.h"
00032 #include "Teddy/Imports/LWSurface.h"
00033 #include "Teddy/Imports/LWSurfaceBlok.h"
00034 #include "Teddy/SysSupport/Messages.h"
00035 #include "Teddy/SysSupport/StdIO.h"
00036 using namespace Teddy::SysSupport;
00037 
00038 
00039 namespace Teddy   {
00040 namespace Imports {
00041 
00042 
00044 LWSurfaceBlok::LWSurfaceBlok( LWSurface *surface ){
00045     this->f       = surface->getLayer()->getModel()->getFile();
00046     this->surface = surface;
00047     texture_channel    = 0;
00048     enable             = 0;
00049     opacity_type       = 0;
00050     opacity            = 0;
00051     opacity_envelope   = 0;
00052     displacement_axis  = 0;
00053 
00054     texture_center                        = Vector(0,0,0);
00055     texture_center_envelope               = 0;
00056     texture_size                          = Vector(1,1,1);
00057     texture_size_envelope                 = 0;
00058     texture_rotation                      = Vector(0,0,0);
00059     texture_rotation_envelope             = 0;
00060     texture_falloff_type                  = 0;
00061     texture_falloff                       = Vector(0,0,0);
00062     texture_falloff_envelope              = 0;
00063     texture_coordinate_system             = 0;
00064 
00065     texture_projection_mode               = 0;
00066     texture_major_axis                    = 0;
00067     texture_image_map                     = 0;
00068     texture_width_wrap                    = 0;
00069     texture_height_wrap                   = 0;
00070     texture_wrap_width_cycles             = 0;
00071     texture_wrap_width_cycles_envelope    = 0;
00072     texture_wrap_height_cycles            = 0;
00073     texture_wrap_height_cycles_envelope   = 0;
00074     texture_antialiasing_type             = 0;
00075     texture_antialiasing_strength         = 0;
00076     texture_pixel_blending                = 0;
00077     texture_stack                         = 0;
00078     texture_amplitude                     = 0;
00079     texture_amplitude_envelope            = 0;
00080     texture_negative                      = 0;
00081     procedural_axis       = 0;
00082     gradient_range_start  = 0;
00083     gradient_range_end    = 0;
00084     gradient_repeat       = 0;
00085 }
00086 
00087 
00163 void LWSurfaceBlok::processBlok(){
00164     ID4  blok_type    = f->read_ID4();
00165     ID4  blok_ordinal = f->read_ID4();
00166     bool header_done  = false;
00167     ID4  subchunk;
00168     U2   length;
00169 
00170     while( f->domainLeft() > 0 ){
00171 
00172         subchunk = f->read_ID4();
00173         length   = f->read_U2();
00174         f->pushDomain( length );
00175 
00176         dmsg( M_LWO,
00177             "LWO2::SURF::BLOK::%s::%s (%d bytes)",
00178             did( blok_type ),
00179             did( subchunk  ),
00180             length
00181         );
00182 
00183         //  Headers are accepted only in the beginning
00184         if( header_done == false ){
00185             switch( subchunk ){
00186             case ID_CHAN: readChannel_ID4        (); break;
00187             case ID_ENAB: readEnable_U2          (); break;
00188             case ID_OPAC: readOpacity_U2_FP4_VX  (); break;
00189             case ID_AXIS: readDisplacementAxis_U2(); break;
00190             default:      header_done = true;        break;
00191             }
00192         }
00193 
00194         //  Other than headers
00195         if( header_done == true ){
00196             //  LWO2 BLOK Block Headers
00197             //  
00198             //  Every block contains a header subchunk.
00199             //  
00200             //  block-header { ordinal[S0], block-attributes[SUB-CHUNK] * } 
00201             //  
00202             //  The ID of the header subchunk identifies the block type and can
00203             //  be one of the following.
00204             //  
00205             //  IMAP - an image map texture
00206             //  PROC - a procedural texture
00207             //  GRAD - a gradient texture
00208             //  SHDR - a shader plug-in
00209             //  
00210             //  The header contains an ordinal string (described above) and
00211             //  subchunks that are common to all block types. 
00212             switch( blok_type ){
00213             //  LWO2 BLOK Image Maps
00214             //  
00215             //  Texture blocks with a header type of IMAP are image maps.
00216             //  These use an image to modulate one of the surface channels.
00217             //  In addition to the basic parameters listed below, the block
00218             //  may also contain a TMAP chunk. 
00219             //
00220             case ID_IMAP:
00221                 switch( subchunk ){
00222                 case ID_TMAP: readTextureMap               ( ID_IMAP ); break;
00223                 case ID_PROJ: readTextureProjectionMode_U2          (); break;
00224                 case ID_AXIS: readTextureMajorAxis_U2               (); break;
00225                 case ID_IMAG: readTextureImageMap_VX                (); break;
00226                 case ID_WRAP: readTextureWrapOptions_U2_U2          (); break;
00227                 case ID_WRPW: readTextureWrapWidthAmount_FP4_VX     (); break;
00228                 case ID_WRPH: readTextureWrapHeightAmount_FP4_VX    (); break;
00229                 case ID_VMAP: readTextureUV_VertexMap_S0            (); break;
00230                 case ID_AAST: readTextureAntialiasingStrength_U2_FP4(); break;
00231                 case ID_PIXB: readTexturePixelBlending_U2           (); break;
00232                 case ID_STCK: readTextureStack_VX                   (); break;
00233                 case ID_TAMP: readTextureAmplitude_FP4_VX           (); break;
00234                 case ID_NEGA: readTextureNegative_U2                (); break;
00235 
00236                 //  New block state?
00237                 default:
00238                     dmsg( M_LWO, "FIX End IMAP, to %s", did(subchunk) );
00239                     applyAttributes( blok_type );
00240                     blok_type = subchunk;
00241                     break;
00242                 }
00243                 break;  //  ID_IMAP
00244 
00245             //  LWO2 BLOK Procedural Textures
00246             //  
00247             //  Texture blocks of type PROC are procedural textures
00248             //  that modulate the value of a surface channel
00249             //  algorithmically. 
00250             //  
00251             case ID_PROC:
00252                 switch( subchunk ){
00253                 case ID_TMAP: readTextureMap            ( ID_PROC ); break;
00254                 case ID_AXIS: readProceduralAxis_U2              (); break;
00255                 case ID_VALU: readProceduralBasicValue_FP4_1_or_3(); break;
00256                 case ID_FUNC: readProceduralAlgorithm_S0_data    (); break;
00257                                                                   
00258                 //  New block state?
00259                 default:
00260                     dmsg( M_LWO, "FIX End PROC, to %s", did(subchunk) );
00261                     applyAttributes( blok_type );
00262                     blok_type = subchunk;
00263                     break;
00264                 }
00265                 break;  //  ID_PROC
00266 
00267             //  Gradient Textures
00268             //  
00269             //  Texture blocks of type GRAD are gradient textures that
00270             //  modify a surface channel by mapping an input parameter
00271             //  through an arbitrary transfer function. Gradients are
00272             //  represented to the user as a line containing keys. Each
00273             //  key is a color, and the gradient function is an interpolation
00274             //  of the keys in RGB space. The input parameter selects a
00275             //  point on the line, and the output of the texture is the
00276             //  value of the gradient at that point. 
00277             //  
00278             case ID_GRAD:
00279                 switch( subchunk ){
00280                 case ID_PNAM: readGradientParameter_S0           (); break;
00281                 case ID_INAM: readGradientItem_S0                (); break;
00282                 case ID_GRST: readGradientRangeStart_FP4         (); break;
00283                 case ID_GREN: readGradientRangeEnd_FP4           (); break;
00284                 case ID_GRPT: readGradientRepeat_U2              (); break;
00285                 case ID_FKEY: readGradientKeys_FP4_data_FP4      (); break;
00286                 case ID_IKEY: readGradientKeyParameters_data_U2  (); break;
00287 
00288                 //  New blok state?
00289                 default:
00290                     dmsg( M_LWO, "FIX End GRAD, to %s", did(subchunk) );
00291                     applyAttributes( blok_type );
00292                     blok_type = subchunk;
00293                     break;
00294                 }
00295                 break;  //  ID_GRAD
00296 
00297             //  LWO2 BLOK Shaders
00298             //  
00299             //  Shaders are BLOK subchunks with a header type
00300             //  of SHDR. They are applied to a surface after
00301             //  all basic channels and texture layers are
00302             //  evaluated, and in the order specified by the
00303             //  ordinal sequence. The only header chunk they
00304             //  support is ENAB and they need only one data
00305             //  chunk to describe them. 
00306             //  
00307             case ID_SHDR:
00308                 switch( subchunk ){
00309                 case ID_FUNC: readShaderAlgorithm_S0_data        (); break;
00310 
00311                 //  New blok state?
00312                 default:
00313                     dmsg( M_LWO, "FIX End SHDR, to %s", did(subchunk) );
00314                     applyAttributes( blok_type );
00315                     blok_type = subchunk;
00316                     break;
00317                 }
00318                 break;  //  ID_SHDR
00319 
00320             //  Unknown attribute -- blok_state
00321             default:
00322                 dmsg( M_LWO,
00323                     "LWO2::SURF::BLOK parser confused by blok type %s",
00324                     did(blok_type)
00325                 );
00326                 break;
00327             }
00328         }
00329 
00330         f->popDomain( true );
00331     }
00332     applyAttributes( blok_type );
00333 }
00334 
00335 
00336 void LWSurfaceBlok::applyAttributes( ID4 type ){
00337     switch( type ){
00338     case ID_IMAP: applyImageMap  (); break;
00339     case ID_PROC: applyProcedural(); break;
00340     case ID_GRAD: applyGradient  (); break;
00341     case ID_SHDR: applyShader    (); break;
00342     default:
00343         dmsg( M_LWO, "Unknown BLOK attribute %s", type );
00344         break;
00345     }
00346 }
00347 
00348 
00361 void LWSurfaceBlok::readTextureMap( ID4 parent ){
00362     ID4  subchunk;
00363     U2   length;
00364 
00365     while( f->domainLeft() > 0 ){
00366 
00367         subchunk = f->read_ID4();
00368         length   = f->read_U2();
00369 
00370         dmsg( M_LWO,
00371             "LWO2::SURF::BLOK::%s::TMAP::%s (%d bytes)",
00372             did( parent   ),
00373             did( subchunk ),
00374             length
00375         );
00376 
00377         f->pushDomain( length );
00378         switch( subchunk ){
00379         case ID_CNTR: readTextureCenter_VEC12_VX            (); break;
00380         case ID_SIZE: readTextureSize_VEC12_VX              (); break;
00381         case ID_ROTA: readTextureRotation_VEC12_VX          (); break;
00382         case ID_OREF: readTextureReferenceObject_S0         (); break;
00383         case ID_FALL: readTextureFalloff_U2_VEC12_VX        (); break;
00384         case ID_CSYS: readTextureCoordinateSystem_U2        (); break;
00385 
00386         //  New blok state?
00387         default: 
00388             dmsg( M_LWO, "Unknown TMAP::%s", did(subchunk) );
00389             break;
00390         }
00391         f->popDomain( true );
00392     }
00393 }
00394 
00395 
00407 void LWSurfaceBlok::readChannel_ID4(){
00408     texture_channel = f->read_ID4();
00409 }
00410 
00411 
00419 void LWSurfaceBlok::readEnable_U2(){
00420     enable = f->read_U2();
00421 }
00422 
00423 
00448 void LWSurfaceBlok::readOpacity_U2_FP4_VX(){
00449     opacity_type     = f->read_U2 ();
00450     opacity          = f->read_FP4();
00451     opacity_envelope = f->read_VX ();  //  FIX envelope
00452 }
00453 
00454 
00464 void LWSurfaceBlok::readDisplacementAxis_U2(){
00465     displacement_axis = f->read_U2();
00466 }
00467 
00468 
00481 void LWSurfaceBlok::readTextureCenter_VEC12_VX(){
00482     texture_center          = f->read_VEC12();
00483     texture_center_envelope = f->read_VX   ();  //  FIX envelope
00484 }
00485 
00486 
00487 void LWSurfaceBlok::readTextureSize_VEC12_VX(){
00488     texture_size          = f->read_VEC12();
00489     texture_size_envelope = f->read_VX   ();  //  FIX envelope
00490 }
00491 
00492 void LWSurfaceBlok::readTextureRotation_VEC12_VX(){
00493     texture_rotation          = f->read_VEC12();
00494     texture_rotation_envelope = f->read_VX   ();  //  FIX envelope
00495 }
00496 
00497 
00509 void LWSurfaceBlok::readTextureReferenceObject_S0(){
00510     texture_reference_object = f->read_S0();
00511 }
00512 
00513 
00532 void LWSurfaceBlok::readTextureFalloff_U2_VEC12_VX(){
00533     texture_falloff_type     = f->read_U2   ();
00534     texture_falloff          = f->read_VEC12();
00535     texture_falloff_envelope = f->read_VX   ();  //  FIX envelope
00536 }
00537 
00538 
00548 void LWSurfaceBlok::readTextureCoordinateSystem_U2(){
00549     texture_coordinate_system = f->read_U2();
00550 }
00551 
00552 
00595 void LWSurfaceBlok::readTextureProjectionMode_U2(){
00596     texture_projection_mode = f->read_U2();
00597 }
00598 
00599 
00608 void LWSurfaceBlok::readTextureMajorAxis_U2(){
00609     texture_major_axis = f->read_U2();
00610 }
00611 
00612 
00620 void LWSurfaceBlok::readTextureImageMap_VX(){
00621     texture_image_map = f->read_VX();
00622 }
00623 
00624 
00652 void LWSurfaceBlok::readTextureWrapOptions_U2_U2(){
00653     texture_width_wrap  = f->read_U2();
00654     texture_height_wrap = f->read_U2();
00655 }
00656 
00657 
00666 void LWSurfaceBlok::readTextureWrapWidthAmount_FP4_VX(){
00667     texture_wrap_width_cycles          = f->read_FP4();
00668     texture_wrap_width_cycles_envelope = f->read_VX ();  //  FIX envelope
00669 }
00670 
00671 
00672 void LWSurfaceBlok::readTextureWrapHeightAmount_FP4_VX(){
00673     texture_wrap_height_cycles          = f->read_FP4();
00674     texture_wrap_height_cycles_envelope = f->read_VX ();  //  FIX envelope
00675 }
00676 
00677 
00686 void LWSurfaceBlok::readTextureUV_VertexMap_S0(){
00687     texture_uv_vertex_map = f->read_S0();
00688 }
00689 
00690 
00701 void LWSurfaceBlok::readTextureAntialiasingStrength_U2_FP4(){
00702     texture_antialiasing_type     = f->read_U2 ();
00703     texture_antialiasing_strength = f->read_FP4();
00704 }
00705 
00706 
00717 void LWSurfaceBlok::readTexturePixelBlending_U2(){
00718     texture_pixel_blending = f->read_U2();
00719 }
00720 
00721 
00729 void LWSurfaceBlok::readTextureStack_VX(){
00730     texture_stack = f->read_VX();  //  FIX envelope
00731 }
00732 
00733 
00743 void LWSurfaceBlok::readTextureAmplitude_FP4_VX(){
00744     texture_amplitude          = f->read_FP4();
00745     texture_amplitude_envelope = f->read_VX ();  //  FIX envelope
00746 }
00747 
00748 
00749 void LWSurfaceBlok::readTextureNegative_U2(){
00750     texture_negative = f->read_U2();
00751 }
00752 
00753 
00762 void LWSurfaceBlok::readProceduralAxis_U2(){
00763     procedural_axis = f->read_U2();
00764 }
00765 
00775 void LWSurfaceBlok::readProceduralBasicValue_FP4_1_or_3(){
00776     //lwo_debug_msg( "# (1, 3)" );
00777 }
00778 
00779 
00790 void LWSurfaceBlok::readProceduralAlgorithm_S0_data(){
00791     procedural_algorithm = f->read_S0();
00792     //lwo_debug_msg( "data[...]" );
00793 }
00794 
00795 
00815 void LWSurfaceBlok::readGradientParameter_S0(){
00816     gradient_parameter = f->read_S0();
00817 }
00818 
00819 
00828 void LWSurfaceBlok::readGradientItem_S0(){
00829     gradient_item = f->read_S0();
00830 }
00831 
00832 
00842 void LWSurfaceBlok::readGradientRangeStart_FP4(){
00843     gradient_range_start = f->read_FP4();
00844 }
00845 
00846 void LWSurfaceBlok::readGradientRangeEnd_FP4(){
00847     gradient_range_end = f->read_FP4();
00848 }
00849 
00850 
00857 void LWSurfaceBlok::readGradientRepeat_U2(){
00858     gradient_repeat = f->read_U2();
00859 }
00860 
00861 
00876 void LWSurfaceBlok::readGradientKeys_FP4_data_FP4(){
00877     //lwo_debug_msg( "FKEY { ( input[FP4], output[FP4] # 4 )* }" );
00878 }
00879 
00880 
00892 void LWSurfaceBlok::readGradientKeyParameters_data_U2(){
00893     //lwo_debug_msg( "IKEY { interpolation[U2] * }" );
00894 }
00895 
00896 
00906 void LWSurfaceBlok::readShaderAlgorithm_S0_data(){
00907     shader_algorithm = f->read_S0();
00908     //lwo_debug_msg( "FUNC { algorithm-name[S0], data[...] }" );
00909 }
00910 
00911 
00912 };  //  namespace Imports
00913 };  //  namespace Teddy
00914 
00915 
00916 #endif  //  TEDDY_INCLUDE_LW_SCENE
00917