def test_save_load_tree(): sso = SSO("foo") sso2 = SSO("bar") sso2.reparentTo(sso) with tmpfile() as pth: with pth.open("w") as fid: sso.save_tree(fid) sso3 = SSO.load_tree(pth) with pth.open() as fid: sso4 = SSO.load_tree(fid) sso.save_tree(pth) sso5 = SSO.load_tree(pth) with pth.open() as fid: sso6 = SSO.load_tree(fid) assert (sso.tree_prop() == sso3.tree_prop() == sso4.tree_prop() == sso5.tree_prop() == sso6.tree_prop())
def load(args): """ Setup Bullet and load SSOs from input arguments.""" ssos = [] for filename in args: if path(filename).isfile(): ssos.append(SSO.load_tree(filename)) else: print("Cannot find file: %s" % filename) return ssos
def load(args): """ Setup Bullet and load SSOs from input arguments.""" ssos = [] for filename in args: if path(filename).isfile(): ssos.append(SSO.load_tree(filename)) else: print("Cannot find file: %s" % filename) return ssos
# create dimension for kappa data = data[:, :, None] else: raise ValueError("unexpected number of dimensions: %d" % data.ndim) # convert stimuli names to something coherent stims = [convert_name(stim) for stim in meta['stim']] # figure out object names objs = None for stim in stims: stim_path = os.path.join(stimset_path, stim + ".cpo") if not stim_path.exists(): raise IOError("cannot find stimulus: %s" % stim) cpo = SSO.load_tree(stim_path) psos = cpo.descendants(type_=RBSO) pso_names = [x.getName() for x in psos] if objs is None: objs = pso_names else: if objs != pso_names: raise AssertionError("inconsistent pso names") # construct the new metadata dictionary diminfo = { 'sigma': map(float, meta['sigmas']), 'phi': map(float, meta['phis']), 'kappa': map(float, meta.get('kappas', [0.0])), 'stimulus': stims,
import json import os from scenesim.objects.sso import SSO from libpanda import LVector3f, LPoint3f, LVecBase3f, LQuaternionf, LVecBase4f sso_paths = [] for dirname, dirnames, filenames in os.walk("stimuli"): for filename in filenames: if filename.endswith(".cpo"): sso_paths.append(os.path.join(dirname, filename)) for filename in sso_paths: sso_name = os.path.splitext(os.path.basename(filename))[0] dest = os.path.join(os.path.split(filename)[0], "{}.json".format(sso_name)) print(dest) sso = SSO.load_tree(filename) types, props, porder = sso.state_prop() types = [[t.__module__, t.__name__] for t in types] for p in props: for prop, val in p.items(): if isinstance(val, (LVecBase3f, LVecBase4f, LVector3f, LPoint3f, LQuaternionf)): p[prop] = {"__class__": [type(val).__module__, type(val).__name__], "value": list(val)} with open(dest, 'w') as fh: json.dump([types, props, porder], fh)
import os from scenesim.objects.sso import SSO from libpanda import LVector3f, LPoint3f, LVecBase3f, LQuaternionf, LVecBase4f sso_paths = [] for dirname, dirnames, filenames in os.walk("stimuli"): for filename in filenames: if filename.endswith(".cpo"): sso_paths.append(os.path.join(dirname, filename)) for filename in sso_paths: sso_name = os.path.splitext(os.path.basename(filename))[0] dest = os.path.join(os.path.split(filename)[0], "{}.json".format(sso_name)) print(dest) sso = SSO.load_tree(filename) types, props, porder = sso.state_prop() types = [[t.__module__, t.__name__] for t in types] for p in props: for prop, val in p.items(): if isinstance( val, (LVecBase3f, LVecBase4f, LVector3f, LPoint3f, LQuaternionf)): p[prop] = { "__class__": [type(val).__module__, type(val).__name__], "value": list(val) } with open(dest, 'w') as fh: json.dump([types, props, porder], fh)
def load_cpo(pth): """Load a cpo from disk.""" with open(pth, "r") as fid: cpo = SSO.load_tree(fid) return cpo
def get_objects(cpo_path): """Get the names of all of an SSO's children""" sso = SSO.load_tree(cpo_path) children = sso.descendants(type_=PSO) objs = [x.getName() for x in children] return objs