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