Panda3D

egg_parametrics.cxx
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file egg_parametrics.cxx
10 * @author drose
11 * @date 2003-10-13
12 */
13
14 #include "egg_parametrics.h"
15 #include "config_egg2pg.h"
16
17 /**
18 * Returns a new NurbsSurfaceEvaluator that's filled in with the values from
19 * the given EggSurface (and transformed by the indicated matrix), or NULL if
20 * the object is invalid. If there is vertex color, it will be applied to
21 * values 0 - 3 of the extended vertex values.
22 */
23 PT(NurbsSurfaceEvaluator)
24 make_nurbs_surface(EggNurbsSurface *egg_surface, const LMatrix4d &mat) {
25 if (egg_surface->get_u_order() < 1 || egg_surface->get_u_order() > 4) {
26 egg2pg_cat.error()
27 << "Invalid NURBSSurface U order for " << egg_surface->get_name() << ": "
28 << egg_surface->get_u_order() << "\n";
29 return nullptr;
30 }
31
32 if (egg_surface->get_v_order() < 1 || egg_surface->get_v_order() > 4) {
33 egg2pg_cat.error()
34 << "Invalid NURBSSurface V order for " << egg_surface->get_name() << ": "
35 << egg_surface->get_v_order() << "\n";
36 return nullptr;
37 }
38
39 PT(NurbsSurfaceEvaluator) nurbs = new NurbsSurfaceEvaluator;
40
41 nurbs->set_u_order(egg_surface->get_u_order());
42 nurbs->set_v_order(egg_surface->get_v_order());
43
44 int num_u_vertices = egg_surface->get_num_u_cvs();
45 int num_v_vertices = egg_surface->get_num_v_cvs();
46 nurbs->reset(num_u_vertices, num_v_vertices);
47 for (int ui = 0; ui < num_u_vertices; ui++) {
48 for (int vi = 0; vi < num_v_vertices; vi++) {
49 int i = egg_surface->get_vertex_index(ui, vi);
50 EggVertex *egg_vertex = egg_surface->get_vertex(i);
51 nurbs->set_vertex(ui, vi, LCAST(PN_stdfloat, egg_vertex->get_pos4() * mat));
52
53 LColor color = egg_vertex->get_color();
54 nurbs->set_extended_vertices(ui, vi, 0, color.get_data(), 4);
55 }
56 }
57
58 int num_u_knots = egg_surface->get_num_u_knots();
59 if (num_u_knots != nurbs->get_num_u_knots()) {
60 egg2pg_cat.error()
61 << "Invalid NURBSSurface number of U knots for "
62 << egg_surface->get_name() << ": got " << num_u_knots
63 << " knots, expected " << nurbs->get_num_u_knots() << "\n";
64 return nullptr;
65 }
66
67 int num_v_knots = egg_surface->get_num_v_knots();
68 if (num_v_knots != nurbs->get_num_v_knots()) {
69 egg2pg_cat.error()
70 << "Invalid NURBSSurface number of U knots for "
71 << egg_surface->get_name() << ": got " << num_v_knots
72 << " knots, expected " << nurbs->get_num_v_knots() << "\n";
73 return nullptr;
74 }
75
76 int i;
77 for (i = 0; i < num_u_knots; i++) {
78 nurbs->set_u_knot(i, egg_surface->get_u_knot(i));
79 }
80 for (i = 0; i < num_v_knots; i++) {
81 nurbs->set_v_knot(i, egg_surface->get_v_knot(i));
82 }
83
84 return nurbs;
85 }
86
87 /**
88 * Returns a new NurbsCurveEvaluator that's filled in with the values from the
89 * given EggCurve (and transformed by the indicated matrix), or NULL if the
90 * object is invalid. If there is vertex color, it will be applied to values
91 * 0 - 3 of the extended vertex values.
92 */
93 PT(NurbsCurveEvaluator)
94 make_nurbs_curve(EggNurbsCurve *egg_curve, const LMatrix4d &mat) {
95 if (egg_curve->get_order() < 1 || egg_curve->get_order() > 4) {
96 egg2pg_cat.error()
97 << "Invalid NURBSCurve order for " << egg_curve->get_name() << ": "
98 << egg_curve->get_order() << "\n";
99 return nullptr;
100 }
101
102 PT(NurbsCurveEvaluator) nurbs = new NurbsCurveEvaluator;
103 nurbs->set_order(egg_curve->get_order());
104
105 nurbs->reset(egg_curve->size());
106 EggPrimitive::const_iterator pi;
107 int vi = 0;
108 for (pi = egg_curve->begin(); pi != egg_curve->end(); ++pi) {
109 EggVertex *egg_vertex = (*pi);
110 nurbs->set_vertex(vi, LCAST(PN_stdfloat, egg_vertex->get_pos4() * mat));
111 LColor color = egg_vertex->get_color();
112 nurbs->set_extended_vertices(vi, 0, color.get_data(), 4);
113 vi++;
114 }
115
116 int num_knots = egg_curve->get_num_knots();
117 if (num_knots != nurbs->get_num_knots()) {
118 egg2pg_cat.error()
119 << "Invalid NURBSCurve number of knots for "
120 << egg_curve->get_name() << ": got " << num_knots
121 << " knots, expected " << nurbs->get_num_knots() << "\n";
122 return nullptr;
123 }
124
125 for (int i = 0; i < num_knots; i++) {
126 nurbs->set_knot(i, egg_curve->get_knot(i));
127 }
128
129 return nurbs;
130 }
EggAttributes::get_color
LColor get_color() const
Returns the color set on this particular attribute.
Definition: eggAttributes.I:91
EggNurbsCurve
A parametric NURBS curve.
Definition: eggNurbsCurve.h:26
EggNurbsCurve::get_order
get_order
Returns the order of the curve.
Definition: eggNurbsCurve.h:55
EggNurbsCurve::get_num_knots
get_num_knots
Returns the number of knots.
Definition: eggNurbsCurve.h:51
EggNurbsCurve::get_knot
get_knot
Returns the nth knot value defined.
Definition: eggNurbsCurve.h:51
EggNurbsSurface
A parametric NURBS surface.
Definition: eggNurbsSurface.h:27
EggNurbsSurface::get_u_order
int get_u_order() const
Returns the order of the surface in the U direction.
Definition: eggNurbsSurface.I:112
EggNurbsSurface::get_num_u_knots
get_num_u_knots
Returns the number of knots in the U direction.
Definition: eggNurbsSurface.h:73
EggNurbsSurface::get_vertex_index
int get_vertex_index(int ui, int vi) const
Returns the index number within the EggPrimitive's list of the control vertex at position ui,...
Definition: eggNurbsSurface.I:225
EggNurbsSurface::get_v_order
int get_v_order() const
Returns the order of the surface in the V direction.
Definition: eggNurbsSurface.I:122
EggNurbsSurface::get_v_knot
get_v_knot
Returns the nth knot value defined in the V direction.
Definition: eggNurbsSurface.h:75
EggNurbsSurface::get_num_v_cvs
int get_num_v_cvs() const
Returns the number of control vertices that should be present in the V direction.
Definition: eggNurbsSurface.I:180
EggNurbsSurface::get_u_knot
get_u_knot
Returns the nth knot value defined in the U direction.
Definition: eggNurbsSurface.h:73
EggNurbsSurface::get_num_u_cvs
int get_num_u_cvs() const
Returns the number of control vertices that should be present in the U direction.
Definition: eggNurbsSurface.I:168
EggNurbsSurface::get_num_v_knots
get_num_v_knots
Returns the number of knots in the V direction.
Definition: eggNurbsSurface.h:75
EggPrimitive::get_vertex
get_vertex
Returns a particular index based on its index number.
Definition: eggPrimitive.h:187
EggVertex
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
Definition: eggVertex.h:39
EggVertex::get_pos4
LPoint4d get_pos4() const
This is always valid, regardless of the value of get_num_dimensions.
Definition: eggVertex.I:145
NurbsCurveEvaluator
This class is an abstraction for evaluating NURBS curves.
Definition: nurbsCurveEvaluator.h:39
NurbsSurfaceEvaluator
This class is an abstraction for evaluating NURBS surfaces.
Definition: nurbsSurfaceEvaluator.h:34
config_egg2pg.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PT
PT(NurbsSurfaceEvaluator) make_nurbs_surface(EggNurbsSurface *egg_surface
Returns a new NurbsSurfaceEvaluator that's filled in with the values from the given EggSurface (and t...
egg_parametrics.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.