Hi again.
i am once again in the solar sys script and i have some problem in the 5th step
i check my code alot of time and the python shell always
tell me the same thing
AttributeError: World instance has no attribute
the original script was just beside mine to avoid all error, without success.
here’s my code:
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
from panda3d.core import Vec3, Vec4
import sys
class World:
def __init__(self):
#Set previous instalation
self.title = OnscreenText(
text="Python Powered",
style =1, fg=(1,1,1,1), pos=(0.8,-0.95), scale= .07)
base.setBackgroundColor(0, 0, 0) #set background color to blue
base.disableMouse() #disable mouse function
camera.setPos(0, 0, 45) #set cam position
camera.setHpr(0, -90, 0) #set heading and rotation
self.yearscale = 60
self.dayscale = self.yearscale / 365.0 * 5
self.orbit = 10 #set orbit scale
self.sizescale = 0.6 #set size scale
self.loadplanets() #load all the planets
self.rotateplanets() #set the planets to motion
def loadplanets(self):
#create dummy node
self.orbit_rot_mercury = render.attachNewNode("orbit_rot_mercury")
self.orbit_rot_venus = render.attachNewNode("orbit_rot_venus")
self.orbit_rot_mars = render.attachNewNode("orbit_rot_mars")
self.orbit_rot_earth = render.attachNewNode("orbit_rot_earth")
#Set orbit rotation for moon, arround the earth
self.orbit_rot_moon = (
self.orbit_rot_earth.attachNewNode("orbit_rot_moon"))
######################################################################
#load the sky sphere
self.sky = loader.loadModel("models/solar_sky_sphere")
self.sky_tex = loader.loadTexture("models/stars_1k_tex.jpg")
self.sky.setTexture(self.sky_tex, 1)
self.sky.reparentTo(render)
self.sky.setScale(40)
#load the sun
self.sun = loader.loadModel("models/planet_sphere")
self.sun_tex = loader.loadTexture("models/sun_1k_tex.jpg")
self.sun.setTexture(self.sun_tex, 1)
self.sun.reparentTo(render)
self.sun.setScale (2 * self.sizescale)
#load mercury
self.mercury = loader.loadModel("models/planet_sphere")
self.mercury_tex = loader.loadTexture("models/mercury_1k_tex.jpg")
self.mercury.setTexture(self.mercury_tex, 1)
self.mercury.reparentTo(self.orbit_rot_mercury)
self.mercury.setPos ( 0.38 * self.orbitscale, 0, 0)
self.mercury.setScale( 0.385 * self.sizescale)
#load venus
self.venus = loader.loadModel("models/planet_sphere")
self.venus_tex = loader.loadTexture("models/venus_1k_tex.jpg")
self.venus.setTexture(self.venus_tex, 1)
self.venus.reparentTo(self.orbit_rot_venus)
self.venus.setPos (0.72 * self.orbitscale, 0, 0)
self.venus.setScale ( 0.923 * self.sizescale)
#load mars
self.mars = loader.loadModel("models/planet_sphere")
self.mars_tex = loader.loadTexture("models/mars_1k_tex.jpg")
self.mars.reparentTo(self.orbit_rot_mars)
self.mars.setPos ( 1.52 * self.orbitscale, 0 ,0)
self.mars.setScale (0.515 * self.sizescale)
#load earth
self.earth = loader.loadModel("models/planet_sphere")
self.earth_tex = loader.loadTexture("models/earth_1k_tex.jpg")
self.earth.setTexture(self.earth_tex, 1)
self.earth.reparentTo(self.orbit_rot_earth)
self.earth.setScale (self.sizescale)
self.earth.setPos (self.orbitscale, 0, 0)
#set moon dummy node so it will rotate around earth
self.orbit_rot_moon.setPos( self.orbitscale, 0, 0)
#load the moon
self.moon = loader.loadModel("models/planet_sphere")
self.moon_tex = loader.loadTexture("models/moon_1k_tex.jpg")
self.moon.setTexture (self.moon_tex, 1)
self.moon.reparentTo(self.orbit_rot_moon)
self.moon.setScale (0.1 * self.sizescale)
self.moon.setPos (0.1 * self.orbitscale, 0, 0)
#load planet definition ended
def rotateplanets(self):
self.day_period_sun = self.sun.hprInterval(20, Vec3(360, 0, 0))
#mercury
self.orbit_period_mercury = self.orbit_rot_mercury.hprInterval(
(0.241 * self.yearscale), Vec3(360, 0, 0))
self.day_period_mercury = self.mercury.hprInterval(
(59 * self.dayscale), Vec3(360, 0, 0))
#venus
self.orbit_period_venus = self.orbit_rot_venus.hprInterval(
(0.615 * self.yearscale), Vec3(360, 0 ,0))
self.day_period_venus = self.venus.hprInterval(
(243 * self.dayscale), Vec3(360,0,0))
#earth
self.orbit_period_earth = self.orbit_rot_earth.hprInterval(
self.yearscale, Vec3(360,0,0))
self.day_period_earth = self.earth.hprInterval(
self.dayscale, Vec3(360,0,0))
#moon
self.orbit_period_moon = self.orbit_rot_moon.hprInterval(
(.0749 * self.yearscale), Vec3(360,0,0))
self.day_period_moon = self.moon.hprInterval(
(.0749 * self.yearscale), Vec3(360,0,0))
#mars
self.orbit_period_mars = self.orbit_rot_mars.hprInterval(
(1.881 * self.yearscale), Vec3(360,0,0))
self.day_period_mars = self.mars.hprInterval(
(1.03 * self.dayscale), Vec3(360,0,0))
self.day_period_sun.loop()
self.orbit_period_mercury.loop()
self.day_period_mercury.loop()
self.orbit_period_venus.loop()
self.day_period_venus.loop()
self.orbit_period_earth.loop()
self.day_period_earth.loop()
self.orbit_period_moon.loop()
self.day_period_moon.loop()
self.orbit_period_mars.loop()
self.day_period_mars.loop()
#rotateplanet definition endded
#end World class
w = World()
run() #engage Program
number of test i’ve make: alot
this topic has for goal to help people this this issue, and will (maybe) help to avoid it in the future
Greetings,