Panda3D Code Collection

Hi everyone,

over all those years I’m working with panda3d now, I’ve collected many snippets and code used in my projects. And now it’s time to share them all with the community.

Therefor I’ve created this Launchpad project:
https://launchpad.net/panda3dcodecollection

I’d highly recomend to use bazaar to check out the repository to always get the most recent revision of the source, but for anyone who can’t use bazaar, here’s a download link to get the, as of this writing, current revision of the code collection:
https://bazaar.launchpad.net/~fireclawthefox/panda3dcodecollection/trunk/tarball/67?start_revid=67

All snippets are sorted, documented and hopefully useful and easy to understand for anyone who want to use them.

Here is a quick overview of what’s currently in it:

  • Core functionality snippets like asynchronous loading of models, handling multifiles, etc…
  • DirectGUI snippets for loading screens and simple HUD setups
  • Input handling via panda3d and pygame (for joystick support)
  • Internationalization snippet with gettext
  • Pandas DistributedNetwork sample codes
  • Snippet for loading shader files
  • “Special” snippets like taking screenshots and fullscreen toggle

This project will grow over time as I and maybe others will put snippets in it. Everyone is welcome to contribute to this collection.

Fireclaw

3 Likes

Hello everyone,
as there is quite a lot of new stuff in the collection and to make it simpler to find this post if someone is searching for something specific that may be covered in this project, here is an updated and exhaustive list of all the samples that are currently readily available and well documented in the Collection.

The collection comes with all necessary models (aside of those shipped by default with Panda3D) so you should be able to open any of the scripts and just run them to see how they work and what they do.
Most if not all of the scripts should work with Panda3D 1.9.x and up.

Camera Systems

  • FPS
  • Fixed
  • Follow
  • Follow extended (even more extended version can be found in the extended character controller)
  • Top-down

Character Systems

  • Simple Character Controller Featuring:
    [list][*]Basic walking
  • Basic 3rd person camera handler
  • PyGame Gamepad support
    [/:m]
    [
    ]Extended Character Controller Featuring:
  • Extended Movements
    [list][*]Walking
  • Running
  • Jumping
  • Wall runs
    [/:m]
    [
    ]Smooth animation transitions[/:m]
    [
    ]Prevent from slipping off of slopes of arbitrary angles[/:m]
    [
    ]Extended 3rd person camera handler
  • Keep camera out of walls and out of the character
  • Move camera with mouse and/or keyboard
  • Center camera behind player
  • Lazy camera positioning
    [/:m]
    [
    ]Using Panda3D internal Physic engine (support for bullet engine is planned)[/:m]
    [
    ]Simply and highly configurable[/:m]
    [
    ]Demo script showing it’s usage[/:m][/list:u][/:m][/list:u]

Core Features and basics

  • A rather complex main.py template to start a new Panda3D project from
    [list][*]Contains various graphic enhancements
  • Game configuration loading and saving
  • Basic window setup
    [/:m]
    [
    ]Asynchronous model loading snippet[/:m]
    [
    ]Selection box drawing[/:m]
    [
    ]Multifile extraction to temp directory[/:m]
    [
    ]Show a X/Y/Z Axis on the windows edge[/:m]
    [
    ]Using PRC files to simply store and load game configurations[/:m]
    [
    ]Snippets that show of Panda3D basics
  • Simple event handling
  • Simple (Finite State Machine) FSM usage
  • Load multifiles in Virtual File System
  • On Screen Debug (OSD)
  • Panda3D’s Tasks system
    [/*:m][/list:u]

DirectGUI and other UI related things

  • Automatically scrolling Text Frame
  • Countdown
  • Drag and drop
  • Fade in/out
  • Loading screen
  • Simple Mouse Cursor changing with distiction between linux/unix and windows based systems
  • A simple HUD example
  • Automatic text writer pannel (for example for story elements in a game)

Input handling features

  • PyGame gamepad input
  • Basic mouse and keyboard input

Localisation
[]gettext example
[list]Contains how-to for creating gettext files
Shows how to select language manually as well as using the systems default language[/
:m][/list:u]
Level design features

  • Sky Cube around camera

Multimedia snippets

  • Very simple espeak snippet

Networking

  • Distributed Networking example with documentation

Physics

  • Bullet physics ball shooting example

Special effects (SFX)

  • Very basic shader loading and sample glsl shader

Specials snippets

  • Fullscreen toggle
  • Various graphic quality settings that can be set by Panda3D Like:
    [list][*]Multisampling
  • Anistropic texture filtering
  • The automatic shader generator (Per pixel lighting and Shadow mapping)
  • Antialiasing
  • Screen resolution
    [/:m]
    [
    ]Taking Screenshots[/:m]
    [
    ]Window title changing[/*:m][/list:u]

If you want to see something specific in this collection, I may be able to come up with a new snippet or example code. Other than that, every kind of contribution to it is still very welcome, especially reviewing and testing.

I looked at the code and I think you did a good job.
Good

Thank you very much! :slight_smile:

I’ve only just started with Panda3d but wow, thank you! I have bookmarked this.

As there are again quite some new features and snippets in the collection, here’s a change log of what has been added since my last post.

Camera Systems

  • Added strategy game like topdown camera system snippet
  • Added Blender like trackball camera system snippet

Character Systems

  • Added ledge grab mode to extended character controller
  • Added first person camera mode to extended character controller

Core Features and basics

  • Added simple savegame snippet

DirectGUI and other UI related things

  • Added snippet showing all the various DirectGUI elements
  • Textwriter now will scroll automatically or at button press instead of write lines out of the frame
  • Enhanced Textwriter sample by showing the differences between auto scroll and manual scrolling
  • Added Side scrolling text snippet

Input handling features

  • Added Joystick usage example using pyglet

Level design features

  • Added sample showing objects following a path

I downloaded most of the code manually, without using Bazaar.

Here is a link to my zip file with the code, for other users who may not want to use Bazaar. (Some of the folders are different, but I think I got all the important stuff.)

http://dropcanvas.com/#61dI327E46c7Q0

You can also download a tarball directly: bazaar.launchpad.net/~fireclawth … t_revid=62

Hey everyone,

as of revision 67, some nice and big new features just landed in the collection. So I wanted to update you with them.

general

  • Added instructions in the readme.txt on how to generally use the samples

Character Systems

  • Added gamepad support (preview of Panda3D’s own gamepad handling, needs 1.10 input-overhaul build and currently only supports the Wii Remote further gamepad support will be added over time)
  • Added missing textures from the character
  • Some bugfixes and improvements

Multimedia snippets

  • Added 3D Audio sample
  • Added simple Video sample

Special effects (SFX)

  • Added simple but useful glsl shaders. Currently there are:
    [list][*]simple per-vertex shader
  • normal mapping
  • lambert (flat and phong shaded)
  • half-lambert
  • velvet (rim-light)
  • gray scale
  • a snippet file with color models (currently WIP)
    [/*:m][/list:u]

I’ll also add a download link to the current revision in the first post for anyone who may not want to or can’t use bazaar.

Wolf

Is it possible to make this great collection code indexed by google (currently it not, AFAIK)? I believe this will give it best availability to people who search for example how to do something.

With best regards
Yosi

Hey everyone,

I’m glad to hear my snippets are a helpful addition for some of you.

The latest revision 71 adds a few more things and enhances existing snippets.

DirectGUI and other UI related things

  • Added snippet for simple tooltip that always stay within the window
  • Enhanced Textwriter sample with Font Kerning, better text speed processing and better performance
  • Added windows cursor file in replacement of the ico format to add cursor hotspot on windows and mac systems

Special effects (SFX)

  • Some work in progress stuff like mirror effect and a test cube for texture scaling shaders

Character Systems

Core Features and basics

  • Added a snippet to show how window events can be handled

@elkav, I’m not aware of any way to specifically index this repository for google search, but I think it already ranks rather high if you search for panda3d code snippets for example (was the 4. entry on my last search). Aside of that, telling newcomers and generally all other panda3d users about this collection would probably help rise it’s visibility too. And if rdb or other maintainers would be ok with that, it could be added to this manual section: http://www.panda3d.org/manual/index.php/User_Contributed_Tutorials_and_Examples or somewhere below my already added books on http://www.panda3d.org/manual/index.php/More_Panda3D_Resources.

Hello, it’s possible to include grass/three terrain example and to add water demonstration ? like this :
youtube.com/watch?v=1LAIEjmjRic

Hi sazearte, it definitely is possible to add such examples but probably will take some time untill I get to it. In the meantime you could already take them from the demomaster which you see in the linked video. It can be found over at Demomaster application framework with wxpython navigator Not sure how well it does work for recent versions of P3D though.
As soon as I get time I’ll take a look into vegetation, terrain and water as those are things I personally need too.

thank you very much wolf, i think is very interesting to have demo of lod grass terrain

thank for your link but i had read this post before post here and the sampler is verry old and not work in modern panda version.

As of revision 75, some bugs have been fixed and most scripts should run fine on the Python3 version of Panda3D now.

Also as the extended character controller got rather big, I’ve put it into its own separate project. Will post a new topic about that.

Hello, thanks for your samples
Like other people I would like to have an sample of a map with many 3d grass and trees

Maybe it’s a bug, the AI folder is empty

It’s not a bug, the AI folder is empty. I planned to fill it once, but haven’t got to it since. The terrain foliage is still planned, but I don’t know when I’ll get to it yet. As soon as it’s available, I’ll update this post.

thank you for your feedback.
when do you plan to add the foliage ? it seems to take you some time, is it difficult to implement in panda3d ?

You’re welcome. I’m not sure when I’ll get to it, usually I’ll add snippets as soon as I used them in my personal projects and as adding gras and other plants is part of something I want to add to my level, it may not be to far in the distant future.

As for the difficulty, there are also plenty of ways to add foliage to levels and even more possible dependencies for its implementation, so it depends. Like, should it be physical move with things like wind, water and other environmental things or move when the player runs through it as well as things like how should it be placed, should there be a texture map defining the amount and possition or should it be randomly scattered throughout the world and so on.

In general, nowdays you usually create a shader that implements a particle system to populate the floor with your defined foliage geometries. This isn’t all that hard if you know how to write glsl shaders in general. If this is out of your scope for now, you can also add static geometry to your level using your modelling application, blender for example has a few ways and good tutorials to spread objects randomly on the ground, which then could easily be exported to Panda3Ds model format, which in the end would probably be the most simple, but also performance wise worst way. But I don’t expect heavy frame drops if you don’t have particularely large levels.

Hope that information helps you for now. If you need anything in specific, you should open a new topic specific to adding foliage to your game or ask in the irc or discord channel or PM me.