28 set_program_brief(
"generate a tube or sphere from geometry in an .egg file");
29 set_program_description
30 (
"egg-make-tube generates an egg file representing a \"tube\" model, "
31 "a cylinder capped on both ends by hemispheres. This is similar "
32 "in shape to the CollisionCapsule object within Panda.\n\n"
33 "This program can also generate spheres if you omit -b; in this "
34 "case, you are generating a degenerate tube of length 0.");
38 "Specify the first endpoint of the tube.",
39 &EggWriter::dispatch_double_triple,
nullptr, _point_a);
43 "Specify the second endpoint of the tube.",
44 &EggWriter::dispatch_double_triple, &_got_point_b, _point_b);
48 "Specify the radius of the tube. The tube will extend beyond "
49 "the endpoints in each direction by the amount of radius.",
50 &EggWriter::dispatch_double,
nullptr, &_radius);
53 (
"slices",
"count", 0,
54 "Specify the number of slices appearing radially around the tube.",
55 &EggWriter::dispatch_int,
nullptr, &_num_slices);
58 (
"crings",
"count", 0,
59 "Specify the number of rings appearing in each endcap of the tube.",
60 &EggWriter::dispatch_int,
nullptr, &_num_crings);
63 (
"trings",
"count", 0,
64 "Specify the number of rings appearing in the cylindrical body "
66 &EggWriter::dispatch_int,
nullptr, &_num_trings);
89 _point_b[0] = _point_a[0];
90 _point_b[1] = _point_a[1];
91 _point_b[2] = _point_a[2];
96 LVector3d direction(_point_b[0] - _point_a[0],
97 _point_b[1] - _point_a[1],
98 _point_b[2] - _point_a[2]);
99 _length = direction.length();
103 _data->add_child(_group);
113 for (ri = 0; ri < _num_crings; ri++) {
116 for (si = 0; si <= _num_slices; si++) {
117 EggVertex *vtx_3 = calc_sphere1_vertex(ri, si);
118 EggVertex *vtx_4 = calc_sphere1_vertex(ri + 1, si);
119 add_polygon(vtx_1, vtx_2, vtx_4, vtx_3);
126 if (_length != 0.0) {
127 for (ri = 0; ri < _num_trings; ri++) {
130 for (si = 0; si <= _num_slices; si++) {
131 EggVertex *vtx_3 = calc_tube_vertex(ri, si);
132 EggVertex *vtx_4 = calc_tube_vertex(ri + 1, si);
133 add_polygon(vtx_1, vtx_2, vtx_4, vtx_3);
141 for (ri = _num_crings - 1; ri >= 0; ri--) {
144 for (si = 0; si <= _num_slices; si++) {
145 EggVertex *vtx_3 = calc_sphere2_vertex(ri + 1, si);
146 EggVertex *vtx_4 = calc_sphere2_vertex(ri, si);
147 add_polygon(vtx_1, vtx_2, vtx_4, vtx_3);
155 look_at(mat, direction, LVector3d(0.0, 0.0, 1.0), CS_zup_right);
156 mat.set_row(3, LPoint3d(_point_a[0], _point_a[1], _point_a[2]));
167calc_sphere1_vertex(
int ri,
int si) {
168 double r = (double)ri / (
double)_num_crings;
169 double s = (double)si / (
double)_num_slices;
172 double theta = s * 2.0 * MathNumbers::pi;
173 double x_rim = cos(theta);
174 double z_rim = sin(theta);
177 double phi = r * 0.5 * MathNumbers::pi;
178 double to_pole = sin(phi);
180 double x = _radius * x_rim * to_pole;
181 double y = -_radius * cos(phi);
182 double z = _radius * z_rim * to_pole;
185 vert.
set_pos(LPoint3d(x, y, z));
194calc_tube_vertex(
int ri,
int si) {
195 double r = (double)ri / (
double)_num_trings;
196 double s = (double)si / (
double)_num_slices;
199 double theta = s * 2.0 * MathNumbers::pi;
200 double x_rim = cos(theta);
201 double z_rim = sin(theta);
203 double x = _radius * x_rim;
204 double y = _length * r;
205 double z = _radius * z_rim;
208 vert.
set_pos(LPoint3d(x, y, z));
218calc_sphere2_vertex(
int ri,
int si) {
219 double r = (double)ri / (
double)_num_crings;
220 double s = (double)si / (
double)_num_slices;
223 double theta = s * 2.0 * MathNumbers::pi;
224 double x_rim = cos(theta);
225 double z_rim = sin(theta);
228 double phi = r * 0.5 * MathNumbers::pi;
229 double to_pole = sin(phi);
231 double x = _radius * x_rim * to_pole;
232 double y = _length + _radius * cos(phi);
233 double z = _radius * z_rim * to_pole;
236 vert.
set_pos(LPoint3d(x, y, z));
265int main(
int argc,
char *argv[]) {
EggNode * add_child(EggNode *node)
Adds the indicated child to the group and returns it.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
A program to generate an egg file representing a tube model, similar in shape to a CollisionCapsule.
void transform(const LMatrix4d &mat)
Applies the indicated transformation to the node and all of its descendants.
EggVertex * add_vertex(EggVertex *vertex)
Adds the indicated vertex to the end of the primitive's list of vertices, and returns it.
A collection of vertices.
EggVertex * create_unique_vertex(const EggVertex ©)
Creates a new vertex in the pool that is a copy of the indicated one and returns it.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal.
void set_pos(double pos)
Sets the vertex position.
void write_egg_file()
Writes out the egg file as the normal result of the program.
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.