51 _tex_mat = LMatrix3d::ident_mat();
52 _inv_tex_mat = LMatrix3d::ident_mat();
53 _source_texture =
nullptr;
57 _min_uv.set(0.0, 0.0);
58 _max_uv.set(0.0, 0.0);
59 _wrap_u = EggTexture::WM_unspecified;
60 _wrap_v = EggTexture::WM_unspecified;
79 _tref_name = egg_tex->get_name();
83 if (!_inv_tex_mat.invert_from(_tex_mat)) {
84 _inv_tex_mat = LMatrix3d::ident_mat();
87 _tex_mat = LMatrix3d::ident_mat();
88 _inv_tex_mat = LMatrix3d::ident_mat();
98 _properties._format = _egg_tex->get_format();
99 _properties._minfilter = _egg_tex->get_minfilter();
100 _properties._magfilter = _egg_tex->get_magfilter();
101 _properties._quality_level = _egg_tex->get_quality_level();
106 if (texture->get_name() != name) {
107 nout <<
"Texture name conflict: \"" << name
108 <<
"\" conflicts with existing texture named \""
109 << texture->get_name() <<
"\".\n";
116 _source_texture = texture->
get_source(filename, alpha_filename,
122 if (alpha_mode == EggRenderMode::AM_unspecified) {
128 }
else if (alpha_mode == EggRenderMode::AM_off) {
135 get_uv_range(_egg_data, pal->_remap_uv);
150 nassertv(_tref_name == other._tref_name);
151 _egg_file = other._egg_file;
152 _egg_tex = other._egg_tex;
153 _egg_data = other._egg_data;
173 nassertv(_tref_name == egg_tex->get_name());
191 return _source_texture;
199 nassertr(_source_texture !=
nullptr,
nullptr);
217 return _tref_name < other._tref_name;
235 nassertr(_any_uvs, _min_uv);
244 nassertr(_any_uvs, _max_uv);
272 if (_source_texture != other._source_texture) {
278 if (_uses_alpha != other._uses_alpha) {
281 if (_any_uvs != other._any_uvs) {
284 if (_wrap_u != other._wrap_u ||
285 _wrap_v != other._wrap_v) {
289 if (!_min_uv.almost_equal(other._min_uv, 0.00001)) {
292 if (!_max_uv.almost_equal(other._max_uv, 0.00001)) {
296 if (!_tex_mat.almost_equal(other._tex_mat, 0.00001)) {
309 if (_placement != placement) {
310 if (_placement !=
nullptr) {
314 _placement = placement;
315 if (_placement !=
nullptr) {
345 if (_egg_file !=
nullptr) {
356 if (_egg_tex ==
nullptr) {
361 if (_placement ==
nullptr) {
369 if (texture !=
nullptr) {
382 if (am != EggRenderMode::AM_unspecified) {
413 nassertv(dest !=
nullptr);
422 nassertv(image !=
nullptr);
429 _egg_tex->set_wrap_mode(EggTexture::WM_unspecified);
430 _egg_tex->set_wrap_u(EggTexture::WM_unspecified);
431 _egg_tex->set_wrap_v(EggTexture::WM_unspecified);
433 LMatrix3d new_tex_mat;
442 if (_egg_tex->get_tex_gen() == EggTexture::TG_unspecified) {
443 update_uv_range(_egg_data, pal->_remap_uv);
454 nassertv(_source_texture !=
nullptr);
461 void TextureReference::
462 output(std::ostream &out)
const {
463 out << *_source_texture;
469 void TextureReference::
470 write(std::ostream &out,
int indent_level)
const {
475 out <<
" (uses alpha)";
481 LTexCoordd box = _max_uv - _min_uv;
482 double area = box[0] * box[1];
484 out <<
" coverage " << area;
487 if (_wrap_u != EggTexture::WM_unspecified ||
488 _wrap_v != EggTexture::WM_unspecified) {
489 if (_wrap_u != _wrap_v) {
490 out <<
" (" << _wrap_u <<
", " << _wrap_v <<
")";
492 out <<
" " << _wrap_u;
496 if (_properties._format != EggTexture::F_unspecified) {
497 out <<
" " << _properties._format;
500 switch (_properties._minfilter) {
501 case EggTexture::FT_nearest_mipmap_nearest:
502 case EggTexture::FT_linear_mipmap_nearest:
503 case EggTexture::FT_nearest_mipmap_linear:
504 case EggTexture::FT_linear_mipmap_linear:
512 if(_properties._anisotropic_degree>1) {
513 out <<
" aniso " << _properties._anisotropic_degree;
535 bool TextureReference::
536 get_uv_range(
EggGroupNode *group, Palettizer::RemapUV remap) {
537 if (group->
is_of_type(EggGroup::get_class_type())) {
539 DCAST_INTO_R(egg_group, group,
false);
541 if (egg_group->get_dart_type() != EggGroup::DT_none) {
543 remap = pal->_remap_char_uv;
547 bool group_any_uvs =
false;
548 LTexCoordd group_min_uv, group_max_uv;
550 EggGroupNode::iterator ci;
551 for (ci = group->begin(); ci != group->end(); ci++) {
553 if (child->
is_of_type(EggNurbsSurface::get_class_type())) {
555 if (nurbs->has_texture(_egg_tex)) {
566 collect_nominal_uv_range();
569 }
else if (child->
is_of_type(EggPrimitive::get_class_type())) {
575 if (_egg_tex->get_tex_gen() != EggTexture::TG_unspecified) {
581 collect_nominal_uv_range();
588 LTexCoordd geom_min_uv, geom_max_uv;
590 if (get_geom_uvs(geom, geom_min_uv, geom_max_uv)) {
591 if (remap == Palettizer::RU_poly) {
592 LVector2d trans = translate_uv(geom_min_uv, geom_max_uv);
593 geom_min_uv += trans;
594 geom_max_uv += trans;
596 collect_uv(group_any_uvs, group_min_uv, group_max_uv,
597 geom_min_uv, geom_max_uv);
602 }
else if (child->
is_of_type(EggGroupNode::get_class_type())) {
604 if (!get_uv_range(cg, remap)) {
611 if (remap == Palettizer::RU_group) {
612 LVector2d trans = translate_uv(group_min_uv, group_max_uv);
613 group_min_uv += trans;
614 group_max_uv += trans;
616 collect_uv(_any_uvs, _min_uv, _max_uv, group_min_uv, group_max_uv);
626 void TextureReference::
627 update_uv_range(
EggGroupNode *group, Palettizer::RemapUV remap) {
628 if (group->
is_of_type(EggGroup::get_class_type())) {
630 DCAST_INTO_V(egg_group, group);
632 if (egg_group->get_dart_type() != EggGroup::DT_none) {
634 remap = pal->_remap_char_uv;
638 bool group_any_uvs =
false;
639 LTexCoordd group_min_uv, group_max_uv;
641 EggGroupNode::iterator ci;
642 for (ci = group->begin(); ci != group->end(); ci++) {
644 if (child->
is_of_type(EggNurbsSurface::get_class_type())) {
648 }
else if (child->
is_of_type(EggPrimitive::get_class_type())) {
649 if (remap != Palettizer::RU_never) {
652 LTexCoordd geom_min_uv, geom_max_uv;
654 if (get_geom_uvs(geom, geom_min_uv, geom_max_uv)) {
655 if (remap == Palettizer::RU_poly) {
656 LVector2d trans = translate_uv(geom_min_uv, geom_max_uv);
657 trans = trans * _inv_tex_mat;
658 if (!trans.almost_equal(LVector2d::zero())) {
659 translate_geom_uvs(geom, trans);
662 collect_uv(group_any_uvs, group_min_uv, group_max_uv,
663 geom_min_uv, geom_max_uv);
669 }
else if (child->
is_of_type(EggGroupNode::get_class_type())) {
671 update_uv_range(cg, remap);
675 if (group_any_uvs && remap == Palettizer::RU_group) {
676 LVector2d trans = translate_uv(group_min_uv, group_max_uv);
677 trans = trans * _inv_tex_mat;
678 if (!trans.almost_equal(LVector2d::zero())) {
679 for (ci = group->begin(); ci != group->end(); ci++) {
681 if (child->
is_of_type(EggPrimitive::get_class_type())) {
684 translate_geom_uvs(geom, trans);
696 bool TextureReference::
698 LTexCoordd &geom_min_uv, LTexCoordd &geom_max_uv) {
700 bool geom_any_uvs =
false;
702 EggPrimitive::iterator pi;
703 for (pi = geom->begin(); pi != geom->end(); ++pi) {
705 if (vtx->
has_uv(uv_name)) {
706 LTexCoordd uv = vtx->
get_uv(uv_name) * _tex_mat;
707 collect_uv(geom_any_uvs, geom_min_uv, geom_max_uv, uv, uv);
717 void TextureReference::
718 translate_geom_uvs(
EggPrimitive *geom,
const LTexCoordd &trans)
const {
721 EggPrimitive::iterator pi;
722 for (pi = geom->begin(); pi != geom->end(); ++pi) {
724 if (vtx->
has_uv(uv_name)) {
726 vtx_copy.set_uv(uv_name, vtx_copy.get_uv(uv_name) + trans);
742 void TextureReference::
743 collect_nominal_uv_range() {
744 static const int num_nurbs_uvs = 4;
745 static LTexCoordd nurbs_uvs[num_nurbs_uvs] = {
746 LTexCoordd(0.0, 0.0),
747 LTexCoordd(0.0, 1.0),
748 LTexCoordd(1.0, 1.0),
752 for (
int i = 0; i < num_nurbs_uvs; i++) {
753 LTexCoordd uv = nurbs_uvs[i] * _tex_mat;
754 collect_uv(_any_uvs, _min_uv, _max_uv, uv, uv);
762 void TextureReference::
763 collect_uv(
bool &any_uvs, LTexCoordd &min_uv, LTexCoordd &max_uv,
764 const LTexCoordd &got_min_uv,
const LTexCoordd &got_max_uv) {
766 min_uv.set(min(min_uv[0], got_min_uv[0]),
767 min(min_uv[1], got_min_uv[1]));
768 max_uv.set(max(max_uv[0], got_max_uv[0]),
769 max(max_uv[1], got_max_uv[1]));
782 LVector2d TextureReference::
783 translate_uv(
const LTexCoordd &min_uv,
const LTexCoordd &max_uv) {
784 LTexCoordd center = (min_uv + max_uv) / 2;
785 return LVector2d(-floor(center[0]), -floor(center[1]));
794 register_factory(get_class_type(), make_TextureReference);
810 _tex_mat.write_datagram(datagram);
811 _inv_tex_mat.write_datagram(datagram);
837 if (p_list[pi] !=
nullptr) {
838 DCAST_INTO_R(_egg_file, p_list[pi], pi);
842 if (p_list[pi] !=
nullptr) {
843 DCAST_INTO_R(_source_texture, p_list[pi], pi);
847 if (p_list[pi] !=
nullptr) {
848 DCAST_INTO_R(_placement, p_list[pi], pi);
869 me->fillin(scan, manager);
877 void TextureReference::
882 if (Palettizer::_read_pi_version >= 11) {
886 _tex_mat.read_datagram(scan);
887 _inv_tex_mat.read_datagram(scan);
898 _wrap_u = (EggTexture::WrapMode)scan.
get_int32();
899 _wrap_v = (EggTexture::WrapMode)scan.
get_int32();
900 _properties.
fillin(scan, manager);
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
A class to retrieve the individual data elements previously stored in a Datagram.
PN_float64 get_float64()
Extracts a 64-bit floating-point number.
bool get_bool()
Extracts a boolean value.
std::string get_string()
Extracts a variable-length string.
int32_t get_int32()
Extracts a signed 32-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_int32(int32_t value)
Adds a signed 32-bit integer to the datagram.
void add_bool(bool value)
Adds a boolean value to the datagram.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
void add_float64(PN_float64 value)
Adds a 64-bit floating-point number to the datagram.
This represents a texture filename as it has been resized and copied to the map directory (e....
This is the primary interface into all the egg data, and the root of the egg file structure.
This represents a single egg file known to the palettizer.
void mark_stale()
Marks this particular egg file as stale, meaning that something has changed, such as the location of ...
const Filename & get_filename() const
Returns a nonmodifiable reference to the filename.
A base class for nodes in the hierarchy that are not leaf nodes.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
A base class for things that may be directly added into the egg hierarchy.
A parametric NURBS surface.
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
bool has_texture() const
Returns true if the primitive has any textures specified, false otherwise.
void replace(iterator position, EggVertex *vertex)
Replaces the vertex at the indicated position with the indicated vertex.
void set_alpha_mode(AlphaMode mode)
Specifies precisely how the transparency for this geometry should be achieved, or if it should be use...
AlphaMode get_alpha_mode() const
Returns the alpha mode that was set, or AM_unspecified if nothing was set.
Defines a texture map that may be applied to geometry.
WrapMode determine_wrap_u() const
Determines the appropriate wrap in the U direction.
get_uv_name
Returns the texcoord name that has been specified for this texture, or the empty string if no texcoor...
get_alpha_file_channel
Returns the particular channel that has been specified for the alpha-file image, or 0 if no channel h...
bool has_alpha_channel(int num_components) const
Given the number of color components (channels) in the image file as actually read from the disk,...
WrapMode determine_wrap_v() const
Determines the appropriate wrap in the V direction.
get_anisotropic_degree
Returns the anisotropic filtering degree that has been specified for this texture,...
get_alpha_filename
Returns the separate file assigned for the alpha channel.
has_alpha_filename
Returns true if a separate file for the alpha component has been applied, false otherwise.
EggVertex * create_unique_vertex(const EggVertex ©)
Creates a new vertex in the pool that is a copy of the indicated one and returns it.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
EggVertexPool * get_pool() const
Returns the vertex pool this vertex belongs in.
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
GroupRef::size_type gref_size() const
Returns the number of elements between gref_begin() and gref_end().
void copy_grefs_from(const EggVertex &other)
Copies all the group references from the other vertex onto this one.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
The name of a file, such as a texture file or an Egg file.
std::string get_basename() const
Returns the basename part of the filename.
std::string get_basename_wo_extension() const
Returns the basename part of the filename, without the file extension.
void update_egg_tex(EggTexture *egg_tex) const
Sets the indicated EggTexture to refer to this file.
int get_num_channels() const
Returns the number of channels of the image.
void update_properties(const TextureProperties &properties)
If the indicate TextureProperties structure is more specific than this one, updates this one.
bool has_num_channels() const
Returns true if the number of channels in the image is known, false otherwise.
This is a single palette image, one of several within a PalettePage, which is in turn one of several ...
TextureImage * get_texture(const std::string &name)
Returns the TextureImage with the given name.
This is a texture image reference as it appears in an egg file: the source image of the texture.
bool get_size()
Determines the size of the SourceTextureImage, if it is not already known.
TextureImage * get_texture() const
Returns the particular texture that this image is one of the sources for.
This represents a single source texture that is referenced by one or more egg files.
EggTexture::WrapMode get_txa_wrap_v() const
Returns the wrap mode specified in the v direction in the txa file, or WM_unspecified.
EggRenderMode::AlphaMode get_alpha_mode() const
Returns the alpha mode that should be used to render objects with this texture, as specified by the u...
SourceTextureImage * get_source(const Filename &filename, const Filename &alpha_filename, int alpha_file_channel)
Returns the SourceTextureImage corresponding to the given filename(s).
EggTexture::WrapMode get_txa_wrap_u() const
Returns the wrap mode specified in the u direction in the txa file, or WM_unspecified.
This corresponds to a particular assignment of a TextureImage with a PaletteGroup,...
OmitReason get_omit_reason() const
Returns the reason the texture has been omitted from a palette image, or OR_none if it has not.
DestTextureImage * get_dest() const
Returns the DestTextureImage that corresponds to this texture as it was copied to the install directo...
void remove_egg(TextureReference *reference)
Notes that a particular egg file is no longer using this particular TexturePlacement.
void add_egg(TextureReference *reference)
Records the fact that a particular egg file is using this particular TexturePlacement.
PaletteImage * get_image() const
Returns the particular PaletteImage on which the texture has been placed.
void compute_tex_matrix(LMatrix3d &transform)
Stores in the indicated matrix the appropriate texture matrix transform for the new placement of the ...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
bool egg_properties_match(const TextureProperties &other) const
Returns true if all of the properties that are reflected directly in an egg file match between this T...
void fillin(DatagramIterator &scan, BamReader *manager)
Reads the binary data from the given datagram iterator, which was written by a previous call to write...
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
This is the particular reference of a texture filename by an egg file.
bool has_uvs() const
Returns true if this TextureReference actually uses the texture on geometry, with UV's and everything...
const std::string & get_tref_name() const
Returns the name of the EggTexture entry that references this texture.
bool is_equivalent(const TextureReference &other) const
Returns true if all essential properties of this TextureReference are the same as that of the other,...
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
void apply_properties_to_source()
Applies the texture properties as read from the egg file to the source image's properties.
void update_egg()
Updates the egg file with all the relevant information to reference the texture in its new home,...
const LTexCoordd & get_max_uv() const
Returns the maximum UV coordinate in use for the texture by this reference.
void from_egg(EggFile *egg_file, EggData *data, EggTexture *egg_tex)
Sets up the TextureReference using information extracted from an egg file.
void clear_placement()
Removes any reference to a TexturePlacement.
void rebind_egg_data(EggData *data, EggTexture *egg_tex)
After an EggData has previously been released via release_egg_data(), this can be called to indicate ...
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
EggTexture::WrapMode get_wrap_u() const
Returns the specification for the wrapping in the U direction.
void set_placement(TexturePlacement *placement)
Sets the particular TexturePlacement that is appropriate for this egg file.
bool operator<(const TextureReference &other) const
Defines an ordering of TextureReference pointers in alphabetical order by their tref name.
EggFile * get_egg_file() const
Returns the EggFile that references this texture.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
EggTexture::WrapMode get_wrap_v() const
Returns the specification for the wrapping in the V direction.
TexturePlacement * get_placement() const
Returns the particular TexturePlacement that is appropriate for this egg file.
const LTexCoordd & get_min_uv() const
Returns the minimum UV coordinate in use for the texture by this reference.
TextureImage * get_texture() const
Returns the TextureImage that this object refers to.
SourceTextureImage * get_source() const
Returns the SourceTextureImage that this object refers to.
void from_egg_quick(const TextureReference &other)
Sets up the pointers within the TextureReference to the same egg file pointers indicated by the other...
void release_egg_data()
Called to indicate that the EggData previously passed to from_egg() is about to be deallocated,...
void mark_egg_stale()
Marks the egg file that shares this reference as stale.
TypeHandle is the identifier used to differentiate C++ class types.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Base class for objects that can be written to and read from Bam files.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.