Surface sample texture with Color from texture
@LeviPesin Try again, new branch
Description
use MeshSurfaceSampler to return colours from mesh texture map

This contribution is funded by AirCards
Thanks @IanSweeneyAC!
Hm, I think the underlying problem might be that MeshSurfaceSampler's .sample( ... ) method does not provide any access to the sampled vertex indices (e.g. as barycentric coordinates). A user might want to access any of the vertex attributes, or sample other textures with the UVs.
Maybe we should add an additional method or two? For example, sampleBarycentric could return the sample as vertex indices and weights, and getAttribute could read a specified attribute for that sample:
// pointer to sample
const face = new THREE.Face();
const weights = new THREE.Vector3();
// values from sample
const position = new THREE.Vector3();
const uv = new THREE.Vector2();
sampler.sampleBarycentric( face, weights );
sampler.getAttribute( face, weights, 'position', position );
sampler.getAttribute( face, weights, 'uv', uv );
// ...
This could be more flexible for future use? I might prefer to leave the example demo as it is, though.
Another possible benefit of the new API above — I think that would provide enough flexibility to sample an animated SkinnedMesh, apply the bone transform to the three vertices, and then blend the result using the weights. Related discussion:
https://discourse.threejs.org/t/reuse-model-animation-with-samples-of-its-geometry/28780
I suppose we could do that 'by default' too, but the flexibility here is nice.
@donmccurdy you are ahead of me. I require sampling of animated skinnedMesh. Investigating.
sampler.getAttribute( face, weights, 'position', position );
It might be a harder change to convince the project of but I could see this being added to core BufferGeometry to make reading barycentric interpolated values from geometry more convenient. Or perhaps a general utility in BufferGeometryUtils.
I am also looking into the sampling of animated skinnedMesh. Has anyone made any progress on this so far? I'd be happy to jump and work together on this.
@synergyseeker I'm investigating sampling a base skinned mesh so that when its animating, attached instances move accordingly. I was looking to attach flowers to sampled points of the bones demo and then enabling the animation loop. It looks like each sampled position will need to be its own geometry, so can no longer use InstancedMesh, which is the problem I got to before being diverted.
WIP is a bit messy, but I have something for looking up the weighted sample point bone weights an indexes.
Let's continue in the PR below:
- https://github.com/mrdoob/three.js/pull/26207