Skip to content

Commit 959c100

Browse files
committed
add/remove scenes, added log file
1 parent 4933c2c commit 959c100

File tree

9 files changed

+193
-41
lines changed

9 files changed

+193
-41
lines changed

Sources/build_scripts/global_functions.py

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def SendPieData(id, name, color='#3e95cd', flush=True):
3939
Log("pie:"+str(id)+":"+str(name)+":"+str(color), flush)
4040

4141
#data contains an array or normalized inputs (from 0 to 1)
42-
def SendImageData(id, data, width=32, height=32, name="", rgba=False, flush=True, invert=False, offset=0):
42+
def SendImageData(id, data, width=32, height=32, name="", rgba=False, flush=True, invert=False, offset=0, resize=[]):
4343
if EDITOR_MODE:
4444
img = Image.new( 'RGBA', (width,height), "white")
4545
pixels = img.load()
@@ -57,6 +57,8 @@ def SendImageData(id, data, width=32, height=32, name="", rgba=False, flush=True
5757
else:
5858
pixels[x,y] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly
5959

60+
if len(resize)>0:
61+
img = img.resize((resize[0], resize[1]), Image.NEAREST)
6062

6163
tmpDir = tempfile.gettempdir()
6264
imgPath = str(tmpDir)+"/"+name+"_out_"+str(id)+"_"+str(offset)+".png"
@@ -178,6 +180,27 @@ def CarveNumber(pixels, number, x, y, bg = (255, 255, 255, 255), color=(0, 0, 0,
178180
IOHelpers.CarveDigit(pixels, str_num[i], x+loc_x, y, bg, color)
179181
loc_x+=4
180182

183+
def CreateImage(data, width=32, height=32, rgba=False, invert=False, resize=[]):
184+
img = Image.new( 'RGBA', (width,height), "white")
185+
pixels = img.load()
186+
187+
for i in range(len(data)): # for every pixel:
188+
y = int(np.floor(i/width))
189+
x = i-y*width
190+
#print("coord: "+str(x)+"_"+str(y)+":"+str(data[i]))
191+
if rgba:
192+
pixel = max(0, data[i])
193+
else:
194+
pixel = [max(0, data[i]), max(0, data[i]), max(0, data[i]), 1]
195+
if invert:
196+
pixels[x,height-y-1] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly
197+
else:
198+
pixels[x,y] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly
199+
200+
if len(resize)>0:
201+
img = img.resize((resize[0], resize[1]), Image.NEAREST)
202+
203+
return img
181204

182205
def CarveDigit(pixels, digit, x, y, bg = (255, 255, 255, 255), color=(0, 0, 0, 255)):
183206
#3x5 = 15pixels
@@ -732,7 +755,7 @@ def avg(data=[], steps=-1):
732755

733756
return _sum/divider
734757

735-
def entropy(data=[], ground=0.5, multiplier = 3):
758+
def entropy(data=[], ground=0, multiplier = 3):
736759
_sum = 0
737760
_len = max(1, len(data))
738761
for v in data:
@@ -775,7 +798,22 @@ def normalize(sample):
775798
sample[i] = sample[i]/_max
776799
return sample
777800

801+
def normalize2D(sample):
802+
_max = 0
803+
for m in sample:
804+
for n in m:
805+
if abs(n)>_max:
806+
_max = abs(n)
807+
808+
for i in range(len(sample)):
809+
for j in range(len(sample[i])):
810+
sample[i][j] = sample[i][j]/_max
811+
return sample
812+
778813
def Spectrogram(samples, samplerate):
779814
from scipy import signal
780815
frequencies, times, spectogram = signal.spectrogram(samples, len(samples))
781-
return spectogram
816+
return spectogram
817+
818+
def Sigmoid(data):
819+
pass

Sources/scripts/convolutions.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,54 @@
1-
#description An onvolutional layer
1+
#description An 2D convolutional layer
22
#icon fa fa-sitemap
3-
#param list:conv,deconv,
4-
type = "conv"
3+
#param list:conv2d,deconv2d,maxpool2d
4+
type = "conv2d"
5+
#zone type==conv2d
6+
#param array|int
7+
shape = [5, 5, 1, 32]
58
#param int
6-
out_channels = 32
7-
#zone type==conv
9+
strides = 1
10+
#endzone
11+
12+
#zone type==maxpool2d
813
#param int
9-
stride = 2
14+
k = 2
1015
#endzone
1116

12-
def Run(batch_input):
13-
out_channels = self.out_channels
14-
stride = self.stride
17+
self.variables = []
1518

16-
if self.type=="conv":
17-
with tf.variable_scope(self.name):
18-
in_channels = batch_input.get_shape()[3]
19-
filter = tf.get_variable("filter", [4, 4, in_channels, out_channels], dtype=tf.float32, initializer=tf.random_normal_initializer(0, 0.02))
20-
# [batch, in_height, in_width, in_channels], [filter_width, filter_height, in_channels, out_channels]
21-
# => [batch, out_height, out_width, out_channels]
22-
padded_input = tf.pad(batch_input, [[0, 0], [1, 1], [1, 1], [0, 0]], mode="CONSTANT")
23-
conv = tf.nn.conv2d(padded_input, filter, [1, stride, stride, 1], padding="VALID")
24-
return conv
19+
def Run(self, batch_input, reuse=False):
20+
21+
if self.type=="conv2d":
22+
W = tf.Variable(tf.random_normal(self.shape))
23+
b = tf.Variable(tf.random_normal([self.shape[3]]))
24+
25+
self.variables.append(W)
26+
self.variables.append(b)
27+
28+
x = self.conv2d(batch_input, W, b, strides=self.strides, name=self.name)
29+
Log(self.name+" "+str(x.get_shape()))
30+
return x
31+
elif self.type=="maxpool2d":
32+
x = self.maxpool2d(batch_input, k=self.k, name=self.name)
33+
Log(self.name+" "+str(x.get_shape()))
34+
return x
2535
else:
36+
stride = self.strides
37+
out_channels = self.out_channels
2638
with tf.variable_scope(self.name):
2739
batch, in_height, in_width, in_channels = [int(d) for d in batch_input.get_shape()]
2840
filter = tf.get_variable("filter", [4, 4, out_channels, in_channels], dtype=tf.float32, initializer=tf.random_normal_initializer(0, 0.02))
2941
# [batch, in_height, in_width, in_channels], [filter_width, filter_height, out_channels, in_channels]
3042
# => [batch, out_height, out_width, out_channels]
3143
conv = tf.nn.conv2d_transpose(batch_input, filter, [batch, in_height * 2, in_width * 2, out_channels], [1, 2, 2, 1], padding="SAME")
32-
return conv
44+
return conv
45+
46+
def conv2d(self, x, W, b, strides=1, name=""):
47+
# Conv2D wrapper, with bias and relu activation
48+
x = tf.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding='SAME', name=name)
49+
x = tf.nn.bias_add(x, b)
50+
return tf.nn.relu(x)
51+
52+
def maxpool2d(self, x, k=2, name=""):
53+
# MaxPool2D wrapper
54+
return tf.nn.max_pool(x, ksize=[1, k, k, 1], strides=[1, k, k, 1], padding='SAME', name=name)

Sources/scripts/function.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
#description Activation functions: softmax, relu, tanh, sigmoid etc...
44
#icon fa fa-flask
55

6-
#param list: sigmoid, tanh, softmax, relu, batchnorm, lrelu
6+
#param list: sigmoid, tanh, softmax, relu, batchnorm, lrelu, reshape
77
function = "sigmoid"
88
#zone function==lrelu
99
#param float
1010
a = 1
1111
#endzone
1212

13+
#zone function==reshape
14+
#param array|eval
15+
shape = [-1, 100]
16+
#endzone
17+
18+
1319
def Run(self, x, reuse=False):
1420
Log(self.function)
1521

@@ -23,6 +29,8 @@ def Run(self, x, reuse=False):
2329
return self.batchnorm(x)
2430
elif self.function=="lrelu":
2531
return self.lrelu(x)
32+
elif self.function=="reshape":
33+
return tf.reshape(x, self.shape)
2634
else:
2735
return tf.nn.relu(x)
2836

Sources/src/Model/Controllers/GlobalService.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default class GlobalService
2424
this.sceneReady = false;
2525
this.hierarchyReady = false;
2626
this.running = false;
27+
this.running_scene = 0;
2728

2829
this.propertiesUI = null;
2930
this.projectPropertiesUI = null;
@@ -217,6 +218,7 @@ export default class GlobalService
217218
this.runningUI.forceUpdate();
218219
this.sceneUI.forceUpdate();
219220
window.service.builder = null;
221+
document.getElementById("activeTab_"+window.service.running_scene).className = "glyphicon glyphicon-picture";
220222
}
221223

222224
copySelection()

Sources/src/Model/Managers/ProjectRunner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ const { spawn } = require('child_process');
44
export default class ProjectRunner{
55
constructor(folder) {
66
this.folder = folder;
7-
window.service.log("Running scene: "+window.service.currentScene, "", 0);
7+
window.service.running_scene = window.service.currentScene;
8+
window.service.log("Running scene: "+window.service.project.sceneNames[window.service.currentScene], "", 0);
89
window.service.consoleWindow.selectTab(1)
10+
window.service.updatedDynamicVars = true;
911

1012
const exec = spawn('python', [folder+'/main.py']);
1113
window.service.runningProcess = exec;

Sources/src/Model/UI/Properties.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,18 @@ export default class Properties extends React.Component {
148148
filePicker(script, paramID, listIndex, isFile)
149149
{
150150
let selected_dir;
151+
152+
/*let defaultpath;
153+
if(listIndex!=null)
154+
{
155+
let splitlist = script.params[paramID].value.split(";")
156+
defaultpath = splitlist[listIndex];
157+
}
158+
else
159+
{
160+
defaultpath = script.params[paramID].value;
161+
}*/
162+
151163
if(isFile)
152164
selected_dir = require('electron').remote.dialog.showOpenDialog({title:"Select a file...", properties: ['openFile']});
153165
else
@@ -248,6 +260,7 @@ export default class Properties extends React.Component {
248260
else if(script.params[p].type.trim()=="folder" || script.params[p].type.trim()=="file")
249261
{
250262
let domID = "script_input_"+p;
263+
251264
params.push(
252265
<div key={script.params[p].name+"_"+script.id+"_"+p} className="input-group">
253266
<span className="input-group-addon input-group-small input-group-addon-small">{script.params[p].name}:</span>

Sources/src/Model/UI/Window.js

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class Window extends React.Component {
1414

1515
editSceneName(sceneID)
1616
{
17-
this.setState({editing:true, sceneEdit:sceneID, newSceneName:window.service.project.sceneNames[sceneID-1]});
17+
this.setState({editing:true, sceneEdit:sceneID, newSceneName:window.service.project.sceneNames[sceneID]});
1818
}
1919

2020
updateNewSceneName(evt)
@@ -24,35 +24,70 @@ export default class Window extends React.Component {
2424

2525
saveNewName()
2626
{
27-
window.service.project.sceneNames[this.state.sceneEdit-1] = this.state.newSceneName;
27+
window.service.project.sceneNames[this.state.sceneEdit] = this.state.newSceneName;
28+
this.setState({editing:false, newSceneName:""});
29+
}
30+
31+
addScene()
32+
{
33+
window.service.project.sceneNames.push("New Scene");
34+
this.forceUpdate();
35+
}
36+
37+
removeScene()
38+
{
39+
window.service.project.sceneNames.splice(this.state.activeTab, 1);
2840
this.setState({editing:false, newSceneName:""});
2941
}
3042

3143
renderTabs() {
3244
let first = true;
3345
let counter = 0;
34-
const listItems = this.props.tabs.map((element) => {
35-
counter++;
3646

37-
let name = element;
38-
let edit = "";
39-
if(this.props.scene_selector && window.service.project.sceneNames)
47+
if(this.props.scene_selector)
48+
{
49+
let listItems = [];
50+
51+
for (let i in window.service.project.sceneNames) {
52+
let name = window.service.project.sceneNames[i];
53+
let edit = (<span onClick={this.editSceneName.bind(this, counter)} className="glyphicon glyphicon-edit" style={{cursor:'pointer'}}></span>);
54+
55+
if (counter==this.state.activeTab)
56+
{
57+
listItems.push(<li key={counter} className="active"><a style={{"user-select":"none", background:this.props.color}}><span id={"activeTab_"+counter} className={"glyphicon glyphicon-"+this.props.icons[0]}></span> {name} {edit}</a></li>);
58+
}
59+
else
4060
{
41-
name = window.service.project.sceneNames[counter-1];
42-
edit = (<span onClick={this.editSceneName.bind(this, counter)} className="glyphicon glyphicon-edit" style={{cursor:'pointer'}}></span>);
61+
listItems.push(<li key={counter} className="inactivetab"><a className="inactivetabLink" style={{"user-select":"none"}} href="#" onClick={this.selectTab.bind(this, counter)}><span id={"activeTab_"+counter} className={"glyphicon glyphicon-"+this.props.icons[0]}></span> {name}</a></li>);
4362
}
63+
counter++;
64+
}
65+
66+
listItems.push(<li key={counter} className="inactivetab"><a className="inactivetabLink" style={{"user-select":"none"}} href="#" onClick={this.addScene.bind(this)}><span class="glyphicon glyphicon-plus"></span> Add Scene</a></li>)
67+
return listItems;
68+
}
69+
else
70+
{
71+
72+
const listItems = this.props.tabs.map((element) => {
73+
counter++;
74+
75+
let name = element;
4476

4577
if (counter-1==this.state.activeTab)
4678
{
47-
return <li key={counter} className="active"><a style={{"user-select":"none", background:this.props.color}}><span className={"glyphicon glyphicon-"+this.props.icons[counter-1]}></span> {name} {edit}</a></li> ;
79+
return <li key={counter} className="active"><a style={{"user-select":"none", background:this.props.color}}><span className={"glyphicon glyphicon-"+this.props.icons[counter-1]}></span> {name}</a></li> ;
4880
}
4981
else
5082
{
5183
return <li key={counter} className="inactivetab"><a className="inactivetabLink" style={{"user-select":"none"}} href="#" onClick={this.selectTab.bind(this, counter-1)}><span className={"glyphicon glyphicon-"+this.props.icons[counter-1]}></span> {name}</a></li>;
5284
}
53-
});
85+
});
86+
87+
return listItems;
88+
}
5489

55-
return listItems;
90+
5691
}
5792

5893
getActiveChild() {
@@ -75,6 +110,7 @@ export default class Window extends React.Component {
75110
window.service.sceneUI.update();
76111
window.service.sceneUI.clearSelection();
77112
window.service.hierarchyUI.forceUpdate();
113+
this.setState({editing:false, newSceneName:""});
78114
}
79115

80116
this.setState({
@@ -135,14 +171,18 @@ export default class Window extends React.Component {
135171
}
136172

137173
let edit = "";
138-
139-
if(this.state.editing)
174+
175+
if(this.state.editing)
140176
{
177+
let left = document.getElementById("activeTab_"+window.service.currentScene).getBoundingClientRect().left-17;
141178
edit = (
142-
<div className="input-group editSceneName">
179+
<div className="input-group editSceneName" style={{left:left+"px"}}>
143180
<input type="text" className="form-control" value={this.state.newSceneName} placeholder="Scene Name" onChange={this.updateNewSceneName.bind(this)}/>
144181
<div className="input-group-btn">
145-
<button className="btn btn-default" type="submit" onClick={this.saveNewName.bind(this)} style={{height: "31px"}}>
182+
<button className="btn btn-default" type="submit" onClick={this.removeScene.bind(this)} style={{height: "31px"}}>
183+
<i className="fa fa-trash"></i>
184+
</button>
185+
<button className="btn btn-default" type="submit" onClick={this.saveNewName.bind(this)} style={{height: "31px"}}>
146186
<i className="fa fa-check"></i>
147187
</button>
148188
</div>

0 commit comments

Comments
 (0)