mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-17 12:12:10 -04:00
*** empty log message ***
This commit is contained in:
parent
5251fa5667
commit
cb4340724d
@ -76,3 +76,67 @@ get_egg_filename() const {
|
||||
return _egg_filename;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggData::recompute_vertex_normals
|
||||
// Access: Public
|
||||
// Description: Recomputes all the vertex normals for polygon
|
||||
// geometry at this group node and below so that they
|
||||
// accurately reflect the vertex positions. A shared
|
||||
// edge between two polygons (even in different groups)
|
||||
// is considered smooth if the angle between the two
|
||||
// edges is less than threshold degrees.
|
||||
//
|
||||
// This function also removes degenerate polygons that
|
||||
// do not have enough vertices to define a normal. It
|
||||
// does not affect normals for other kinds of primitives
|
||||
// like Nurbs or Points.
|
||||
//
|
||||
// This function does not remove or adjust vertices in
|
||||
// the vertex pool; it only adds new vertices with the
|
||||
// correct normals. Thus, it is a good idea to call
|
||||
// remove_unused_vertices() after calling this.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void EggData::
|
||||
recompute_vertex_normals(double threshold) {
|
||||
EggGroupNode::recompute_vertex_normals(threshold, _coordsys);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggData::recompute_polygon_normals
|
||||
// Access: Public
|
||||
// Description: Recomputes all the polygon normals for polygon
|
||||
// geometry at this group node and below so that they
|
||||
// accurately reflect the vertex positions. Normals are
|
||||
// removed from the vertices and defined only on
|
||||
// polygons, giving the geometry a faceted appearance.
|
||||
//
|
||||
// This function also removes degenerate polygons that
|
||||
// do not have enough vertices to define a normal. It
|
||||
// does not affect normals for other kinds of primitives
|
||||
// like Nurbs or Points.
|
||||
//
|
||||
// This function does not remove or adjust vertices in
|
||||
// the vertex pool; it only adds new vertices with the
|
||||
// normals removed. Thus, it is a good idea to call
|
||||
// remove_unused_vertices() after calling this.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void EggData::
|
||||
recompute_polygon_normals() {
|
||||
EggGroupNode::recompute_polygon_normals(_coordsys);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: EggData::strip_normals
|
||||
// Access: Public
|
||||
// Description: Removes all normals from primitives, and the vertices
|
||||
// they reference, at this node and below.
|
||||
//
|
||||
// This function does not remove or adjust vertices in
|
||||
// the vertex pool; it only adds new vertices with the
|
||||
// normal removed. Thus, it is a good idea to call
|
||||
// remove_unused_vertices() after calling this.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void EggData::
|
||||
strip_normals() {
|
||||
EggGroupNode::strip_normals();
|
||||
}
|
||||
|
@ -54,6 +54,10 @@ public:
|
||||
INLINE void set_egg_filename(const Filename &directory);
|
||||
INLINE const Filename &get_egg_filename() const;
|
||||
|
||||
INLINE void recompute_vertex_normals(double threshold);
|
||||
INLINE void recompute_polygon_normals();
|
||||
INLINE void strip_normals();
|
||||
|
||||
protected:
|
||||
virtual void write(ostream &out, int indent_level = 0) const;
|
||||
|
||||
|
@ -328,11 +328,11 @@ reverse_vertex_ordering() {
|
||||
// remove_unused_vertices() after calling this.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggGroupNode::
|
||||
recompute_vertex_normals(double threshold) {
|
||||
recompute_vertex_normals(double threshold, CoordinateSystem cs) {
|
||||
// First, collect all the vertices together with their shared
|
||||
// polygons.
|
||||
NVertexCollection collection;
|
||||
r_collect_vertex_normals(collection, threshold);
|
||||
r_collect_vertex_normals(collection, threshold, cs);
|
||||
|
||||
// Now bust them into separate groups according to the edge
|
||||
// threshold. Two polygons that share a vertex belong in the same
|
||||
@ -401,7 +401,7 @@ recompute_vertex_normals(double threshold) {
|
||||
// remove_unused_vertices() after calling this.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggGroupNode::
|
||||
recompute_polygon_normals() {
|
||||
recompute_polygon_normals(CoordinateSystem cs) {
|
||||
Children::iterator ci, cnext;
|
||||
ci = _children.begin();
|
||||
while (ci != _children.end()) {
|
||||
@ -412,7 +412,7 @@ recompute_polygon_normals() {
|
||||
if (child->is_of_type(EggPolygon::get_class_type())) {
|
||||
EggPolygon *polygon = DCAST(EggPolygon, child);
|
||||
|
||||
if (!polygon->recompute_polygon_normal()) {
|
||||
if (!polygon->recompute_polygon_normal(cs)) {
|
||||
// The polygon is degenerate. Remove it.
|
||||
prepare_remove_child(child);
|
||||
_children.erase(ci);
|
||||
@ -436,7 +436,7 @@ recompute_polygon_normals() {
|
||||
}
|
||||
|
||||
} else if (child->is_of_type(EggGroupNode::get_class_type())) {
|
||||
DCAST(EggGroupNode, child)->recompute_polygon_normals();
|
||||
DCAST(EggGroupNode, child)->recompute_polygon_normals(cs);
|
||||
}
|
||||
|
||||
ci = cnext;
|
||||
@ -944,7 +944,7 @@ prepare_remove_child(EggNode *node) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void EggGroupNode::
|
||||
r_collect_vertex_normals(EggGroupNode::NVertexCollection &collection,
|
||||
double threshold) {
|
||||
double threshold, CoordinateSystem cs) {
|
||||
// We can do this ci/cnext iteration through the list as we modify
|
||||
// it, only because we know this works with an STL list type
|
||||
// container. If this were a vector or a set, this wouldn't
|
||||
@ -963,7 +963,7 @@ r_collect_vertex_normals(EggGroupNode::NVertexCollection &collection,
|
||||
|
||||
NVertexReference ref;
|
||||
ref._polygon = polygon;
|
||||
if (!polygon->calculate_normal(ref._normal)) {
|
||||
if (!polygon->calculate_normal(ref._normal, cs)) {
|
||||
// The polygon is degenerate. Remove it.
|
||||
|
||||
prepare_remove_child(child);
|
||||
@ -986,9 +986,9 @@ r_collect_vertex_normals(EggGroupNode::NVertexCollection &collection,
|
||||
// We can't share vertices across an Instance node. Don't
|
||||
// even bother trying. Instead, just restart.
|
||||
if (group->is_under_instance()) {
|
||||
group->recompute_vertex_normals(threshold);
|
||||
group->recompute_vertex_normals(threshold, cs);
|
||||
} else {
|
||||
group->r_collect_vertex_normals(collection, threshold);
|
||||
group->r_collect_vertex_normals(collection, threshold, cs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,8 @@ public:
|
||||
void resolve_filenames(const DSearchPath &searchpath);
|
||||
void reverse_vertex_ordering();
|
||||
|
||||
void recompute_vertex_normals(double threshold);
|
||||
void recompute_polygon_normals();
|
||||
void recompute_vertex_normals(double threshold, CoordinateSystem cs = CS_default);
|
||||
void recompute_polygon_normals(CoordinateSystem cs = CS_default);
|
||||
void strip_normals();
|
||||
|
||||
int triangulate_polygons(bool convex_also);
|
||||
@ -142,7 +142,7 @@ private:
|
||||
typedef map<Vertexd, NVertexGroup> NVertexCollection;
|
||||
|
||||
void r_collect_vertex_normals(NVertexCollection &collection,
|
||||
double threshold);
|
||||
double threshold, CoordinateSystem cs);
|
||||
void do_compute_vertex_normals(const NVertexGroup &group);
|
||||
|
||||
public:
|
||||
|
@ -43,9 +43,9 @@ operator = (const EggPolygon ©) {
|
||||
// degenerate and does not have a normal.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool EggPolygon::
|
||||
recompute_polygon_normal() {
|
||||
recompute_polygon_normal(CoordinateSystem cs) {
|
||||
Normald normal;
|
||||
if (calculate_normal(normal)) {
|
||||
if (calculate_normal(normal, cs)) {
|
||||
set_normal(normal);
|
||||
return true;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ cleanup() {
|
||||
// does not have at least three noncollinear vertices.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool EggPolygon::
|
||||
calculate_normal(Normald &result) const {
|
||||
calculate_normal(Normald &result, CoordinateSystem cs) const {
|
||||
// Get the first three unique vertices.
|
||||
Vertexd v[3];
|
||||
int i = 0;
|
||||
@ -71,8 +71,16 @@ calculate_normal(Normald &result) const {
|
||||
LVector3d normal = a.cross(b);
|
||||
|
||||
if (normal.normalize()) {
|
||||
result = normal;
|
||||
// If we are in a left-handed coordinate system, we must
|
||||
// reverse the normal.
|
||||
if (cs == CS_default) {
|
||||
cs = default_coordinate_system;
|
||||
}
|
||||
if (cs == CS_zup_left || cs == CS_yup_left) {
|
||||
normal = -normal;
|
||||
}
|
||||
|
||||
result = normal;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ public:
|
||||
|
||||
virtual bool cleanup();
|
||||
|
||||
bool calculate_normal(Normald &result) const;
|
||||
INLINE bool recompute_polygon_normal();
|
||||
bool calculate_normal(Normald &result, CoordinateSystem cs = CS_default) const;
|
||||
INLINE bool recompute_polygon_normal(CoordinateSystem cs = CS_default);
|
||||
|
||||
INLINE bool triangulate_into(EggGroupNode *container, bool convex_also) const;
|
||||
PT(EggPolygon) triangulate_in_place(bool convex_also);
|
||||
|
Loading…
x
Reference in New Issue
Block a user