00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef NODEPATH_H
00020 #define NODEPATH_H
00021
00022 #include "pandabase.h"
00023
00024 #include "pandaNode.h"
00025 #include "renderState.h"
00026 #include "transformState.h"
00027 #include "nodePathComponent.h"
00028
00029 #include "pointerTo.h"
00030 #include "referenceCount.h"
00031 #include "notify.h"
00032 #include "typedObject.h"
00033
00034 class NodePathCollection;
00035 class TextureCollection;
00036 class FindApproxLevel;
00037 class FindApproxPath;
00038 class Texture;
00039 class Material;
00040 class Fog;
00041 class GlobPattern;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 class EXPCL_PANDA NodePath {
00137 PUBLISHED:
00138
00139
00140 enum ErrorType {
00141 ET_ok = 0,
00142 ET_not_found,
00143 ET_removed,
00144 ET_fail,
00145
00146
00147
00148 };
00149
00150 INLINE NodePath();
00151 INLINE NodePath(const string &top_node_name);
00152 INLINE NodePath(PandaNode *node);
00153 INLINE static NodePath any_path(PandaNode *node);
00154 INLINE NodePath(const NodePath &parent, PandaNode *child_node);
00155
00156 INLINE NodePath(const NodePath ©);
00157 INLINE void operator = (const NodePath ©);
00158
00159 INLINE static NodePath not_found();
00160 INLINE static NodePath removed();
00161 INLINE static NodePath fail();
00162
00163 INLINE static void set_max_search_depth(int max_search_depth);
00164 INLINE static int get_max_search_depth();
00165
00166
00167 INLINE bool is_empty() const;
00168 INLINE bool is_singleton() const;
00169 int get_num_nodes() const;
00170 PandaNode *get_node(int index) const;
00171
00172 INLINE ErrorType get_error_type() const;
00173
00174 PandaNode *get_top_node() const;
00175 INLINE PandaNode *node() const;
00176
00177 INLINE int get_key() const;
00178
00179
00180
00181
00182 NodePathCollection get_children() const;
00183 INLINE int get_num_children() const;
00184 INLINE NodePath get_child(int n) const;
00185
00186 INLINE bool has_parent() const;
00187 INLINE NodePath get_parent() const;
00188
00189 NodePath find(const string &path) const;
00190 NodePath find_path_to(PandaNode *node) const;
00191 NodePathCollection find_all_matches(const string &path) const;
00192 NodePathCollection find_all_paths_to(PandaNode *node) const;
00193
00194
00195
00196
00197
00198
00199 void reparent_to(const NodePath &other, int sort = 0);
00200 void wrt_reparent_to(const NodePath &other, int sort = 0);
00201 NodePath instance_to(const NodePath &other, int sort = 0) const;
00202 NodePath instance_under_node(const NodePath &other, const string &name,
00203 int sort = 0) const;
00204 NodePath copy_to(const NodePath &other, int sort = 0) const;
00205 NodePath attach_new_node(PandaNode *node, int sort = 0) const;
00206 INLINE NodePath attach_new_node(const string &name, int sort = 0) const;
00207 void remove_node();
00208 void detach_node();
00209
00210
00211
00212
00213 void output(ostream &out) const;
00214
00215 INLINE void ls() const;
00216 INLINE void ls(ostream &out, int indent_level = 0) const;
00217
00218
00219
00220 INLINE const RenderState *get_state() const;
00221 INLINE void set_state(const RenderState *state) const;
00222 CPT(RenderState) get_state(const NodePath &other) const;
00223 void set_state(const NodePath &other, const RenderState *state) const;
00224 INLINE CPT(RenderState) get_net_state() const;
00225
00226 INLINE const TransformState *get_transform() const;
00227 INLINE void set_transform(const TransformState *transform) const;
00228 CPT(TransformState) get_transform(const NodePath &other) const;
00229 void set_transform(const NodePath &other, const TransformState *transform) const;
00230 INLINE CPT(TransformState) get_net_transform() const;
00231
00232
00233
00234
00235
00236 INLINE void set_pos(float x, float y, float z);
00237 void set_pos(const LVecBase3f &pos);
00238 void set_x(float x);
00239 void set_y(float y);
00240 void set_z(float z);
00241 LPoint3f get_pos() const;
00242 INLINE float get_x() const;
00243 INLINE float get_y() const;
00244 INLINE float get_z() const;
00245
00246 INLINE void set_hpr(float h, float p, float r);
00247 void set_hpr(const LVecBase3f &hpr);
00248 void set_h(float h);
00249 void set_p(float p);
00250 void set_r(float r);
00251 LVecBase3f get_hpr() const;
00252 LVecBase3f get_hpr(float roll) const;
00253 INLINE float get_h() const;
00254 INLINE float get_p() const;
00255 INLINE float get_r() const;
00256
00257 void set_quat(const LQuaternionf &quat);
00258 LQuaternionf get_quat() const;
00259
00260 INLINE void set_scale(float scale);
00261 INLINE void set_scale(float sx, float sy, float sz);
00262 void set_scale(const LVecBase3f &scale);
00263 void set_sx(float sx);
00264 void set_sy(float sy);
00265 void set_sz(float sz);
00266 LVecBase3f get_scale() const;
00267 INLINE float get_sx() const;
00268 INLINE float get_sy() const;
00269 INLINE float get_sz() const;
00270
00271 INLINE void set_pos_hpr(float x, float y, float z,
00272 float h, float p, float r);
00273 void set_pos_hpr(const LVecBase3f &pos,
00274 const LVecBase3f &hpr);
00275
00276 INLINE void set_hpr_scale(float h, float p, float r,
00277 float sx, float sy, float sz);
00278 void set_hpr_scale(const LVecBase3f &hpr,
00279 const LVecBase3f &scale);
00280 INLINE void set_pos_hpr_scale(float x, float y, float z,
00281 float h, float p, float r,
00282 float sx, float sy, float sz);
00283 void set_pos_hpr_scale(const LVecBase3f &pos,
00284 const LVecBase3f &hpr,
00285 const LVecBase3f &scale);
00286 void set_pos_quat_scale(const LVecBase3f &pos,
00287 const LQuaternionf &quat,
00288 const LVecBase3f &scale);
00289
00290 void set_mat(const LMatrix4f &mat);
00291 INLINE void clear_mat();
00292 INLINE bool has_mat() const;
00293 INLINE const LMatrix4f &get_mat() const;
00294
00295 bool has_color_scale() const;
00296 void clear_color_scale();
00297 void set_color_scale(const LVecBase4f &scale);
00298 INLINE void set_color_scale(float sx, float sy, float sz, float sa);
00299 INLINE void set_sr(float sr);
00300 INLINE void set_sg(float sg);
00301 INLINE void set_sb(float sb);
00302 INLINE void set_sa(float sa);
00303
00304 const LVecBase4f &get_color_scale() const;
00305 INLINE float get_sr() const;
00306 INLINE float get_sg() const;
00307 INLINE float get_sb() const;
00308 INLINE float get_sa() const;
00309
00310 INLINE void look_at(float x, float y, float z);
00311 void look_at(const LPoint3f &point, const LVector3f &up = LVector3f::up());
00312 INLINE void heads_up(float x, float y, float z);
00313 void heads_up(const LPoint3f &point, const LVector3f &up = LVector3f::up());
00314
00315
00316
00317
00318 INLINE void set_pos(const NodePath &other, float x, float y, float z);
00319 void set_pos(const NodePath &other, const LVecBase3f &pos);
00320 void set_x(const NodePath &other, float x);
00321 void set_y(const NodePath &other, float y);
00322 void set_z(const NodePath &other, float z);
00323 LPoint3f get_pos(const NodePath &other) const;
00324 INLINE float get_x(const NodePath &other) const;
00325 INLINE float get_y(const NodePath &other) const;
00326 INLINE float get_z(const NodePath &other) const;
00327
00328 INLINE void set_hpr(const NodePath &other, float h, float p, float r);
00329 void set_hpr(const NodePath &other, const LVecBase3f &hpr);
00330 void set_h(const NodePath &other, float h);
00331 void set_p(const NodePath &other, float p);
00332 void set_r(const NodePath &other, float r);
00333 LVecBase3f get_hpr(const NodePath &other) const;
00334 LVecBase3f get_hpr(const NodePath &other, float roll) const;
00335 INLINE float get_h(const NodePath &other) const;
00336 INLINE float get_p(const NodePath &other) const;
00337 INLINE float get_r(const NodePath &other) const;
00338
00339 void set_quat(const NodePath &other, const LQuaternionf &quat);
00340 LQuaternionf get_quat(const NodePath &other) const;
00341
00342 INLINE void set_scale(const NodePath &other, float sx, float sy, float sz);
00343 void set_scale(const NodePath &other, const LVecBase3f &scale);
00344 void set_sx(const NodePath &other, float sx);
00345 void set_sy(const NodePath &other, float sy);
00346 void set_sz(const NodePath &other, float sz);
00347 LVecBase3f get_scale(const NodePath &other) const;
00348 INLINE float get_sx(const NodePath &other) const;
00349 INLINE float get_sy(const NodePath &other) const;
00350 INLINE float get_sz(const NodePath &other) const;
00351
00352 INLINE void set_pos_hpr(const NodePath &other,
00353 float x, float y, float z,
00354 float h, float p, float r);
00355 void set_pos_hpr(const NodePath &other,
00356 const LVecBase3f &pos,
00357 const LVecBase3f &hpr);
00358 INLINE void set_hpr_scale(const NodePath &other,
00359 float h, float p, float r,
00360 float sx, float sy, float sz);
00361 void set_hpr_scale(const NodePath &other,
00362 const LVecBase3f &hpr,
00363 const LVecBase3f &scale);
00364 INLINE void set_pos_hpr_scale(const NodePath &other,
00365 float x, float y, float z,
00366 float h, float p, float r,
00367 float sx, float sy, float sz);
00368 void set_pos_hpr_scale(const NodePath &other,
00369 const LVecBase3f &pos,
00370 const LVecBase3f &hpr,
00371 const LVecBase3f &scale);
00372 void set_pos_quat_scale(const NodePath &other,
00373 const LVecBase3f &pos,
00374 const LQuaternionf &quat,
00375 const LVecBase3f &scale);
00376
00377 const LMatrix4f &get_mat(const NodePath &other) const;
00378 void set_mat(const NodePath &other, const LMatrix4f &mat);
00379
00380 LPoint3f get_relative_point(const NodePath &other, const LVecBase3f &point);
00381
00382 INLINE void look_at(const NodePath &other,
00383 float x, float y, float z);
00384 void look_at(const NodePath &other,
00385 const LPoint3f &point = LPoint3f(0.0, 0.0, 0.0),
00386 const LVector3f &up = LVector3f::up());
00387 INLINE void heads_up(const NodePath &other,
00388 float x, float y, float z);
00389 void heads_up(const NodePath &other,
00390 const LPoint3f &point = LPoint3f(0.0, 0.0, 0.0),
00391 const LVector3f &up = LVector3f::up());
00392
00393 INLINE float get_distance(const NodePath &other) const;
00394
00395
00396
00397
00398
00399 void set_color(float r, float g, float b, float a = 1.0,
00400 int priority = 0);
00401 void set_color(const Colorf &color, int priority = 0);
00402 void set_color_off(int priority = 0);
00403 void clear_color();
00404 bool has_color() const;
00405 Colorf get_color() const;
00406
00407 void set_bin(const string &bin_name, int draw_order, int priority = 0);
00408 void clear_bin();
00409 bool has_bin() const;
00410 string get_bin_name() const;
00411 int get_bin_draw_order() const;
00412
00413 void set_texture(Texture *tex, int priority = 0);
00414 void set_texture_off(int priority = 0);
00415 void clear_texture();
00416 bool has_texture() const;
00417 bool has_texture_off() const;
00418 Texture *get_texture() const;
00419
00420 Texture *find_texture(const string &name) const;
00421 TextureCollection find_all_textures() const;
00422 TextureCollection find_all_textures(const string &name) const;
00423
00424 void set_material(Material *tex, int priority = 0);
00425 void set_material_off(int priority = 0);
00426 void clear_material();
00427 bool has_material() const;
00428 PT(Material) get_material() const;
00429
00430 void set_fog(Fog *fog, int priority = 0);
00431 void set_fog_off(int priority = 0);
00432 void clear_fog();
00433 bool has_fog() const;
00434 bool has_fog_off() const;
00435 Fog *get_fog() const;
00436
00437 void set_render_mode_wireframe(int priority = 0);
00438 void set_render_mode_filled(int priority = 0);
00439 void clear_render_mode();
00440 bool has_render_mode() const;
00441
00442 void set_two_sided(bool two_sided, int priority = 0);
00443 void clear_two_sided();
00444 bool has_two_sided() const;
00445 bool get_two_sided() const;
00446 #if 0
00447 void set_alpha_test(RenderAttrib::PandaCompareFunc alpha_test_mode,float reference_alpha,int priority = 0);
00448 void clear_alpha_test();
00449 bool has_alpha_test() const;
00450 bool get_alpha_test() const;
00451 #endif
00452 void set_depth_test(bool depth_test, int priority = 0);
00453 void clear_depth_test();
00454 bool has_depth_test() const;
00455 bool get_depth_test() const;
00456
00457 void set_depth_write(bool depth_write, int priority = 0);
00458 void clear_depth_write();
00459 bool has_depth_write() const;
00460 bool get_depth_write() const;
00461
00462 void do_billboard_axis(const NodePath &camera, float offset);
00463 void do_billboard_point_eye(const NodePath &camera, float offset);
00464 void do_billboard_point_world(const NodePath &camera, float offset);
00465 INLINE void set_billboard_axis(float offset = 0.0);
00466 INLINE void set_billboard_point_eye(float offset = 0.0);
00467 INLINE void set_billboard_point_world(float offset = 0.0);
00468 void set_billboard_axis(const NodePath &camera, float offset);
00469 void set_billboard_point_eye(const NodePath &camera, float offset);
00470 void set_billboard_point_world(const NodePath &camera, float offset);
00471 void clear_billboard();
00472 bool has_billboard() const;
00473
00474 void set_compass(const NodePath &reference = NodePath());
00475 void clear_compass();
00476 bool has_compass() const;
00477
00478 void set_transparency(bool transparency, int priority = 0);
00479 void clear_transparency();
00480 bool has_transparency() const;
00481 bool get_transparency() const;
00482
00483 INLINE void adjust_all_priorities(int adjustment);
00484
00485
00486 INLINE void show();
00487 INLINE void show(DrawMask camera_mask);
00488 INLINE void hide();
00489 INLINE void hide(DrawMask camera_mask);
00490 INLINE bool is_hidden(DrawMask camera_mask = DrawMask::all_on()) const;
00491 NodePath get_hidden_ancestor(DrawMask camera_mask = DrawMask::all_on()) const;
00492
00493 INLINE bool stash();
00494 INLINE bool unstash();
00495 INLINE bool is_stashed() const;
00496 NodePath get_stashed_ancestor() const;
00497
00498
00499 INLINE bool operator == (const NodePath &other) const;
00500 INLINE bool operator != (const NodePath &other) const;
00501 INLINE bool operator < (const NodePath &other) const;
00502 INLINE int compare_to(const NodePath &other) const;
00503
00504
00505 bool verify_complete() const;
00506
00507 void prepare_scene(GraphicsStateGuardianBase *gsg, bool force_retained_mode = false);
00508
00509 void show_bounds();
00510 void hide_bounds();
00511 PT(BoundingVolume) get_bounds() const;
00512 void force_recompute_bounds();
00513 void write_bounds(ostream &out) const;
00514 bool calc_tight_bounds(LPoint3f &min_point, LPoint3f &max_point);
00515
00516 int flatten_light();
00517 int flatten_medium();
00518 int flatten_strong();
00519
00520 bool write_bam_file(const string &filename) const;
00521
00522 private:
00523 void uncollapse_head() const;
00524 static void find_common_ancestor(const NodePath &a, const NodePath &b,
00525 int &a_count, int &b_count);
00526
00527 CPT(RenderState) r_get_net_state(NodePathComponent *comp) const;
00528 CPT(RenderState) r_get_partial_state(NodePathComponent *comp, int n) const;
00529 CPT(TransformState) r_get_net_transform(NodePathComponent *comp) const;
00530 CPT(TransformState) r_get_partial_transform(NodePathComponent *comp, int n) const;
00531
00532 void find_matches(NodePathCollection &result,
00533 const string &approx_path_str,
00534 int max_matches) const;
00535 void find_matches(NodePathCollection &result,
00536 FindApproxPath &approx_path,
00537 int max_matches) const;
00538 void r_find_matches(NodePathCollection &result,
00539 const FindApproxLevel &level,
00540 int max_matches, int num_levels_remaining) const;
00541
00542 void r_adjust_all_priorities(PandaNode *node, int adjustment);
00543
00544 void r_force_recompute_bounds(PandaNode *node);
00545
00546 typedef pset<Texture *> Textures;
00547 Texture *r_find_texture(PandaNode *node, const RenderState *state,
00548 const GlobPattern &glob) const;
00549 void r_find_all_textures(PandaNode *node, const RenderState *state,
00550 Textures &textures) const;
00551 void r_prepare_scene(PandaNode *node, const RenderState *state,
00552 GraphicsStateGuardianBase *gsg, bool do_retained_mode);
00553
00554 PT(NodePathComponent) _head;
00555 ErrorType _error_type;
00556 static int _max_search_depth;
00557
00558 public:
00559 static TypeHandle get_class_type() {
00560 return _type_handle;
00561 }
00562 static void init_type() {
00563 register_type(_type_handle, "NodePath");
00564 }
00565
00566 private:
00567 static TypeHandle _type_handle;
00568
00569 friend class NodePathCollection;
00570 friend class WorkingNodePath;
00571 };
00572
00573 INLINE ostream &operator << (ostream &out, const NodePath &node_path);
00574
00575 #include "nodePath.I"
00576
00577 #endif