Panda3D
|
00001 // Filename: textureReference.h 00002 // Created by: drose (28Nov00) 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 #ifndef TEXTUREREFERENCE_H 00016 #define TEXTUREREFERENCE_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "textureProperties.h" 00021 #include "palettizer.h" 00022 00023 #include "luse.h" 00024 #include "typedWritable.h" 00025 00026 class TextureImage; 00027 class SourceTextureImage; 00028 class Filename; 00029 class EggFile; 00030 class EggData; 00031 class EggTexture; 00032 class EggGroupNode; 00033 class EggPrimitive; 00034 class TexturePlacement; 00035 00036 //////////////////////////////////////////////////////////////////// 00037 // Class : TextureReference 00038 // Description : This is the particular reference of a texture 00039 // filename by an egg file. It also includes 00040 // information about the way in which the egg file uses 00041 // the texture; e.g. does it repeat. 00042 //////////////////////////////////////////////////////////////////// 00043 class TextureReference : public TypedWritable { 00044 public: 00045 TextureReference(); 00046 ~TextureReference(); 00047 00048 void from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex); 00049 void from_egg_quick(const TextureReference &other); 00050 void release_egg_data(); 00051 void rebind_egg_data(EggData *data, EggTexture *egg_tex); 00052 00053 EggFile *get_egg_file() const; 00054 SourceTextureImage *get_source() const; 00055 TextureImage *get_texture() const; 00056 const string &get_tref_name() const; 00057 00058 bool operator < (const TextureReference &other) const; 00059 00060 bool has_uvs() const; 00061 const LTexCoordd &get_min_uv() const; 00062 const LTexCoordd &get_max_uv() const; 00063 00064 EggTexture::WrapMode get_wrap_u() const; 00065 EggTexture::WrapMode get_wrap_v() const; 00066 00067 bool is_equivalent(const TextureReference &other) const; 00068 00069 void set_placement(TexturePlacement *placement); 00070 void clear_placement(); 00071 TexturePlacement *get_placement() const; 00072 00073 void mark_egg_stale(); 00074 void update_egg(); 00075 void apply_properties_to_source(); 00076 00077 void output(ostream &out) const; 00078 void write(ostream &out, int indent_level = 0) const; 00079 00080 00081 private: 00082 bool get_uv_range(EggGroupNode *group, Palettizer::RemapUV remap); 00083 void update_uv_range(EggGroupNode *group, Palettizer::RemapUV remap); 00084 00085 bool get_geom_uvs(EggPrimitive *geom, 00086 LTexCoordd &geom_min_uv, LTexCoordd &geom_max_uv); 00087 void translate_geom_uvs(EggPrimitive *geom, const LTexCoordd &trans) const; 00088 void collect_nominal_uv_range(); 00089 static void collect_uv(bool &any_uvs, LTexCoordd &min_uv, LTexCoordd &max_uv, 00090 const LTexCoordd &got_min_uv, 00091 const LTexCoordd &got_max_uv); 00092 static LVector2d translate_uv(const LTexCoordd &min_uv, 00093 const LTexCoordd &max_uv); 00094 00095 EggFile *_egg_file; 00096 EggTexture *_egg_tex; 00097 EggData *_egg_data; 00098 00099 string _tref_name; 00100 LMatrix3d _tex_mat, _inv_tex_mat; 00101 SourceTextureImage *_source_texture; 00102 TexturePlacement *_placement; 00103 00104 bool _uses_alpha; 00105 00106 bool _any_uvs; 00107 LTexCoordd _min_uv, _max_uv; 00108 EggTexture::WrapMode _wrap_u, _wrap_v; 00109 00110 TextureProperties _properties; 00111 00112 // The TypedWritable interface follows. 00113 public: 00114 static void register_with_read_factory(); 00115 virtual void write_datagram(BamWriter *writer, Datagram &datagram); 00116 virtual int complete_pointers(TypedWritable **p_list, 00117 BamReader *manager); 00118 00119 protected: 00120 static TypedWritable *make_TextureReference(const FactoryParams ¶ms); 00121 void fillin(DatagramIterator &scan, BamReader *manager); 00122 00123 public: 00124 static TypeHandle get_class_type() { 00125 return _type_handle; 00126 } 00127 static void init_type() { 00128 TypedWritable::init_type(); 00129 register_type(_type_handle, "TextureReference", 00130 TypedWritable::get_class_type()); 00131 } 00132 virtual TypeHandle get_type() const { 00133 return get_class_type(); 00134 } 00135 00136 private: 00137 static TypeHandle _type_handle; 00138 }; 00139 00140 INLINE ostream & 00141 operator << (ostream &out, const TextureReference &ref) { 00142 ref.output(out); 00143 return out; 00144 } 00145 00146 #endif 00147 00148