Skip to content

Commit

Permalink
Brush direction
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsturges committed Nov 7, 2024
1 parent 6b35b49 commit 4e9e786
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/brushes/DisplacementBrush.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Falloff } from "../constants/Falloff.js";
/**
* Moves vertices within a specified radius around a target position along a given direction
*/
export const displacementBrush = (geometry, position, radius, strength, axis = Direction.UP, falloffFn = Falloff.LINEAR) => {
export const displacementBrush = (geometry, position, radius, strength, direction = Direction.UP, falloffFn = Falloff.LINEAR) => {
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const vertex = new Vector3();
Expand All @@ -19,7 +19,7 @@ export const displacementBrush = (geometry, position, radius, strength, axis = D
const influence = falloff * strength;

// Apply the effect (e.g., pulling the vertex upwards)
vertex.add(axis.clone().multiplyScalar(influence));
vertex.add(direction.clone().multiplyScalar(influence));

// Update the vertex position
positions.setXYZ(i, vertex.x, vertex.y, vertex.z);
Expand Down
6 changes: 3 additions & 3 deletions src/brushes/FlattenBrush.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Falloff} from "../constants/Falloff.js";
/**
* Flattens vertices to a given plane defined by a target height or normal direction.
*/
export const flattenBrush = (geometry, position, radius, targetHeight, strength, axis = Direction.UP, falloffFn = Falloff.LINEAR) => {
export const flattenBrush = (geometry, position, radius, targetHeight, strength, direction = Direction.UP, falloffFn = Falloff.LINEAR) => {
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const vertex = new Vector3();
Expand All @@ -17,10 +17,10 @@ export const flattenBrush = (geometry, position, radius, targetHeight, strength,
const influence = falloff * strength;

// Project vertex onto flatten plane
const projectedHeight = vertex.dot(axis.normalize());
const projectedHeight = vertex.dot(direction.normalize());
const delta = targetHeight - projectedHeight;

vertex.add(axis.clone().multiplyScalar(delta * influence));
vertex.add(direction.clone().multiplyScalar(delta * influence));
positions.setXYZ(i, vertex.x, vertex.y, vertex.z);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/brushes/TwistBrush.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Direction } from "../constants/Direction.js";
import { Falloff } from "../constants/Falloff.js";

/**
* Applies a twisting force to the vertices, rotating them around the axis defined by the target position.
* Applies a twisting force to the vertices, rotating them around the direction defined by the target position.
*/
export const twistBrush = (geometry, position, radius, strength, axis = Direction.UP, falloffFn = Falloff.LINEAR) => {
export const twistBrush = (geometry, position, radius, strength, direction = Direction.UP, falloffFn = Falloff.LINEAR) => {
const positions = geometry.attributes.position;
const quaternion = new Quaternion();

Expand All @@ -20,7 +20,7 @@ export const twistBrush = (geometry, position, radius, strength, axis = Directio
const angle = falloff * strength;

// Create quaternion for rotation around the axis
quaternion.setFromAxisAngle(axis, angle);
quaternion.setFromAxisAngle(direction, angle);

// Apply twist rotation
vertex.sub(position).applyQuaternion(quaternion).add(position);
Expand Down

0 comments on commit 4e9e786

Please sign in to comment.