def test_disabled_textures(self): loader = colobot.loader.Loader(enable_textures=False) loader.add_directory('data/models') self.assertTrue(loader.get_model('keya.mod')) self.assertTrue(loader.get_model('keyb.mod')) self.assertTrue(loader.get_model('home1.mod')) self.assertRaises(KeyError, loader.get_model, 'blehblehbleh.mod') self.assertRaises(KeyError, loader.get_model, 'keya')
def test_loading_success(self): loader = colobot.loader.Loader() loader.add_directory('data/models') loader.add_directory('data/diagram') loader.add_directory('data/textures') self.assertTrue(loader.get_model('keya.mod')) self.assertTrue(loader.get_model('keyb.mod')) self.assertTrue(loader.get_model('home1.mod')) self.assertRaises(KeyError, loader.get_model, 'blehblehbleh.mod') self.assertRaises(KeyError, loader.get_model, 'keya')
if __name__ == '__main__': import g3d import g3d.gl import g3d.camera_drivers import g3d.model import g3d.serialize import colobot.loader loader = colobot.loader.Loader(enable_textures=True) loader.add_directory('data/models') loader.add_directory('data/anim') loader.add_directory('data/diagram') loader.add_directory('data/textures') #g3d.model.read(loader=loader, name='wheeled-transporter.model') model = loader.get_model('keya.mod') s = g3d.serialize.Serializer() sha1hash = s.add(model) print sha1hash.encode('hex') data = s.get_by_sha1(sha1hash) import zlib print len(data), len(zlib.compress(data)) print [ i.encode('hex') for i in s.deps[model] ] print [ i.encode('hex') for i in s.get_dependencies(model) ] uns = g3d.serialize.Unserializer() uns.add(sha1hash, data) for hash in s.get_dependencies(model): data = s.get_by_sha1(hash) uns.add(hash, data)
import g3d import g3d.gl import g3d.camera_drivers import g3d.model import colobot.loader loader = colobot.loader.Loader() loader.add_directory("data/models") loader.add_directory("data/anim") loader.add_directory("data/diagram") loader.add_directory("data/textures") name = sys.argv[1] if name.endswith(".mod"): obj = loader.get_model(name) else: model = g3d.model.read(loader=loader, name=name) obj = model.root g3d.options.enable_textures = True win = g3d.gl.Window() win.root.add(obj) def rotate(): rot = g3d.Quaternion.new_rotate_axis(3.14 / 180 * 5, g3d.Vector3(0, 1, 0)) win.root.rotation = win.root.rotation * rot