Panda3D
pview.cxx
1 // Filename: pview.cxx
2 // Created by: rdb (12Jan13)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pandaFramework.h"
16 #include "pandaSystem.h"
17 #include "pystub.h"
18 #include "texturePool.h"
19 #include "multitexReducer.h"
20 #include "sceneGraphReducer.h"
21 #include "partGroup.h"
22 #include "cardMaker.h"
23 #include "bamCache.h"
24 #include "virtualFileSystem.h"
25 
26 // By including checkPandaVersion.h, we guarantee that runtime
27 // attempts to run pview will fail if it inadvertently links with the
28 // wrong version of libdtool.so/.dll.
29 
30 #include "checkPandaVersion.h"
31 
32 int main(int argc, char **argv) {
33  // A call to pystub() to force libpystub.so to be linked in.
34  pystub();
35 
36  PandaFramework framework;
37  framework.open_framework(argc, argv);
38  framework.set_window_title("Panda Viewer");
39 
40  int hierarchy_match_flags = PartGroup::HMF_ok_part_extra |
41  PartGroup::HMF_ok_anim_extra;
42 
43  WindowFramework *window = framework.open_window();
44  if (window != (WindowFramework *)NULL) {
45  // We've successfully opened a window.
46 
47  NodePath loading_np;
48 
49  if (true) {
50  // Put up a "loading" message for the user's benefit.
51  NodePath aspect_2d = window->get_aspect_2d();
52  PT(TextNode) loading = new TextNode("loading");
53  loading_np = aspect_2d.attach_new_node(loading);
54  loading_np.set_scale(0.125f);
55  loading->set_text_color(1.0f, 1.0f, 1.0f, 1.0f);
56  loading->set_shadow_color(0.0f, 0.0f, 0.0f, 1.0f);
57  loading->set_shadow(0.04, 0.04);
58  loading->set_align(TextNode::A_center);
59  loading->set_text("Loading...");
60 
61  // Allow a couple of frames to go by so the window will be fully
62  // created and the text will be visible.
63  Thread *current_thread = Thread::get_current_thread();
64  framework.do_frame(current_thread);
65  framework.do_frame(current_thread);
66  }
67 
68  window->enable_keyboard();
69  window->setup_trackball();
70  framework.get_models().instance_to(window->get_render());
71  //if (argc < 2) {
72  // If we have no arguments, get that trusty old triangle out.
73  //window->load_default_model(framework.get_models());
74  //} else {
75  // window->load_models(framework.get_models(), argc, argv);
76  //}
77 
78  window->load_model(framework.get_models(), "panda-model.egg");
79  window->load_model(framework.get_models(), "panda-walk4.egg");
80 
81  window->loop_animations(hierarchy_match_flags);
82 
83  // Make sure the textures are preloaded.
84  framework.get_models().prepare_scene(window->get_graphics_output()->get_gsg());
85 
86  loading_np.remove_node();
87 
88  window->center_trackball(framework.get_models());
89  window->set_anim_controls(true);
90 
91  framework.enable_default_keys();
92  framework.main_loop();
93  framework.report_frame_rate(nout);
94  } else {
95  assert(false);
96  }
97 
98  framework.close_framework();
99  return (0);
100 }
void loop_animations(int hierarchy_match_flags=PartGroup::HMF_ok_part_extra|PartGroup::HMF_ok_anim_extra)
Looks for characters and their matching animation files in the scene graph; binds and loops any match...
void enable_default_keys()
Sets callbacks on the event handler to handle all of the normal viewer keys, like t to toggle texture...
NodePath & get_models()
Returns the root of the scene graph normally reserved for parenting models and such.
NodePath get_render()
Returns the root of the 3-d scene graph.
void close_framework()
Should be called at the end of an application to close Panda.
NodePath get_aspect_2d()
Returns the node under the 2-d scene graph that is scaled to suit the window&#39;s aspect ratio...
GraphicsOutput * get_graphics_output() const
Returns a pointer to the underlying GraphicsOutput object.
void set_scale(PN_stdfloat scale)
Sets the scale component of the transform, leaving translation and rotation untouched.
Definition: nodePath.I:848
This encapsulates the data that is normally associated with a single window, or with a single display...
void set_anim_controls(bool enable)
Creates an onscreen animation slider for frame-stepping through the animations.
NodePath instance_to(const NodePath &other, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Adds the referenced node of the NodePath as a child of the referenced node of the indicated other Nod...
Definition: nodePath.cxx:618
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
void prepare_scene(GraphicsStateGuardianBase *gsg)
Walks through the scene graph beginning at the bottom node, and does whatever initialization is requi...
Definition: nodePath.cxx:6088
NodePath load_model(const NodePath &parent, Filename filename)
Loads up the indicated model and returns the new NodePath, or the empty NodePath if the model could n...
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
Definition: nodePath.cxx:723
void center_trackball(const NodePath &object)
Centers the trackball on the indicated object, and scales the trackball motion suitably.
void main_loop()
Called to yield control to the panda framework.
void enable_keyboard()
Creates a ButtonThrower to listen to button presses and throw them as events.
WindowFramework * open_window()
Opens a window on the default graphics pipe.
void open_framework(int &argc, char **&argv)
Should be called once at the beginning of the application to initialize Panda (and the framework) for...
GraphicsStateGuardian * get_gsg() const
Returns the GSG that is associated with this window.
A thread; that is, a lightweight process.
Definition: thread.h:51
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
Definition: nodePath.cxx:757
The primary interface to this module.
Definition: textNode.h:52
void report_frame_rate(ostream &out) const
Reports the currently measured average frame rate to the indicated ostream.
void set_window_title(const string &title)
Specifies the title that is set for all subsequently created windows.
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
void setup_trackball()
Sets up the mouse to trackball around the camera.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
virtual bool do_frame(Thread *current_thread)
Renders one frame and performs all associated processing.