Panda3D
|
00001 // Filename: nodePath.h 00002 // Created by: drose (25Feb02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef NODEPATH_H 00016 #define NODEPATH_H 00017 00018 #include "pandabase.h" 00019 00020 #include "pandaNode.h" 00021 #include "renderState.h" 00022 #include "transformState.h" 00023 #include "renderModeAttrib.h" 00024 #include "transparencyAttrib.h" 00025 #include "nodePathComponent.h" 00026 #include "pointerTo.h" 00027 #include "referenceCount.h" 00028 #include "pnotify.h" 00029 #include "typedObject.h" 00030 00031 class NodePathCollection; 00032 class FindApproxPath; 00033 class FindApproxLevelEntry; 00034 class Light; 00035 class PolylightNode; 00036 class InternalNameCollection; 00037 class Texture; 00038 class TextureStage; 00039 class TextureCollection; 00040 class TextureStageCollection; 00041 class Material; 00042 class MaterialCollection; 00043 class Fog; 00044 class GlobPattern; 00045 class PreparedGraphicsObjects; 00046 class Shader; 00047 class ShaderInput; 00048 00049 // 00050 // A NodePath is the fundamental unit of high-level interaction with 00051 // the scene graph. It encapsulates the complete path down to a node 00052 // from some other node, usually the root of the scene graph. This is 00053 // used to resolve ambiguities associated with instancing. 00054 // 00055 // NodePath also contains a number of handy high-level methods for 00056 // common scene-graph manipulations, such as reparenting, and common 00057 // state changes, such as repositioning. 00058 // 00059 // There are also a number of NodePath methods for finding nodes deep 00060 // within the tree by name or by type. These take a path string, 00061 // which at its simplest consists of a series of node names separated 00062 // by slashes, like a directory pathname. 00063 // 00064 // Each component of the path string may optionally consist of one of 00065 // the following special names, instead of a node name: 00066 // 00067 // * -- matches exactly one node, with any name. 00068 // ** -- matches any sequence of zero or more nodes. 00069 // +typename -- matches any node that is or derives from the given type. 00070 // -typename -- matches any node that is the given type exactly. 00071 // =tag -- matches any node that has the indicated tag. 00072 // =tag=value -- matches any node whose tag matches the indicated value. 00073 // 00074 // Furthermore, a node name may itself contain standard filename 00075 // globbing characters, like *, ?, and [a-z], that will be accepted as 00076 // a partial match. (In fact, the '*' special name may be seen as 00077 // just a special case of this.) The globbing characters may not be 00078 // used with the typename matches or with tag matches, but they may 00079 // be used to match a tag's value in the =tag=value syntax. 00080 // 00081 // The special characters "@@", appearing at the beginning of a node 00082 // name, indicate a stashed node. Normally, stashed nodes are not 00083 // returned by a find (but see the special flags, below), but a 00084 // stashed node may be found if it is explicitly named with its 00085 // leading @@ characters. By extension, "@@*" may be used to identify 00086 // any stashed node. 00087 // 00088 // Examples: 00089 // 00090 // "room//graph" will look for a node named "graph", which is a child 00091 // of an unnamed node, which is a child of a node named "room", which 00092 // is a child of the starting path. 00093 // 00094 // "**/red*" will look for any node anywhere in the tree (below the 00095 // starting path) with a name that begins with "red". 00096 // 00097 // "**/+PartBundleNode/**/head" will look for a node named "head", 00098 // somewhere below a PartBundleNode anywhere in the tree. 00099 // 00100 // 00101 // The search is always potentially ambiguous, even if the special 00102 // wildcard operators are not used, because there may be multiple 00103 // nodes in the tree with the same name. In general, in the case of 00104 // an ambiguity, the shortest path is preferred; when a method (such 00105 // as extend_by) must choose only only one of several possible paths, 00106 // it will choose the shortest available; on the other hand, when a 00107 // method (such as find_all_matches) is to return all of the matching 00108 // paths, it will sort them so that the shortest paths appear first in 00109 // the output. 00110 // 00111 // 00112 // Special flags. The entire string may optionally be followed by the 00113 // ";" character, followed by one or more of the following special 00114 // control flags, with no intervening spaces or punctuation: 00115 // 00116 // -h Do not return hidden nodes. 00117 // +h Do return hidden nodes. 00118 // -s Do not return stashed nodes unless explicitly referenced with @@. 00119 // +s Return stashed nodes even without any explicit @@ characters. 00120 // -i Node name comparisons are not case insensitive: case must match 00121 // exactly. 00122 // +i Node name comparisons are case insensitive: case is not important. 00123 // This affects matches against the node name only; node type 00124 // and tag strings are always case sensitive. 00125 // 00126 // The default flags are +h-s-i. 00127 // 00128 00129 00130 //////////////////////////////////////////////////////////////////// 00131 // Class : NodePath 00132 // Description : NodePath is the fundamental system for disambiguating 00133 // instances, and also provides a higher-level interface 00134 // for manipulating the scene graph. 00135 // 00136 // A NodePath is a list of connected nodes from the root 00137 // of the graph to any sub-node. Each NodePath 00138 // therefore uniquely describes one instance of a node. 00139 // 00140 // NodePaths themselves are lightweight objects that may 00141 // easily be copied and passed by value. Their data is 00142 // stored as a series of NodePathComponents that are 00143 // stored on the nodes. Holding a NodePath will keep a 00144 // reference count to all the nodes in the path. 00145 // However, if any node in the path is removed or 00146 // reparented (perhaps through a different NodePath), 00147 // the NodePath will automatically be updated to reflect 00148 // the changes. 00149 //////////////////////////////////////////////////////////////////// 00150 class EXPCL_PANDA_PGRAPH NodePath { 00151 PUBLISHED: 00152 // This enumeration is returned by get_error_type() for an empty 00153 // NodePath to report the reason it's empty. 00154 enum ErrorType { 00155 ET_ok = 0, // i.e. not empty, or never assigned to anything. 00156 ET_not_found, // returned from a failed find() or similar function. 00157 ET_removed, // remove_node() was previously called on this NodePath. 00158 ET_fail, // general failure return from some function. 00159 }; 00160 00161 INLINE NodePath(); 00162 INLINE NodePath(const string &top_node_name, Thread *current_thread = Thread::get_current_thread()); 00163 INLINE NodePath(PandaNode *node, Thread *current_thread = Thread::get_current_thread()); 00164 INLINE static NodePath any_path(PandaNode *node, Thread *current_thread = Thread::get_current_thread()); 00165 NodePath(const NodePath &parent, PandaNode *child_node, 00166 Thread *current_thread = Thread::get_current_thread()); 00167 00168 INLINE NodePath(const NodePath ©); 00169 INLINE void operator = (const NodePath ©); 00170 00171 #ifdef HAVE_PYTHON 00172 NodePath __copy__() const; 00173 PyObject *__deepcopy__(PyObject *self, PyObject *memo) const; 00174 PyObject *__reduce__(PyObject *self) const; 00175 PyObject *__reduce_persist__(PyObject *self, PyObject *pickler) const; 00176 #endif 00177 00178 INLINE static NodePath not_found(); 00179 INLINE static NodePath removed(); 00180 INLINE static NodePath fail(); 00181 00182 INLINE static void set_max_search_depth(int max_search_depth); 00183 INLINE static int get_max_search_depth(); 00184 00185 // Methods to query a NodePath's contents. 00186 INLINE bool is_empty() const; 00187 operator bool () const; 00188 00189 INLINE bool is_singleton(Thread *current_thread = Thread::get_current_thread()) const; 00190 int get_num_nodes(Thread *current_thread = Thread::get_current_thread()) const; 00191 PandaNode *get_node(int index, Thread *current_thread = Thread::get_current_thread()) const; 00192 MAKE_SEQ(get_nodes, get_num_nodes, get_node); 00193 NodePath get_ancestor(int index, Thread *current_thread = Thread::get_current_thread()) const; 00194 MAKE_SEQ(get_ancestors, get_num_nodes, get_ancestor); 00195 00196 INLINE ErrorType get_error_type() const; 00197 00198 INLINE PandaNode *get_top_node(Thread *current_thread = Thread::get_current_thread()) const; 00199 NodePath get_top(Thread *current_thread = Thread::get_current_thread()) const; 00200 00201 INLINE PandaNode *node() const; 00202 00203 INLINE int get_key() const; 00204 00205 INLINE bool is_same_graph(const NodePath &other, Thread *current_thread = Thread::get_current_thread()) const; 00206 INLINE bool is_ancestor_of(const NodePath &other, Thread *current_thread = Thread::get_current_thread()) const; 00207 INLINE NodePath get_common_ancestor(const NodePath &other, Thread *current_thread = Thread::get_current_thread()) const; 00208 00209 // Methods that return collections of NodePaths derived from or 00210 // related to this one. 00211 00212 NodePathCollection get_children(Thread *current_thread = Thread::get_current_thread()) const; 00213 INLINE int get_num_children(Thread *current_thread = Thread::get_current_thread()) const; 00214 INLINE NodePath get_child(int n, Thread *current_thread = Thread::get_current_thread()) const; 00215 NodePathCollection get_stashed_children(Thread *current_thread = Thread::get_current_thread()) const; 00216 00217 INLINE int count_num_descendants() const; 00218 00219 INLINE bool has_parent(Thread *current_thread = Thread::get_current_thread()) const; 00220 INLINE NodePath get_parent(Thread *current_thread = Thread::get_current_thread()) const; 00221 int get_sort(Thread *current_thread = Thread::get_current_thread()) const; 00222 00223 NodePath find(const string &path) const; 00224 NodePath find_path_to(PandaNode *node) const; 00225 NodePathCollection find_all_matches(const string &path) const; 00226 NodePathCollection find_all_paths_to(PandaNode *node) const; 00227 00228 // Methods that actually move nodes around in the scene graph. The 00229 // optional "sort" parameter can be used to force a particular 00230 // ordering between sibling nodes, useful when dealing with LOD's 00231 // and similar switch nodes. If the sort value is the same, nodes 00232 // will be arranged in the order they were added. 00233 void reparent_to(const NodePath &other, int sort = 0, 00234 Thread *current_thread = Thread::get_current_thread()); 00235 void stash_to(const NodePath &other, int sort = 0, 00236 Thread *current_thread = Thread::get_current_thread()); 00237 void wrt_reparent_to(const NodePath &other, int sort = 0, 00238 Thread *current_thread = Thread::get_current_thread()); 00239 NodePath instance_to(const NodePath &other, int sort = 0, 00240 Thread *current_thread = Thread::get_current_thread()) const; 00241 NodePath instance_under_node(const NodePath &other, const string &name, 00242 int sort = 0, 00243 Thread *current_thread = Thread::get_current_thread()) const; 00244 NodePath copy_to(const NodePath &other, int sort = 0, 00245 Thread *current_thread = Thread::get_current_thread()) const; 00246 NodePath attach_new_node(PandaNode *node, int sort = 0, 00247 Thread *current_thread = Thread::get_current_thread()) const; 00248 INLINE NodePath attach_new_node(const string &name, int sort = 0, 00249 Thread *current_thread = Thread::get_current_thread()) const; 00250 void remove_node(Thread *current_thread = Thread::get_current_thread()); 00251 void detach_node(Thread *current_thread = Thread::get_current_thread()); 00252 00253 // Handy ways to look at what's there, and other miscellaneous 00254 // operations. 00255 00256 void output(ostream &out) const; 00257 00258 INLINE void ls() const; 00259 INLINE void ls(ostream &out, int indent_level = 0) const; 00260 INLINE void reverse_ls() const; 00261 INLINE int reverse_ls(ostream &out, int indent_level = 0) const; 00262 00263 00264 // Aggregate transform and state information. 00265 const RenderState *get_state(Thread *current_thread = Thread::get_current_thread()) const; 00266 INLINE void set_state(const RenderState *state, Thread *current_thread = Thread::get_current_thread()); 00267 CPT(RenderState) get_state(const NodePath &other, Thread *current_thread = Thread::get_current_thread()) const; 00268 void set_state(const NodePath &other, const RenderState *state, Thread *current_thread = Thread::get_current_thread()); 00269 INLINE CPT(RenderState) get_net_state(Thread *current_thread = Thread::get_current_thread()) const; 00270 00271 INLINE void set_attrib(const RenderAttrib *attrib, int priority = 0); 00272 INLINE const RenderAttrib *get_attrib(TypeHandle type) const; 00273 INLINE bool has_attrib(TypeHandle type) const; 00274 INLINE void clear_attrib(TypeHandle type); 00275 00276 INLINE void set_effect(const RenderEffect *effect); 00277 INLINE const RenderEffect *get_effect(TypeHandle type) const; 00278 INLINE bool has_effect(TypeHandle type) const; 00279 INLINE void clear_effect(TypeHandle type); 00280 00281 INLINE void set_effects(const RenderEffects *effects); 00282 INLINE const RenderEffects *get_effects() const; 00283 INLINE void clear_effects(); 00284 00285 const TransformState *get_transform(Thread *current_thread = Thread::get_current_thread()) const; 00286 INLINE void clear_transform(Thread *current_thread = Thread::get_current_thread()); 00287 INLINE void set_transform(const TransformState *transform, Thread *current_thread = Thread::get_current_thread()); 00288 CPT(TransformState) get_transform(const NodePath &other, Thread *current_thread = Thread::get_current_thread()) const; 00289 INLINE void clear_transform(const NodePath &other, Thread *current_thread = Thread::get_current_thread()); 00290 void set_transform(const NodePath &other, const TransformState *transform, Thread *current_thread = Thread::get_current_thread()); 00291 INLINE CPT(TransformState) get_net_transform(Thread *current_thread = Thread::get_current_thread()) const; 00292 00293 const TransformState *get_prev_transform(Thread *current_thread = Thread::get_current_thread()) const; 00294 INLINE void set_prev_transform(const TransformState *transform, Thread *current_thread = Thread::get_current_thread()); 00295 CPT(TransformState) get_prev_transform(const NodePath &other, Thread *current_thread = Thread::get_current_thread()) const; 00296 void set_prev_transform(const NodePath &other, const TransformState *transform, Thread *current_thread = Thread::get_current_thread()); 00297 INLINE CPT(TransformState) get_net_prev_transform(Thread *current_thread = Thread::get_current_thread()) const; 00298 00299 00300 // Methods that get and set the matrix transform: pos, hpr, scale, 00301 // in the local coordinate system. 00302 00303 INLINE void set_pos(float x, float y, float z); 00304 void set_pos(const LVecBase3f &pos); 00305 void set_x(float x); 00306 void set_y(float y); 00307 void set_z(float z); 00308 INLINE void set_fluid_pos(float x, float y, float z); 00309 void set_fluid_pos(const LVecBase3f &pos); 00310 void set_fluid_x(float x); 00311 void set_fluid_y(float y); 00312 void set_fluid_z(float z); 00313 LPoint3f get_pos() const; 00314 INLINE float get_x() const; 00315 INLINE float get_y() const; 00316 INLINE float get_z() const; 00317 00318 LVector3f get_pos_delta() const; 00319 00320 INLINE void set_hpr(float h, float p, float r); 00321 void set_hpr(const LVecBase3f &hpr); 00322 void set_h(float h); 00323 void set_p(float p); 00324 void set_r(float r); 00325 LVecBase3f get_hpr() const; 00326 INLINE float get_h() const; 00327 INLINE float get_p() const; 00328 INLINE float get_r() const; 00329 00330 void set_quat(const LQuaternionf &quat); 00331 LQuaternionf get_quat() const; 00332 00333 INLINE void set_scale(float scale); 00334 INLINE void set_scale(float sx, float sy, float sz); 00335 void set_scale(const LVecBase3f &scale); 00336 void set_sx(float sx); 00337 void set_sy(float sy); 00338 void set_sz(float sz); 00339 LVecBase3f get_scale() const; 00340 INLINE float get_sx() const; 00341 INLINE float get_sy() const; 00342 INLINE float get_sz() const; 00343 00344 INLINE void set_shear(float shxy, float shxz, float shyz); 00345 void set_shear(const LVecBase3f &shear); 00346 void set_shxy(float shxy); 00347 void set_shxz(float shxz); 00348 void set_shyz(float shyz); 00349 LVecBase3f get_shear() const; 00350 INLINE float get_shxy() const; 00351 INLINE float get_shxz() const; 00352 INLINE float get_shyz() const; 00353 00354 INLINE void set_pos_hpr(float x, float y, float z, 00355 float h, float p, float r); 00356 void set_pos_hpr(const LVecBase3f &pos, 00357 const LVecBase3f &hpr); 00358 void set_pos_quat(const LVecBase3f &pos, 00359 const LQuaternionf &quat); 00360 00361 INLINE void set_hpr_scale(float h, float p, float r, 00362 float sx, float sy, float sz); 00363 void set_hpr_scale(const LVecBase3f &hpr, 00364 const LVecBase3f &scale); 00365 void set_quat_scale(const LQuaternionf &quat, 00366 const LVecBase3f &scale); 00367 INLINE void set_pos_hpr_scale(float x, float y, float z, 00368 float h, float p, float r, 00369 float sx, float sy, float sz); 00370 void set_pos_hpr_scale(const LVecBase3f &pos, 00371 const LVecBase3f &hpr, 00372 const LVecBase3f &scale); 00373 void set_pos_quat_scale(const LVecBase3f &pos, 00374 const LQuaternionf &quat, 00375 const LVecBase3f &scale); 00376 void set_pos_hpr_scale_shear(const LVecBase3f &pos, 00377 const LVecBase3f &hpr, 00378 const LVecBase3f &scale, 00379 const LVecBase3f &shear); 00380 void set_pos_quat_scale_shear(const LVecBase3f &pos, 00381 const LQuaternionf &quat, 00382 const LVecBase3f &scale, 00383 const LVecBase3f &shear); 00384 00385 void set_mat(const LMatrix4f &mat); 00386 INLINE void clear_mat(); 00387 INLINE bool has_mat() const; 00388 INLINE const LMatrix4f &get_mat() const; 00389 00390 INLINE void look_at(float x, float y, float z); 00391 void look_at(const LPoint3f &point, const LVector3f &up = LVector3f::up()); 00392 INLINE void heads_up(float x, float y, float z); 00393 void heads_up(const LPoint3f &point, const LVector3f &up = LVector3f::up()); 00394 00395 // Methods that get and set the matrix transforms relative to some 00396 // other node in the scene graph. These perform an implicit wrt(). 00397 00398 INLINE void set_pos(const NodePath &other, float x, float y, float z); 00399 void set_pos(const NodePath &other, const LVecBase3f &pos); 00400 void set_x(const NodePath &other, float x); 00401 void set_y(const NodePath &other, float y); 00402 void set_z(const NodePath &other, float z); 00403 INLINE void set_fluid_pos(const NodePath &other, float x, float y, float z); 00404 void set_fluid_pos(const NodePath &other, const LVecBase3f &pos); 00405 void set_fluid_x(const NodePath &other, float x); 00406 void set_fluid_y(const NodePath &other, float y); 00407 void set_fluid_z(const NodePath &other, float z); 00408 LPoint3f get_pos(const NodePath &other) const; 00409 INLINE float get_x(const NodePath &other) const; 00410 INLINE float get_y(const NodePath &other) const; 00411 INLINE float get_z(const NodePath &other) const; 00412 00413 LVector3f get_pos_delta(const NodePath &other) const; 00414 00415 INLINE void set_hpr(const NodePath &other, float h, float p, float r); 00416 void set_hpr(const NodePath &other, const LVecBase3f &hpr); 00417 void set_h(const NodePath &other, float h); 00418 void set_p(const NodePath &other, float p); 00419 void set_r(const NodePath &other, float r); 00420 LVecBase3f get_hpr(const NodePath &other) const; 00421 INLINE float get_h(const NodePath &other) const; 00422 INLINE float get_p(const NodePath &other) const; 00423 INLINE float get_r(const NodePath &other) const; 00424 00425 void set_quat(const NodePath &other, const LQuaternionf &quat); 00426 LQuaternionf get_quat(const NodePath &other) const; 00427 00428 INLINE void set_scale(const NodePath &other, float scale); 00429 INLINE void set_scale(const NodePath &other, float sx, float sy, float sz); 00430 void set_scale(const NodePath &other, const LVecBase3f &scale); 00431 void set_sx(const NodePath &other, float sx); 00432 void set_sy(const NodePath &other, float sy); 00433 void set_sz(const NodePath &other, float sz); 00434 LVecBase3f get_scale(const NodePath &other) const; 00435 INLINE float get_sx(const NodePath &other) const; 00436 INLINE float get_sy(const NodePath &other) const; 00437 INLINE float get_sz(const NodePath &other) const; 00438 00439 INLINE void set_shear(const NodePath &other, float shxy, float shxz, float shyz); 00440 void set_shear(const NodePath &other, const LVecBase3f &shear); 00441 void set_shxy(const NodePath &other, float shxy); 00442 void set_shxz(const NodePath &other, float shxz); 00443 void set_shyz(const NodePath &other, float shyz); 00444 LVecBase3f get_shear(const NodePath &other) const; 00445 INLINE float get_shxy(const NodePath &other) const; 00446 INLINE float get_shxz(const NodePath &other) const; 00447 INLINE float get_shyz(const NodePath &other) const; 00448 00449 INLINE void set_pos_hpr(const NodePath &other, 00450 float x, float y, float z, 00451 float h, float p, float r); 00452 void set_pos_hpr(const NodePath &other, 00453 const LVecBase3f &pos, 00454 const LVecBase3f &hpr); 00455 void set_pos_quat(const NodePath &other, 00456 const LVecBase3f &pos, 00457 const LQuaternionf &quat); 00458 INLINE void set_hpr_scale(const NodePath &other, 00459 float h, float p, float r, 00460 float sx, float sy, float sz); 00461 void set_hpr_scale(const NodePath &other, 00462 const LVecBase3f &hpr, 00463 const LVecBase3f &scale); 00464 void set_quat_scale(const NodePath &other, 00465 const LQuaternionf &quat, 00466 const LVecBase3f &scale); 00467 INLINE void set_pos_hpr_scale(const NodePath &other, 00468 float x, float y, float z, 00469 float h, float p, float r, 00470 float sx, float sy, float sz); 00471 void set_pos_hpr_scale(const NodePath &other, 00472 const LVecBase3f &pos, 00473 const LVecBase3f &hpr, 00474 const LVecBase3f &scale); 00475 void set_pos_quat_scale(const NodePath &other, 00476 const LVecBase3f &pos, 00477 const LQuaternionf &quat, 00478 const LVecBase3f &scale); 00479 void set_pos_hpr_scale_shear(const NodePath &other, 00480 const LVecBase3f &pos, 00481 const LVecBase3f &hpr, 00482 const LVecBase3f &scale, 00483 const LVecBase3f &shear); 00484 void set_pos_quat_scale_shear(const NodePath &other, 00485 const LVecBase3f &pos, 00486 const LQuaternionf &quat, 00487 const LVecBase3f &scale, 00488 const LVecBase3f &shear); 00489 00490 LMatrix4f get_mat(const NodePath &other) const; 00491 void set_mat(const NodePath &other, const LMatrix4f &mat); 00492 00493 LPoint3f get_relative_point(const NodePath &other, const LVecBase3f &point) const; 00494 LVector3f get_relative_vector(const NodePath &other, const LVecBase3f &vec) const; 00495 00496 INLINE void look_at(const NodePath &other, 00497 float x, float y, float z); 00498 void look_at(const NodePath &other, 00499 const LPoint3f &point = LPoint3f(0.0, 0.0, 0.0), 00500 const LVector3f &up = LVector3f::up()); 00501 INLINE void heads_up(const NodePath &other, 00502 float x, float y, float z); 00503 void heads_up(const NodePath &other, 00504 const LPoint3f &point = LPoint3f(0.0, 0.0, 0.0), 00505 const LVector3f &up = LVector3f::up()); 00506 00507 INLINE float get_distance(const NodePath &other) const; 00508 00509 00510 // Methods that affect appearance of geometry: color, texture, etc. 00511 // These affect the state at the bottom level only. 00512 00513 void set_color(float r, float g, float b, float a = 1.0, 00514 int priority = 0); 00515 void set_color(const Colorf &color, int priority = 0); 00516 void set_color_off(int priority = 0); 00517 void clear_color(); 00518 bool has_color() const; 00519 Colorf get_color() const; 00520 00521 bool has_color_scale() const; 00522 void clear_color_scale(); 00523 void set_color_scale(const LVecBase4f &scale, 00524 int priority = 0); 00525 INLINE void set_color_scale(float sx, float sy, float sz, float sa, 00526 int priority = 0); 00527 void compose_color_scale(const LVecBase4f &scale, 00528 int priority = 0); 00529 INLINE void compose_color_scale(float sx, float sy, float sz, float sa, 00530 int priority = 0); 00531 void set_color_scale_off(int priority = 0); 00532 00533 void set_alpha_scale(float scale, int priority = 0); 00534 void set_all_color_scale(float scale, int priority = 0); 00535 INLINE void set_sr(float sr); 00536 INLINE void set_sg(float sg); 00537 INLINE void set_sb(float sb); 00538 INLINE void set_sa(float sa); 00539 00540 const LVecBase4f &get_color_scale() const; 00541 INLINE float get_sr() const; 00542 INLINE float get_sg() const; 00543 INLINE float get_sb() const; 00544 INLINE float get_sa() const; 00545 00546 void set_light(const NodePath &light, int priority = 0); 00547 void set_light_off(int priority = 0); 00548 void set_light_off(const NodePath &light, int priority = 0); 00549 void clear_light(); 00550 void clear_light(const NodePath &light); 00551 bool has_light(const NodePath &light) const; 00552 bool has_light_off() const; 00553 bool has_light_off(const NodePath &light) const; 00554 00555 void set_clip_plane(const NodePath &clip_plane, int priority = 0); 00556 void set_clip_plane_off(int priority = 0); 00557 void set_clip_plane_off(const NodePath &clip_plane, int priority = 0); 00558 void clear_clip_plane(); 00559 void clear_clip_plane(const NodePath &clip_plane); 00560 bool has_clip_plane(const NodePath &clip_plane) const; 00561 bool has_clip_plane_off() const; 00562 bool has_clip_plane_off(const NodePath &clip_plane) const; 00563 00564 void set_scissor(float left, float right, float bottom, float top); 00565 void set_scissor(const LPoint3f &a, const LPoint3f &b); 00566 void set_scissor(const LPoint3f &a, const LPoint3f &b, 00567 const LPoint3f &c, const LPoint3f &d); 00568 void set_scissor(const NodePath &other, 00569 const LPoint3f &a, const LPoint3f &b); 00570 void set_scissor(const NodePath &other, 00571 const LPoint3f &a, const LPoint3f &b, 00572 const LPoint3f &c, const LPoint3f &d); 00573 void clear_scissor(); 00574 bool has_scissor() const; 00575 00576 void set_bin(const string &bin_name, int draw_order, int priority = 0); 00577 void clear_bin(); 00578 bool has_bin() const; 00579 string get_bin_name() const; 00580 int get_bin_draw_order() const; 00581 00582 void set_texture(Texture *tex, int priority = 0); 00583 void set_texture(TextureStage *stage, Texture *tex, int priority = 0); 00584 void set_texture_off(int priority = 0); 00585 void set_texture_off(TextureStage *stage, int priority = 0); 00586 void clear_texture(); 00587 void clear_texture(TextureStage *stage); 00588 bool has_texture() const; 00589 bool has_texture(TextureStage *stage) const; 00590 bool has_texture_off() const; 00591 bool has_texture_off(TextureStage *stage) const; 00592 Texture *get_texture() const; 00593 Texture *get_texture(TextureStage *stage) const; 00594 00595 void set_shader(const Shader *sha, int priority = 0); 00596 void set_shader_off(int priority = 0); 00597 void set_shader_auto(int priority = 0); 00598 void clear_shader(); 00599 void set_shader_input(const ShaderInput *inp); 00600 void set_shader_input(InternalName *id, Texture *tex, int priority=0); 00601 void set_shader_input(InternalName *id, const NodePath &np, int priority=0); 00602 void set_shader_input(InternalName *id, const LVector4f &v, int priority=0); 00603 void set_shader_input(InternalName *id, double n1=0, double n2=0, double n3=0, double n4=1, int priority=0); 00604 void set_shader_input(const string &id, Texture *tex, int priority=0); 00605 void set_shader_input(const string &id, const NodePath &np, int priority=0); 00606 void set_shader_input(const string &id, const LVector4f &v, int priority=0); 00607 void set_shader_input(const string &id, double n1=0, double n2=0, double n3=0, double n4=1, int priority=0); 00608 void clear_shader_input(InternalName *id); 00609 void clear_shader_input(const string &id); 00610 void set_instance_count(int instance_count); 00611 00612 const Shader *get_shader() const; 00613 const ShaderInput *get_shader_input(InternalName *id) const; 00614 const ShaderInput *get_shader_input(const string &id) const; 00615 const int get_instance_count() const; 00616 00617 void set_tex_transform(TextureStage *stage, const TransformState *transform); 00618 void clear_tex_transform(); 00619 void clear_tex_transform(TextureStage *stage); 00620 bool has_tex_transform(TextureStage *stage) const; 00621 CPT(TransformState) get_tex_transform(TextureStage *stage) const; 00622 00623 INLINE void set_tex_offset(TextureStage *stage, float u, float v); 00624 INLINE void set_tex_offset(TextureStage *stage, const LVecBase2f &uv); 00625 INLINE void set_tex_rotate(TextureStage *stage, float r); 00626 INLINE void set_tex_scale(TextureStage *stage, float scale); 00627 INLINE void set_tex_scale(TextureStage *stage, float su, float sv); 00628 INLINE void set_tex_scale(TextureStage *stage, const LVecBase2f &scale); 00629 INLINE LVecBase2f get_tex_offset(TextureStage *stage) const; 00630 INLINE float get_tex_rotate(TextureStage *stage) const; 00631 INLINE LVecBase2f get_tex_scale(TextureStage *stage) const; 00632 00633 INLINE void set_tex_pos(TextureStage *stage, float u, float v, float w); 00634 INLINE void set_tex_pos(TextureStage *stage, const LVecBase3f &uvw); 00635 INLINE void set_tex_hpr(TextureStage *stage, float h, float p, float r); 00636 INLINE void set_tex_hpr(TextureStage *stage, const LVecBase3f &hpr); 00637 INLINE void set_tex_scale(TextureStage *stage, float su, float sv, float sw); 00638 INLINE void set_tex_scale(TextureStage *stage, const LVecBase3f &scale); 00639 INLINE LVecBase3f get_tex_pos(TextureStage *stage) const; 00640 INLINE LVecBase3f get_tex_hpr(TextureStage *stage) const; 00641 INLINE LVecBase3f get_tex_scale_3d(TextureStage *stage) const; 00642 00643 void set_tex_transform(const NodePath &other, TextureStage *stage, const TransformState *transform); 00644 CPT(TransformState) get_tex_transform(const NodePath &other, TextureStage *stage) const; 00645 00646 INLINE void set_tex_offset(const NodePath &other, TextureStage *stage, float u, float v); 00647 INLINE void set_tex_offset(const NodePath &other, TextureStage *stage, const LVecBase2f &uv); 00648 INLINE void set_tex_rotate(const NodePath &other, TextureStage *stage, float r); 00649 INLINE void set_tex_scale(const NodePath &other, TextureStage *stage, float scale); 00650 INLINE void set_tex_scale(const NodePath &other, TextureStage *stage, float su, float sv); 00651 INLINE void set_tex_scale(const NodePath &other, TextureStage *stage, const LVecBase2f &scale); 00652 INLINE LVecBase2f get_tex_offset(const NodePath &other, TextureStage *stage) const; 00653 INLINE float get_tex_rotate(const NodePath &other, TextureStage *stage) const; 00654 INLINE LVecBase2f get_tex_scale(const NodePath &other, TextureStage *stage) const; 00655 00656 INLINE void set_tex_pos(const NodePath &other, TextureStage *stage, float u, float v, float w); 00657 INLINE void set_tex_pos(const NodePath &other, TextureStage *stage, const LVecBase3f &uvw); 00658 INLINE void set_tex_hpr(const NodePath &other, TextureStage *stage, float h, float p, float r); 00659 INLINE void set_tex_hpr(const NodePath &other, TextureStage *stage, const LVecBase3f &hpr); 00660 INLINE void set_tex_scale(const NodePath &other, TextureStage *stage, float su, float sv, float sw); 00661 INLINE void set_tex_scale(const NodePath &other, TextureStage *stage, const LVecBase3f &scale); 00662 INLINE LVecBase3f get_tex_pos(const NodePath &other, TextureStage *stage) const; 00663 INLINE LVecBase3f get_tex_hpr(const NodePath &other, TextureStage *stage) const; 00664 INLINE LVecBase3f get_tex_scale_3d(const NodePath &other, TextureStage *stage) const; 00665 00666 void set_tex_gen(TextureStage *stage, RenderAttrib::TexGenMode mode, int priority = 0); 00667 void set_tex_gen(TextureStage *stage, RenderAttrib::TexGenMode mode, 00668 const string &source_name, const NodePath &light, 00669 int priority = 0); 00670 void set_tex_gen(TextureStage *stage, RenderAttrib::TexGenMode mode, 00671 const TexCoord3f &constant_value, 00672 int priority = 0); 00673 void clear_tex_gen(); 00674 void clear_tex_gen(TextureStage *stage); 00675 bool has_tex_gen(TextureStage *stage) const; 00676 RenderAttrib::TexGenMode get_tex_gen(TextureStage *stage) const; 00677 NodePath get_tex_gen_light(TextureStage *stage) const; 00678 00679 void set_tex_projector(TextureStage *stage, const NodePath &from, const NodePath &to); 00680 void clear_tex_projector(TextureStage *stage); 00681 void clear_tex_projector(); 00682 bool has_tex_projector(TextureStage *stage) const; 00683 NodePath get_tex_projector_from(TextureStage *stage) const; 00684 NodePath get_tex_projector_to(TextureStage *stage) const; 00685 00686 void project_texture(TextureStage *stage, Texture *tex, const NodePath &projector); 00687 INLINE void clear_project_texture(TextureStage *stage); 00688 00689 void set_normal_map(Texture *normal_map, const string &texcoord_name = string(), 00690 bool preserve_color = false); 00691 void clear_normal_map(); 00692 00693 INLINE bool has_texcoord(const string &texcoord_name) const; 00694 bool has_vertex_column(const InternalName *name) const; 00695 InternalNameCollection find_all_vertex_columns() const; 00696 InternalNameCollection find_all_vertex_columns(const string &name) const; 00697 InternalNameCollection find_all_texcoords() const; 00698 InternalNameCollection find_all_texcoords(const string &name) const; 00699 00700 Texture *find_texture(const string &name) const; 00701 Texture *find_texture(TextureStage *stage) const; 00702 TextureCollection find_all_textures() const; 00703 TextureCollection find_all_textures(const string &name) const; 00704 TextureCollection find_all_textures(TextureStage *stage) const; 00705 00706 TextureStage *find_texture_stage(const string &name) const; 00707 TextureStageCollection find_all_texture_stages() const; 00708 TextureStageCollection find_all_texture_stages(const string &name) const; 00709 00710 void unify_texture_stages(TextureStage *stage); 00711 00712 Material *find_material(const string &name) const; 00713 MaterialCollection find_all_materials() const; 00714 MaterialCollection find_all_materials(const string &name) const; 00715 00716 void set_material(Material *tex, int priority = 0); 00717 void set_material_off(int priority = 0); 00718 void clear_material(); 00719 bool has_material() const; 00720 PT(Material) get_material() const; 00721 00722 void set_fog(Fog *fog, int priority = 0); 00723 void set_fog_off(int priority = 0); 00724 void clear_fog(); 00725 bool has_fog() const; 00726 bool has_fog_off() const; 00727 Fog *get_fog() const; 00728 00729 void set_render_mode_wireframe(int priority = 0); 00730 void set_render_mode_filled(int priority = 0); 00731 void set_render_mode_thickness(float thickness, int priority = 0); 00732 void set_render_mode_perspective(bool perspective, int priority = 0); 00733 void set_render_mode(RenderModeAttrib::Mode mode, float thickness, int priority = 0); 00734 void clear_render_mode(); 00735 bool has_render_mode() const; 00736 RenderModeAttrib::Mode get_render_mode() const; 00737 float get_render_mode_thickness() const; 00738 bool get_render_mode_perspective() const; 00739 00740 void set_two_sided(bool two_sided, int priority = 0); 00741 void clear_two_sided(); 00742 bool has_two_sided() const; 00743 bool get_two_sided() const; 00744 00745 void set_depth_test(bool depth_test, int priority = 0); 00746 void clear_depth_test(); 00747 bool has_depth_test() const; 00748 bool get_depth_test() const; 00749 00750 void set_depth_write(bool depth_write, int priority = 0); 00751 void clear_depth_write(); 00752 bool has_depth_write() const; 00753 bool get_depth_write() const; 00754 00755 void set_depth_offset(int bias, int priority = 0); 00756 void clear_depth_offset(); 00757 bool has_depth_offset() const; 00758 int get_depth_offset() const; 00759 00760 void do_billboard_axis(const NodePath &camera, float offset); 00761 void do_billboard_point_eye(const NodePath &camera, float offset); 00762 void do_billboard_point_world(const NodePath &camera, float offset); 00763 INLINE void set_billboard_axis(float offset = 0.0); 00764 INLINE void set_billboard_point_eye(float offset = 0.0); 00765 INLINE void set_billboard_point_world(float offset = 0.0); 00766 void set_billboard_axis(const NodePath &camera, float offset); 00767 void set_billboard_point_eye(const NodePath &camera, float offset); 00768 void set_billboard_point_world(const NodePath &camera, float offset); 00769 void clear_billboard(); 00770 bool has_billboard() const; 00771 00772 void set_compass(const NodePath &reference = NodePath()); 00773 void clear_compass(); 00774 bool has_compass() const; 00775 00776 void set_transparency(TransparencyAttrib::Mode mode, int priority = 0); 00777 void clear_transparency(); 00778 bool has_transparency() const; 00779 TransparencyAttrib::Mode get_transparency() const; 00780 00781 void set_antialias(unsigned short mode, int priority = 0); 00782 void clear_antialias(); 00783 bool has_antialias() const; 00784 unsigned short get_antialias() const; 00785 00786 bool has_audio_volume() const; 00787 void clear_audio_volume(); 00788 void set_audio_volume(float volume, 00789 int priority = 0); 00790 void set_audio_volume_off(int priority = 0); 00791 float get_audio_volume() const; 00792 float get_net_audio_volume() const; 00793 00794 INLINE void adjust_all_priorities(int adjustment); 00795 00796 // Variants on show and hide 00797 INLINE void show(); 00798 INLINE void show(DrawMask camera_mask); 00799 INLINE void show_through(); 00800 INLINE void show_through(DrawMask camera_mask); 00801 INLINE void hide(); 00802 INLINE void hide(DrawMask camera_mask); 00803 INLINE bool is_hidden(DrawMask camera_mask = PandaNode::get_overall_bit()) const; 00804 NodePath get_hidden_ancestor(DrawMask camera_mask = PandaNode::get_overall_bit(), 00805 Thread *current_thread = Thread::get_current_thread()) const; 00806 00807 void stash(int sort = 0, Thread *current_thread = Thread::get_current_thread()); 00808 void unstash(int sort = 0, Thread *current_thread = Thread::get_current_thread()); 00809 void unstash_all(Thread *current_thread = Thread::get_current_thread()); 00810 INLINE bool is_stashed() const; 00811 NodePath get_stashed_ancestor(Thread *current_thread = Thread::get_current_thread()) const; 00812 00813 INLINE CollideMask get_collide_mask() const; 00814 INLINE void set_collide_mask(CollideMask new_mask, CollideMask bits_to_change = CollideMask::all_on(), 00815 TypeHandle node_type = TypeHandle::none()); 00816 00817 // Comparison methods 00818 INLINE bool operator == (const NodePath &other) const; 00819 INLINE bool operator != (const NodePath &other) const; 00820 INLINE bool operator < (const NodePath &other) const; 00821 INLINE int compare_to(const NodePath &other) const; 00822 00823 // Miscellaneous 00824 bool verify_complete(Thread *current_thread = Thread::get_current_thread()) const; 00825 00826 void premunge_scene(GraphicsStateGuardianBase *gsg = NULL); 00827 void prepare_scene(GraphicsStateGuardianBase *gsg); 00828 00829 void show_bounds(); 00830 void show_tight_bounds(); 00831 void hide_bounds(); 00832 PT(BoundingVolume) get_bounds(Thread *current_thread = Thread::get_current_thread()) const; 00833 void force_recompute_bounds(); 00834 void write_bounds(ostream &out) const; 00835 bool calc_tight_bounds(LPoint3f &min_point, LPoint3f &max_point, 00836 Thread *current_thread = Thread::get_current_thread()) const; 00837 00838 // void analyze() const; 00839 00840 int flatten_light(); 00841 int flatten_medium(); 00842 int flatten_strong(); 00843 void apply_texture_colors(); 00844 INLINE int clear_model_nodes(); 00845 00846 INLINE void set_tag(const string &key, const string &value); 00847 INLINE string get_tag(const string &key) const; 00848 INLINE bool has_tag(const string &key) const; 00849 INLINE void clear_tag(const string &key); 00850 INLINE string get_net_tag(const string &key) const; 00851 INLINE bool has_net_tag(const string &key) const; 00852 NodePath find_net_tag(const string &key) const; 00853 00854 #ifdef HAVE_PYTHON 00855 INLINE void set_python_tag(const string &key, PyObject *value); 00856 INLINE PyObject *get_python_tag(const string &key) const; 00857 INLINE bool has_python_tag(const string &key) const; 00858 INLINE void clear_python_tag(const string &key); 00859 INLINE PyObject *get_net_python_tag(const string &key) const; 00860 INLINE bool has_net_python_tag(const string &key) const; 00861 NodePath find_net_python_tag(const string &key) const; 00862 #endif // HAVE_PYTHON 00863 00864 INLINE void list_tags() const; 00865 00866 INLINE void set_name(const string &name); 00867 INLINE string get_name() const; 00868 00869 BLOCKING bool write_bam_file(const Filename &filename) const; 00870 BLOCKING bool write_bam_stream(ostream &out) const; 00871 00872 INLINE string encode_to_bam_stream() const; 00873 bool encode_to_bam_stream(string &data, BamWriter *writer = NULL) const; 00874 static NodePath decode_from_bam_stream(const string &data, BamReader *reader = NULL); 00875 00876 private: 00877 static NodePathComponent * 00878 find_common_ancestor(const NodePath &a, const NodePath &b, 00879 int &a_count, int &b_count, 00880 Thread *current_thread); 00881 00882 CPT(RenderState) r_get_net_state(NodePathComponent *comp, 00883 Thread *current_thread) const; 00884 CPT(RenderState) r_get_partial_state(NodePathComponent *comp, int n, 00885 Thread *current_thread) const; 00886 CPT(TransformState) r_get_net_transform(NodePathComponent *comp, 00887 Thread *current_thread) const; 00888 CPT(TransformState) r_get_partial_transform(NodePathComponent *comp, int n, 00889 Thread *current_thread) const; 00890 CPT(TransformState) r_get_net_prev_transform(NodePathComponent *comp, 00891 Thread *current_thread) const; 00892 CPT(TransformState) r_get_partial_prev_transform(NodePathComponent *comp, 00893 int n, Thread *current_thread) const; 00894 00895 void find_matches(NodePathCollection &result, 00896 const string &approx_path_str, 00897 int max_matches) const; 00898 void find_matches(NodePathCollection &result, 00899 FindApproxPath &approx_path, 00900 int max_matches) const; 00901 void find_matches(NodePathCollection &result, 00902 FindApproxLevelEntry *level, 00903 int max_matches) const; 00904 00905 int r_clear_model_nodes(PandaNode *node); 00906 void r_adjust_all_priorities(PandaNode *node, int adjustment); 00907 00908 void r_force_recompute_bounds(PandaNode *node); 00909 00910 void r_set_collide_mask(PandaNode *node, 00911 CollideMask and_mask, CollideMask or_mask, 00912 TypeHandle node_type); 00913 00914 typedef phash_set<InternalName *, pointer_hash> InternalNames; 00915 bool r_has_vertex_column(PandaNode *node, const InternalName *name) const; 00916 void r_find_all_vertex_columns(PandaNode *node, 00917 InternalNames &vertex_columns) const; 00918 00919 typedef phash_set<Texture *, pointer_hash> Textures; 00920 Texture *r_find_texture(PandaNode *node, const RenderState *state, 00921 const GlobPattern &glob) const; 00922 void r_find_all_textures(PandaNode *node, const RenderState *state, 00923 Textures &textures) const; 00924 Texture *r_find_texture(PandaNode *node, TextureStage *stage) const; 00925 void r_find_all_textures(PandaNode *node, TextureStage *stage, 00926 Textures &textures) const; 00927 00928 typedef phash_set<TextureStage *, pointer_hash> TextureStages; 00929 TextureStage *r_find_texture_stage(PandaNode *node, const RenderState *state, 00930 const GlobPattern &glob) const; 00931 void r_find_all_texture_stages(PandaNode *node, const RenderState *state, 00932 TextureStages &texture_stages) const; 00933 00934 void r_unify_texture_stages(PandaNode *node, TextureStage *stage); 00935 00936 typedef phash_set<Material *, pointer_hash> Materials; 00937 Material *r_find_material(PandaNode *node, const RenderState *state, 00938 const GlobPattern &glob) const; 00939 void r_find_all_materials(PandaNode *node, const RenderState *state, 00940 Materials &materials) const; 00941 00942 PT(NodePathComponent) _head; 00943 int _backup_key; 00944 ErrorType _error_type; 00945 static int _max_search_depth; 00946 00947 public: 00948 static TypeHandle get_class_type() { 00949 return _type_handle; 00950 } 00951 static void init_type() { 00952 register_type(_type_handle, "NodePath"); 00953 } 00954 00955 private: 00956 static TypeHandle _type_handle; 00957 00958 friend class NodePathCollection; 00959 friend class WorkingNodePath; 00960 friend class WeakNodePath; 00961 }; 00962 00963 INLINE ostream &operator << (ostream &out, const NodePath &node_path); 00964 00965 #ifdef HAVE_PYTHON 00966 BEGIN_PUBLISH 00967 NodePath py_decode_NodePath_from_bam_stream(const string &data); 00968 NodePath py_decode_NodePath_from_bam_stream_persist(PyObject *unpickler, const string &data); 00969 END_PUBLISH 00970 #endif 00971 00972 #include "nodePath.I" 00973 00974 #endif