forked from Spark-AR-Community/SparkAR-Snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHairColorAverage.js
More file actions
27 lines (23 loc) · 826 Bytes
/
HairColorAverage.js
File metadata and controls
27 lines (23 loc) · 826 Bytes
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
// Load in the required modules
const Materials = require('Materials');
const Segmentation = require('Segmentation');
const Reactive = require('Reactive');
const Shaders = require('Shaders');
// Enable async/await in JS [part 1]
(async function () {
//Find Material
const [mat] = await Promise.all([
Materials.findFirst('defaultMaterial0')
]);
// Getting averge color of the hair
const color = Reactive.pack4(
Segmentation.hair.averageColor.red,
Segmentation.hair.averageColor.green,
Segmentation.hair.averageColor.blue,
Segmentation.hair.averageColor.alpha
);
// Getting the texture Slot
const textureslot = Shaders.DefaultMaterialTextures.DIFFUSE;
// Setting the color in the Texture slot
mat.setTextureSlot(textureslot, color);
})();