Skip to content

Commit 3e40bfb

Browse files
committed
color space property in texture node + just replace metallic and roughness if input plugged do not multiply them
1 parent 0e7df80 commit 3e40bfb

File tree

6 files changed

+89
-101
lines changed

6 files changed

+89
-101
lines changed

src/nodes/shader/MeshStandardNode.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ export class MeshStandardNode extends WinNode {
1818
constructor() {
1919

2020
const colorNodeInput = new BaseColorProperty();
21-
const metallic = new InputOrValue(1, { label:"Metallic", min:0, max:1, asBar:true });
22-
metallic.multiplyInputWithValue = true;
21+
const metallic = new InputOrValue(1, { label:"Metallic", min:0, max:1, asBar:true });
2322

24-
const roughness = new InputOrValue(1, { label:"Roughness", min:0, max:1, asBar:true });
25-
roughness.multiplyInputWithValue = true;
23+
const roughness = new InputOrValue(1, { label:"Roughness", min:0, max:1, asBar:true });
2624

2725
const normal = new BasicInputProperty(2, "Normal");
2826

src/nodes/texture/ImageTextureNode.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import { TextureMappingModeProperty } from "../../properties/TextureMappingModeP
66
import { UVTransformProperty } from "../../properties/UVTransformProperty";
77
import { TextureTypeNode } from "./BaseTextureNode";
88
import { Script } from '../../export/Script';
9+
import { TextureColorSpaceProperty } from '../../properties/TextureColorSpaceProperty';
910
export class ImageTextureNode extends TextureTypeNode {
1011

1112
private imageProp:TextureProperty;
1213
private uv:UVTransformProperty;
1314
private extensionPolicy:TextureExtensionProperty;
1415
private mappingPolicy:TextureMappingModeProperty;
16+
private colorSpace:TextureColorSpaceProperty;
1517

1618
constructor() {
1719
super("Image Texture",
@@ -21,6 +23,7 @@ export class ImageTextureNode extends TextureTypeNode {
2123
new TextureProperty(),
2224
new TextureExtensionProperty(),
2325
new TextureMappingModeProperty(),
26+
new TextureColorSpaceProperty(),
2427
new UVTransformProperty()
2528
]
2629
);
@@ -29,6 +32,7 @@ export class ImageTextureNode extends TextureTypeNode {
2932
this.uv = this.getChildOfType(UVTransformProperty)!;
3033
this.extensionPolicy = this.getChildOfType(TextureExtensionProperty)!;
3134
this.mappingPolicy = this.getChildOfType(TextureMappingModeProperty)!;
35+
this.colorSpace = this.getChildOfType(TextureColorSpaceProperty)!;
3236
}
3337

3438
override writeScript(script: Script): string {
@@ -43,9 +47,10 @@ export class ImageTextureNode extends TextureTypeNode {
4347

4448

4549
texture => `
46-
${texture}.wrapS = ${ this.extensionPolicy.extensionMode };
47-
${texture}.wrapT = ${ this.extensionPolicy.extensionMode };
48-
${texture}.mapping = ${ this.mappingPolicy.mappingType };
50+
${texture}.wrapS = ${ this.extensionPolicy.value };
51+
${texture}.wrapT = ${ this.extensionPolicy.value };
52+
${texture}.mapping = ${ this.mappingPolicy.value };
53+
${texture}.colorSpace = ${ this.colorSpace.value };
4954
${texture}.flipY = false;
5055
`
5156
) ;
@@ -60,8 +65,9 @@ ${texture}.flipY = false;
6065
return {
6166
...super.serialize(),
6267
src: this.imageProp.isFromDisk? "" : this.imageProp.imageSrc,
63-
extension: this.extensionPolicy.extensionMode,
64-
mapping: this.mappingPolicy.mappingType
68+
extension: this.extensionPolicy.value,
69+
mapping: this.mappingPolicy.value,
70+
colorSpace: this.colorSpace.value
6571
}
6672
}
6773

@@ -71,8 +77,9 @@ ${texture}.flipY = false;
7177
if( data.src !="" )
7278
this.imageProp.src = data.src;
7379

74-
this.extensionPolicy.extensionMode = data.extension;
75-
this.mappingPolicy.mappingType = data.mapping;
80+
this.extensionPolicy.value = data.extension;
81+
this.mappingPolicy.value = data.mapping;
82+
this.colorSpace.value = data.colorSpace;
7683
}
7784

7885
override onRemoved(): void {

src/properties/ComboBoxProperty.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { AnyMapping, ClampToEdgeWrapping, CubeReflectionMapping, CubeRefractionMapping, CubeUVReflectionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, MirroredRepeatWrapping, RepeatWrapping, UVMapping, Wrapping } from "three";
2+
import { Layout } from "../layout/Layout";
3+
import { LayoutElement } from "../layout/LayoutElement";
4+
import { ComboBox } from "../components/ComboBox";
5+
6+
type Mode = [ string, string ]
7+
8+
export class ComboBoxProperty extends LayoutElement
9+
{
10+
11+
private combo:ComboBox;
12+
13+
constructor( title:string, protected modes :Mode[]) {
14+
super();
15+
16+
//this.xPadding = 10;
17+
18+
this.combo = new ComboBox(title, this.modes.map(m=>m[1]), this.onComboChange.bind(this));
19+
20+
this.layout = new Layout([
21+
this.combo
22+
], {
23+
direction:"column",
24+
align:"stretch"
25+
});
26+
}
27+
28+
/**
29+
* The type of UV mapping the object should have...
30+
*/
31+
get value() {
32+
return this.modes[ this.combo.index ][0];
33+
}
34+
35+
set value( mapping:string ) {
36+
this.combo.index = this.modes.findIndex(m=>m[0]==mapping);
37+
}
38+
39+
protected onComboChange( i:number )
40+
{
41+
this.root.update()
42+
}
43+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ComboBoxProperty } from "./ComboBoxProperty";
2+
3+
4+
export class TextureColorSpaceProperty extends ComboBoxProperty
5+
{
6+
constructor() {
7+
super("Color Space", [
8+
[ "THREE.SRGBColorSpace", "sRGB" ],
9+
[ "THREE.LinearSRGBColorSpace", "Non-Color" ],
10+
])
11+
}
12+
}
Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
1-
import { ClampToEdgeWrapping, MirroredRepeatWrapping, RepeatWrapping, Wrapping } from "three";
2-
import { Layout } from "../layout/Layout";
3-
import { LayoutElement } from "../layout/LayoutElement";
4-
import { ComboBox } from "../components/ComboBox";
5-
6-
type Mode = [ string, string ]
7-
8-
export class TextureExtensionProperty extends LayoutElement
9-
{
10-
private modes :Mode[] = [
11-
[ "THREE.RepeatWrapping", "Repeat" ],
12-
[ "THREE.ClampToEdgeWrapping", "Clamp" ],
13-
[ "THREE.MirroredRepeatWrapping", "Mirror" ]
14-
];
15-
16-
private combo:ComboBox;
1+
import { ComboBoxProperty } from "./ComboBoxProperty";
172

3+
export class TextureExtensionProperty extends ComboBoxProperty {
184
constructor() {
19-
super();
20-
21-
//this.xPadding = 10;
22-
23-
this.combo = new ComboBox("Wrapping mode", this.modes.map(m=>m[1]), this.onComboChange.bind(this));
24-
25-
this.layout = new Layout([
26-
this.combo
27-
], {
28-
direction:"column",
29-
align:"stretch"
30-
});
31-
}
32-
33-
get extensionMode() {
34-
return this.modes[ this.combo.index ][0]
35-
}
36-
37-
set extensionMode( value:string ) {
38-
this.combo.index = this.modes.findIndex( m=>m[0]==value );
39-
}
40-
41-
protected onComboChange( i:number )
42-
{
43-
// todo: do somehting.
44-
this.root.update();
5+
super("Wrapping mode", [
6+
[ "THREE.RepeatWrapping", "Repeat" ],
7+
[ "THREE.ClampToEdgeWrapping", "Clamp" ],
8+
[ "THREE.MirroredRepeatWrapping", "Mirror" ]
9+
])
4510
}
46-
}
11+
}
Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,14 @@
1-
import { AnyMapping, ClampToEdgeWrapping, CubeReflectionMapping, CubeRefractionMapping, CubeUVReflectionMapping, EquirectangularReflectionMapping, EquirectangularRefractionMapping, MirroredRepeatWrapping, RepeatWrapping, UVMapping, Wrapping } from "three";
2-
import { Layout } from "../layout/Layout";
3-
import { LayoutElement } from "../layout/LayoutElement";
4-
import { ComboBox } from "../components/ComboBox";
5-
6-
type Mode = [ string, string ]
7-
8-
export class TextureMappingModeProperty extends LayoutElement
9-
{
10-
private modes :Mode[] = [
11-
[ "THREE.UVMapping", "UV" ],
12-
[ "THREE.CubeReflectionMapping", "Cube Reflection" ],
13-
[ "THREE.CubeRefractionMapping", "Cube Refraction" ],
14-
[ "THREE.CubeUVReflectionMapping", "Cube UV Reflection" ],
15-
[ "THREE.EquirectangularReflectionMapping", "Equirectangular Reflection" ],
16-
[ "THREE.EquirectangularRefractionMapping", "Equirectangular Refraction" ],
17-
];
18-
19-
private combo:ComboBox;
1+
import { ComboBoxProperty } from "./ComboBoxProperty";
202

3+
export class TextureMappingModeProperty extends ComboBoxProperty {
214
constructor() {
22-
super();
23-
24-
//this.xPadding = 10;
25-
26-
this.combo = new ComboBox("Mapping mode", this.modes.map(m=>m[1]), this.onComboChange.bind(this));
27-
28-
this.layout = new Layout([
29-
this.combo
30-
], {
31-
direction:"column",
32-
align:"stretch"
33-
});
34-
}
35-
36-
/**
37-
* The type of UV mapping the object should have...
38-
*/
39-
get mappingType() {
40-
return this.modes[ this.combo.index ][0];
41-
}
42-
43-
set mappingType( mapping:string ) {
44-
this.combo.index = this.modes.findIndex(m=>m[0]==mapping);
45-
}
46-
47-
protected onComboChange( i:number )
48-
{
49-
this.root.update()
5+
super("Mapping Mode",[
6+
[ "THREE.UVMapping", "UV" ],
7+
[ "THREE.CubeReflectionMapping", "Cube Reflection" ],
8+
[ "THREE.CubeRefractionMapping", "Cube Refraction" ],
9+
[ "THREE.CubeUVReflectionMapping", "Cube UV Reflection" ],
10+
[ "THREE.EquirectangularReflectionMapping", "Equirectangular Reflection" ],
11+
[ "THREE.EquirectangularRefractionMapping", "Equirectangular Refraction" ],
12+
]);
5013
}
5114
}

0 commit comments

Comments
 (0)