File tree Expand file tree Collapse file tree 1 file changed +17
-23
lines changed
Expand file tree Collapse file tree 1 file changed +17
-23
lines changed Original file line number Diff line number Diff line change 11import { processColor } from 'react-native' ;
2- import { intersection } from 'lodash' ;
2+ import { isString , mapValues , set } from 'lodash' ;
33
44// https://developer.apple.com/documentation/scenekit/scnmaterial
5- const materialPropertiesWithMaps = [
6- 'normal' ,
7- 'diffuse' ,
8- 'displacement' ,
9- 'specular' ,
10- ] ;
5+ const propsWithMaps = [ 'normal' , 'diffuse' , 'displacement' , 'specular' ] ;
116
127export default function processMaterial ( material ) {
13- const propsToUpdate = intersection (
14- Object . keys ( material ) ,
15- materialPropertiesWithMaps ,
16- ) ;
8+ // previously it was possible to set { material: { color:'colorstring'}}... translate this to { material: { diffuse: { color: 'colorstring'}}}
9+ if ( material . color ) {
10+ set ( material , 'diffuse.color' , material . color ) ;
11+ }
1712
18- return propsToUpdate . reduce (
19- ( prev , curr ) => ( {
20- ...prev ,
21- [ curr ] : {
22- ...prev [ curr ] ,
23- color : processColor (
24- curr === 'diffuse' && typeof prev [ curr ] === 'string'
25- ? prev [ curr ]
26- : prev [ curr ] . color ,
27- ) ,
28- } ,
29- } ) ,
13+ return mapValues (
3014 material ,
15+ ( prop , key ) =>
16+ propsWithMaps . includes ( key )
17+ ? {
18+ ...prop ,
19+ color : processColor (
20+ // allow for setting a diffuse colorstring { diffuse: 'colorstring'}
21+ key === 'diffuse' && isString ( prop ) ? prop : prop . color ,
22+ ) ,
23+ }
24+ : prop ,
3125 ) ;
3226}
You can’t perform that action at this time.
0 commit comments