Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 75 lines (66 sloc) 1.59 kb
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
use PolygonMeshRT;
use GeometryAttributesRT;
use Vec3;

operator WaveDeformerPerVertex(
  Index i,
  ScalarAttribute originalPositions,
  io Scalar positions[],
  Vec3 axis,
  Vec3 center,
  Scalar amplitude,
  Scalar frequency,
  Scalar speed,
  Scalar time
)
{
  Size index = i * 3;
  
  // pull out a single positions
  Vec3 pos(
    originalPositions.data[index+0],
    originalPositions.data[index+1],
    originalPositions.data[index+2]
  );
  
  // compute some wave deformation
  Vec3 localPos = pos - center;
  Scalar distance = axis.dot(localPos);
  Vec3 onAxisPos = center + axis * distance;
  localPos = pos - onAxisPos;
  Scalar factor = sin(distance * frequency + time * speed) * amplitude;
  localPos *= 1.0 + factor;
  pos = onAxisPos + localPos;
  
  // push back a single position
  positions[index+0] = pos.x;
  positions[index+1] = pos.y;
  positions[index+2] = pos.z;
}

operator WaveDeformer(
  io PolygonMesh mesh,
  io GeometryAttributes attributes,
  io Vec3 axis,
  io Vec3 center,
  io Scalar amplitude,
  io Scalar frequency,
  io Scalar speed,
  io Scalar time
) {

  // pull out positions data
  Scalar positions[];
  positions.resize(attributes.size() * 3);
  
  // invoke multithreading
  executeParallel(
    WaveDeformerPerVertex,
    attributes.size(),
    attributes.scalarAttributes[Attribute_Pos],
    positions,
    axis,
    center,
    amplitude,
    frequency,
    speed,
    time
  );
  
  // push back the positions data
  attributes.scalarAttributes[Attribute_Pos].data = positions;
  
  // recompute normals
  mesh.computeNormals(attributes);
}
Something went wrong with that request. Please try again.