I’m having issues moving the model from the UserInputClass, it is accepting keypresses and printing the statements but how to access the model? I tried importing the classes but it did not work.
This is my main.py file.
from direct.showbase.ShowBase import ShowBase
from direct.showbase import DirectObject
from direct.task.Task import Task
from panda3d.core import *
from direct.gui.OnscreenImage import OnscreenImage
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
#from UserInputControl import *
from direct.showbase.ShowBase import ShowBase
import sys
class Application(ShowBase):
def __init__(self):
ShowBase.__init__(self)
keys = Keys()
self.firstModel = Actor("./models/test.x", {"Run":"./models/test.x"})
self.firstModel.loop("Run")
# Load movie and its sound (if it has sound).
self.movie = self.loader.loadTexture("videos/loading_screen.ogm")
self.sound = self.loader.loadSfx("videos/loading_screen.ogm")
# Make a plane to play the movie on.
self.cm = CardMaker("plane")
self.cm.setFrame(-1, 1, -1, 1)
# Render that plane to the render2d for Panda.
self.plane = self.render2d.attachNewNode(self.cm.generate())
# Load movie into the texture plane.
self.plane.setTexture(self.movie)
# This can prevent squashing or distorting of the video.
self.plane.setTexScale(TextureStage.getDefault(), self.movie.getTexScale())
# 0 means do not loop infinitely.
self.movie.setLoop(0)
# If it has sound, synchronize it to the video.
self.movie.synchronizeTo(self.sound)
# Will set the Sound to loop.
self.sound.setLoopCount(0)
# Play the sound.
self.sound.play()
# Schedule bg image to show 10 seconds later.
taskMgr.doMethodLater(1, self.loadImageAsPlane, "ImageLoader")
""" To do, add more commands """
#completed now to make it work??
""" To do, implement text below model """
#self.background_text = "Health"
#self.backgroundText = OnscreenText(self.background_text, pos = (0.95,-0.95) ,
# scale = 0.07, fg = (1,0.5,0.5,1), align = TextNode.ACenter,
# mayChange = 1)
def loadWorld(self):
#self.background_text = "Thy journey has begun..."
#self.backgroundText.setText(self.background_text)
# Remove the buttons and the background image.
self.newGameButton.destroy()
self.loadSavedGameButton.destroy()
self.background.removeNode()
# Loads and renders the model.
self.background.removeNode()
self.firstModel.reparentTo(self.render)
#self.setModelPosition()
self.firstModel.setScale(0.75, 0.75, 0.75)
self.firstModel.setPos(0, 50, 0)
#self.firstModel.setTexture(self.firstTexture)
# Will stop the sound if the button is pressed.
self.sound.stop()
#def setModelPosition(self, x=0, y=0, z=0):
#self.firstModel.setPos(x,y,z)
def loadImageAsPlane(self, task):
# Loads image and puts it onscreen.
self.background = OnscreenImage(parent=render2d, image='images/Fireworks.jpg')
# Let's add a button..
self.newGameButton = DirectButton(text = ("New Game", None, None, None),
pressEffect = 1, scale = .05, command = self.loadWorld)
self.loadSavedGameButton = DirectButton(text = ("Load Game", None, None, None),
pressEffect = 1, scale = .05, command = self.loadWorld)
self.newGameButton.setPos(-1,1,-0.1)
self.loadSavedGameButton.setPos(-1,1,-0.2)
# Removes Intro Movie.
self.plane.removeNode()
# Assign the class to a variable.
app = Application()
# And finally, run it!!
app.run()
And this is my user input class:
from main import Application
from direct.showbase import DirectObject
from direct.task.Task import Task
from panda3d.core import *
from direct.gui.OnscreenImage import OnscreenImage
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from direct.actor.Actor import Actor
import sys
from pandac.PandaModules import RenderState
class Keys(DirectObject):
def __init__(self):
self.isTyping = False
self.keyMap = {"mvUp":0, "mvDown":0, "mvLeft":0, "mvRight":0}
self.accept("escape", sys.exit)
self.accept("w", self.setKey, ["mvUp", 1])
self.accept("s", self.setKey, ["mvDown", 1])
self.accept("a", self.setKey, ["mvLeft", 1])
self.accept("d", self.setKey, ["mvRight", 1])
self.accept("w-up", self.setKey, ["mvUp", 0])
self.accept("s-up", self.setKey, ["mvDown", 0])
self.accept("a-up", self.setKey, ["mvLeft", 0])
self.accept("d-up", self.setKey, ["mvRight", 0])
def setKey(self, key, value):
if not self.isTyping:
print "why did you call me? I serve no purpose, also you pressed %s \n" %key
self.keyMap[key] = value
print self.keyMap
Any help would be aprpeciated thanks