This repository has been archived by the owner on Oct 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Augmenta.js
180 lines (150 loc) · 4.37 KB
/
Augmenta.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
172
173
174
175
176
177
178
179
180
/*
Augmenta protocol :
https://github.com/Theoriz/Augmenta/wiki
This code has been tested on Chataigne 1.6.0
*/
// The module currently display 5 objects maximum declared in module.json
var maxPersonDisplayed = 5;
function init()
{
local.parameters.pass_through.setCollapsed(true);
local.values.singlePerson.setCollapsed(true);
local.scripts.setCollapsed(true);
local.scripts.getChild("Augmenta").enableLog.set(true);
for(var i = 0 ; i < maxPersonDisplayed ; i++)
{
local.values.getChild("Person" + i).setCollapsed(true);
}
}
function moduleParameterChanged(param)
{
if(param.is(local.parameters.singlePersonMode)) {
if(local.parameters.singlePersonMode.get() == "none")
{
// Clean and fold single person object
local.values.singlePerson.setCollapsed(true);
resetAugmentaPerson(local.values.singlePerson, args);
} else {
// Unfold single person object panel
local.values.singlePerson.setCollapsed(false);
}
}
}
function oscEvent(address,args)
{
if(address == "/au/scene")
{
setAugmentaScene(local.values.scene, args);
} else if(address == "/au/personUpdated")
{
// Update objects
for(var i = 0 ; i < maxPersonDisplayed ; i++)
{
if(args[1] == i) //args[1] = oid
{
setAugmentaPerson(local.values.getChild("Person" + i), args);
}
}
// Update Oldest and newest
// Oldest is always oid = 0 if algo is correctly implemented
if(local.parameters.singlePersonMode.get() == "oldest" && args[1] == 0)
{
setAugmentaPerson(local.values.singlePerson, args);
} else if(local.parameters.singlePersonMode.get() == "newest" && args[1] == getNewestId())
{
setAugmentaPerson(local.values.singlePerson, args);
}
} else if(address == "/au/personEntered")
{
// Update objects
for(var i = 0 ; i < maxPersonDisplayed ; i++)
{
if(args[1] == i) //args[1] = oid
{
local.values.getChild("Person" + i).setCollapsed(false);
setAugmentaPerson(local.values.getChild("Person" + i), args);
}
}
// Update Oldest and newest
// Oldest is always oid = 0 if algo is correctly implemented
if(local.parameters.singlePersonMode.get() == "oldest" && args[1] == 0)
{
setAugmentaPerson(local.values.singlePerson, args);
} else if(local.parameters.singlePersonMode.get() == "newest" && args[1] == getNewestId())
{
setAugmentaPerson(local.values.singlePerson, args);
}
} else if(address == "/au/personWillLeave")
{
for(var i = 0 ; i < maxPersonDisplayed ; i++)
{
if(args[1] == i) //args[1] = oid
{
local.values.getChild("Person" + i).setCollapsed(true);
resetAugmentaPerson(local.values.getChild("Person" + i), args);
}
}
// Reset Oldest and newest
// Oldest is always oid = 0 if algo is correctly implemented
if(local.parameters.singlePersonMode.get() == "oldest" && args[1] == 0)
{
resetAugmentaPerson(local.values.singlePerson);
} else if(local.parameters.singlePersonMode.get() == "newest" && args[1] == getNewestId())
{
resetAugmentaPerson(local.values.singlePerson);
} else if(address == "/scene")
{
script.logWarning(" : This module can display only V1 protocol data, not V2+");
}
}
}
function setAugmentaPerson(person, args)
{
person.hasData.set(true);
person.pid.set(args[0]);
person.oid.set(args[1]);
person.age.set(args[2]);
person.centroid.set(args[3],args[4]);
person.velocity.set(args[5],args[6]);
person.depth.set(args[7]);
person.boundingRectCoord.set(args[8],args[9]);
person.boundingRectWidth.set(args[10]);
person.boundingRectHeight.set(args[11]);
person.highestPoint.set(args[12],args[13],args[14]);
}
function resetAugmentaPerson(person)
{
person.hasData.set(false);
person.pid.set(0);
person.oid.set(0);
person.age.set(0);
person.centroid.set(0,0);
person.velocity.set(0,0);
person.depth.set(0);
person.boundingRectCoord.set(0,0);
person.boundingRectWidth.set(0);
person.boundingRectHeight.set(0);
person.highestPoint.set(0,0,0);
}
function setAugmentaScene(scene, args)
{
scene.currentTime.set(args[0]);
scene.percentCovered.set(args[1]);
scene.numPeople.set(args[2]);
scene.averageMotion.set(args[3],args[4]);
scene.width.set(args[5]);
scene.height.set(args[6]);
scene.depth.set(args[7]);
}
function getNewestId(args)
{
if(local.values.scene.numPeople.get() > 0)
{
// Newest is last id of the scene so newest oid is objectCount-1
return local.values.scene.numPeople.get() - 1;
} else
{
// no object in the scene
return -1;
}
}