Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/flt/fltMaterial.cxx

Go to the documentation of this file.
00001 // Filename: fltMaterial.cxx
00002 // Created by:  drose (25Aug00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "fltMaterial.h"
00020 #include "fltRecordReader.h"
00021 #include "fltRecordWriter.h"
00022 
00023 TypeHandle FltMaterial::_type_handle;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: FltMaterial::Constructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 FltMaterial::
00031 FltMaterial(FltHeader *header) : FltRecord(header) {
00032   _material_index = 0;
00033   _flags = 0;
00034   _ambient.set(0.0, 0.0, 0.0);
00035   _diffuse.set(0.0, 0.0, 0.0);
00036   _specular.set(0.0, 0.0, 0.0);
00037   _emissive.set(0.0, 0.0, 0.0);
00038   _shininess = 0.0;
00039   _alpha = 1.0;
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: FltMaterial::extract_record
00044 //       Access: Protected, Virtual
00045 //  Description: Fills in the information in this record based on the
00046 //               information given in the indicated datagram, whose
00047 //               opcode has already been read.  Returns true on
00048 //               success, false if the datagram is invalid.
00049 ////////////////////////////////////////////////////////////////////
00050 bool FltMaterial::
00051 extract_record(FltRecordReader &reader) {
00052   if (!FltRecord::extract_record(reader)) {
00053     return false;
00054   }
00055 
00056   nassertr(reader.get_opcode() == FO_15_material, false);
00057   DatagramIterator &iterator = reader.get_iterator();
00058 
00059   _material_index = iterator.get_be_int32();
00060   _material_name = iterator.get_fixed_string(12);
00061   _flags = iterator.get_be_uint32();
00062   _ambient[0] = iterator.get_be_float32();
00063   _ambient[1] = iterator.get_be_float32();
00064   _ambient[2] = iterator.get_be_float32();
00065   _diffuse[0] = iterator.get_be_float32();
00066   _diffuse[1] = iterator.get_be_float32();
00067   _diffuse[2] = iterator.get_be_float32();
00068   _specular[0] = iterator.get_be_float32();
00069   _specular[1] = iterator.get_be_float32();
00070   _specular[2] = iterator.get_be_float32();
00071   _emissive[0] = iterator.get_be_float32();
00072   _emissive[1] = iterator.get_be_float32();
00073   _emissive[2] = iterator.get_be_float32();
00074   _shininess = iterator.get_be_float32();
00075   _alpha = iterator.get_be_float32();
00076   iterator.skip_bytes(4);
00077 
00078   check_remaining_size(iterator);
00079   return true;
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: FltMaterial::build_record
00084 //       Access: Protected, Virtual
00085 //  Description: Fills up the current record on the FltRecordWriter with
00086 //               data for this record, but does not advance the
00087 //               writer.  Returns true on success, false if there is
00088 //               some error.
00089 ////////////////////////////////////////////////////////////////////
00090 bool FltMaterial::
00091 build_record(FltRecordWriter &writer) const {
00092   if (!FltRecord::build_record(writer)) {
00093     return false;
00094   }
00095 
00096   writer.set_opcode(FO_15_material);
00097   Datagram &datagram = writer.update_datagram();
00098 
00099   datagram.add_be_int32(_material_index);
00100   datagram.add_fixed_string(_material_name, 12);
00101   datagram.add_be_uint32(_flags);
00102   datagram.add_be_float32(_ambient[0]);
00103   datagram.add_be_float32(_ambient[1]);
00104   datagram.add_be_float32(_ambient[2]);
00105   datagram.add_be_float32(_diffuse[0]);
00106   datagram.add_be_float32(_diffuse[1]);
00107   datagram.add_be_float32(_diffuse[2]);
00108   datagram.add_be_float32(_specular[0]);
00109   datagram.add_be_float32(_specular[1]);
00110   datagram.add_be_float32(_specular[2]);
00111   datagram.add_be_float32(_emissive[0]);
00112   datagram.add_be_float32(_emissive[1]);
00113   datagram.add_be_float32(_emissive[2]);
00114   datagram.add_be_float32(_shininess);
00115   datagram.add_be_float32(_alpha);
00116   datagram.pad_bytes(4);
00117 
00118   return true;
00119 }
00120 
00121 ////////////////////////////////////////////////////////////////////
00122 //     Function: FltMaterial::extract_14_record
00123 //       Access: Public
00124 //  Description: Fills in the information in this record based on the
00125 //               information from the current position within the v14
00126 //               material palette.  Leaves the iterator at the
00127 //               beginning of the next material.
00128 ////////////////////////////////////////////////////////////////////
00129 bool FltMaterial::
00130 extract_14_record(int index, DatagramIterator &di) {
00131   _material_index = index;
00132 
00133   _ambient[0] = di.get_be_float32();
00134   _ambient[1] = di.get_be_float32();
00135   _ambient[2] = di.get_be_float32();
00136   _diffuse[0] = di.get_be_float32();
00137   _diffuse[1] = di.get_be_float32();
00138   _diffuse[2] = di.get_be_float32();
00139   _specular[0] = di.get_be_float32();
00140   _specular[1] = di.get_be_float32();
00141   _specular[2] = di.get_be_float32();
00142   _emissive[0] = di.get_be_float32();
00143   _emissive[1] = di.get_be_float32();
00144   _emissive[2] = di.get_be_float32();
00145   _shininess = di.get_be_float32();
00146   _alpha = di.get_be_float32();
00147   _flags = di.get_be_uint32();
00148   _material_name = di.get_fixed_string(12);
00149   di.skip_bytes(4 * 28);
00150 
00151   return true;
00152 }
00153 
00154 ////////////////////////////////////////////////////////////////////
00155 //     Function: FltMaterial::build_14_record
00156 //       Access: Public
00157 //  Description: Fills up the current record on the FltRecordWriter
00158 //               with data for this record, formatted as a part of a
00159 //               v14 material palette.  Returns true on success, false
00160 //               if there is some error.
00161 ////////////////////////////////////////////////////////////////////
00162 bool FltMaterial::
00163 build_14_record(Datagram &datagram) {
00164   datagram.add_be_float32(_ambient[0]);
00165   datagram.add_be_float32(_ambient[1]);
00166   datagram.add_be_float32(_ambient[2]);
00167   datagram.add_be_float32(_diffuse[0]);
00168   datagram.add_be_float32(_diffuse[1]);
00169   datagram.add_be_float32(_diffuse[2]);
00170   datagram.add_be_float32(_specular[0]);
00171   datagram.add_be_float32(_specular[1]);
00172   datagram.add_be_float32(_specular[2]);
00173   datagram.add_be_float32(_emissive[0]);
00174   datagram.add_be_float32(_emissive[1]);
00175   datagram.add_be_float32(_emissive[2]);
00176   datagram.add_be_float32(_shininess);
00177   datagram.add_be_float32(_alpha);
00178   datagram.add_be_uint32(_flags);
00179   datagram.add_fixed_string(_material_name, 12);
00180   datagram.pad_bytes(4 * 28);
00181 
00182   return true;
00183 }

Generated on Fri May 2 03:19:24 2003 for Panda-Tool by doxygen1.3