Skip to content

Instantly share code, notes, and snippets.

@kergalym
Last active December 6, 2021 19:25
Show Gist options
  • Save kergalym/162f221cbf72c86cc42a9b56198ab0d4 to your computer and use it in GitHub Desktop.
Save kergalym/162f221cbf72c86cc42a9b56198ab0d4 to your computer and use it in GitHub Desktop.
Example code for Character Clothes Wearing for Panda3D
from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# assemble player from the parts and attach it to render node
# all parts have same skeleton
self.player = Actor(
# part dictionary
{
"modelRoot": "Assets/Inventory/CharItems/Korlan_body.egg",
"helmet": "Assets/Inventory/CharItems/Korlan_helmet.egg",
"armor": "Assets/Inventory/CharItems/Korlan_armor.egg",
"pants": "Assets/Inventory/CharItems/Korlan_pants.egg",
"boots": "Assets/Inventory/CharItems/Korlan_boots.egg"
},
# dictionary of animation
{
"modelRoot": {
"idle": 'Assets/Animations/exp/Korlan-Standing_idle_female.egg'
},
"helmet": {
"idle": 'Assets/Animations/exp/Korlan-Standing_idle_female.egg'
},
"armor": {
"idle": 'Assets/Animations/exp/Korlan-Standing_idle_female.egg'
},
"pants": {
"idle": 'Assets/Animations/exp/Korlan-Standing_idle_female.egg'
},
"boots": {
"idle": 'Assets/Animations/exp/Korlan-Standing_idle_female.egg'
}
}
)
self.player.reparent_to(render)
# animate player
self.player.loop('idle')
# switch visibility
self.accept("k", self.toggle_visibility, ["helmet"])
def toggle_visibility(self, name):
# find any part of player and switch its visibility
cloth = self.player.find("**/__Actor_{0}".format(name))
if self.player and cloth:
if cloth.is_hidden():
cloth.show()
else:
cloth.hide()
app = MyApp()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment