Skip to content

Instantly share code, notes, and snippets.

@gsimone
Created February 2, 2022 12:41
Show Gist options
  • Save gsimone/023133e31da92c02ba0f2445437dc727 to your computer and use it in GitHub Desktop.
Save gsimone/023133e31da92c02ba0f2445437dc727 to your computer and use it in GitHub Desktop.
Spheriphy box three.js
function createGeometry() {
const r = 2
const geometry = new THREE.BoxGeometry(2, 2, 2, 32, 32, 32)
const positionAttribute = geometry.attributes.position
for (let i = 0; i < positionAttribute.count; i++) {
const x = positionAttribute.getX(i)
const y = positionAttribute.getY(i)
const z = positionAttribute.getZ(i)
positionAttribute.set(
[
x * Math.sqrt(1 - (y * y) / 2 - (z * z) / 2 + (y * y * z * z) / 3) * r,
y * Math.sqrt(1 - (z * z) / 2 - (x * x) / 2 + (z * z * x * x) / 3) * r,
z * Math.sqrt(1 - (x * x) / 2 - (y * y) / 2 + (x * x * y * y) / 3) * r,
],
i * 3
)
}
return geometry
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment