Make the planet more "resolution".
- User
Make the planet more "resolution".
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Make the planet more "resolution".
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
It looks like you're asking to increase the "resolution" of the planet, which I interpret as making the voxel grid finer for more detailed terrain. This could mean adding more voxels, reducing their size, or increasing the overall density of the planet's surface.
In the current code, the planet is generated with a resolution based on the planetRadius (set to 10), where voxels are placed at integer coordinates (e.g., -10 to 10). This results in a relatively low-resolution sphere. To improve this:
resolutionStep (e.g., 0.5 or 0.25) to control the spacing between voxels. A smaller step means more voxels and higher detail.planetRadius or implement optimizations like limiting the visible voxels.Here's the updated code with higher resolution support:
<!DOCTYPE html>
<html lang="en">
<head>
<title>High-Resolution Voxel Planet Generator</title>
<style>
body {
margin: 0;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
let scene, camera, renderer;
let planet;
const planetRadius = 10; // Controls the overall size of the planet
const noiseScale = 10; // For noise function
let resolutionStep = 0.5; // New parameter: Lower value = higher resolution (e.g., 0.5 for more detail)
function init() {
// Setup scene
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Add lighting
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(50, 50, 50);
scene.add(light);
scene.add(new THREE.AmbientLight(0x404040));
// Setup camera position
camera.position.z = 30;
// Generate planet with higher resolution
generatePlanet();
// Add stars
addStars();
// Start animation loop
animate();
// Add controls
document.addEventListener('keydown', handleKeyDown);
document.addEventListener('mousemove', handleMouseMove);
}
function generatePlanet() {
planet = new THREE.Group();
// Materials for different voxel types
const materials = {
water: new THREE.MeshPhongMaterial({ color: 0x0077be }),
sand: new THREE.MeshPhongMaterial({ color: 0xc2b280 }),
grass: new THREE.MeshPhongMaterial({ color: 0x567d46 })
};
// Voxel geometry scaled by resolutionStep
const voxelSize = resolutionStep; // Make voxels smaller for higher resolution
const voxelGeometry = new THREE.BoxGeometry(voxelSize, voxelSize, voxelSize);
// Generate voxels with finer steps
for (let x = -planetRadius; x <= planetRadius; x += resolutionStep) {
for (let z = -planetRadius; z <= planetRadius; z += resolutionStep) {
for (let y = -planetRadius; y <= planetRadius; y += resolutionStep) {
const position = new THREE.Vector3(x, y, z);
if (position.length() <= planetRadius) { // Only add if inside the sphere
// Simple noise function
const noise = Math.abs(Math.sin(x / noiseScale) * Math.cos(z / noiseScale));
let material;
if (noise < 0.3) material = materials.water;
else if (noise < 0.6) material = materials.sand;
else material = materials.grass;
const voxel = new THREE.Mesh(voxelGeometry, material);
voxel.position.set(x, y, z); // Position based on the finer grid
planet.add(voxel);
}
}
}
}
scene.add(planet);
}
function addStars() {
const starGeometry = new THREE.BufferGeometry();
const starMaterial = new THREE.PointsMaterial({
color: 0xFFFFFF,
size: 0.1
});
const starVertices = [];
for (let i = 0; i < 10000; i++) {
const x = (Math.random() - 0.5) * 2000;
const y = (Math.random() - 0.5) * 2000;
const z = (Math.random() - 0.5) * 2000;
starVertices.push(x, y, z);
}
starGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starVertices, 3));
const stars = new THREE.Points(starGeometry, starMaterial);
scene.add(stars);
}
// Camera controls
const moveSpeed = 0.5;
const rotateSpeed = 0.01;
function handleKeyDown(event) {
switch(event.key) {
case 'w': camera.position.z -= moveSpeed; break;
case 's': camera.position.z += moveSpeed; break;
case 'a': camera.position.x -= moveSpeed; break;
case 'd': camera.position.x += moveSpeed; break;
case ' ': camera.position.y += moveSpeed; break;
case 'Shift': camera.position.y -= moveSpeed; break;
}
}
function handleMouseMove(event) {
if (event.buttons === 1) { // Left mouse button
camera.rotation.y += event.movementX * rotateSpeed;
camera.rotation.x += event.movementY * rotateSpeed;
}
}
function animate() {
requestAnimationFrame(animate);
if (planet) planet.rotation.y += 0.001; // Slow planet rotation
renderer.render(scene, camera);
}
window.addEventListener('resize', onWindowResize, false);
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
init();
</script>
</body>
</html>
Added resolutionStep Variable:
x += resolutionStep).0.5 (you can change it in the code, e.g., to 0.25 for even higher resolution).resolutionStep = 1 (original), it generates voxels at integer positions.resolutionStep = 0.5, it generates voxels at half-unit intervals (e.g., -10, -9.5, -9, etc.), doubling the detail in each dimension.Adjusted Voxel Size:
new THREE.BoxGeometry(voxelSize, voxelSize, voxelSize), where voxelSize = resolutionStep.Performance Considerations:
resolutionStep = 1, it's roughly a 21x21x21 grid (for radius 10).resolutionStep = 0.5, it's about 41x41x41, which is 8 times more voxels!planetRadius (e.g., to 5) for a smaller planet.resolutionStep = 0.5 and test; if it's too slow, increase it back to 1.THREE.InstancedMesh for rendering multiple voxels efficiently.How to Test and Adjust:
resolutionStep in the code (e.g., change it to 0.25 for ultra-high resolution, but be cautious).simplex-noise.This should give you a more detailed planet while keeping the code simple and CodePen-compatible. If you run into performance problems or want further enhancements (e.g., real Perlin noise or optimizations), let me know!