Panda3D/Manual/FAQ

Origem: Wikilivros, livros abertos por um mundo aberto.

Contents

   * 1 Q: What is the .pz files I am seeing the samples?
         o 1.1 A: Those are zipped files that are zipped with panda pzip/punzip command line tools tools that panda3d knows how to read
   * 2 Q: What is the .pyc files i that are created every where?
         o 2.1 A: .pyc and .pyo are python compiled and python optimized compiled files
   * 3 Q: I have a bunch of Maya Animations of one model in different mb files. I used maya2egg to port them into panda, but only one of the animations work.
         o 3.1 A: The key is to use the -cn <character's name> flag in maya2egg for every file. This ensures that the files work together.
   * 4 Q: I'm using the lookAt function on a nodepath to point it at another object. It works fine until I point upwards, and then it starts to spin my object around randomly
         o 4.1 A: lookAt works as long as you aren't telling it to look in the direction of its up vector. Luckily, you can specify the up vector as the second argument.
   * 5 Q: I'm building a 3d game, and I have a huge world. When my world starts up, the program hangs for a few seconds the first time I look around. Is there any way to avoid this?
         o 5.1 A: It can take a while to prepare objects to be rendered.
   * 6 Q: Is there a way to hide the mouse pointer so that it doesn't show up on my screen?
         o 6.1 A: You can change to properties of the panda window so that it doesn't show the cursor:
   * 7 Q: If a model has an animation, is that animation necessarily represented by an additional .egg file?
         o 7.1 A: No. An .egg file can either be just geometry, just an animation, or a combination of the two.
   * 8 Q: I have a model with an animation. When i try to play the animation I get this error:
         o 8.1 A: This often happens when you are trying to load animations onto a model that wasn't exported to have animations.
   * 9 Q: I called setTexture('tex.jpg') and it didn't change or send an error.
         o 9.1 A: To override an existing texture, you need to specify a priority: setTexture('tex.jpg', 1).
   * 10 Q: I get this error:
         o 10.1 A: Sequences and Parallels are a way to combine intervals. You can't put anything inside them that isn't an interval. If you want this code to work you want something like:
   * 11 Q: Does panda use degrees or radians?
         o 11.1 A: Degrees. But see also the deg2Rad() and rad2Deg() functions.
   * 12 Q: Why do all my flat objects look weird when lit?
         o 12.1 A: Flats don't often have a lot of vertices.
   * 13 Q: To smooth my animations, I used "interpolate-frames 1" option but it doesn't work somehow. Why?
         o 13.1 A: Interpolate-frames flag gets set in the PartBundle at the time it is first created, and then baked into the bam cache.
   * 14 Q: I'm trying to redirect the output of some commands like "myNode.ls()" to a file but the usual method "python >>file, myNode.ls()" doesn't work. What's the alternative?
         o 14.1 A: You can try:
   * 15 Q: How do we create a node from a string containing .egg source?
         o 15.1 A: Use the EggData class:
   * 16 Q: How can we know which letter was bellow the pointer when we click on a TextNode?
         o 16.1 A: Use the TextAssembler class like this:


Q: What is the .pz files I am seeing the samples? A: Those are zipped files that are zipped with panda pzip/punzip command line tools tools that panda3d knows how to read

Usage:

 pzip file [file2 file3 ...]
 pzip -o dest_file file

Usage:

 punzip file.pz [file2.pz file3.pz ...]
 punzip -o dest_file file.pz

Q: What is the .pyc files i that are created every where? A: .pyc and .pyo are python compiled and python optimized compiled files

As an important speed-up of the start-up time for short programs that use a lot of standard modules, if a file called "spam.pyc" exists in the directory where "spam.py" is found, this is assumed to contain an already-``byte-compiled version of the module spam. The modification time of the version of "spam.py" used to create "spam.pyc" is recorded in "spam.pyc", and the file is ignored if these don't match. http://www.python.org/doc/1.5.1p1/tut/node43.html Q: I have a bunch of Maya Animations of one model in different mb files. I used maya2egg to port them into panda, but only one of the animations work. A: The key is to use the -cn <character's name> flag in maya2egg for every file. This ensures that the files work together.

Let's say you are making an animated dog. You have the following animations:

  dog-walk.mb
  dog-sit.mb
  dog-run.mb

To convert these into panda, you would call

  maya2egg6 dog-walk.mb -a model -cn dog -o dog-model.egg

Note, we can grab the model from any of the animations, as long as they are all using the exact same rig:

  maya2egg6 dog-walk.mb -a chan -cn dog -o dog-walk.egg
  maya2egg6 dog-sit.mb -a chan -cn dog -o dog-sit.egg
  maya2egg6 dog-run.mb -a chan -cn dog -o dog-run.egg


Q: I'm using the lookAt function on a nodepath to point it at another object. It works fine until I point upwards, and then it starts to spin my object around randomly A: lookAt works as long as you aren't telling it to look in the direction of its up vector. Luckily, you can specify the up vector as the second argument.

  lookAt(object,Vec3(0,0,1))


Q: I'm building a 3d game, and I have a huge world. When my world starts up, the program hangs for a few seconds the first time I look around. Is there any way to avoid this? A: It can take a while to prepare objects to be rendered.

Ideally, you don't want this to happen the first time you see an object. You can offload the wait time to the beginning by calling:

  # self.myWorld is a nodepath that contains a ton of objects
  self.myWorld.prepareScene(base.win.getGsg())

This will walk through the scene graph, starting at self.myWorld, and prepare each object for rendering.


Q: Is there a way to hide the mouse pointer so that it doesn't show up on my screen? A: You can change to properties of the panda window so that it doesn't show the cursor:

  props = WindowProperties()
  props.setCursorHidden(True)
  base.win.requestProperties(props)


Q: If a model has an animation, is that animation necessarily represented by an additional .egg file? A: No. An .egg file can either be just geometry, just an animation, or a combination of the two.

It's often easiest, however, to create a separate egg for every animation and an egg that contains just the model/skeleton information.


Q: I have a model with an animation. When i try to play the animation I get this error:

  KeyError: lodRoot
  display: Closing wglGraphicsWindow

A: This often happens when you are trying to load animations onto a model that wasn't exported to have animations.

There are two pieces to objects that have animations; their geometry and their skeleton. The geometry is what you see when you load a model, the skeleton is what controls the geometry in an animation. If only the geometry was used to make the egg file, you will have problems when you try to play animations. Look at the manual for more details about exporting models as eggs.


Q: I called setTexture('tex.jpg') and it didn't change or send an error. A: To override an existing texture, you need to specify a priority: setTexture('tex.jpg', 1).

The setTexture() call includes an optional priority parameter, and if the priority is less than 1 the texture will not change.


Q: I get this error:

  assert(self.validateComponents(self.ivals))
  AssertionError

It happens at this line of code:

  move = Sequence(obj.setX(5))

A: Sequences and Parallels are a way to combine intervals. You can't put anything inside them that isn't an interval. If you want this code to work you want something like:

  self.move = Sequence(Func(obj.setX, 5))

This will start the execution of the function, but not wait for it to finish.


Q: Does panda use degrees or radians? A: Degrees. But see also the deg2Rad() and rad2Deg() functions.

  But note that the math.sin, math.cos, math.tan, etc. functions are calculated in radians.
  Don't forget to convert the values!


P: Porque todos os meus objetos planos parecem estranhos quando iluminados? R: Planos geralmente não tem muitas vértices

Lighting is only calculated at the vertices, and then linearly interpolated between the vertices. If your vertices are very far apart, lighting can look very strange--for instance, a point light in the center of a large polygon might not show up at all (the light is far from all four vertices, even though it's very near the polygon's center).

Uma solução é criar um modelo com muitos polígonos para acompanhar a iluminação. Também ajuda fazer uma superficie plana ligeiramente curvada para melhorar sua aparência. Outra alternativa seria criar uma luz ambiente que apenas afete este objeto. Veja o manual para mais detalhes sobre vincular luz á objetos em sua cena.

P: Para suavizar minhas animações, eu usei a opção "interpolate-frames 1", mas por algum motivo isso não funciona. Porque? R: A flag interpolate-frames é setada no PartBundle no momento que este é criado pela primeira vez, e então ela é >baked< no cache bam.

Por isso, mudanças realizadas posteriormente na variável interpolate-frames são nulas. Se você mudou a flag interpolate-frames, você também precisará limpar sua pasta modelcache.

Atualmente não é recomendado o uso de interpolate-frames; ele é uma configuração global. É melhor conseguir o mesmo efeito através de actor.setBlend(frameBlend = true ), que é uma configuração por ator ( e não é >baked< no cache de modelos )

P: Eu estou tentando redirecionar o output de comandos como "myNode.ls()" para um arquivo, mas o método usual "python>>file, myNode.ls()" não funciona, Qual é a alternativa? R: Você pode tentar:

  strm = StringStream()
  render.ls(strm)
  open('out.txt', 'w').write(strm.getData())

Outra alternativa:

  strm = StringStream()
  cvMgr.write(strm)
  open('out.txt', 'w').write(strm.getData())

Se você não quiser usar a StringStream você pode fazer o seguinte:

  strm = MultiplexStream()
  strm.addFile(Filename('out.txt'))
  render.ls(strm)

Existe também um meio de especificar o arquivo a ser escrito no arquivo config.

  notify-output out.txt


P: Como nós criamos um nodo de uma string contendo fonte .egg? R: Use a classe EggData:

  egg = EggData()
  egg.read(StringStream(eggText))
  model = NodePath(loadEggData(egg))


P: Como nós podemos saber que letra estava abaixo do cursor quando nós clicamos em um TextNode? R: Use a classe TextAssembler como a seguir:

  tn = TextNode('tn')
  tn.setText('abcdef\nghi')
  ta = TextAssembler(tn)
  ta.setWtext(tn.getWtext())
  for ri in range(ta.getNumRows()):
      for ci in range(ta.getNumCols(ri)):
          print "ri = %s, ci = %s, char = %s, pos = %s, %s" % (ri, ci, chr(ta.getCharacter(ri, ci)), ta.getXpos(ri, ci), ta.getYpos(ri, ci))