[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft/
0

Configure Feed

Select the types of activity you want to include in your feed.

shapecraft / tests / modifiers.test.ts
2.5 kB 82 lines
1import { describe, it, expect } from 'vitest' 2import { box, cylinder } from '../src/primitives' 3import { twist, bend, taper } from '../src/modifiers' 4import { smooth } from '../src/modifiers/smooth' 5import { UberNoise } from '../src/noise' 6 7describe('modifiers', () => { 8 it('twist modifies positions', () => { 9 const b = box({ heightSegments: 4 }) 10 const twisted = b.warp(twist({ amount: 2 })) 11 // Positions should differ 12 const origPos = b.positions 13 const newPos = twisted.positions 14 let changed = false 15 for (let i = 0; i < origPos.length; i++) { 16 if (Math.abs(origPos[i] - newPos[i]) > 0.001) { 17 changed = true 18 break 19 } 20 } 21 expect(changed).toBe(true) 22 }) 23 24 it('taper scales vertices at extremes', () => { 25 const c = cylinder({ height: 2 }) 26 // Taper along Y: top should be smaller 27 const tapered = c.warp(taper({ axis: 'y', curve: (t) => 1 - t * 0.5 })) 28 expect(tapered.vertexCount).toBe(c.vertexCount) 29 }) 30 31 it('displace moves vertices along normals', () => { 32 const b = box() 33 const displaced = b.displace(() => 0.1) 34 const origPos = b.positions 35 const newPos = displaced.positions 36 let changed = false 37 for (let i = 0; i < origPos.length; i++) { 38 if (Math.abs(origPos[i] - newPos[i]) > 0.001) { 39 changed = true 40 break 41 } 42 } 43 expect(changed).toBe(true) 44 }) 45 46 it('displaceNoise produces non-zero displacement', () => { 47 const b = box({ widthSegments: 4, heightSegments: 4, depthSegments: 4 }) 48 const noise = new UberNoise({ seed: 42 }) 49 const displaced = b.displaceNoise(noise, 0.5) 50 const origPos = b.positions 51 const newPos = displaced.positions 52 let changed = false 53 for (let i = 0; i < origPos.length; i++) { 54 if (Math.abs(origPos[i] - newPos[i]) > 0.001) { 55 changed = true 56 break 57 } 58 } 59 expect(changed).toBe(true) 60 }) 61 62 it('smooth produces a mesh with same vertex count (indexed)', () => { 63 const b = box() 64 const smoothed = smooth(b, 1) 65 expect(smoothed.vertexCount).toBe(b.vertexCount) 66 }) 67 68 it('bend modifies positions', () => { 69 const b = box({ heightSegments: 4 }) 70 const bent = b.warp(bend({ amount: 1 })) 71 const origPos = b.positions 72 const newPos = bent.positions 73 let changed = false 74 for (let i = 0; i < origPos.length; i++) { 75 if (Math.abs(origPos[i] - newPos[i]) > 0.001) { 76 changed = true 77 break 78 } 79 } 80 expect(changed).toBe(true) 81 }) 82})