-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataModelMan.js
171 lines (161 loc) · 4.57 KB
/
DataModelMan.js
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function DataModelMan()
{
console.log('createing datamodelman');
var self = this;
self.triangles = [];
self.lights = [];
//You can essentially 'subscribe functions' to these events
//by adding them to these arrays
self.trianglesUpdatedCallbacks = [];
self.lightsUpdatedCallbacks = [];
self.stateDeclaredCallbacks = [];
self.createTriangle = function()
{
console.log('datamodelman createtriangle');
var t = {};
t.vertexes = [];
for(var i = 0; i < 3; i++)
{
t.vertexes[i] = {};
t.vertexes[i].position = [0,0,0];
t.vertexes[i].color = [0,0,0];
t.vertexes[i].normal = [0,0,0];
}
return t;
}
self.addTriangle = function(triangle)
{
console.log('datamodelman addtriangle');
self.triangles[self.triangles.length] = triangle;
self.trianglesUpdated({'added':[triangle],'removed':[]});
}
self.removeTriangle = function(index)
{
console.log('datamodelman removetriangle');
var oldTriangle = self.triangles[index];
self.triangles.splice(index,1);
self.trianglesUpdated({'added':[],'removed':[oldTriangle]});
}
self.removeAllTriangles = function()
{
console.log('datamodelman removealltriangles');
var oldTriangles = self.triangles;
self.triangles = [];
self.trianglesUpdated({'added':[],'removed':oldTriangles});
}
self.changeTriangle = function(triangle, index)
{
console.log('datamodelman changetriangle');
var oldTriangle = self.triangles[index];
self.triangles[index] = triangle;
self.trianglesUpdated({'added':[triangle],'removed':[oldTriangle]});
}
self.createLight = function()
{
console.log('datamodelman createlight');
var l = {};
l.position = [0,0,0];
return l;
}
self.addLight = function(light)
{
console.log('datamodelman addlight');
self.lights[self.lights.length] = light;
self.lightsUpdated({'added':[light],'removed':[]});
}
self.removeLight = function(index)
{
console.log('datamodelman removelight');
var oldLight = self.lights[index];
self.lights.splice(index,1);
self.lightsUpdated({'added':[],'removed':[oldLight]});
}
self.removeAllLights = function()
{
console.log('datamodelman removealllights');
var oldLights = self.lights;
self.lights = [];
self.lightsUpdated({'added':[],'removed':oldLights});
}
self.changeLight = function(light, index)
{
console.log('datamodelman changelight');
var oldLight = self.lights[index];
self.lights[index] = light;
self.lightsUpdated({'added':[light],'removed':[oldLight]});
}
self.requestStateDeclaration = function()
{
self.stateDeclared();
}
self.registerCallback = function(eventname,callback)
{
console.log('datamodelman registercallback');
callbackArray = self[eventname+'Callbacks'];
if(callbackArray)
callbackArray[callbackArray.length] = callback;
}
self.trianglesUpdated = function(deltas)
{
console.log('datamodelman trianglesupdated');
for(var i = 0; i < self.trianglesUpdatedCallbacks.length; i++)
self.trianglesUpdatedCallbacks[i](self.triangles, deltas);
}
self.lightsUpdated = function(deltas)
{
console.log('datamodelman lightsupdated');
for(var i = 0; i < self.lightsUpdatedCallbacks.length; i++)
self.lightsUpdatedCallbacks[i](self.lights, deltas);
}
self.stateDeclared = function()
{
console.log('datamodelman statedeclared');
for(var i = 0; i < self.stateDeclaredCallbacks.length; i++)
self.stateDeclaredCallbacks[i](self.triangles, self.lights);
}
}
/*
self.dirtybit = false;
self.tris = [];
self.lights = [];
self.addTri = function(tri)
{
console.log('datamodelman addtri');
self.tris[self.tris.length] = tri;
glm.geoProgram.addGeo(tri);
self.dirtybit = true;
}
self.saveTri = function()
{
console.log('datamodelman savetri');
self.dirtybit = true;
}
self.removeTri = function(tri)
{
console.log('datamodelman removetri');
self.tris.splice(tri.programGeoListIndex,1);
glm.geoProgram.removeGeo(tri);
self.dirtybit = true;
}
self.addLight = function(light)
{
console.log('datamodelman addlight');
self.lights[self.lights.length] = light;
glm.geoProgram.addLight(light);
self.dirtybit = true;
}
self.saveLight = function()
{
console.log('datamodelman savelight');
self.dirtybit = true;
}
self.removeLight = function(light)
{
if(self.lights.length == 1) return;
console.log('datamodelman removelight');
self.lights.splice(light.programGeoListIndex,1);
glm.geoProgram.removeLight(light);
self.dirtybit = true;
}
}
*/