-
Notifications
You must be signed in to change notification settings - Fork 8
/
brick.js
47 lines (36 loc) · 1.38 KB
/
brick.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
import { Input } from 'rete';
import FieldControl from '../../controls/field';
import TextureComponent from '../../common/components/texture';
import Utils from '../../utils';
import sockets from '../../sockets';
export default class Brick extends TextureComponent {
constructor() {
super('Brick texture');
this.allocation = ['Generator'];
}
builder(node) {
super.builder(node);
const inp = new Input('count', 'Count', sockets.num);
const inp2 = new Input('margin', 'Margin', sockets.num);
const ctrl = new FieldControl(this.editor, 'count', {type: 'number', value: 12});
const ctrl2 = new FieldControl(this.editor, 'margin', {type: 'number', value: 0.04})
inp.addControl(ctrl);
inp2.addControl(ctrl2);
return node
.addInput(inp)
.addInput(inp2);
}
async worker(node, inputs, outputs) {
const count = typeof inputs['count'][0] === 'number'
? inputs['count'][0]
: node.data.count;
const margin = typeof inputs['margin'][0] === 'number'
? inputs['margin'][0]
: node.data.margin;
const result = Utils.createMockCanvas();
result.fillStyle([1, 1, 1, 1]);
result.drawBricks(count, margin);
outputs['image'] = result.toTexture();
this.updatePreview(node, outputs['image']);
}
}