Skip to content

Commit

Permalink
Merge pull request #1 from flo-bit/main
Browse files Browse the repository at this point in the history
stuff
  • Loading branch information
flo-bit authored Sep 23, 2024
2 parents b88f374 + 0c1d84e commit 5fe29b2
Show file tree
Hide file tree
Showing 13 changed files with 939 additions and 373 deletions.
8 changes: 6 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# tiny planets

procedurally generated tiny planets in three.js
procedurally generated tiny planets in three.js. work in progress.


https://github.com/user-attachments/assets/55ba1872-d064-483b-9a31-2c95adaa201a


## features

- generated using web workers
- adjustable detail level
- with vegetation
- presets
- presets
14 changes: 11 additions & 3 deletions features.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
- [x] height
- [ ] slope
- [ ] different materials
- [ ] make vegetation sway in the wind
- [ ] make all random stuff dependent on seed

### weather
- [ ] clouds
- [ ] particles (snow, rain, etc)

### water
- [ ] moving water
- [x] moving water
- [ ] water reflections
- [ ] water refractions
- [ ] water caustics
- [x] water caustics
- [ ] water foam

### biomes
Expand All @@ -34,5 +36,11 @@
- [ ] shadows
- [ ] ambient occlusion

- [ ] physics

- [ ] physics
## filters
- [ ] selective bloom (for glowy things)
- [ ] tilt shift

## other
- [ ]
13 changes: 8 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
<link rel="stylesheet" href="./index.css" />
</head>

<body class="bg-black"
>
<button id="button" class="p-2 px-3 border border-white/20 rounded-md text-white z-10 bg-white/10 absolute bottom-2 right-2 font-semibold text-lg hover:bg-white/20">random</button>
<body class="bg-black"></body>
<button
id="button"
class="hidden p-2 px-3 border border-white/20 rounded-md text-white z-10 bg-white/10 absolute bottom-2 right-2 font-semibold text-lg hover:bg-white/20"
>
random
</button>

<canvas id="root" ></canvas>
<canvas id="root"></canvas>

<script src="src/script.ts" type="module"></script>

</body>
</html>
8 changes: 6 additions & 2 deletions src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ light.shadow.camera.left = -2;
const ambientLight = new THREE.AmbientLight(0xffffff, 0.1);
scene.add(ambientLight);


let total = 0;
let lastDelta = 0;
renderer.setAnimationLoop((delta) => {
Expand All @@ -72,7 +73,7 @@ renderer.setAnimationLoop((delta) => {

if (!hasPlanet) {
console.log("Creating planet");
createPlanet();
createPlanet("beach");
hasPlanet = true;
}
});
Expand Down Expand Up @@ -104,7 +105,10 @@ async function createPlanet(preset: string | undefined = undefined) {
}

console.time("planet");
const planet = new Planet({ preset });
const planet = new Planet({
detail: 50,
biome: { preset },
});
let mesh = await planet.create();
scene.remove(planetMesh);
scene.add(mesh);
Expand Down
46 changes: 35 additions & 11 deletions src/worlds/biome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ import {
type ColorGradientOptions,
} from "./helper/colorgradient";
import { biomePresets } from "./presets";
import { Octree } from "./helper/octree";

export type VegetationItem = {
name: string;
density: number;

minimumHeight?: number;
maximumHeight?: number;

minimumSlope?: number;
maximumSlope?: number;

minimumDistance?: number;
maximumDistance?: number;
colors?: Record<string, { array?: number[] }>;
};

export type BiomeOptions = {
name?: string;
Expand All @@ -21,17 +37,10 @@ export type BiomeOptions = {
tintColor?: number;

vegetation?: {
items: {
name: string;
density: number;

minimumHeight?: number;
maximumHeight?: number;

minimumDistance?: number;
maximumDistance?: number;
colors?: Record<string, { array?: number[] }>;
}[];
defaults?: {
density?: number;
};
items: VegetationItem[];
};
};

Expand All @@ -44,6 +53,8 @@ export class Biome {

options: BiomeOptions;

vegetationPositions: Octree = new Octree();

constructor(opts: BiomeOptions = {}) {
if (opts.preset) {
const preset = biomePresets[opts.preset];
Expand Down Expand Up @@ -122,4 +133,17 @@ export class Biome {

return undefined;
}

addVegetation(
item: VegetationItem,
position: Vector3,
normalizedHeight: number,
steepness: number,
) {
this.vegetationPositions.insert(position, item);
}

itemsAround(position: Vector3, radius: number): Vector3[] {
return this.vegetationPositions.query(position, radius);
}
}
Loading

0 comments on commit 5fe29b2

Please sign in to comment.