forked from hikaruAi/HPanda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HPlayer.py
75 lines (69 loc) · 2.98 KB
/
HPlayer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from direct.actor.Actor import Actor
from panda3d.bullet import BulletCharacterControllerNode as Character
from panda3d.core import NodePath
from HUtils import *
class HPlayer(NodePath): # ##Implementarlo como Nodepath y el actor como hijo
def __init__(self, name, scene, visualMesh, collisionMesh, animations, step=0.2, margin=0.01):
"""
:type collisionMesh: String
:type visualMesh: String
:type name: String
:type margin: Float
:param name: Name
:param scene: Scene
:param visualMesh: Egg to use as visual mesh
:param collisionMesh: Egg to use as convex shape for physics
:param animations: Animation dict
:param step: Character step height
:param margin: Physics shape margin
"""
self.name = name
self.scene = scene
m = self.scene.Base.loader.loadModel(collisionMesh)
sTuple = modelToConvex(m)
sTuple[0].setMargin(margin)
self.body = Character(sTuple[0], step, self.name + "_Character")
#self.attachNewNode(self.body)
self.body.setPythonTag("name", self.name + "_Character")
self.scene.world.attachCharacter(self.body)
NodePath.__init__(self, self.body)
self.actor = Actor(self.scene.loadEgg(visualMesh), animations)
self.actor.reparentTo(self)
#self.setPhysics(collisionMesh, step, margin)
def setPhysics(self, collisionMesh, step, margin):
m = self.scene.Base.loader.loadModel(collisionMesh)
sTuple = modelToConvex(m)
sTuple[0].setMargin(margin)
self.body = Character(sTuple[0], step, self.name + "_Character")
self.attachNewNode(self.body)
self.body.setPythonTag("name", self.name + "_Character")
self.scene.world.attachCharacter(self.body)
self.actor.reparentTo(self)
class RigidPlayer(NodePath):
def __init__(self, name, scene, visualMesh, collisionMesh, animations, mass, step=0.2, margin=0.01):
"""
:type collisionMesh: String
:type visualMesh: String
:type name: String
:type margin: Float
:param name: Name
:param scene: Scene
:param visualMesh: Egg to use as visual mesh
:param collisionMesh: Egg to use as convex shape for physics
:param animations: Animation dict
:param step: Character step height
:param margin: Physics shape margin
"""
self.name = name
self.scene = scene
self.body = BulletRigidBodyNode(self.name + "_RigidPlayer")
self.body.setMass(mass)
m = self.scene.Base.loader.loadModel(collisionMesh)
sTuple = modelToConvex(m)
sTuple[0].setMargin(margin)
self.body.addShape(sTuple[0], sTuple[1])
self.body.setPythonTag("name", self.name + "_RigidPlayer")
self.scene.world.attachRigidBody(self.body)
NodePath.__init__(self, self.body)
self.actor = Actor(self.scene.loadEgg(visualMesh), animations)
self.actor.reparentTo(self)