Skip to content

Instantly share code, notes, and snippets.

@loonaticx
Created October 8, 2020 01:59
Show Gist options
  • Save loonaticx/8a2127d55de57835c292f4e1d5bc2dac to your computer and use it in GitHub Desktop.
Save loonaticx/8a2127d55de57835c292f4e1d5bc2dac to your computer and use it in GitHub Desktop.
Incomplete script I was working on several months ago. It was intended to read and parse the auto-generated zone modules to view the setup independently.
# import your zones however you like.
import LawbotOfficeEntrance_Action00
import LawbotOfficeOilRoom_Battle00
import LawbotOfficeOilRoom_Battle01
import LawbotOfficeBoilerRoom_Security00
import LawbotOfficeBoilerRoom_Battle00
import LawbotOfficeGearRoom_Action00
import LawbotOfficeLobby_Action00
import LawbotOfficeGearRoom_Security00
import LawbotOfficeLobby_Trap00
import LawbotOfficeDiamondRoom_Security00
import LawbotOfficeDiamondRoom_Trap00
import LawbotOfficeGearRoom_Platform00
import LawbotOfficeLobby_Lights00
import LawbotOfficeBoilerRoom_Action01
import LawbotOfficeBoilerRoom_Action01_Cogs
import LawbotOfficeDiamondRoom_Action00
import LawbotOfficeDiamondRoom_Action01
import LawbotOfficeLobby_Action01
import LawbotOfficeDiamondRoom_Battle00
import LawbotOfficeGearRoom_Battle00
# spaghetti cos im lazy
def Point3(x, y, z):
return [x, y, z]
# self.P3.append([x, y, z])
def Vec3(h, p, r):
return [h, p, r]
# self.V3.append([x, y, z])
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
class readLawbotDNA(ShowBase):
def __init__(self):
ShowBase.__init__(self)
base.startDirect()
#self.loadZone08a()
base.oobe()
#base.accept('f9', self.writeBam)
self.parentDict = {} # intended to store down entID:entName for respected children
self.P3 = {}
self.V3 = {}
self.modelList = []
# [modelPath, pos, hpr, scale]
# LawbotOfficeGearRoom_Security00
self.GlobalEntities = LawbotOfficeBoilerRoom_Action01.GlobalEntities
# I guess we can add actual parameters & formal params to the method
# if we wanna scale this in the future lol
self.parseEntry()
def Point3(self, x, y, z):
return [x, y, z]
#self.P3.append([x, y, z])
def Vec3(self, h, p, r):
return [h, p, r]
#self.V3.append([x, y, z])
def parseEntry(self):
# GlobalEntities = {zone: {zoneinfo} }
# type -> modelPath -> pos, hpr, scale
# if type battleBlocker --> modelPath = snowball
# if type model --> for sub-element in entity: find sube['modelPath'] , sube['pos'] sube['hpr'], sube['scale']
# list = (modelPath, pos, hpr, scale)
# total.append(list) --> for elements in total, model = elements[0], pos = elements[1]... etc
for entityID in self.GlobalEntities:
entType = self.GlobalEntities[entityID]['type']
if entType is not None:
#print(entType)
if entType == 'model':
#print(self.GlobalEntities[entityID]['pos'])
modelName = self.GlobalEntities[entityID]['name']
modelPath = self.GlobalEntities[entityID]['modelPath']
modelPos = self.GlobalEntities[entityID]['pos']
modelHpr = self.GlobalEntities[entityID]['hpr']
modelSc = self.GlobalEntities[entityID]['scale']
modelParent = self.GlobalEntities[entityID]['parentEntId']
self.modelList.append([modelName, modelPath, modelPos, modelHpr, modelSc, entityID, modelParent])
self.parentDict.update({entityID: modelName})
# we're going to store these to refer back to them later
elif entType == 'levelMgr':
modelPath = self.GlobalEntities[entityID]['modelFilename']
# Assuming there's only one levelMgr entity in the dict
# We'll just use 'levelMgr' as the name for this node
entName = entType
# The levelMgr entity does not have keys for these three values
# Thus, let's make sure that we still define transformations @ the origin
# since it's going into the ModelList anyway
entPos = [0, 0, 0]
entHpr = [0, 0, 0]
entScale = [1, 1, 1]
self.modelList.append([entType, modelPath, entPos, entHpr, entScale])
self.parentDict.update({entityID: entName})
print(self.parentDict)
self.loadList()
"""
might be useful for reparenting
https://docs.panda3d.org/1.10/python/reference/panda3d.core.NodePath#panda3d.core.NodePath.getNode
"""
"""
Example model arr
Model arr = ['levelMgr', 'phase_11/models/lawbotHQ/LB_Zone08a', [0, 0, 0], [0, 0, 0], [1, 1, 1]] <-- This has two less indexes than the rest
Model arr = ['<unnamed>', 'phase_9/models/char/da_goon', [0, 0, 0], [164.055, 0, 0], [2, 2, 2], 10007]
Model arr = ['<unnamed>', 'phase_11/models/lawbotHQ/LA_filing_cabA', [0, 0, 0], [0, 0, 0], 1, 10060]
"""
def loadList(self):
for index, model in enumerate(self.modelList):
print("Model arr = %s " % model)
#name = "model%s%s" % (model[0], index)
try:
# this is intended for nodes that are a model type
name = model[6]
# ran into a key error previously, dunno if this code will stay long-term
# this is really just to test if it can find its parent id from the dict
try:
parent = self.parentDict[model[6]]
print("SUCCESS! Parented model %s to parent ID %s" % (model[0], model[6]))
except KeyError as e:
print("WARNING! Missing parent ID for %s: %s" % (model[0], model[6]))
parent = "error"
#parent = render
#parent = self.modelList[model[6]['name']]
print("Parent -- %s" %parent)
#parent = render
except IndexError:
# this is intended for nodes that are NOT a model type
name = "model%s%s" % (model[0], index)
print("Name: %s" % name)
name = loader.loadModel("%s.bam" % model[1])
name.reparentTo(render) # Intended to be reparentTo(parent) [defaults to render]
x = model[2][0]
y = model[2][1]
z = model[3][2]
h = model[3][0]
p = model[3][1]
r = model[3][2]
if not model[4] == 1:
# scale value of x, y, and z
sx = model[4][0]
sy = model[4][1]
sz = model[4][2]
else:
sx = 1
sy = 1
sz = 1
print(model)
#print(model[4])
name.setPosHprScale(x, y, z, h, p, r, sx, sy, sz)
def loadZone08a(self):
zone = loader.loadModel("phase_11/models/lawbotHQ/LB_Zone08a.bam")
zone.reparentTo(render)
zone.place()
app = readLawbotDNA()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment