Panda3D
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
GeomTransformer Class Reference

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"

Public Member Functions

 GeomTransformer (const GeomTransformer &copy)
 
bool apply_state (GeomNode *node, const RenderState *state)
 Applies the indicated render state to all the of Geoms. More...
 
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. More...
 
bool apply_texture_colors (GeomNode *node, const RenderState *state)
 Removes textures from Geoms by applying the texture colors to the vertices. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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(). More...
 
bool make_compatible_state (GeomNode *node)
 Checks if the different geoms in the GeomNode have different RenderStates. More...
 
 PT (Geom) premunge_geom(const Geom *geom
 
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. More...
 
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. More...
 
bool remove_column (Geom *geom, const InternalName *column)
 Removes the named column from the vertex data in the Geom. More...
 
bool remove_column (GeomNode *node, const InternalName *column)
 Removes the named column from the vertex datas within the GeomNode. More...
 
bool reverse (GeomNode *node)
 Reverses the winding order of triangles in this GeomNode so that each triangle is facing in the opposite direction. More...
 
bool reverse_normals (Geom *geom)
 Reverses the lighting normals on the vertex data, if any. More...
 
bool set_color (Geom *geom, const LColor &color)
 Overrides the color indicated within the Geom with the given replacement color. More...
 
bool set_color (GeomNode *node, const LColor &color)
 Overrides the color indicated within the GeomNode with the given replacement color. More...
 
bool set_format (Geom *geom, const GeomVertexFormat *new_format)
 Changes the GeomVertexData of the indicated Geom to use the specified format. More...
 
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(). More...
 
bool transform_colors (Geom *geom, const LVecBase4 &scale)
 Transforms the colors in the indicated Geom by the indicated scale. More...
 
bool transform_colors (GeomNode *node, const LVecBase4 &scale)
 Transforms the colors in all of the Geoms within the indicated GeomNode by the indicated scale. More...
 
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. More...
 
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. More...
 
bool transform_vertices (Geom *geom, const LMatrix4 &mat)
 Transforms the vertices and the normals in the indicated Geom by the indicated matrix. More...
 
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. More...
 

Static Public Member Functions

static void init_type ()
 

Public Attributes

GeomMungermunger
 

Detailed Description

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 42 of file geomTransformer.h.

Member Function Documentation

◆ apply_state()

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 636 of file geomTransformer.cxx.

◆ apply_texture_colors() [1/2]

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 382 of file geomTransformer.cxx.

◆ apply_texture_colors() [2/2]

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 577 of file geomTransformer.cxx.

◆ collect_vertex_data() [1/2]

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 944 of file geomTransformer.cxx.

Referenced by collect_vertex_data().

◆ collect_vertex_data() [2/2]

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 1047 of file geomTransformer.cxx.

References collect_vertex_data(), and finish_collect().

◆ doubleside()

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 857 of file geomTransformer.cxx.

References GeomNode::get_num_geoms.

◆ finish_apply()

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 913 of file geomTransformer.cxx.

◆ finish_collect()

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 1091 of file geomTransformer.cxx.

Referenced by collect_vertex_data().

◆ get_max_collect_vertices()

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 20 of file geomTransformer.I.

◆ make_compatible_state()

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 739 of file geomTransformer.cxx.

References GeomNode::get_num_geoms.

◆ register_vertices() [1/2]

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 75 of file geomTransformer.cxx.

◆ register_vertices() [2/2]

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 88 of file geomTransformer.cxx.

◆ remove_column() [1/2]

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 695 of file geomTransformer.cxx.

Referenced by remove_column().

◆ remove_column() [2/2]

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 715 of file geomTransformer.cxx.

References remove_column().

◆ reverse()

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 894 of file geomTransformer.cxx.

References GeomNode::get_num_geoms.

◆ 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 820 of file geomTransformer.cxx.

◆ set_color() [1/2]

bool GeomTransformer::set_color ( Geom geom,
const LColor &  color 
)

Overrides the color indicated within the Geom with the given replacement color.

Returns true if the Geom was changed, false otherwise.

Definition at line 262 of file geomTransformer.cxx.

References Geom::set_vertex_data().

Referenced by set_color().

◆ set_color() [2/2]

bool GeomTransformer::set_color ( GeomNode node,
const LColor &  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 296 of file geomTransformer.cxx.

References set_color().

◆ set_format()

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 659 of file geomTransformer.cxx.

◆ set_max_collect_vertices()

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 30 of file geomTransformer.I.

Referenced by SceneGraphReducer::clear_gsg().

◆ transform_colors() [1/2]

bool GeomTransformer::transform_colors ( Geom geom,
const LVecBase4 &  scale 
)

Transforms the colors in the indicated Geom by the indicated scale.

Returns true if the Geom was changed, false otherwise.

Definition at line 319 of file geomTransformer.cxx.

◆ transform_colors() [2/2]

bool GeomTransformer::transform_colors ( GeomNode node,
const LVecBase4 &  scale 
)

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 357 of file geomTransformer.cxx.

◆ transform_texcoords() [1/2]

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 174 of file geomTransformer.cxx.

◆ transform_texcoords() [2/2]

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 237 of file geomTransformer.cxx.

◆ transform_vertices() [1/2]

bool GeomTransformer::transform_vertices ( Geom geom,
const LMatrix4 &  mat 
)

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 108 of file geomTransformer.cxx.

Referenced by GeomNode::apply_attribs_to_vertices().

◆ transform_vertices() [2/2]

bool GeomTransformer::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.

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 142 of file geomTransformer.cxx.


The documentation for this class was generated from the following files: