/** * Normal Operations * * Comprehensive normal calculation and management for meshes * * Normals are vectors that point outward from surfaces: * - Face normals: One per face (for flat shading) * - Vertex normals: One per vertex, averaged from connected faces (for smooth shading) */ import { Mesh } from '../geometry/mesh'; import { MeshFace } from '../geometry/mesh_face'; import { Cube } from '../geometry/cube'; import { CubeFace } from '../geometry/cube_face'; import { Vector3 } from './transform'; /** * Calculate face normal using cross product * * Formula: n = (v2 - v1) × (v3 - v1) * * @param v1 First vertex position * @param v2 Second vertex position * @param v3 Third vertex position * @param normalize Whether to normalize the result * @returns Face normal vector */ export declare function calculateFaceNormal(v1: Vector3, v2: Vector3, v3: Vector3, normalize?: boolean): Vector3; /** * Get face normal for a mesh face */ export declare function getFaceNormal(face: MeshFace, normalize?: boolean): Vector3; /** * Calculate vertex normal by averaging connected face normals * * @param mesh Mesh containing the vertex * @param vertexKey Vertex key * @returns Normalized vertex normal */ export declare function calculateVertexNormal(mesh: Mesh, vertexKey: string): Vector3; /** * Calculate all vertex normals for a mesh * * This is the main function for smooth shading. * It averages face normals for each vertex. */ export declare function calculateAllVertexNormals(mesh: Mesh): Record; /** * Calculate face normals for all faces in a mesh */ export declare function calculateAllFaceNormals(mesh: Mesh): Record; /** * Recalculate normals for specific vertices * * Useful when only certain vertices have changed. */ export declare function recalculateVertexNormals(mesh: Mesh, vertexKeys: string[]): Record; /** * Recalculate normals for faces that use specific vertices */ export declare function recalculateFaceNormalsForVertices(mesh: Mesh, vertexKeys: string[]): Record; /** * Get cube face normal (axis-aligned) */ export declare function getCubeFaceNormal(cube: Cube, face: CubeFace): Vector3; /** * Check if face normal is pointing outward * * Compares face normal with vector from mesh center to face center. */ export declare function isNormalOutward(face: MeshFace, mesh: Mesh): boolean; /** * Flip face normal by reversing vertex order */ export declare function flipFaceNormal(face: MeshFace): void; /** * Flip normals for multiple faces */ export declare function flipFaceNormals(mesh: Mesh, faceKeys: string[]): void; /** * Ensure all face normals point outward */ export declare function fixNormalsOutward(mesh: Mesh): number; /** * Calculate angle between two face normals */ export declare function getNormalAngle(normal1: Vector3, normal2: Vector3): number; /** * Get average normal from multiple normals */ export declare function averageNormals(normals: Vector3[]): Vector3; /** * Smooth normals by averaging with neighboring faces * * This creates smoother transitions between faces. */ export declare function smoothNormals(mesh: Mesh, angleThreshold?: number): Record; /** * Hard edges: Use face normals instead of vertex normals * * This creates sharp edges by using face normals directly. */ export declare function hardenEdges(mesh: Mesh, edgeKeys: Array<[string, string]>): Record; /** * Recalculate all normals after geometry changes * * This should be called after any operation that modifies geometry: * - Moving vertices * - Adding/removing faces * - Splitting edges * - Extruding * - etc. */ export declare function recalculateAllNormals(mesh: Mesh): { faceNormals: Record; vertexNormals: Record; }; /** * Check if normals need recalculation * * This can be used to optimize by only recalculating when needed. */ export declare function needsNormalRecalculation(mesh: Mesh, lastRecalculation: number): boolean; /** * Get normal for a specific vertex (with caching) */ export declare function getVertexNormal(mesh: Mesh, vertexKey: string, cachedNormals?: Record): Vector3; /** * Get normal for a specific face (with caching) */ export declare function getFaceNormalCached(face: MeshFace, cachedNormals?: Record, faceKey?: string): Vector3; /** * Calculate normals for triangulated mesh * * When a mesh is triangulated, each triangle gets its own normal. */ export declare function calculateTriangulatedNormals(mesh: Mesh): Record; /** * Export normals for rendering * * Returns normals in a format suitable for GPU rendering. */ export declare function exportNormalsForRendering(mesh: Mesh, shadingMode?: 'flat' | 'smooth'): { vertexNormals: Float32Array; faceNormals?: Float32Array; }; //# sourceMappingURL=normal_operations.d.ts.map