Panda3D
|
An object specifically designed to transform the vertices of a Geom without disturbing indexing or affecting any other Geoms that may share the same vertex arrays, and without needlessly wasting memory when different Geoms sharing the same vertex arrays are transformed by the same amount. More...
#include "geomTransformer.h"
Classes | |
class | AlreadyCollectedData |
class | NewCollectedData |
class | NewCollectedKey |
class | NewVertexData |
class | SourceColors |
class | SourceData |
class | SourceFormat |
class | SourceGeom |
class | SourceTexCoords |
class | SourceTextureColors |
class | SourceVertices |
class | VertexDataAssoc |
Public Member Functions | |
GeomTransformer (const GeomTransformer ©) | |
bool | apply_state (GeomNode *node, const RenderState *state) |
Applies the indicated render state to all the of Geoms. | |
bool | apply_texture_colors (GeomNode *node, const RenderState *state) |
Removes textures from Geoms by applying the texture colors to the vertices. | |
bool | apply_texture_colors (Geom *geom, TextureStage *ts, Texture *tex, const TexMatrixAttrib *tma, const LColor &base_color, bool keep_vertex_color) |
Removes textures from Geoms by applying the texture colors to the vertices. | |
int | collect_vertex_data (Geom *geom, int collect_bits, bool format_only) |
Collects together GeomVertexDatas from different geoms into one big (or several big) GeomVertexDatas. | |
int | collect_vertex_data (GeomNode *node, int collect_bits, bool format_only) |
Collects together individual GeomVertexData structures that share the same format into one big GeomVertexData structure. | |
bool | doubleside (GeomNode *node) |
Duplicates triangles in this GeomNode so that each triangle is back-to-back with another triangle facing in the opposite direction. | |
void | finish_apply () |
Should be called after performing any operations--particularly PandaNode::apply_attribs_to_vertices()--that might result in new GeomVertexData objects being duplicated and modified. | |
int | finish_collect (bool format_only) |
This should be called after a call to collect_vertex_data() to finalize the changes and apply them to the vertices in the graph. | |
int | get_max_collect_vertices () const |
Returns the maximum number of vertices that may be put into a single GeomVertexData as a result of collecting multiple objects in collect_vertex_data(). | |
bool | make_compatible_state (GeomNode *node) |
Checks if the different geoms in the GeomNode have different RenderStates. | |
PT (Geom) premunge_geom(const Geom *geom | |
void | register_vertices (GeomNode *node, bool might_have_unused) |
Records the association of the Geom with its GeomVertexData, for the purpose of later removing unused vertices. | |
void | register_vertices (Geom *geom, bool might_have_unused) |
Records the association of the Geom with its GeomVertexData, for the purpose of later removing unused vertices. | |
bool | remove_column (GeomNode *node, const InternalName *column) |
Removes the named column from the vertex datas within the GeomNode. | |
bool | remove_column (Geom *geom, const InternalName *column) |
Removes the named column from the vertex data in the Geom. | |
bool | reverse (GeomNode *node) |
Reverses the winding order of triangles in this GeomNode so that each triangle is facing in the opposite direction. | |
bool | reverse_normals (Geom *geom) |
Reverses the lighting normals on the vertex data, if any. | |
bool | set_color (GeomNode *node, const LColor &color) |
Overrides the color indicated within the GeomNode with the given replacement color. | |
bool | set_color (Geom *geom, const LColor &color) |
Overrides the color indicated within the Geom with the given replacement color. | |
bool | set_format (Geom *geom, const GeomVertexFormat *new_format) |
Changes the GeomVertexData of the indicated Geom to use the specified format. | |
void | set_max_collect_vertices (int max_collect_vertices) |
Specifies the maximum number of vertices that may be put into a single GeomVertexData as a result of collecting multiple objects in collect_vertex_data(). | |
bool | transform_colors (Geom *geom, const LVecBase4 &scale) |
Transforms the colors in the indicated Geom by the indicated scale. | |
bool | transform_colors (GeomNode *node, const LVecBase4 &scale) |
Transforms the colors in all of the Geoms within the indicated GeomNode by the indicated scale. | |
bool | transform_texcoords (GeomNode *node, const InternalName *from_name, InternalName *to_name, const LMatrix4 &mat) |
Transforms the texture coordinates in all of the Geoms within the indicated GeomNode by the indicated matrix. | |
bool | transform_texcoords (Geom *geom, const InternalName *from_name, InternalName *to_name, const LMatrix4 &mat) |
Transforms the texture coordinates in the indicated Geom by the indicated matrix. | |
bool | transform_vertices (GeomNode *node, const LMatrix4 &mat) |
Transforms the vertices and the normals in all of the Geoms within the indicated GeomNode by the indicated matrix. | |
bool | transform_vertices (Geom *geom, const LMatrix4 &mat) |
Transforms the vertices and the normals in the indicated Geom by the indicated matrix. | |
Static Public Member Functions | |
static void | init_type () |
Public Attributes | |
GeomMunger * | munger |
An object specifically designed to transform the vertices of a Geom without disturbing indexing or affecting any other Geoms that may share the same vertex arrays, and without needlessly wasting memory when different Geoms sharing the same vertex arrays are transformed by the same amount.
If you create a single GeomTransformer and use it to transform a number of different Geoms by various transformations, then those Geoms which happen to share the same arrays and are transformed by the same amounts will still share the same arrays as each other (but different from the original arrays).
Definition at line 46 of file geomTransformer.h.
bool GeomTransformer::apply_state | ( | GeomNode * | node, |
const RenderState * | state | ||
) |
Applies the indicated render state to all the of Geoms.
Returns true if the GeomNode was changed, false otherwise.
Definition at line 686 of file geomTransformer.cxx.
bool GeomTransformer::apply_texture_colors | ( | Geom * | geom, |
TextureStage * | ts, | ||
Texture * | tex, | ||
const TexMatrixAttrib * | tma, | ||
const LColor & | base_color, | ||
bool | keep_vertex_color | ||
) |
Removes textures from Geoms by applying the texture colors to the vertices.
See apply_texure_colors(GeomNode *, RenderState *).
Definition at line 422 of file geomTransformer.cxx.
References LMatrix4f::almost_equal(), TexMatrixAttrib::get_mat(), GeomVertexColumn::get_num_components(), TextureStage::get_texcoord_name(), TexMatrixAttrib::has_stage(), LMatrix4f::ident_mat(), set_color(), Geom::set_vertex_data(), and transform_colors().
Referenced by GeomNode::apply_attribs_to_vertices(), and apply_texture_colors().
bool GeomTransformer::apply_texture_colors | ( | GeomNode * | node, |
const RenderState * | state | ||
) |
Removes textures from Geoms by applying the texture colors to the vertices.
This is primarily useful to simplify a low-LOD model.
Only the bottommost texture is used (if there is more than one), and it is applied as if it were M_modulate, and WM_repeat, regardless of its actual settings. If the texture has a simple_ram_image, this may be used if the main image isn't resident.
After this call, there will be no texturing specified on the GeomNode level. Of course, there might still be texturing inherited from above.
Definition at line 624 of file geomTransformer.cxx.
References apply_texture_colors().
int GeomTransformer::collect_vertex_data | ( | Geom * | geom, |
int | collect_bits, | ||
bool | format_only | ||
) |
Collects together GeomVertexDatas from different geoms into one big (or several big) GeomVertexDatas.
Returns the number of unique GeomVertexDatas created.
If format_only is true, this only makes GeomVertexFormats compatible; it does not otherwise combine vertices.
You should follow this up with a call to finish_collect(), but you probably don't want to call this method directly anyway. Call SceneGraphReducer::collect_vertex_data() instead.
Definition at line 1031 of file geomTransformer.cxx.
Referenced by collect_vertex_data(), and SceneGraphReducer::r_collect_vertex_data().
int GeomTransformer::collect_vertex_data | ( | GeomNode * | node, |
int | collect_bits, | ||
bool | format_only | ||
) |
Collects together individual GeomVertexData structures that share the same format into one big GeomVertexData structure.
This is intended to minimize context switches on the graphics card.
If format_only is true, this only makes GeomVertexFormats compatible; it does not otherwise combine vertices.
You should follow this up with a call to finish_collect(), but you probably don't want to call this method directly anyway. Call SceneGraphReducer::collect_vertex_data() instead.
Definition at line 1140 of file geomTransformer.cxx.
References collect_vertex_data(), and finish_collect().
bool GeomTransformer::doubleside | ( | GeomNode * | node | ) |
Duplicates triangles in this GeomNode so that each triangle is back-to-back with another triangle facing in the opposite direction.
If the geometry has vertex normals, this will also duplicate and reverse the normals, so that lighting will work correctly from both sides. Note that calling this when the geometry is already doublesided (with back-to-back polygons) will result in multiple redundant coplanar polygons.
Also see CullFaceAttrib, which can enable rendering of both sides of a triangle without having to duplicate it (but which doesn't necessarily work in the presence of lighting).
Returns true if any Geoms are modified, false otherwise.
Definition at line 930 of file geomTransformer.cxx.
References GeomNode::add_geom(), GeomNode::get_geom_state(), GeomNode::get_num_geoms(), and reverse_normals().
void GeomTransformer::finish_apply | ( | ) |
Should be called after performing any operations--particularly PandaNode::apply_attribs_to_vertices()--that might result in new GeomVertexData objects being duplicated and modified.
This walks through those newly duplicated objects and ensures that redundant unused vertices have not been created, removing them if they have.
Definition at line 996 of file geomTransformer.cxx.
Referenced by SceneGraphReducer::apply_attribs(), SceneGraphReducer::make_compatible_state(), SceneGraphReducer::remove_column(), and SceneGraphReducer::remove_unused_vertices().
int GeomTransformer::finish_collect | ( | bool | format_only | ) |
This should be called after a call to collect_vertex_data() to finalize the changes and apply them to the vertices in the graph.
If this is not called, it will be called automatically by the GeomTransformer destructor.
If format_only is true, this returns the number of GeomVertexDatas modified to use a new format. If false, it returns the number of GeomVertexDatas created.
Definition at line 1189 of file geomTransformer.cxx.
Referenced by SceneGraphReducer::collect_vertex_data(), collect_vertex_data(), SceneGraphReducer::make_compatible_format(), and SceneGraphReducer::r_collect_vertex_data().
int GeomTransformer::get_max_collect_vertices | ( | ) | const [inline] |
Returns the maximum number of vertices that may be put into a single GeomVertexData as a result of collecting multiple objects in collect_vertex_data().
Definition at line 24 of file geomTransformer.I.
bool GeomTransformer::make_compatible_state | ( | GeomNode * | node | ) |
Checks if the different geoms in the GeomNode have different RenderStates.
If so, tries to make the RenderStates the same. It does this by canonicalizing the ColorAttribs, and in the future, possibly other attribs.
Definition at line 801 of file geomTransformer.cxx.
References ColorAttrib::get_color(), ColorAttrib::get_color_type(), GeomNode::get_num_geoms(), and set_color().
Referenced by SceneGraphReducer::r_make_compatible_state().
void GeomTransformer::register_vertices | ( | GeomNode * | node, |
bool | might_have_unused | ||
) |
Records the association of the Geom with its GeomVertexData, for the purpose of later removing unused vertices.
Definition at line 99 of file geomTransformer.cxx.
References Thread::get_current_thread(), and register_vertices().
void GeomTransformer::register_vertices | ( | Geom * | geom, |
bool | might_have_unused | ||
) |
Records the association of the Geom with its GeomVertexData, for the purpose of later removing unused vertices.
Definition at line 83 of file geomTransformer.cxx.
Referenced by GeomNode::apply_attribs_to_vertices(), SceneGraphReducer::r_register_vertices(), and register_vertices().
bool GeomTransformer::remove_column | ( | GeomNode * | node, |
const InternalName * | column | ||
) |
Removes the named column from the vertex datas within the GeomNode.
Returns true if the GeomNode was changed, false otherwise.
Definition at line 773 of file geomTransformer.cxx.
References remove_column().
bool GeomTransformer::remove_column | ( | Geom * | geom, |
const InternalName * | column | ||
) |
Removes the named column from the vertex data in the Geom.
Returns true if the Geom was changed, false otherwise.
Definition at line 750 of file geomTransformer.cxx.
References set_format().
Referenced by GeomNode::apply_attribs_to_vertices(), SceneGraphReducer::r_remove_column(), and remove_column().
bool GeomTransformer::reverse | ( | GeomNode * | node | ) |
Reverses the winding order of triangles in this GeomNode so that each triangle is facing in the opposite direction.
If the geometry has vertex normals, this will also reverse the normals, so that lighting will work correctly.
Also see CullFaceAttrib, which can effectively change the facing of a triangle having to modify its vertices (but which doesn't necessarily work in the presence of lighting).
Returns true if any Geoms are modified, false otherwise.
Definition at line 972 of file geomTransformer.cxx.
References GeomNode::get_num_geoms(), and reverse_normals().
bool GeomTransformer::reverse_normals | ( | Geom * | geom | ) |
Reverses the lighting normals on the vertex data, if any.
Returns true if the Geom was changed, false otherwise.
Definition at line 886 of file geomTransformer.cxx.
References Geom::set_vertex_data().
Referenced by GeomNode::apply_attribs_to_vertices(), doubleside(), and reverse().
Overrides the color indicated within the Geom with the given replacement color.
Returns true if the Geom was changed, false otherwise.
Definition at line 290 of file geomTransformer.cxx.
References Geom::set_vertex_data().
Referenced by GeomNode::apply_attribs_to_vertices(), apply_texture_colors(), make_compatible_state(), and set_color().
Overrides the color indicated within the GeomNode with the given replacement color.
Returns true if any Geom in the GeomNode was changed, false otherwise.
Definition at line 327 of file geomTransformer.cxx.
References set_color().
bool GeomTransformer::set_format | ( | Geom * | geom, |
const GeomVertexFormat * | new_format | ||
) |
Changes the GeomVertexData of the indicated Geom to use the specified format.
Definition at line 711 of file geomTransformer.cxx.
References Geom::set_vertex_data().
Referenced by remove_column().
void GeomTransformer::set_max_collect_vertices | ( | int | max_collect_vertices | ) | [inline] |
Specifies the maximum number of vertices that may be put into a single GeomVertexData as a result of collecting multiple objects in collect_vertex_data().
Definition at line 36 of file geomTransformer.I.
Referenced by SceneGraphReducer::clear_gsg(), and SceneGraphReducer::set_gsg().
Transforms the colors in the indicated Geom by the indicated scale.
Returns true if the Geom was changed, false otherwise.
Definition at line 353 of file geomTransformer.cxx.
References Geom::set_vertex_data().
Referenced by GeomNode::apply_attribs_to_vertices(), apply_texture_colors(), and transform_colors().
Transforms the colors in all of the Geoms within the indicated GeomNode by the indicated scale.
Does not destructively change Geoms; instead, a copy will be made of each Geom to be changed, in case multiple GeomNodes reference the same Geom. Returns true if the GeomNode was changed, false otherwise.
Definition at line 394 of file geomTransformer.cxx.
References transform_colors().
bool GeomTransformer::transform_texcoords | ( | Geom * | geom, |
const InternalName * | from_name, | ||
InternalName * | to_name, | ||
const LMatrix4 & | mat | ||
) |
Transforms the texture coordinates in the indicated Geom by the indicated matrix.
Returns true if the Geom was changed, false otherwise.
Definition at line 195 of file geomTransformer.cxx.
References GeomVertexColumn::get_contents(), GeomVertexReader::get_data4(), GeomVertexColumn::get_num_components(), GeomVertexColumn::get_numeric_type(), GeomVertexReader::is_at_end(), GeomVertexWriter::set_data4(), and Geom::set_vertex_data().
Referenced by GeomNode::apply_attribs_to_vertices(), and transform_texcoords().
bool GeomTransformer::transform_texcoords | ( | GeomNode * | node, |
const InternalName * | from_name, | ||
InternalName * | to_name, | ||
const LMatrix4 & | mat | ||
) |
Transforms the texture coordinates in all of the Geoms within the indicated GeomNode by the indicated matrix.
Does not destructively change Geoms; instead, a copy will be made of each Geom to be changed, in case multiple GeomNodes reference the same Geom. Returns true if the GeomNode was changed, false otherwise.
Definition at line 262 of file geomTransformer.cxx.
References transform_texcoords().
Transforms the vertices and the normals in all of the Geoms within the indicated GeomNode by the indicated matrix.
Does not destructively change Geoms; instead, a copy will be made of each Geom to be changed, in case multiple GeomNodes reference the same Geom. Returns true if the GeomNode was changed, false otherwise.
Definition at line 160 of file geomTransformer.cxx.
References Thread::get_current_thread(), PandaNode::mark_internal_bounds_stale(), and transform_vertices().
Transforms the vertices and the normals in the indicated Geom by the indicated matrix.
Returns true if the Geom was changed, false otherwise.
Definition at line 122 of file geomTransformer.cxx.
References Geom::set_vertex_data().
Referenced by GeomNode::apply_attribs_to_vertices(), transform_vertices(), and GeomNode::xform().