Skip to content

Instantly share code, notes, and snippets.

@ELI7VH
Created January 4, 2023 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ELI7VH/17097cab0270df74a5ca6c999a45392a to your computer and use it in GitHub Desktop.
Save ELI7VH/17097cab0270df74a5ca6c999a45392a to your computer and use it in GitHub Desktop.
const starCount = 2000
const starInstances = new app.THREE.InstancedMesh(this.starGeometry, this.starMaterial, starCount)
this.stars = mapI(starCount, (i) => {
const r = 425 + rand(120)
const xyAngle = rand(Math.PI * 2)
const zAngle = rand(Math.PI * 2)
const x = Math.cos(xyAngle) * Math.sin(zAngle) * r
const y = Math.sin(xyAngle) * Math.sin(zAngle) * r + 2
const z = Math.cos(zAngle) * r
const n = simplex.noise3D(x * 20, y * 20, z * 20) * 0.001
// const star = new app.THREE.Mesh(this.starGeometry, this.starMaterial, starCount)
const dummyStar = new app.THREE.Object3D()
dummyStar.position.set(x, y, z)
dummyStar.lookAt(0, 0, 0)
starInstances.setMatrixAt(i, dummyStar.matrix)
starInstances.instanceMatrix.needsUpdate = true
return { x, y, z, n, r }
})
this.el.object3D.add(starInstances)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment