@@ -7,17 +7,28 @@ import NodeKeywords from './NodeKeywords.js';
77import NodeCache from './NodeCache.js' ;
88import { NodeUpdateType , defaultBuildStages , shaderStages } from './constants.js' ;
99
10- import { REVISION , NoColorSpace , LinearEncoding , sRGBEncoding , SRGBColorSpace , Color , Vector2 , Vector3 , Vector4 } from 'three' ;
10+ import { REVISION , NoColorSpace , LinearEncoding , sRGBEncoding , SRGBColorSpace , Color , Vector2 , Vector3 , Vector4 , Float16BufferAttribute } from 'three' ;
1111
1212import { stack } from './StackNode.js' ;
1313import { maxMipLevel } from '../utils/MaxMipLevelNode.js' ;
1414
15- const typeFromLength = new Map ( ) ;
16- typeFromLength . set ( 2 , 'vec2' ) ;
17- typeFromLength . set ( 3 , 'vec3' ) ;
18- typeFromLength . set ( 4 , 'vec4' ) ;
19- typeFromLength . set ( 9 , 'mat3' ) ;
20- typeFromLength . set ( 16 , 'mat4' ) ;
15+ const typeFromLength = new Map ( [
16+ [ 2 , 'vec2' ] ,
17+ [ 3 , 'vec3' ] ,
18+ [ 4 , 'vec4' ] ,
19+ [ 9 , 'mat3' ] ,
20+ [ 16 , 'mat4' ]
21+ ] ) ;
22+
23+ const typeFromArray = new Map ( [
24+ [ Int8Array , 'int' ] ,
25+ [ Int16Array , 'int' ] ,
26+ [ Int32Array , 'int' ] ,
27+ [ Uint8Array , 'uint' ] ,
28+ [ Uint16Array , 'uint' ] ,
29+ [ Uint32Array , 'uint' ] ,
30+ [ Float32Array , 'float' ]
31+ ] ) ;
2132
2233const toFloat = ( value ) => {
2334
@@ -412,12 +423,42 @@ class NodeBuilder {
412423 getTypeFromLength ( length , componentType = 'float' ) {
413424
414425 if ( length === 1 ) return componentType ;
426+
415427 const baseType = typeFromLength . get ( length ) ;
416428 const prefix = componentType === 'float' ? '' : componentType [ 0 ] ;
429+
417430 return prefix + baseType ;
418431
419432 }
420433
434+ getTypeFromArray ( array ) {
435+
436+ return typeFromArray . get ( array . constructor ) ;
437+
438+ }
439+
440+ getTypeFromAttribute ( attribute ) {
441+
442+ let dataAttribute = attribute ;
443+
444+ if ( attribute . isInterleavedBufferAttribute ) dataAttribute = attribute . data ;
445+
446+ const array = dataAttribute . array ;
447+ const itemSize = dataAttribute . stride || attribute . itemSize ;
448+ const normalized = attribute . normalized ;
449+
450+ let arrayType ;
451+
452+ if ( ! ( attribute instanceof Float16BufferAttribute ) && normalized !== true ) {
453+
454+ arrayType = this . getTypeFromArray ( array ) ;
455+
456+ }
457+
458+ return this . getTypeFromLength ( itemSize , arrayType ) ;
459+
460+ }
461+
421462 getTypeLength ( type ) {
422463
423464 const vecType = this . getVectorType ( type ) ;
@@ -677,7 +718,7 @@ class NodeBuilder {
677718
678719 if ( propertyName !== null ) {
679720
680- flowData . code += `${ propertyName } = ${ flowData . result } ;\n` + this . tab ;
721+ flowData . code += `${ this . tab + propertyName } = ${ flowData . result } ;\n` ;
681722
682723 }
683724
@@ -864,7 +905,7 @@ class NodeBuilder {
864905
865906 if ( fromTypeLength > toTypeLength ) {
866907
867- return this . format ( `${ snippet } .${ 'xyz' . slice ( 0 , toTypeLength ) } ` , this . getTypeFromLength ( toTypeLength ) , toType ) ;
908+ return this . format ( `${ snippet } .${ 'xyz' . slice ( 0 , toTypeLength ) } ` , this . getTypeFromLength ( toTypeLength , this . getComponentType ( fromType ) ) , toType ) ;
868909
869910 }
870911
0 commit comments