34 _real_world_size_u = 0;
35 _real_world_size_v = 0;
38 _file_format = FF_none;
39 _min_filter = MN_point;
40 _mag_filter = MG_point;
42 _repeat_u = RT_repeat;
43 _repeat_v = RT_repeat;
47 _env_type = ET_modulate;
48 _intensity_is_alpha =
false;
49 _float_real_world_size_u = 0.0;
50 _float_real_world_size_v = 0.0;
51 _imported_origin_code = 0;
52 _kernel_version = 1520;
53 _internal_format = IF_default;
54 _external_format = EF_default;
55 _use_mipmap_kernel =
false;
56 memset(_mipmap_kernel, 0,
sizeof(_mipmap_kernel));
57 _use_lod_scale =
false;
58 memset(_lod_scale, 0,
sizeof(_lod_scale));
60 _mag_filter_alpha = MG_point;
61 _mag_filter_color = MG_point;
62 _lambert_conic_central_meridian = 0.0;
63 _lambert_conic_upper_latitude = 0.0;
64 _lambert_conic_lower_latitude = 0.0;
72 _tile_lower_left_u = 0.0;
73 _tile_lower_left_v = 0.0;
74 _tile_upper_right_u = 0.0;
75 _tile_upper_right_v = 0.0;
76 _projection = PT_flat_earth;
77 _earth_model = EM_wgs84;
79 _image_origin = IO_lower_left;
80 _geospecific_points_units = PU_degrees;
81 _geospecific_hemisphere = H_southern;
102 return _converted_filename;
110 _converted_filename = filename;
127 return Filename::binary_filename(texture_filename +
".attr");
141 return FE_could_not_open;
145 attr.seekg(0, std::ios::end);
147 return FE_read_error;
149 std::streampos length = attr.tellg();
151 char *buffer =
new char[length];
153 attr.seekg(0, std::ios::beg);
154 attr.read(buffer, length);
156 return FE_read_error;
162 return unpack_attr(datagram);
181 FltError result = pack_attr(datagram);
182 if (result != FE_ok) {
189 return FE_could_not_open;
194 return FE_write_error;
206 if (!FltRecord::extract_record(reader)) {
210 nassertr(reader.
get_opcode() == FO_texture,
false);
213 if (_header->get_flt_version() < 1420) {
214 _orig_filename = iterator.get_fixed_string(80);
216 _orig_filename = iterator.get_fixed_string(200);
219 _pattern_index = iterator.get_be_int32();
220 _x_location = iterator.get_be_int32();
221 _y_location = iterator.get_be_int32();
238 if (!FltRecord::build_record(writer)) {
250 if (_header->get_auto_attr_update() == FltHeader::AU_always ||
251 (_header->get_auto_attr_update() == FltHeader::AU_if_missing &&
264 FltError FltTexture::
265 unpack_attr(
const Datagram &datagram) {
268 _num_texels_u = iterator.get_be_int32();
269 _num_texels_v = iterator.get_be_int32();
270 _real_world_size_u = iterator.get_be_int32();
271 _real_world_size_v = iterator.get_be_int32();
272 _up_vector_x = iterator.get_be_int32();
273 _up_vector_y = iterator.get_be_int32();
274 _file_format = (FileFormat)iterator.get_be_int32();
275 _min_filter = (Minification)iterator.get_be_int32();
276 _mag_filter = (Magnification)iterator.get_be_int32();
277 _repeat = (RepeatType)iterator.get_be_int32();
278 _repeat_u = (RepeatType)iterator.get_be_int32();
279 _repeat_v = (RepeatType)iterator.get_be_int32();
280 _modify_flag = iterator.get_be_int32();
281 _x_pivot_point = iterator.get_be_int32();
282 _y_pivot_point = iterator.get_be_int32();
283 _env_type = (EnvironmentType)iterator.get_be_int32();
284 _intensity_is_alpha = (iterator.get_be_int32() != 0);
285 iterator.skip_bytes(4 * 8);
286 iterator.skip_bytes(4);
287 _float_real_world_size_u = iterator.get_be_float64();
288 _float_real_world_size_v = iterator.get_be_float64();
289 _imported_origin_code = iterator.get_be_int32();
290 _kernel_version = iterator.get_be_int32();
291 _internal_format = (InternalFormat)iterator.get_be_int32();
292 _external_format = (ExternalFormat)iterator.get_be_int32();
293 _use_mipmap_kernel = (iterator.get_be_int32() != 0);
295 for (i = 0; i < 8; i++) {
296 _mipmap_kernel[i] = iterator.get_be_float32();
298 _use_lod_scale = (iterator.get_be_int32() != 0);
299 for (i = 0; i < 8; i++) {
300 _lod_scale[i]._lod = iterator.get_be_float32();
301 _lod_scale[i]._scale = iterator.get_be_float32();
303 _clamp = iterator.get_be_float32();
304 _mag_filter_alpha = (Magnification)iterator.get_be_int32();
305 _mag_filter_color = (Magnification)iterator.get_be_int32();
306 iterator.skip_bytes(4 + 4 * 8);
307 _lambert_conic_central_meridian = iterator.get_be_float64();
308 _lambert_conic_upper_latitude = iterator.get_be_float64();
309 _lambert_conic_lower_latitude = iterator.get_be_float64();
310 iterator.skip_bytes(8 + 4 * 5);
311 _use_detail = (iterator.get_be_int32() != 0);
312 _detail_j = iterator.get_be_int32();
313 _detail_k = iterator.get_be_int32();
314 _detail_m = iterator.get_be_int32();
315 _detail_n = iterator.get_be_int32();
316 _detail_scramble = iterator.get_be_int32();
317 _use_tile = (iterator.get_be_int32() != 0);
318 _tile_lower_left_u = iterator.get_be_float32();
319 _tile_lower_left_v = iterator.get_be_float32();
320 _tile_upper_right_u = iterator.get_be_float32();
321 _tile_upper_right_v = iterator.get_be_float32();
322 _projection = (ProjectionType)iterator.get_be_int32();
323 _earth_model = (EarthModel)iterator.get_be_int32();
324 iterator.skip_bytes(4);
325 _utm_zone = iterator.get_be_int32();
326 _image_origin = (ImageOrigin)iterator.get_be_int32();
327 _geospecific_points_units = (PointsUnits)iterator.get_be_int32();
328 _geospecific_hemisphere = (Hemisphere)iterator.get_be_int32();
329 iterator.skip_bytes(4 + 4 + 149 * 4);
330 iterator.skip_bytes(8);
331 _comment = iterator.get_fixed_string(512);
333 if (iterator.get_remaining_size() != 0) {
334 iterator.skip_bytes(13 * 4);
335 iterator.skip_bytes(4);
336 _file_version = iterator.get_be_int32();
339 _geospecific_control_points.clear();
340 int num_points = iterator.get_be_int32();
341 if (num_points > 0) {
342 iterator.skip_bytes(4);
344 while (num_points > 0) {
345 GeospecificControlPoint gcp;
346 gcp._uv[0] = iterator.get_be_float64();
347 gcp._uv[1] = iterator.get_be_float64();
348 gcp._real_earth[0] = iterator.get_be_float64();
349 gcp._real_earth[1] = iterator.get_be_float64();
353 if (iterator.get_remaining_size() != 0) {
354 int num_defs = iterator.get_be_int32();
355 while (num_defs > 0) {
357 def._name = iterator.get_fixed_string(32);
358 def._left = iterator.get_be_int32();
359 def._bottom = iterator.get_be_int32();
360 def._right = iterator.get_be_int32();
361 def._top = iterator.get_be_int32();
373 FltError FltTexture::
374 pack_attr(
Datagram &datagram)
const {
402 for (i = 0; i < 8; i++) {
406 for (i = 0; i < 8; i++) {
444 datagram.
add_be_int32(_geospecific_control_points.size());
445 if (!_geospecific_control_points.empty()) {
447 GeospecificControlPoints::const_iterator pi;
448 for (pi = _geospecific_control_points.begin();
449 pi != _geospecific_control_points.end();
451 const GeospecificControlPoint &gcp = (*pi);
461 SubtextureDefs::const_iterator di;
462 for (di = _subtexture_defs.begin();
463 di != _subtexture_defs.end();
465 const SubtextureDef &def = (*di);
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly.
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void check_remaining_size(const DatagramIterator &di, const std::string &name=std::string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record.
Filename get_texture_filename() const
Returns the name of the texture image file.
void set_texture_filename(const Filename &filename)
Changes the name of the texture image file.
void set_binary()
Indicates that the filename represents a binary file.
bool open_read(std::ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
virtual void apply_converted_filenames()
Walks the hierarchy at this record and below and copies the _converted_filename record into the _orig...
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
std::string to_os_generic() const
This is similar to to_os_specific(), but it is designed to generate a filename that can be understood...
FltError write_attr_data() const
Writes the texture's .attr file.
void add_be_float64(PN_float64 value)
Adds a 64-bit big-endian floating-point number to the datagram.
virtual void apply_converted_filenames()
Walks the hierarchy at this record and below and copies the _converted_filename record into the _orig...
void add_int8(int8_t value)
Adds a signed 8-bit integer to the datagram.
void add_be_float32(PN_float32 value)
Adds a 32-bit single-precision big-endian floating-point number to the datagram.
The name of a file, such as a texture file or an Egg file.
The base class for all kinds of records in a MultiGen OpenFlight file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FltError read_attr_data()
Opens up the texture's .attr file and reads its data into the extra FltTexture fields.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
void add_fixed_string(const std::string &str, size_t size)
Adds a fixed-length string to the datagram.
void add_be_int32(int32_t value)
Adds a signed 32-bit big-endian integer to the datagram.
TypeHandle is the identifier used to differentiate C++ class types.
Filename get_attr_filename() const
Returns the name of the texture's associated .attr file.
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
size_t get_length() const
Returns the number of bytes in the datagram.
const void * get_data() const
Returns a pointer to the beginning of the datagram's data.