Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

75 lines (66 sloc) 1.59 kb
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);
}
Jump to Line
Something went wrong with that request. Please try again.