Panda3D Manual: Creating MultifilesMultifiles archives are archive files that store game resources. Think of it as a giant zip file that stores, optionally zips and encrypts your data files, but does not need to be extracted.
The multify programThe multify console program creates such files. You can get information about the commandline parameters by running multify with the Usage: multify -[c|r|u|t|x] -f <multifile_name> [options] <subfile_name> ... multify is used to store and extract files from a Panda Multifile. This is similar to a tar or zip file in that it is an archive file that contains a number of subfiles that may later be extracted. Panda's VirtualFileSystem is capable of mounting Multifiles for direct access to the subfiles contained within without having to extract them out to independent files first. The command-line options for multify are designed to be similar to those for tar, the traditional Unix archiver utility. Read AssetsIf you want to prepare to read assets from a Multifile directly, you can "mount" it into the virtual file system:
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
If you want to read assets, you can mount a whole directory structure from a webserver. If your webserver hosts: http://localhost/mydir/models/myfile.bam http://localhost/mydir/maps/mytexture.png Put this in your config.prc: vfs-mount-url http://myserver/mydir /mydir model-path /mydir Or, equivalently, write this Python code at startup: vfs.mount(VirtualFileMountHTTP('http://myserver/mydir'), '/mydir', 0) and then you can load models like this in your Python code: model = loader.loadModel('models/myfile.bam') If you want to prepare for reading and writing assets to a Multifile do the following. from panda3d.core import VirtualFileSystem If you want to prepare for reading and writing assets to a 'subdirectory' Multifile do the following. Note "mysys" must always be literally written in any python code. E.g. "mysys/memfdir/mfbar2.txt" from panda3d.core import VirtualFileSystem If you are having problems loading from multifiles you can list the complete contents of your .mf file with a command like: multify -tvf mymultifile.mf Doing a sanity inspection like this can be useful to ensure that your assets are in the right place within the multifile. Multifile objectsThe Multifile class is designed for opening, reading and writing multifiles. You can open a new multifile by creating an instance of the class and calling the from panda3d.core import Multifile The If you have made important structural changes to a Multifile, it is recommended to rewrite the multifile using the To write it back to disk, you can use the To mount Multifile objects into the VirtualFileSystem without writing them to disk first, here's an example on how to mount them: yourMF = Multifile() SubfilesFiles that are added to a multifile are called subfiles. You can add existing files to a multifile object using the There are several other methods which operate on subfiles, which you can find in the API Reference. Here are a few examples of working with subfiles: from panda3d.core import VirtualFileSystem
std::ostringstream os (std::ios::in | std::ios::out); If the foo.mf file were to have a contained bar.egg.pz file, load the egg and use it similar to other model loading methods. nodepath = loader.loadModel("foo/bar") Stream-BasedMultifile algorithms are stream-based and not random-based.
In a running game, from the output, if a message is received saying something similar to the words # models is the original directory # models.mf it the new target multifile multify -c -f models.mf -v models In the game, from the multifile models.mf, load the .ttf file. font = loader.loadFont("models/arial.ttf")
EncryptionMultifiles can also encrypt your files with a password. To do so, you need to set the encryption flag and password using the At the OS prompt, to create a password protected multifile and print out the contents do the following. # models is the original directory # models.mf it the new target multifile multify -c -f models.mf -ep "mypass" -v models This code creates a multifile and adds an encrypted file to it: m = Multifile() You can read encrypted multifiles the same way: m = Multifile() At the OS prompt, to see the contents of a password protected multifile perform multify -tvf models.mf -p "mypass"
from panda3d.core import Multifile When running the game, the following should be seen. mounted
It is possible to have a multifile where different subfiles have different encryption, but you will not be able to mount it with the VirtualFileSystem or use it with the multify tool. To mount an encrypted file using the VirtualFileSystem, pass the password as parameter to the VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr()
To use encryption with the multify tool, run it with the © Carnegie Mellon University 2010 |