var Sculpture = new function(){ var base = this; base.list = {} base.mouse = new mouse ({ use_offset: false, mousedownUsesCapture: true }) base.init = function(){ app.on("move", base.updateBillboards) base.resize.init() } base.updateBillboards = function(){ base.forEach(function(sculpture){ if (sculpture.billboard) { sculpture.mx.rotationY = cam.rotationY } }) if (Sculpture.resize.obj && Sculpture.resize.obj.billboard) { Sculpture.resize.move_dots() } } base.add = function(opt){ var sculpture switch (opt.media.type) { case 'image': sculpture = new Sculpture.types.image (opt) break } base.list[sculpture.id] = sculpture return sculpture } base.addNext = function(opt){ opt.newMedia = true opt.media = Scenery.nextMedia var sculpture = base.add(opt) // test if sculpture was placed here if (! sculpture) { return null } else { Scenery.nextMedia = null return sculpture } } base.find = function(id){ return base.list[id] || null } base.remove = function(id){ var scene_media = base.list[id] delete base.list[id] scene_media && scene_media.destroy() } base.removeAll = function(){ base.forEach(function(scene_media){ base.remove(scene_media.id) }) } base.uid = new UidGenerator(base.list) base.forEach = function(f){ return base.values().forEach(f) } base.map = function(f){ return base.values().map(f) } base.values = function(){ return _.values(base.list) } base.serialize = function(){ var sculptures = base.map(function(sculpture){ return sculpture.serialize() }) return sculptures } base.deserialize = function(sculpture_data){ var added = [] sculpture_data.forEach(function(data){ var scene_media = base.add({ id: data.id, data: data, media: data.media, }) added.push(scene_media) }) return added } return base } Sculpture.types = {}