File size: 941 Bytes
2b7aae2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * Uniform Utilities
 */

export function cloneUniforms(src) {
	const dst = {};

	for (const u in src) {
		dst[u] = {};

		for (const p in src[u]) {
			const property = src[u][p];

			if (
				property &&
				(property.isColor ||
					property.isMatrix3 ||
					property.isMatrix4 ||
					property.isVector2 ||
					property.isVector3 ||
					property.isVector4 ||
					property.isTexture ||
					property.isQuaternion)
			) {
				dst[u][p] = property.clone();
			} else if (Array.isArray(property)) {
				dst[u][p] = property.slice();
			} else {
				dst[u][p] = property;
			}
		}
	}

	return dst;
}

export function mergeUniforms(uniforms) {
	const merged = {};

	for (let u = 0; u < uniforms.length; u++) {
		const tmp = cloneUniforms(uniforms[u]);

		for (const p in tmp) {
			merged[p] = tmp[p];
		}
	}

	return merged;
}

// Legacy

const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };

export { UniformsUtils };