Simplest example with Drei sampler

Hi,

can you give me the simplest transformInstance function to make the code below works ? I can’t succeed doing this.
Thanks

<Sampler
      weight={"normal"} // the name of the attribute to be used as sampling weight
      transform={transformInstance} // a function that transforms each instance given a sample. See the examples for more.
      count={16} // Number of samples
    >
      <mesh>
        <sphereGeometry args={[2]} />
      </mesh>

      <instancedMesh args={[null, null, 1_000]}>
        <sphereGeometry args={[0.1]} />
      </instancedMesh>
    </Sampler>

here’s a simpler example than the one in the drei github docs

https://codesandbox.io/p/sandbox/donut-sampler-tb2l6h

Here’s another basic example:

https://hgtkym-5173.csb.app/?component=DreiSamplerTest

1 Like

Thank you it works like a charm

your example works but if I replace

<Sampler
      weight={"normal"} // the name of the attribute to be used as sampling weight
      transform={transformInstance} // a function that transforms each instance given a sample. See the examples for more.
      count={count} // Number of samples
    >
 <mesh>
        <sphereGeometry args={[1]} />
        <meshStandardMaterial color="blue" wireframe />
      </mesh>

with


  const nodes = useFBX("/Blue.fbx");
  return (

    <Sampler
          ...
         <mesh>
          <primitive object={nodes} scale={0.1} />
        </mesh>

it doesn’t work, how to place the sphere on the fbx object ?

Not sure if I understand. Can you provide more code, or e.g. a codesandbox?

I believe in general the <Sampler/> abstraction is designed to mount instances of one mesh on the surface of another mesh. not a collection of nodes on the surface of another collection of nodes. that’s how THREE.MeshSurfaceSampler works anyway, unless <Sampler /> adds something else to handle node subtrees.

<Sampler>
  <mesh geometry={nodes.anyOneMesh.geometry} scale={0.1}>
    <meshStandardMaterial color="blue" wireframe />
  </mesh>
</Sampler>

like @donmccurdy said, the MeshSurfaceSampler operates on one single mesh. not a group, or a mesh inside an empty mesh (like in your example). a mesh in threejs has a geometry and a material, if it doesn’t it’s basically a group.

if you want to sample the whole model with all its parts you have to join and possibly bake materials into one in blender.

1 Like