diff --git a/src/geometry/rocks/RockGeometry.ts b/src/geometry/rocks/RockGeometry.ts index 9ed1b2d..0f0aded 100644 --- a/src/geometry/rocks/RockGeometry.ts +++ b/src/geometry/rocks/RockGeometry.ts @@ -1,5 +1,5 @@ +import { Axis } from "../../constants/Axis"; import { BufferGeometry, SphereGeometry } from "three"; -import { Direction } from "../../constants/Direction"; import { randomTransformVertices } from "../../utils/VertexUtils"; export class RockGeometry extends BufferGeometry { @@ -7,7 +7,7 @@ export class RockGeometry extends BufferGeometry { super(); const sphere = new SphereGeometry(radius, widthSegments, heightSegments); - this.copy(randomTransformVertices(sphere, Direction.XYZ, 0.5, 1.0)); + this.copy(randomTransformVertices(sphere, Axis.XYZ, 0.5, 1.0)); this.computeVertexNormals(); this.center(); } diff --git a/src/shaders/addNoiseDisplacement.ts b/src/shaders/addNoiseDisplacement.ts index 095e43f..9565cc8 100644 --- a/src/shaders/addNoiseDisplacement.ts +++ b/src/shaders/addNoiseDisplacement.ts @@ -1,10 +1,10 @@ -import { Direction } from "../constants/Direction"; +import { Axis } from "../constants/Axis"; import { Material, Vector3 } from "three"; interface NoiseDisplacementOptions { time?: number; intensity?: number; - direction?: Vector3; + axis?: Vector3; scale?: number; } @@ -14,24 +14,24 @@ interface NoiseDisplacementOptions { * @param {Object} options - Options for noise modification. * @param {number} [options.time=0.0] - The time value for the noise function. * @param {number} [options.intensity=1.0] - The intensity of the displacement. - * @param {Vector3} [options.direction=new Vector3(1, 1, 1)] - The direction of displacement. + * @param {Vector3} [options.axis=new Vector3(1, 1, 1)] - The axis of displacement. * @param {number} [options.scale=10.0] - The scale of the noise effect. */ export function addNoiseDisplacement( material: T, - { time = 0.0, intensity = 1.0, direction = Direction.XYZ, scale = 10.0 }: NoiseDisplacementOptions = {}, + { time = 0.0, intensity = 1.0, axis = Axis.XYZ, scale = 10.0 }: NoiseDisplacementOptions = {}, ) { material.onBeforeCompile = (shader) => { - // Add uniforms for time, direction, intensity, and scale + // Add uniforms for time, axis, intensity, and scale shader.uniforms.time = { value: time }; - shader.uniforms.direction = { value: direction }; + shader.uniforms.axis = { value: axis }; shader.uniforms.intensity = { value: intensity }; shader.uniforms.scale = { value: scale }; // Add noise function and modify the vertex shader to displace vertices shader.vertexShader = ` uniform float time; - uniform vec3 direction; + uniform vec3 axis; uniform float intensity; uniform float scale; @@ -68,7 +68,7 @@ export function addNoiseDisplacement( ` vec3 transformed = vec3(position); float n = noise(transformed * scale + time); - transformed += normalize(direction) * n * intensity; + transformed += normalize(axis) * n * intensity; vec3 transformedNormal = normal; `, ); diff --git a/src/utils/VertexUtils.ts b/src/utils/VertexUtils.ts index ad7b29f..f4e6a2d 100644 --- a/src/utils/VertexUtils.ts +++ b/src/utils/VertexUtils.ts @@ -1,8 +1,8 @@ +import { Axis } from "../constants/Axis"; import { BufferGeometry, Vector3 } from "three"; -import { Direction } from "../constants/Direction"; import { mergeVertices } from "three-stdlib"; -export function randomTransformVertices(geometry:T, direction = Direction.XYZ, minScale = 0.5, maxScale = 2.0) { +export function randomTransformVertices(geometry:T, axis = Axis.XYZ, minScale = 0.5, maxScale = 2.0) { // Delete unnecessary attributes geometry.deleteAttribute("uv"); geometry.deleteAttribute("normal"); @@ -16,9 +16,9 @@ export function randomTransformVertices(geometry:T, di for (let i = 0; i < positionAttribute.count; i++) { const vertex = new Vector3().fromBufferAttribute(positionAttribute, i); - // Randomly scale the displacement along the given direction + // Randomly scale the displacement along the given axis const randomScale = Math.random() * (maxScale - minScale) + minScale; - const displacement = direction.clone().multiplyScalar(randomScale); + const displacement = axis.clone().multiplyScalar(randomScale); // Apply the displacement to the vertex vertex.add(displacement);