Skip to content

Commit 9b4574e

Browse files
committed
time node
1 parent b518907 commit 9b4574e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ You can also fix bugs or improve the code/interface. Just clone and do a pull re
2323
# == STATUS ==
2424

2525
### TSL to Visual Nodes:
26+
- :white_check_mark: Time node
2627
- :white_check_mark: UV Channel
2728
- :warning: Preview
2829
- :warning: Functions

src/EditorNodes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Theme } from './colors/Theme';
22
import { UVNode } from './nodes/attribute/UVNode';
33
import { ColorNode } from './nodes/input/ColorNode';
4+
import { TimeNode } from './nodes/input/TimeNode';
45
import { tslInputNodes } from './nodes/input/TslInputNode';
56
import { UniformValueNode } from './nodes/input/UniformValueNode';
67
import { ValueNode } from './nodes/input/ValueNode';
@@ -47,6 +48,7 @@ export const NodeTypes: NodeGroupType[] = [
4748
name: 'Uniform Value',
4849
id: 'uniform-value',
4950
},
51+
{ TypeClass: TimeNode, name:"time", id:"timer" },
5052
{ TypeClass: ValueNode, name: 'Value', id: 'input-value' },
5153
{ TypeClass: ColorNode, name: 'Color', id: 'color-value' },
5254
{ TypeClass: UVNode, name: 'UV', id: 'uv' },

src/nodes/input/TimeNode.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
import { Theme } from "../../colors/Theme";
3+
import { DataType, IDataType } from "../../core/IOutlet";
4+
import { Script } from "../../export/Script";
5+
import { Output } from "../../properties/Output";
6+
import { WinNode } from "../WinNode";
7+
8+
9+
10+
/**
11+
* Use this as skeleton for a new node...
12+
*/
13+
export class TimeNode extends WinNode {
14+
15+
constructor() {
16+
super("Timer", Theme.config.groupInput, [
17+
new Output("seconds", DataType.wildcard),
18+
])
19+
}
20+
21+
override width(ctx: CanvasRenderingContext2D): number {
22+
return super.width(ctx)/2;
23+
}
24+
25+
override get nodeDataType(): IDataType | undefined {
26+
return DataType.uint;
27+
}
28+
29+
protected override writeNodeScript( script: Script ): string {
30+
// this is where we write our ThreeJs TSL javascript node code...
31+
32+
const ref = script.defineUniform(
33+
this.nodeName,
34+
'0',
35+
);
36+
37+
script.writeLine(`${ref}.onFrameUpdate( frame => ${ref}.value = frame.time )`);
38+
39+
40+
return ref;
41+
}
42+
}

0 commit comments

Comments
 (0)