import { IUniform } from '@antv/g-webgpu-core' ; import { isPlainObject , isTypedArray } from 'lodash' ; /**
 * 考虑结构体命名, eg:
 * a: { b: 1 }  ->  'a.b'
 * a: [ { b: 1 } ] -> 'a[0].b'
 */ export function extractUniforms ( uniforms ) { const extractedUniforms = { } ; Object . keys ( uniforms ) . forEach ( ( uniformName ) => { extractUniformsRecursively ( uniformName , uniforms [ uniformName ] , extractedUniforms , '' ) ; } ) ; return extractedUniforms ; } function extractUniformsRecursively ( uniformName , uniformValue , uniforms , prefix ) { if ( uniformValue === null || typeof uniformValue === 'number' || typeof uniformValue === 'boolean' || ( Array . isArray ( uniformValue ) && typeof uniformValue [ 0 ] === 'number' ) || isTypedArray ( uniformValue ) || uniformValue === '' || uniformValue . resize !== undefined ) { uniforms [ `${ prefix && prefix + '.' }${ uniformName }` ] = uniformValue ; return ; } if ( isPlainObject ( uniformValue ) ) { Object . keys ( uniformValue ) . forEach ( ( childName ) => { extractUniformsRecursively ( childName , uniformValue [ childName ] , uniforms , `${ prefix && prefix + '.' }${ uniformName }` ) ; } ) ; } if ( Array . isArray ( uniformValue ) ) { uniformValue . forEach ( ( child , idx ) => { Object . keys ( child ) . forEach ( ( childName ) => { extractUniformsRecursively ( childName , child [ childName ] , uniforms , `${ prefix && prefix + '.' }${ uniformName }[${ idx }]` ) ; } ) ; } ) ; } }