Improve color handling approach
This commit is contained in:
parent
e53ca905af
commit
f29293c475
22 changed files with 259 additions and 181 deletions
13
src/helper/code-for-color-access.ts
Normal file
13
src/helper/code-for-color-access.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { vec3, vec4 } from 'gl-matrix';
|
||||
import { colorToString } from './color-to-string';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const codeForColorAccess = (color: vec3 | vec4 | number): string => {
|
||||
if (color instanceof Array || color instanceof Float32Array) {
|
||||
return colorToString(color);
|
||||
}
|
||||
|
||||
return `readFromPalette(${color})`;
|
||||
};
|
||||
7
src/helper/color-to-string.ts
Normal file
7
src/helper/color-to-string.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { vec3, vec4 } from 'gl-matrix';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const colorToString = (v: vec3 | vec4): string =>
|
||||
`vec4(${v[0]}, ${v[1]}, ${v[2]}, ${v.length > 3 ? v[3] : 1})`;
|
||||
Loading…
Add table
Add a link
Reference in a new issue