add vis_2d

This commit is contained in:
David Rose 2011-03-14 21:58:32 +00:00
parent d5f8a968a2
commit aea8fa70bf
3 changed files with 67 additions and 20 deletions

View File

@ -180,3 +180,26 @@ INLINE bool PfmFile::
get_vis_inverse() const { get_vis_inverse() const {
return _vis_inverse; return _vis_inverse;
} }
////////////////////////////////////////////////////////////////////
// Function: PfmFile::set_vis_2d
// Access: Published
// Description: Sets the vis_2d flag. When this flag is true,
// only the first two (x, y) value of each depth point
// is considered meaningful; the z component is ignored.
// This is only relevant for generating visualizations.
////////////////////////////////////////////////////////////////////
INLINE void PfmFile::
set_vis_2d(bool vis_2d) {
_vis_2d = vis_2d;
}
////////////////////////////////////////////////////////////////////
// Function: PfmFile::get_vis_2d
// Access: Published
// Description: Returns the vis_2d flag. See set_vis_2d().
////////////////////////////////////////////////////////////////////
INLINE bool PfmFile::
get_vis_2d() const {
return _vis_2d;
}

View File

@ -37,6 +37,7 @@ PfmFile::
PfmFile() { PfmFile() {
_zero_special = false; _zero_special = false;
_vis_inverse = false; _vis_inverse = false;
_vis_2d = false;
clear(); clear();
} }
@ -52,7 +53,9 @@ PfmFile(const PfmFile &copy) :
_y_size(copy._y_size), _y_size(copy._y_size),
_scale(copy._scale), _scale(copy._scale),
_num_channels(copy._num_channels), _num_channels(copy._num_channels),
_zero_special(copy._zero_special) _zero_special(copy._zero_special),
_vis_inverse(copy._vis_inverse),
_vis_2d(copy._vis_2d)
{ {
} }
@ -69,6 +72,8 @@ operator = (const PfmFile &copy) {
_scale = copy._scale; _scale = copy._scale;
_num_channels = copy._num_channels; _num_channels = copy._num_channels;
_zero_special = copy._zero_special; _zero_special = copy._zero_special;
_vis_inverse = copy._vis_inverse;
_vis_2d = copy._vis_2d;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -613,13 +618,18 @@ generate_vis_points() const {
CPT(GeomVertexFormat) format; CPT(GeomVertexFormat) format;
if (_vis_inverse) { if (_vis_inverse) {
// We need a 3-d texture coordinate if we're inverted the vis. if (_vis_2d) {
GeomVertexArrayFormat *v3t3 = new GeomVertexArrayFormat format = GeomVertexFormat::get_v3t2();
(InternalName::get_vertex(), 3, } else {
Geom::NT_float32, Geom::C_point, // We need a 3-d texture coordinate if we're inverting the vis
InternalName::get_texcoord(), 3, // and it's 3-d.
Geom::NT_float32, Geom::C_texcoord); GeomVertexArrayFormat *v3t3 = new GeomVertexArrayFormat
format = GeomVertexFormat::register_format(v3t3); (InternalName::get_vertex(), 3,
Geom::NT_float32, Geom::C_point,
InternalName::get_texcoord(), 3,
Geom::NT_float32, Geom::C_texcoord);
format = GeomVertexFormat::register_format(v3t3);
}
} else { } else {
format = GeomVertexFormat::get_v3t2(); format = GeomVertexFormat::get_v3t2();
} }
@ -638,6 +648,9 @@ generate_vis_points() const {
if (_vis_inverse) { if (_vis_inverse) {
vertex.add_data2f(uv); vertex.add_data2f(uv);
texcoord.add_data3f(point); texcoord.add_data3f(point);
} else if (_vis_2d) {
vertex.add_data2f(point[0], point[1]);
texcoord.add_data2f(uv);
} else { } else {
vertex.add_data3f(point); vertex.add_data3f(point);
texcoord.add_data2f(uv); texcoord.add_data2f(uv);
@ -724,19 +737,24 @@ make_vis_mesh_geom(GeomNode *gnode, bool inverted) const {
} }
CPT(GeomVertexFormat) format; CPT(GeomVertexFormat) format;
if (_vis_inverse) { if (_vis_2d) {
// We need a 3-d texture coordinate if we're inverting the vis. // No normals needed if we're just generating a 2-d mesh.
// But we don't need normals in that case. format = GeomVertexFormat::get_v3t2();
GeomVertexArrayFormat *v3t3 = new GeomVertexArrayFormat
(InternalName::get_vertex(), 3,
Geom::NT_float32, Geom::C_point,
InternalName::get_texcoord(), 3,
Geom::NT_float32, Geom::C_texcoord);
format = GeomVertexFormat::register_format(v3t3);
} else { } else {
// Otherwise, we only need a 2-d texture coordinate, and we do if (_vis_inverse) {
// want normals. // We need a 3-d texture coordinate if we're inverting the vis
format = GeomVertexFormat::get_v3n3t2(); // and it's 3-d. But we still don't need normals in that case.
GeomVertexArrayFormat *v3t3 = new GeomVertexArrayFormat
(InternalName::get_vertex(), 3,
Geom::NT_float32, Geom::C_point,
InternalName::get_texcoord(), 3,
Geom::NT_float32, Geom::C_texcoord);
format = GeomVertexFormat::register_format(v3t3);
} else {
// Otherwise, we only need a 2-d texture coordinate, and we do
// want normals.
format = GeomVertexFormat::get_v3n3t2();
}
} }
for (int yci = 0; yci < num_y_cells; ++yci) { for (int yci = 0; yci < num_y_cells; ++yci) {
@ -783,6 +801,9 @@ make_vis_mesh_geom(GeomNode *gnode, bool inverted) const {
if (_vis_inverse) { if (_vis_inverse) {
vertex.add_data2f(uv); vertex.add_data2f(uv);
texcoord.add_data3f(point); texcoord.add_data3f(point);
} else if (_vis_2d) {
vertex.add_data2f(point[0], point[1]);
texcoord.add_data2f(uv);
} else { } else {
vertex.add_data3f(point); vertex.add_data3f(point);
texcoord.add_data2f(uv); texcoord.add_data2f(uv);

View File

@ -67,6 +67,8 @@ PUBLISHED:
INLINE void set_vis_inverse(bool vis_inverse); INLINE void set_vis_inverse(bool vis_inverse);
INLINE bool get_vis_inverse() const; INLINE bool get_vis_inverse() const;
INLINE void set_vis_2d(bool vis_2d);
INLINE bool get_vis_2d() const;
NodePath generate_vis_points() const; NodePath generate_vis_points() const;
NodePath generate_vis_mesh(bool double_sided) const; NodePath generate_vis_mesh(bool double_sided) const;
@ -104,6 +106,7 @@ private:
bool _zero_special; bool _zero_special;
bool _vis_inverse; bool _vis_inverse;
bool _vis_2d;
}; };
#include "pfmFile.I" #include "pfmFile.I"