
SVDRV Lab04: Introduction to Panda3D Michele Svanera & Fabrizio Pedersoli Department of Information Engineering University of Brescia 28 Apr 2014 1 Introduction to Panda3D 2 Scene Graph 3 Task 4 Actors and Models 5 Render Attributes 6 Camera control 7 Install and References OpenGL limitations Low-level library! Speaks graphic cards \languages" (translator functionality) Portable and very fast System independent Useful for implementing basic functionality simple objects texture mapping light source little animation . and for something more complex? . Animation? Interaction between objects? Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 3 Panda3D: a game engineI What is it? Open-source (from 2002) game engine Library of subroutines for 3D rendering and game development Provides: Graphics Audio I/O Collision detection ... Set of C++ library with Python bindings [5] Jointly developed by Disney and Carnegie Mellon University Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 4 Panda3D: a game engineII Commercial and Open-source library. So 4 characteristics: Power easy to implement complex scenes Speed important frame-rates Completeness contains tons of essential tools scene graph browsing performance monitoring animation optimizers Error tolerance all developers create bugs! Much code (it is an SDK) is dedicated to the problem of tracking and isolating errors. Panda3D almost never crashes! Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 5 The Use of Models Usually here we don't draw stuff Boring. Tricky to do procedurally Not trivial to design \realistic" models Usually ready-made models are imported into panda Models are drawn with proper modelling tools: Blender (we will see it the next time), Maya, 3DS MAX High-quality Models can be animated by the engine . Drawing is still possible! Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 6 Panda3D books \Panda3D 1.6 Game Engine Beginner's Guide", by Dave Mathews \Panda3D 1.7 Game Developer's Cookbook", by Christoph Lang Panda3D Manual [14] Panda3D Forum [13] Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 7 1 Introduction to Panda3D 2 Scene Graph 3 Task 4 Actors and Models 5 Render Attributes 6 Camera control 7 Install and References The Scene GraphI \Tree of things to render": More flexible than lists (as many other engine uses) and inheritance An object is not visible (and rendered) until it is inserted Objects are children of (super)class PandaNode ModelNode GeomNode LightNode ... usually refer as general NodePath. Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 9 The Scene GraphII Something to know about the tree The root of the tree is called render Each node attributes are inherited by the children (ex. position) Possibility to manipulate the tree, NodePath helper class pointer to a node (in reality it's something more... \handle") when you invoke a method of NodePath, you are actually performing an operation on the node to which it points Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 10 The Scene Graph III Panda3D generates bounding boxes for each node in the tree Number of methods dedicated to finding nodes and returning the NodePaths Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 11 The Scene GraphIV Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 12 The Scene GraphV Example 1: Solar System Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 13 The Scene GraphVI Example 2: What makes a man? Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 14 Dealing with nodesI Loading models NodePath np = window->load_model(framework. get_models(), "path/to/models/model.egg");//ready-made models can be found under"models/" Manipulating nodes np.reparent_to(window->get_render());//attach this node under root np.detach_node();//remove node from tree np.remove_node();//delete node: releasing memory Create empty nodes NodePath dummyNode = window->get_render(). attach_new_node("Dummy_Node_Name"); myModel.reparent_to(dummyNode); myOtherModel.reparent_to(dummyNode) Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 15 Dealing with nodesII Setting attributes: np.set_pos(x, y, z); np.set_hpr(Yaw, Pitch, Roll); np.set_scale(s);//object's size; set_x() _y() //Store current transform information np.get_pos(); //Rotatesa model to face another object np.look_at(otherObject); //Color: floating point numbers from0 to 1,0 being black,1 being white. np.set_color(R, G, B, A); //Temporarily prevent an object from being drawn np. hide (); np. show (); Notes1 1An object's rotation is usually described using Euler angles called Heading, Pitch, and Roll (sometimes called Yaw, Pitch, and Roll in other packages){these specify angle rotations in degrees. Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 16 1 Introduction to Panda3D 2 Scene Graph 3 Task 4 Actors and Models 5 Render Attributes 6 Camera control 7 Install and References TaskI Special functions (subroutines) called on each frame: Similar in concept to threads All tasks run cooperatively within the main thread Defined by GenericAsyncTask class The function receives one parameter: the task object Each task carries information about itself (ex. amount of time) task->get_elapsed_time() //how long task running task->get_elapsed_frames() //number of elapsed frames ... Each task returns after it has finished processing the current frame: AsyncTask::DS_cont = call it again the next frame AsyncTask::DS_done = finished, don't call it anymore AsyncTask::DS_again = perform it again, with same delay Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 18 TaskII Generic Task AsyncTask::DoneStatus your_task(GenericAsyncTask* task , void* data) { // Do your stuff here. //... //... // Tell the task manager to continue this task the next frame. // You can also pass DS_done if this task should not be run again. return AsyncTask::DS_cont; } Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 19 Task III Task example # include"asyncTaskManager.h" // This task runs for two seconds, then prints done AsyncTask::DoneStatus example_task(GenericAsyncTask* task , void* data){ if (task->get_elapsed_time() < 2.0){ return AsyncTask::DS_cont; } cout <<"Done" << endl; return AsyncTask::DS_done; } Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 20 The Task Manager All tasks are handled through the Task Manager object (list) TM can be initialized by PT(AsyncTaskManger) taskMgr = AsyncTaskManager:get_global_ptr(); Adding a new task can be done by PT(GenericAsyncTask) task; task = new GenericAsyncTask("taskName",& function , (void*)NULL); taskMgr->add(task); Tasks con also be removed by task->remove() Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 21 The Task Chain Each TaskChain is a ordered list of tasks that are available to be executed Add tasks to the TaskManager = adding in default Task Chain TaskManager can maintains one or more task chains You can create additional task chains as you see the need Each task chain has the option of run in parallel with others New task chain AsyncTaskManager *task_mgr = AsyncTaskManager::get_global_ptr(); AsyncTaskChain *chain = task_mgr-> make_task_chain("chain_name"); Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 22 Exercise: Rotating CubeI Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 23 Exercise: Rotating CubeII Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 24 1 Introduction to Panda3D 2 Scene Graph 3 Task 4 Actors and Models 5 Render Attributes 6 Camera control 7 Install and References Actors and Models Two main classes for 3D geometry: Model for nonanimated geometry (static) Actor for animated (if it changes shape) geometry (dynamic) Where? .egg file Used to store Geometry May contain Model, Actor, Animation (to be applied to an actor) or both (better to pack in two .egg) Are created by exporting models from 3D modeling programs: Maya, Max, or Blender (Lab06) Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 26 Loading Actors and AnimationsI Actor operations: Required Includes #include"auto_bind.h" Load the Actor Model NodePath Actor = window->load_model(window-> get_render(),"models/panda-model"); Load the Animation // the name of an animation is preceded in the. egg file with<Bundle> window->load_model(Actor,"models/panda-walk4"); One-command animation //bind models and animations+ set it to loop window->loop_animations(0); Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 27 Loading Actors and AnimationsII Bind the Model and the Animation // don't usePT orCPT with AnimControlCollection AnimControlCollection anim_collection; // bind the animations to the model auto_bind(Actor.node(), anim_collection); Control the Animations // loop all animations anim_collection.loop_all(true); // loopa specific animation anim_collection.loop("panda_walk_character", true) // play an animation once anim_collection.play("panda_walk_character"); // pose: holda particular frame of the animation anim_collection.pose("panda_walk_character", 5); Michele Svanera & Fabrizio Pedersoli SVDRV lab04: Introduction to Panda3D 28 1 Introduction to Panda3D 2 Scene Graph 3 Task 4 Actors and Models 5 Render Attributes 6 Camera control
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages50 Page
-
File Size-