blob: 1543def9a5b37ae1ae7af7f7b30d9dec689958e5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
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.updateBillboards = function(){
base.forEach(function(sculpture){
if (sculpture.billboard) {
sculpture.mx.rotationY = cam.rotationY
}
})
}
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 = {}
|