15 #include "pandaFramework.h"
16 #include "pandaSystem.h"
19 #include "configVariableBool.h"
20 #include "texturePool.h"
21 #include "multitexReducer.h"
22 #include "sceneGraphReducer.h"
23 #include "partGroup.h"
24 #include "cardMaker.h"
26 #include "virtualFileSystem.h"
27 #include "panda_getopt.h"
28 #include "preprocess_argv.h"
29 #include "graphicsPipeSelection.h"
35 #include "checkPandaVersion.h"
40 (
"pview-test-hack",
false,
41 "Enable the '0' key in pview to run whatever hacky test happens to be in "
56 cerr <<
"Could not generate screenshot " << fn <<
"\n";
62 event_W(
const Event *,
void *) {
85 event_F(
const Event *,
void *) {
91 event_Enter(
const Event *,
void *) {
114 int flags = GraphicsPipe::BF_require_window;
125 event_2(
const Event *event,
void *) {
130 DCAST_INTO_V(wf, param.
get_ptr());
135 split->setup_trackball();
141 event_0(
const Event *event,
void *) {
145 DCAST_INTO_V(wf, param.
get_ptr());
149 PT(
GraphicsOutput) buffer = win->make_texture_buffer("tex", 256, 256);
150 cerr << buffer->get_type() << "\n";
154 dr->set_camera(
NodePath(wf->get_camera(0)));
158 buffer->set_clear_color(
LColor(1, 1, 0, 0));
163 cm.set_frame(0, 1, 0, 1);
166 card_np.reparent_to(wf->get_render_2d());
167 card_np.set_texture(buffer->get_texture());
174 "Usage: pview [opts] model [model ...]\n"
182 "pview opens a quick Panda window for viewing one or more models and/or\n"
188 " Convert and play animations, if loading an external file type\n"
189 " (like .mb) directly and if the converter supports animations.\n"
190 " Also implicitly enables the animation controls.\n\n"
193 " Automatically center models within the viewing window on startup.\n"
194 " This can also be achieved with the 'c' hotkey at runtime.\n\n"
197 " Open the window before loading any models with the text \"Loading\"\n"
198 " displayed in the window. The default is not to open the window\n"
199 " until all models are loaded.\n\n"
202 " Ignore bundle/group names. Normally, the <group> name must match\n"
203 " the <bundle> name, or the animation will not be used.\n\n"
206 " After displaying the models, immediately take a screenshot and\n"
210 " Delete the model files after loading them (presumably this option\n"
211 " will only be used when loading a temporary model file).\n\n"
214 " Enable lighting in the scene. This can also be achieved with\n"
215 " the 'l' hotkey at runtime.\n\n"
218 " Select the given graphics pipe for the window, rather than using\n"
219 " the platform default. The allowed values for <pipe> are those\n"
220 " from the Config.prc variables 'load-display' and 'aux-display'.\n\n"
223 " Report the current version of Panda, and exit.\n\n"
226 " Display this help text.\n\n";
238 main(
int argc,
char **argv) {
242 preprocess_argv(argc, argv);
246 bool anim_controls =
false;
247 bool auto_center =
false;
248 bool show_loading =
false;
249 bool auto_screenshot =
false;
250 int hierarchy_match_flags = PartGroup::HMF_ok_part_extra |
251 PartGroup::HMF_ok_anim_extra;
253 bool delete_models =
false;
254 bool apply_lighting =
false;
259 static const char *optflags =
"acls:DVhiLP:";
260 int flag = getopt(argc, argv, optflags);
262 while (flag != EOF) {
265 anim_controls =
true;
266 PandaFramework::_loader_options.set_flags(PandaFramework::_loader_options.get_flags() | LoaderOptions::LF_convert_anim);
278 hierarchy_match_flags |= PartGroup::HMF_ok_wrong_root_name;
282 auto_screenshot =
true;
283 screenshotfn = optarg;
287 delete_models =
true;
291 apply_lighting =
true;
297 cerr <<
"No such pipe '" << optarg <<
"' available." << endl;
316 cerr <<
"Unhandled switch: " << flag << endl;
319 flag = getopt(argc, argv, optflags);
321 argc -= (optind - 1);
322 argv += (optind - 1);
334 loading_np = aspect_2d.attach_new_node(loading);
335 loading_np.set_scale(0.125f);
336 loading->set_text_color(1.0f, 1.0f, 1.0f, 1.0f);
337 loading->set_shadow_color(0.0f, 0.0f, 0.0f, 1.0f);
338 loading->set_shadow(0.04, 0.04);
339 loading->set_align(
TextNode::A_center);
340 loading->set_text("Loading...");
345 framework.do_frame(current_thread);
346 framework.do_frame(current_thread);
349 window->enable_keyboard();
350 window->setup_trackball();
351 framework.get_models().instance_to(window->get_render());
360 for (
int i = 1; i < argc && argv[i] != (
char *)NULL; i++) {
363 nout <<
"Deleting " << model <<
"\n";
376 if (apply_lighting) {
384 if (auto_screenshot) {
385 return(output_screenshot(screenshotfn) ? 0:1);
393 framework.
define_key(
"shift-w",
"open a new window", event_W, NULL);
394 framework.
define_key(
"shift-f",
"flatten hierarchy", event_F, NULL);
395 framework.
define_key(
"alt-enter",
"toggle between window/fullscreen", event_Enter, NULL);
396 framework.
define_key(
"2",
"split the window", event_2, NULL);
397 if (pview_test_hack) {
398 framework.
define_key(
"0",
"run quick hacky test", event_0, NULL);
bool save_screenshot(const Filename &filename, const string &image_comment="")
Saves a screenshot of the region to the indicated filename.
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
This class is used as a namespace to group several global properties of Panda.
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...
An optional parameter associated with an event.
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.
const WindowProperties get_properties() const
Returns the current properties of the window.
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
This is a convenience class to specialize ConfigVariable as a boolean type.
NodePath get_aspect_2d()
Returns the node under the 2-d scene graph that is scaled to suit the window's aspect ratio...
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.
void set_lighting(bool enable)
Turns lighting on (true) or off (false).
void set_fullscreen(bool fullscreen)
Specifies whether the window should be opened in fullscreen mode (true) or normal windowed mode (fals...
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...
int get_num_windows() const
Returns the number of windows that are currently open.
NodePath load_default_model(const NodePath &parent)
Loads our favorite blue triangle.
bool get_fullscreen() const
Returns true if the window is in fullscreen mode.
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
WindowFramework * get_window(int n) const
Returns the nth window currently open.
GraphicsPipe * get_pipe() const
Returns the GraphicsPipe that this window is associated with.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
void prepare_scene(GraphicsStateGuardianBase *gsg)
Walks through the scene graph beginning at the bottom node, and does whatever initialization is requi...
A container for the various kinds of properties we might ask to have on a graphics window before we o...
GraphicsWindow * get_graphics_window() const
Returns a pointer to the underlying GraphicsWindow object, if it is in fact a window; or NULL if it i...
The name of a file, such as a texture file or an Egg file.
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.
An object to create GraphicsOutputs that share a particular 3-D API.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
void define_key(const string &event_name, const string &description, EventHandler::EventCallbackFunction *function, void *data)
Sets up a handler for the indicated key.
GraphicsStateGuardian * get_gsg() const
Returns the GSG that is associated with this window.
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.
static GraphicsPipeSelection * get_global_ptr()
Returns a pointer to the one global GraphicsPipeSelection object.
This class generates 2-d "cards", that is, rectangular polygons, particularly useful for showing text...
void close_window(int n)
Closes the nth window and removes it from the list.
This is a base class for the various different classes that represent the result of a frame of render...
This is the base class for all three-component vectors and points.
bool exists(const Filename &filename) const
Convenience function; returns true if the named file exists.
void open_framework(int &argc, char **&argv)
Should be called once at the beginning of the application to initialize Panda (and the framework) for...
int flatten_strong()
The strongest possible flattening.
A thread; that is, a lightweight process.
A named event, possibly with parameters.
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
bool load_models(const NodePath &parent, int argc, char *argv[], int first_arg=1)
Loads up all the model files listed in the indicated argument list.
The primary interface to this module.
Encapsulates all the communication with a particular instance of a given rendering backend...
void set_window_title(const string &title)
Specifies the title that is set for all subsequently created windows.
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
WindowFramework * split_window(SplitType split_type=ST_default)
Divides the window into two display regions, each of which gets its own trackball and keyboard events...
A rectangular subregion within a window for rendering into.
PointerTo is a template class which implements a smart pointer to an object derived from ReferenceCou...
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
bool delete_file(const Filename &filename)
Attempts to delete the indicated file or directory.
void setup_trackball()
Sets up the mouse to trackball around the camera.
void report_frame_rate(ostream &out) const
Reports the currently measured average frame rate to the indicated ostream.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
virtual bool do_frame(Thread *current_thread)
Renders one frame and performs all associated processing.
GraphicsOutput * get_graphics_output() const
Returns a pointer to the underlying GraphicsOutput object.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).