Skip to content

Commit 90e42ad

Browse files
committed
bug fixes + exposing label prop of inputorvalue prop
1 parent 17934c8 commit 90e42ad

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

src/Editor.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ export class Editor {
13621362

13631363
reader.onload = () => {
13641364
const content = reader.result as string;
1365-
const reg = /\*\*LAYOUT\*\*(.*)\*\*LAYOUT\*\*/m;
1365+
const reg = /\*\*LAYOUT\*\*(.*)\*\*LAYOUT\*\*/s;
13661366
const match = content.match(reg);
13671367
if (match) {
13681368
let data: any;
@@ -1412,12 +1412,15 @@ export class Editor {
14121412
layoutMatrix.f,
14131413
);
14141414

1415+
console.log("LOAD", data)
14151416
//
14161417
// recreate nodes
14171418
//
14181419
data.layout.forEach((nodeData: any, i: number) => {
14191420
const node = this.objs[i];
14201421

1422+
console.log("LOADED NODE:", nodeData)
1423+
14211424
if (node) {
14221425
node.unserialize(nodeData);
14231426
} else {
@@ -1429,6 +1432,8 @@ export class Editor {
14291432
// create connections
14301433
//
14311434
data.connections?.forEach((connection: any) => {
1435+
if(!connection) return;
1436+
14321437
const [fromNodeIndex, fromOutletIndex, toNodeIndex, toOutletIndex] = connection;
14331438

14341439
const fromNode = this.objs[fromNodeIndex];

src/nodes/attribute/UVNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class UVNode extends BaseAttributeNode {
3939

4040
override unserialize(data: Record<string, any>): void {
4141
super.unserialize(data);
42-
this.uvChannel.value = data.channel;
42+
this.uvChannel.value = data.channel ?? 0;
4343

4444
}
4545
}

src/nodes/vector/BumpMapNode.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class BumpMapNode extends WinNode {
4949
const bumpTexture =
5050
this.bumpHeight.writeScript(script) + this.invert.value;
5151

52-
let output = `bumpMap( ${bumpTexture}, ${bumpStrength})`;
52+
const output = `bumpMap( ${bumpTexture}, ${bumpStrength})`;
5353

5454
const normal = this.normal.writeScript(script);
5555

@@ -130,4 +130,18 @@ return ${perturbNormalArb}( {
130130
return script.define(this.nodeName, output);
131131
}
132132
}
133+
134+
override serialize(): Record<string, any> {
135+
return {
136+
...super.serialize(),
137+
invert: this.invert.value,
138+
strength: this.strength.value,
139+
}
140+
}
141+
142+
override unserialize(data: Record<string, any>): void {
143+
super.unserialize(data);
144+
this.invert.value = data.invert;
145+
this.strength.value = data.strength;
146+
}
133147
}

src/nodes/vector/NormalMapNode.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { InputOrValue } from '../../properties/InputOrValue';
66
import { WinNode } from '../WinNode';
77
import { Script } from '../../export/Script';
88
import { Output } from '../../properties/Output';
9-
import { DataType } from '../../core/IOutlet';
9+
import { DataType, IDataType } from '../../core/IOutlet';
1010

1111
export class NormalMapNode extends WinNode {
1212
protected typeCombo: ComboBox;
@@ -47,11 +47,15 @@ export class NormalMapNode extends WinNode {
4747
this.update();
4848
}
4949

50+
override get nodeDataType(): IDataType | undefined {
51+
return DataType.vec2;
52+
}
53+
5054
protected override writeNodeScript(script: Script): string {
5155
script.importModule('normalMap');
5256

53-
let map = this.color.writeScript(script);
54-
let strength = this.strength.value;
57+
const map = this.color.writeScript(script);
58+
const strength = this.strength.value;
5559

5660
let node = `
5761
const normalNode = normalMap( ${map}, ${strength});
@@ -73,4 +77,20 @@ normalNode.normalMapType = THREE.ObjectSpaceNormalMap;
7377
true,
7478
);
7579
}
80+
81+
override serialize(): Record<string, any> {
82+
return {
83+
...super.serialize(),
84+
normalType: this.typeCombo.index,
85+
strength: this.strength.value,
86+
color: this.color.baseColor.getHex()
87+
}
88+
}
89+
90+
override unserialize(data: Record<string, any>): void {
91+
super.unserialize(data);
92+
this.typeCombo.index = data.normalType;
93+
this.strength.value = data.strength;
94+
this.color.baseColor = new Color(data.color);
95+
}
7696
}

src/properties/BaseColorProperty.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export class BaseColorProperty extends Input {
1010
protected colorPicker: ColorPicker;
1111

1212
constructor(
13-
title = 'Base Color',
13+
readonly label = 'Base Color',
1414
defaultColor?: Color,
1515
protected multipliesInput = true,
1616
) {
1717
super(DataType.uvec3);
1818

1919
this.colorPicker = new ColorPicker(() => this.root.update(), false);
2020

21-
this.layout = new Layout([new TextLabel(title), this.colorPicker], {
21+
this.layout = new Layout([new TextLabel(label), this.colorPicker], {
2222
justify: 'space-between',
2323
});
2424

src/properties/InputOrValue.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export class InputOrValue extends BasicInputProperty {
7070
});
7171
}
7272

73+
override get label() {
74+
return this.valueSlider.name;
75+
}
7376
override set label(str: string) {
7477
this.valueSlider.name = str;
7578
}

0 commit comments

Comments
 (0)