38(
"pview-test-hack",
false,
39 "Enable the '0' key in pview to run whatever hacky test happens to be in "
48 framework.do_frame(current_thread);
49 framework.do_frame(current_thread);
54 cerr <<
"Could not generate screenshot " << fn <<
"\n";
60event_W(
const Event *,
void *) {
67 if (framework.get_num_windows() > 0) {
75 if (window !=
nullptr) {
78 framework.get_models().instance_to(window->
get_render());
83event_F(
const Event *,
void *) {
85 framework.get_models().flatten_strong();
89event_Enter(
const Event *,
void *) {
98 for (
int i = 0; i < framework.get_num_windows(); ++i) {
101 if (win !=
nullptr) {
105 framework.close_window(old_window);
112 int flags = GraphicsPipe::BF_require_window;
114 WindowFramework *window = framework.open_window(props, flags, pipe, gsg);
115 if (window !=
nullptr) {
118 framework.get_models().instance_to(window->
get_render());
123event_2(
const Event *event,
void *) {
128 DCAST_INTO_V(wf, param.
get_ptr());
131 if (split !=
nullptr) {
134 framework.get_models().instance_to(split->
get_render());
139event_0(
const Event *event,
void *) {
143 DCAST_INTO_V(wf, param.
get_ptr());
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";
241class 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()));
252 CPT(GeometricBoundingVolume) gbv = DCAST(GeometricBoundingVolume, volume);
256 PT(GeometricBoundingVolume) new_gbv = DCAST(GeometricBoundingVolume, gbv->make_copy());
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";
276 _sphere =
new BoundingSphere(gbv->get_approx_center(), 0.0f);
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() {
294 WindowFramework *wf = framework.
get_window(0);
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;
312 CPT(GeometricBoundingVolume) gbv = DCAST(GeometricBoundingVolume, _sphere);
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));
335 PT(BoundingSphere) _sphere;
340main(
int argc,
char **argv) {
342 framework.open_framework(argc, argv);
343 framework.set_window_title(
"Panda Viewer");
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...");
444 framework.do_frame(current_thread);
445 framework.do_frame(current_thread);
450 framework.get_models().instance_to(window->
get_render());
455 window->
load_models(framework.get_models(), argc, argv);
459 for (
int i = 1; i < argc && argv[i] !=
nullptr; i++) {
461 if (vfs->exists(model)) {
462 nout <<
"Deleting " << model <<
"\n";
463 vfs->delete_file(model);
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));
492 framework.get_task_mgr().add(task);
494 framework.enable_default_keys();
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);
502 framework.main_loop();
503 framework.report_frame_rate(nout);
506 framework.close_framework();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class represents a concrete task performed by an AsyncManager.
This class generates 2-d "cards", that is, rectangular polygons, particularly useful for showing text...
This is a convenience class to specialize ConfigVariable as a boolean type.
A rectangular subregion within a window for rendering into.
set_camera
Sets the camera that is associated with this DisplayRegion.
An optional parameter associated with an event.
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
A named event, possibly with parameters.
The name of a file, such as a texture file or an Egg file.
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,...
This is a base class for the various different classes that represent the result of a frame of render...
get_pipe
Returns the GraphicsPipe that this window is associated with.
get_gsg
Returns the GSG that is associated with this window.
GraphicsOutput * make_texture_buffer(const std::string &name, int x_size, int y_size, Texture *tex=nullptr, bool to_ram=false, FrameBufferProperties *fbp=nullptr)
Creates and returns an offscreen buffer for rendering into, the result of which will be a texture sui...
bool save_screenshot(const Filename &filename, const std::string &image_comment="")
Saves a screenshot of the region to the indicated filename.
static GraphicsPipeSelection * get_global_ptr()
Returns a pointer to the one global GraphicsPipeSelection object.
An object to create GraphicsOutputs that share a particular 3-D API.
Encapsulates all the communication with a particular instance of a given rendering backend.
A window, fullscreen or on a desktop, into which a graphics device sends its output for interactive d...
get_properties
Returns the current properties of the window.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
LPoint3 get_pos() const
Retrieves the translation component of the transform.
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
PointerTo< BoundingVolume > get_bounds(Thread *current_thread=Thread::get_current_thread()) const
Returns a newly-allocated bounding volume containing the bottom node and all of its descendants.
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...
has_parent
Returns true if the referenced node has a parent; i.e.
get_parent
Returns the NodePath to the parent of the referenced node: that is, this NodePath,...
void set_scale(PN_stdfloat scale)
Sets the scale component of the transform, leaving translation and rotation untouched.
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
int get_num_windows() const
Returns the number of windows that are currently open.
WindowFramework * get_window(int n) const
Returns the nth window currently open.
NodePath & get_models()
Returns the root of the scene graph normally reserved for parenting models and such.
This class is used as a namespace to group several global properties of Panda.
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
This file defines the classes PointerTo and ConstPointerTo (and their abbreviations,...
The primary interface to this module.
A thread; that is, a lightweight process.
get_current_thread
Returns a pointer to the currently-executing Thread object.
A hierarchy of directories and files that appears to be one continuous file system,...
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
This encapsulates the data that is normally associated with a single window, or with a single display...
NodePath load_default_model(const NodePath &parent)
Loads our favorite blue triangle.
void setup_trackball()
Sets up the mouse to trackball around the camera.
NodePath get_aspect_2d()
Returns the node under the 2-d scene graph that is scaled to suit the window's aspect ratio.
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...
NodePath get_render_2d()
Returns the root of the 2-d scene graph.
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_keyboard()
Creates a ButtonThrower to listen to button presses and throw them as events.
NodePath get_render()
Returns the root of the 3-d scene graph.
void center_trackball(const NodePath &object)
Centers the trackball on the indicated object, and scales the trackball motion suitably.
void set_anim_controls(bool enable)
Creates an onscreen animation slider for frame-stepping through the animations.
Camera * get_camera(int n) const
Returns the nth camera associated with the window.
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.
NodePath get_camera_group()
Returns the node above the collection of 3-d cameras in the scene graph.
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...
void set_lighting(bool enable)
Turns lighting on (true) or off (false).
GraphicsOutput * get_graphics_output() const
Returns a pointer to the underlying GraphicsOutput object.
A container for the various kinds of properties we might ask to have on a graphics window before we o...
get_fullscreen
Returns true if the window is in fullscreen mode.
set_fullscreen
Specifies whether the window should be opened in fullscreen mode (true) or normal windowed mode (fals...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void preprocess_argv(int &argc, char **&argv)
Processes the argc, argv pair as needed before passing it to getopt().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.