packp3d an application written entirely in C++

Hi, iḿ having problems using packp3d an application written entirely in C++. The manual saids that i have to load mi c++ application from a python program, called main.py. My main.py is this:

import subprocess
subprocess.call("./main")

When I run main.py, it runs mi c++ application, but when I create the p3d file, it dont run. For create the p3d file, I type this command (in linux-ubuntu):
packp3d -o Prueba.p3d -d HelloPandav2

Someone could use packp3d for an application written entirely in C++?? How I must write the main.py?
Thanks for your help!!

I’m not sure if you need to include “morepy” to get the subprocess module. But anyhow, you should also make sure that you have explicitly included the “main” executable, and I think you need to write a .pdef file in order to do that.

Hi rdb, thanks for your answer. I tried including morepy and it didn’t work. I dont really understand why you said to write a .pdef file to include the “main” executable. With the instructions:
import subprocess
subprocess.call("./main")

am I not including explicitly the main file? Iḿ not a python programmer, is why i dont know if it is correct.

No, the pdef file contains information on what exactly is included into your .p3d file. You can see with “multify -tvf” on your p3d file that your “main” executable is omitted by default.

So you need to create a pdef file indicating what to include into the p3d package, and pass that to ppackage. The manual contains more information about this, like this manual page:
panda3d.org/manual/index.ph … def_syntax

I tried using packp3d and ppackage and i could not obtain a .p3d file. Im starting to think than nobody write programs entirely in c++ with Panda, or they not distribute the applications. Maybe i should use panda with python too.
Thanks for your help!

I write my applications entirely with c++, I even exclude the whole python layer when I build panda. So do not dispair. If you want write in c++ only the maybe you dont neef to worry to much.about p3d files ?

Also for c++ developers its a bit “harder” to get started for various reasons but omce you got the gist it necomes easier.

Right, the p3d system has been primarily designed for Python users. Although it’s theoretically possible to use it with C++ code, I personally wouldn’t recommend it.

I would recommend new Panda users (assuming there aren’t very special reasons why they can’t use Python) to start with Python, though. There are many advantages to using Panda3D with Python over C++.

Ok, I guess that I’ll start with python. About the performance lost, is it considerable? I know that the engine is written in c++, but I have my doubts…
Thanks again for your answers.

No, not really. The performance sensitive parts of Panda3D are all implemented in C++.

I want to develop panda3D for the web, using c++.

The documentation says a trivial main.py is required to create a .p3d web package, but does not give the listing. Could someone kindly give the listing for this?

Also, since the program runs on the user’s client browser, I guess including main.exe from 64-bit ubuntu linux will not work all the time. It seems the program would need to include main.cxx. But then this would require Panda3D to contain a c++ interpreter, which raises eyebrows. And yet, Panda claims to run c++ scenes over the web. Can someone please give an explicit hello panda listing as to how to accomplish this?

Thanks so much.

You would need to compile your app for every platform, and then pack those into hosted packages. Then, make a .p3d that depends on that package (which you put on a custom host), containing a Python entry point that simply invokes the main executable in that package.

rdb has a point. Further investigation shows that launching on the web in c++ apparently requires compilation on each native device–one for Mac, one for Windows PC, one for Ubuntu, other brand X *nix like Posix? Probably separate versions for 32 bit and 64 bit…ooo, we forgot iOS and Android…gyack. A nightmare to create, and five nightmares to maintain. This is why Java was invented. Python, being interpreted, should also pretty much be a write once, run anywhere language. So the right answer really does seem to be “you don’t want to do that, learn Python”.

C++ seems to be fine as long as you’re only running in-house on your own homogeneous machines.

There is something called pdeploy that allegedly makes different versions. Have not been able to tell yet whether you have to feed it the different executables in the first place, or whether it does cross-compilation for you. Given the Wine windows emulator this is theoretically possible on Ubuntu but I’d be quite impressed if someone pulled off five-platform cross-compilation for real. Or even two-platform.

“learn Python”.

Hi guys,

Did you have success using packp3d with a c++ application? can somebody tell me what I have to put in my main.py to call the c++ main(), or what else I have to add in my c++ file?

Thank you.

.

Hello,

Finally, is it possible to make a .p3d using a c++ application? and if I have dependencies with another dlls, how include this? I need to make a c++ application that runs on a web site, Panda seems perfect for that but I didn’t find any example and the manual just make reference to python.

Is it the only way making a main.py that calls my app.exe and then make a .p3d of all this with a deploy.def file?

thank you.

Panda’s p3d system is well-suited for Python code, but more difficult to use for C++ code, though it can be done. You can’t pack the C++ code into the p3d file itself, but you can put it (along with any required DLL’s) in a Panda3D “package” that you host on your own web server, and then put a trivial Python program in your p3d file that references this package and calls your start function.

It will require a certain degree of comfort with calling into C++ from Python; and with Panda’s packaging system in general. It might be a good idea to try a few simple Python-only programs first to get a feel for how the system works normally.

David

I have to put my panda package on a web server to make it work from the beginning or I can test before directly?

I was making a few python programs at first but Im not sure, for example, I tried to package an sample where Tut-Bump-Mapping.py I renamed it to main.py and made a deploy.def but didnt work, can you please tell me what is the problem in this:

from panda3d.core import *

class myresources(package):
file(Filename(‘models/*’))

class pandagame(p3d):
require(‘panda3d’, ‘myresources’)
config(display_name=‘My_Game’)
dir(‘src’)
mainModule(‘main.py’)

thanks a lot!

You do have to have your package available on some URL. You specify this URL on the require() function, like this:

require(‘myresources’, host = ‘http://mywebhost.com/mydirectory’)

This would mean you’d need to copy your package directory to mywebhost.com/mydirectory. (Note that you will might find it easier to use a different pdef file for your package and for your p3d file). However, it doesn’t have to be an http URL; you can also use a file URL, which means you don’t actually have to host your package on a web server:

require(‘myresources’, host = ‘file:///c:/Users/myname/mydirectory’)

and then you just copy your package directory to c:\Users\myname\mydirectory. Or use the -i parameter to ppackage to build it there in the first place.

David

Hi,

I’ve just learn how to package a python Panda app to get used with ppackage and the p3d files. But, what I need is to package a C++ app.

I just try to package a c++ sample calling the .exe file from the python main:

from panda3d.core import *
import sys

import subprocess 
proc = subprocess.Popen('PrototypeWeb.exe')

I created myresources package where I put my .exe file but I have a warning when I do this:

from panda3d.core import *
import sys

packager.setHost('file:///C:/PrototypeWeb/PrototypeWeb/test/output')

class myresources(package):
	file(Filename("models/*"))		
	file('PrototypeWeb.exe')
Warning: :Packager(warning): Unable to determine dependencies from /c/PrototypeWeb/PrototypeWeb/test/PrototypeWeb.exe

and my p3d with the .pdef file like this:

from panda3d.core import *
import sys

class pandagame(p3d):
	require('panda3d')
	require('models')
	require('morepy')	
	require('myresources', host = 'file:///C:/PrototypeWeb/PrototypeWeb/test/output')
	config(display_name='My_Game')	
	mainModule('main')

When I run my p3d file I don’t have errors but nothing happens and it just shows the panda logo.

Can you tell me please what is the problem?

Thank you in advance!

I’ve never tried running an .exe file using subprocess like that from a p3d file. I guess it should work, though I think the Panda window will remain visible unless you specifically ask it to launch hidden (for instance by specifying config(hidden=1) in the pdef file).

You might also need to put the subprocess call within a main() function.

You can put print statements in your Python file to help track this down. Is the Python program starting? Is it calling subprocess? Is the subprocess.Popen() call returning success? In order to see this output, you can run your p3d file from the command line with “panda3d myfile.p3d”.

Actually, now that I think about it, it might just be that it’s not finding your exe file because that’s placed in a different directory. Try:

filename = Filename.expandFrom("$MYRESOURCES_ROOT/PrototypeWeb.exe")
if not filename.exists():
  print "Could not find %s" % (filename)
else:
  proc = subprocess.Popen(filename.toOsSpecific())
  print "Popen returned %s" % (proc)
  proc.wait()

David