Hi all,
I ran into some errors on Python 3 when trying to use particles. They were pretty easy to fix; just some bytes vs string stuff.
Below is a git patch that fixes the problem. I haven’t tested it on Python 2, but the future import I added at the top probably keeps it compatible.
What’s the general contribution process? If we were on GitHub entirely, I’d send a pull request, but I think we’re still on CVS, right? I’d like to help out wherever I can (in small ways, due to time constraints), so let me know what the best way to contribute would be.
/pennomi
From f62a04529f73d60723fbc34e1ddf575ab80602fc Mon Sep 17 00:00:00 2001
From: Thane Brimhall <thane.brimhall@gmail.com>
Date: Sun, 23 Nov 2014 14:44:38 -0700
Subject: [PATCH] Adjusted the ParticleEffect file to work on Python 3
---
direct/src/particles/ParticleEffect.py | 39 +++++++++++++++++-----------------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/direct/src/particles/ParticleEffect.py b/direct/src/particles/ParticleEffect.py
index 914630f..e5fac90 100644
--- a/direct/src/particles/ParticleEffect.py
+++ b/direct/src/particles/ParticleEffect.py
@@ -1,7 +1,7 @@
-
+from __future__ import unicode_literals
from pandac.PandaModules import *
-import Particles
-import ForceGroup
+from . import Particles
+from . import ForceGroup
from direct.directnotify import DirectNotifyGlobal
class ParticleEffect(NodePath):
@@ -40,7 +40,7 @@ class ParticleEffect(NodePath):
def getName(self):
# override NodePath.getName()
return self.name
-
+
def reset(self):
self.removeAllForces()
self.removeAllParticles()
@@ -77,7 +77,7 @@ class ParticleEffect(NodePath):
for p in self.particlesDict.values():
p.disable()
self.fEnabled = 0
-
+
def isEnabled(self):
"""
Note: this may be misleading if enable(), disable() not used
@@ -161,46 +161,47 @@ class ParticleEffect(NodePath):
filename = Filename(filename)
f = open(filename.toOsSpecific(), 'wb')
- f.write('\n')
+ f.write(b'\n')
# Make sure we start with a clean slate
- f.write('self.reset()\n')
+ f.write(b'self.reset()\n')
pos = self.getPos()
hpr = self.getHpr()
scale = self.getScale()
- f.write('self.setPos(%0.3f, %0.3f, %0.3f)\n' %
- (pos[0], pos[1], pos[2]))
- f.write('self.setHpr(%0.3f, %0.3f, %0.3f)\n' %
- (hpr[0], hpr[1], hpr[2]))
- f.write('self.setScale(%0.3f, %0.3f, %0.3f)\n' %
- (scale[0], scale[1], scale[2]))
+ f.write(('self.setPos(%0.3f, %0.3f, %0.3f)\n' %
+ (pos[0], pos[1], pos[2])).encode())
+ f.write(('self.setHpr(%0.3f, %0.3f, %0.3f)\n' %
+ (hpr[0], hpr[1], hpr[2])).encode())
+ f.write(('self.setScale(%0.3f, %0.3f, %0.3f)\n' %
+ (scale[0], scale[1], scale[2])).encode())
# Save all the particles to file
num = 0
for p in self.particlesDict.values():
target = 'p%d' % num
num = num + 1
- f.write(target + ' = Particles.Particles(\'%s\')\n' % p.getName())
+ f.write((target + ' = Particles.Particles(\'%s\')\n' % p.getName()
+ ).encode())
p.printParams(f, target)
- f.write('self.addParticles(%s)\n' % target)
+ f.write(('self.addParticles(%s)\n' % target).encode())
# Save all the forces to file
num = 0
for fg in self.forceGroupDict.values():
target = 'f%d' % num
num = num + 1
- f.write(target + ' = ForceGroup.ForceGroup(\'%s\')\n' % \
- fg.getName())
+ f.write((target + ' = ForceGroup.ForceGroup(\'%s\')\n' %
+ fg.getName()).encode())
fg.printParams(f, target)
- f.write('self.addForceGroup(%s)\n' % target)
+ f.write(('self.addForceGroup(%s)\n' % target).encode())
# Close the file
f.close()
def loadConfig(self, filename):
data = vfs.readFile(filename, 1)
- data = data.replace('\r', '')
+ data = data.replace(b'\r', b'')
try:
exec(data)
except:
--
1.9.1