@@ -9,34 +9,46 @@ import {Material, Vector3} from '../../style/raytracer';
99export class RaytraceFlowNodeViewModel extends FlowNodeViewModel {
1010
1111 get material ( ) {
12- return new Material ( this . surfaceColor , 0.1 , 0.05 , new Vector3 ( 0.8 , 0 , 0 ) ) ;
12+ return new Material ( this . surfaceColor || new Vector3 ( 0.0 , 0.2 , 0.8 ) , this . reflection || 0. 1, this . transparency || 0.05 , this . emissionColor || new Vector3 ( 0.8 , 0 , 0 ) ) ;
1313 }
1414
1515 get emissionColor ( ) : any {
1616 return this . _emissionColor ;
1717 }
1818
1919 set emissionColor ( value : any ) {
20- value . forEach ( this . ensureUnitSize ) ;
21- this . _emissionColor = value ;
20+ if ( _ . isString ( value ) ) {
21+ const found = this . parseVector3 ( value ) ;
22+ this . _emissionColor = found ;
23+ } else {
24+ value . forEach ( this . ensureUnitSize ) ;
25+ this . _emissionColor = new Vector3 ( value [ 0 ] , value [ 1 ] , value [ 2 ] ) ;
26+ }
27+ this . firePropertyChanged ( 'emissionColor' ) ;
28+ this . setPropertyValue ( 'emissionColor' , this . _emissionColor ) ;
2229 }
2330
24- get reflection ( ) : number {
31+ get reflection ( ) : any {
2532 return this . _reflection ;
2633 }
2734
28- set reflection ( value : number ) {
29- this . ensureUnitSize ( value ) ;
35+ set reflection ( value : any ) {
36+ value = this . parseUnit ( value ) ;
3037 this . _reflection = value ;
38+ this . firePropertyChanged ( 'reflection' ) ;
39+ this . setPropertyValue ( 'reflection' , this . _reflection ) ;
40+
3141 }
3242
33- get transparency ( ) : number {
43+ get transparency ( ) : any {
3444 return this . _transparency ;
3545 }
3646
37- set transparency ( value : number ) {
38- this . ensureUnitSize ( value ) ;
47+ set transparency ( value : any ) {
48+ value = this . parseUnit ( value ) ;
3949 this . _transparency = value ;
50+ this . firePropertyChanged ( 'transparency' ) ;
51+ this . setPropertyValue ( 'transparency' , this . _transparency ) ;
4052 }
4153
4254 get surfaceColor ( ) : any {
@@ -49,7 +61,7 @@ export class RaytraceFlowNodeViewModel extends FlowNodeViewModel {
4961 this . _surfaceColor = found ;
5062 } else {
5163 value . forEach ( this . ensureUnitSize ) ;
52- this . _surfaceColor = new Vector3 ( value [ 0 ] , value [ 1 ] , value [ 2 ] ) ;
64+ this . _surfaceColor = new Vector3 ( value [ 0 ] , value [ 1 ] , value [ 2 ] ) ;
5365 }
5466 this . firePropertyChanged ( 'surfaceColor' ) ;
5567 this . setPropertyValue ( 'surfaceColor' , this . _surfaceColor ) ;
@@ -73,6 +85,9 @@ export class RaytraceFlowNodeViewModel extends FlowNodeViewModel {
7385 super ( 'Raytracer' , model ) ;
7486
7587 this . portViewModels [ 'SurfaceColor' ] = new FlowPortViewModel ( 'surfaceColor' , PortType . INPUT , this , new Point ( 0.0 , 30 - 2 ) ) ;
88+ this . portViewModels [ 'EmissionColor' ] = new FlowPortViewModel ( 'emissionColor' , PortType . INPUT , this , new Point ( 0.0 , 50 - 2 ) ) ;
89+ this . portViewModels [ 'Reflection' ] = new FlowPortViewModel ( 'reflection' , PortType . INPUT , this , new Point ( 0.0 , 70 - 2 ) ) ;
90+ this . portViewModels [ 'Transparency' ] = new FlowPortViewModel ( 'transparency' , PortType . INPUT , this , new Point ( 0.0 , 90 - 2 ) ) ;
7691 this . model . nodes [ this . id ] = new FlowNodeModel ( this . id , this . model ) ;
7792
7893 }
@@ -82,6 +97,13 @@ export class RaytraceFlowNodeViewModel extends FlowNodeViewModel {
8297
8398 }
8499
100+ parseUnit ( x : any ) : number {
101+ if ( _ . isString ( x ) ) {
102+ x = parseFloat ( x ) ;
103+ }
104+ this . ensureUnitSize ( x ) ;
105+ return x ;
106+ }
85107
86108 parseVector3 ( x : string ) : Vector3 {
87109 if ( _ . isString ( x ) ) {
@@ -91,7 +113,7 @@ export class RaytraceFlowNodeViewModel extends FlowNodeViewModel {
91113 throw new Error ( 'Given string is not a Vector3 type.' ) ;
92114 }
93115 found . forEach ( this . ensureUnitSize ) ;
94- return new Vector3 ( found [ 0 ] , found [ 1 ] , found [ 2 ] ) ;
116+ return new Vector3 ( found [ 0 ] , found [ 1 ] , found [ 2 ] ) ;
95117 }
96118 }
97119 throw new Error ( 'Expected a Vector3 type.' ) ;
0 commit comments