38 (
"pview-test-hack",
false,
39 "Enable the '0' key in pview to run whatever hacky test happens to be in " 54 cerr <<
"Could not generate screenshot " << fn <<
"\n";
60 event_W(
const Event *,
void *) {
75 if (window !=
nullptr) {
83 event_F(
const Event *,
void *) {
89 event_Enter(
const Event *,
void *) {
101 if (win !=
nullptr) {
112 int flags = GraphicsPipe::BF_require_window;
115 if (window !=
nullptr) {
123 event_2(
const Event *event,
void *) {
128 DCAST_INTO_V(wf, param.
get_ptr());
131 if (split !=
nullptr) {
133 split->setup_trackball();
139 event_0(
const Event *event,
void *) {
143 DCAST_INTO_V(wf, param.
get_ptr());
147 PT(
GraphicsOutput) buffer = win->make_texture_buffer(
"tex", 256, 256);
148 cerr << buffer->get_type() <<
"\n";
156 buffer->set_clear_color(LColor(1, 1, 0, 0));
160 cm.set_frame(0, 1, 0, 1);
164 card_np.set_texture(buffer->get_texture());
171 "Usage: pview [opts] model [model ...]\n" 179 "pview opens a quick Panda window for viewing one or more models and/or\n" 185 " Convert and play animations, if loading an external file type\n" 186 " (like .mb) directly and if the converter supports animations.\n" 187 " Also implicitly enables the animation controls.\n\n" 190 " Automatically center models within the viewing window on startup.\n" 191 " This can also be achieved with the 'c' hotkey at runtime.\n\n" 194 " Open the window before loading any models with the text \"Loading\"\n" 195 " displayed in the window. The default is not to open the window\n" 196 " until all models are loaded.\n\n" 199 " Ignore bundle/group names. Normally, the <group> name must match\n" 200 " the <bundle> name, or the animation will not be used.\n\n" 203 " After displaying the models, immediately take a screenshot and\n" 207 " Delete the model files after loading them (presumably this option\n" 208 " will only be used when loading a temporary model file).\n\n" 211 " Enable lighting in the scene. This can also be achieved with\n" 212 " the 'l' hotkey at runtime.\n\n" 215 " Select the given graphics pipe for the window, rather than using\n" 216 " the platform default. The allowed values for <pipe> are those\n" 217 " from the Config.prc variables 'load-display' and 'aux-display'.\n\n" 220 " Report the current version of Panda, and exit.\n\n" 223 " Display this help text.\n\n";
241 class AdjustCameraClipPlanesTask :
public AsyncTask {
243 AdjustCameraClipPlanesTask(
const std::string &name,
Camera *camera) :
244 AsyncTask(name), _camera(camera), _lens(camera->get_lens(0)), _sphere(nullptr)
250 nassertv(volume !=
nullptr);
251 nassertv(volume->is_of_type(GeometricBoundingVolume::get_class_type()));
257 new_gbv->xform(net_transform->get_mat());
262 if (gbv->is_infinite()) {
263 framework_cat.warning()
264 <<
"Infinite bounding volume for " << np <<
"\n";
268 if (gbv->is_empty()) {
269 framework_cat.warning()
270 <<
"Empty bounding volume for " << np <<
"\n";
277 if (!_sphere->extend_by(gbv)) {
278 framework_cat.warning()
279 <<
"Cannot determine bounding volume of " << np <<
"\n";
283 ALLOC_DELETED_CHAIN(AdjustCameraClipPlanesTask);
285 virtual DoneStatus do_task() {
301 LPoint3 pos = cameraNP.
get_pos();
304 LPoint3 center = _sphere->get_center();
305 PN_stdfloat radius = _sphere->get_radius();
307 PN_stdfloat min_distance = 0.001 * radius;
311 PN_stdfloat distance;
313 if (gbv->contains(pos)) {
315 distance = min_distance;
318 distance = (center - pos).length();
322 PN_stdfloat ideal_far_plane = distance + radius * 1.5;
323 _lens->set_far(std::max(_lens->get_default_far(), ideal_far_plane));
327 PN_stdfloat ideal_near_plane = std::max(min_distance * 10, distance - radius);
328 _lens->set_near(std::min(_lens->get_default_near(), ideal_near_plane));
340 main(
int argc,
char **argv) {
345 bool anim_controls =
false;
346 bool auto_center =
false;
347 bool show_loading =
false;
348 bool auto_screenshot =
false;
349 int hierarchy_match_flags = PartGroup::HMF_ok_part_extra |
350 PartGroup::HMF_ok_anim_extra;
352 bool delete_models =
false;
353 bool apply_lighting =
false;
358 static const char *optflags =
"acls:DVhiLP:";
359 int flag = getopt(argc, argv, optflags);
361 while (flag != EOF) {
364 anim_controls =
true;
365 PandaFramework::_loader_options.set_flags(PandaFramework::_loader_options.get_flags() | LoaderOptions::LF_convert_anim);
377 hierarchy_match_flags |= PartGroup::HMF_ok_wrong_root_name;
381 auto_screenshot =
true;
382 screenshotfn = optarg;
386 delete_models =
true;
390 apply_lighting =
true;
396 cerr <<
"No such pipe '" << optarg <<
"' available." << endl;
415 cerr <<
"Unhandled switch: " << flag << endl;
418 flag = getopt(argc, argv, optflags);
420 argc -= (optind - 1);
421 argv += (optind - 1);
424 if (window !=
nullptr) {
435 loading->set_text_color(1.0f, 1.0f, 1.0f, 1.0f);
436 loading->set_shadow_color(0.0f, 0.0f, 0.0f, 1.0f);
437 loading->set_shadow(0.04, 0.04);
438 loading->set_align(TextNode::A_center);
439 loading->set_text(
"Loading...");
459 for (
int i = 1; i < argc && argv[i] !=
nullptr; i++) {
462 nout <<
"Deleting " << model <<
"\n";
475 if (apply_lighting) {
483 if (auto_screenshot) {
484 return(output_screenshot(screenshotfn) ? 0:1);
491 PT(AdjustCameraClipPlanesTask) task =
new AdjustCameraClipPlanesTask(
"Adjust Camera Bounds", window->
get_camera(0));
495 framework.
define_key(
"shift-w",
"open a new window", event_W,
nullptr);
496 framework.
define_key(
"shift-f",
"flatten hierarchy", event_F,
nullptr);
497 framework.
define_key(
"alt-enter",
"toggle between window/fullscreen", event_Enter,
nullptr);
498 framework.
define_key(
"2",
"split the window", event_2,
nullptr);
499 if (pview_test_hack) {
500 framework.
define_key(
"0",
"run quick hacky test", event_0,
nullptr);
void report_frame_rate(std::ostream &out) const
Reports the currently measured average frame rate to the indicated ostream.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
NodePath get_render_2d()
Returns the root of the 2-d scene graph.
int get_num_windows() const
Returns the number of windows that are currently open.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
A base class for any number of different kinds of lenses, linear and otherwise.
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.
set_fullscreen
Specifies whether the window should be opened in fullscreen mode (true) or normal windowed mode (fals...
A hierarchy of directories and files that appears to be one continuous 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.
GraphicsOutput * get_graphics_output() const
Returns a pointer to the underlying GraphicsOutput object.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This defines a bounding sphere, consisting of a center and a radius.
void set_scale(PN_stdfloat scale)
Sets the scale component of the transform, leaving translation and rotation untouched.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_lighting(bool enable)
Turns lighting on (true) or off (false).
get_parent
Returns the NodePath to the parent of the referenced node: that is, this NodePath,...
void open_framework()
Should be called once at the beginning of the application to initialize Panda (and the framework) for...
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...
NodePath load_default_model(const NodePath &parent)
Loads our favorite blue triangle.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is another abstract class, for a general class of bounding volumes that actually enclose points ...
void reparent_to(const NodePath &other, int sort=0, Thread *current_thread=Thread::get_current_thread())
Removes the referenced node of the NodePath from its current parent and attaches it to the referenced...
get_current_thread
Returns a pointer to the currently-executing Thread object.
A container for the various kinds of properties we might ask to have on a graphics window before we o...
bool exists(const Filename &filename) const
Convenience function; returns true if the named file exists.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The name of a file, such as a texture file or an Egg file.
void add(AsyncTask *task)
Adds the indicated task to the active queue.
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...
void center_trackball(const NodePath &object)
Centers the trackball on the indicated object, and scales the trackball motion suitably.
get_pipe
Returns the GraphicsPipe that this window is associated with.
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.
bool save_screenshot(const Filename &filename, const std::string &image_comment="")
Saves a screenshot of the region to the indicated filename.
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...
AsyncTaskManager & get_task_mgr()
Returns the Task Manager object that manages tasks in the framework.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void close_window(int n)
Closes the nth window and removes it from the list.
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
This is a base class for the various different classes that represent the result of a frame of render...
void define_key(const std::string &event_name, const std::string &description, EventHandler::EventCallbackFunction *function, void *data)
Sets up a handler for the indicated key.
LPoint3 get_pos() const
Retrieves the translation component of the transform.
void preprocess_argv(int &argc, char **&argv)
Processes the argc, argv pair as needed before passing it to getopt().
set_camera
Sets the camera that is associated with this DisplayRegion.
This class represents a concrete task performed by an AsyncManager.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_window_title(const std::string &title)
Specifies the title that is set for all subsequently created windows.
get_properties
Returns the current properties of the window.
The primary interface to this module.
Encapsulates all the communication with a particular instance of a given rendering backend.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This file defines the classes PointerTo and ConstPointerTo (and their abbreviations,...
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
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...
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.
get_fullscreen
Returns true if the window is in fullscreen mode.
has_parent
Returns true if the referenced node has a parent; i.e.
Camera * get_camera(int n) const
Returns the nth camera associated with the window.
A node that can be positioned around in the scene graph to represent a point of view for rendering a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
WindowFramework * get_window(int n) const
Returns the nth window currently open.
NodePath get_camera_group()
Returns the node above the collection of 3-d cameras in the scene graph.
get_gsg
Returns the GSG that is associated with this window.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
virtual bool do_frame(Thread *current_thread)
Renders one frame and performs all associated processing.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.