Here’s a single‐file HTML example that uses Bulma as a CSS framework and Three.js (plus Tween.js) to render an explodable/re-assemblable, rotating Earth with animated “water” and a surrounding particle field. Just save this as index.html and open in your browser.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Explodable Earth in Three.js</title>
<!-- Bulma CSS Framework -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css"
/>
<style>
body { margin: 0; overflow: hidden; }
canvas { display: block; }
#explodeBtn {
position: absolute;
top: 20px; right: 20px;
z-index: 10;
}
</style>
</head>
<body>
<button id="explodeBtn" class="button is-primary">
Explode ↔ Reassemble
</button>
<!-- Three.js Core -->
<script src="https://cdn.jsdelivr.net/npm/three@0.142.0/build/three.min.js"></script>
<!-- OrbitControls -->
<script src="https://cdn.jsdelivr.net/npm/three@0.142.0/examples/js/controls/OrbitControls.js"></script>
<!-- Tween.js for smooth animation -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tween.js/18.6.4/Tween.min.js"></script>
<script>
// GLOBALS
let scene, camera, renderer, controls;
let earthMesh, waterMesh;
let earthGeom, waterGeom;
let earthOrig = [], earthNorms = [];
let waterOrig = [], waterNorms = [];
let params = { explosion: 0 };
init();
animate();
function init() {
// Scene + Camera
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(
45, window.innerWidth / window.innerHeight, 0.1, 100
);
camera.position.set(0, 1.5, 3);
// Renderer
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Controls
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
// Lights
const ambient = new THREE.AmbientLight(0xffffff, 0.3);
scene.add(ambient);
const sun = new THREE.DirectionalLight(0xffffff, 1);
sun.position.set(5, 3, 5);
scene.add(sun);
// Loaders
const texLoader = new THREE.TextureLoader();
const earthTex = texLoader.load(
'https://threejs.org/examples/textures/planets/earth_atmos_2048.jpg'
);
const earthNormMap = texLoader.load(
'https://threejs.org/examples/textures/planets/earth_normal_2048.jpg'
);
const waterNorm = texLoader.load(
'https://threejs.org/examples/textures/waternormals.jpg'
);
waterNorm.wrapS = waterNorm.wrapT = THREE.RepeatWrapping;
// Earth Geometry + Material
earthGeom = new THREE.SphereGeometry(1, 64, 64);
const earthMat = new THREE.MeshPhongMaterial({
map: earthTex,
normalMap: earthNormMap,
specular: new THREE.Color(0x333333),
shininess: 10
});
earthMesh = new THREE.Mesh(earthGeom, earthMat);
scene.add(earthMesh);
// Store original positions & normals
const posAttr = earthGeom.attributes.position;
const normAttr = earthGeom.attributes.normal;
for (let i = 0; i < posAttr.count; i++) {
earthOrig.push(new THREE.Vector3().fromBufferAttribute(posAttr, i));
earthNorms.push(new THREE.Vector3().fromBufferAttribute(normAttr, i));
}
// Water Layer (slightly bigger sphere)
waterGeom = new THREE.SphereGeometry(1.01, 64, 64);
const waterMat = new THREE.MeshPhongMaterial({
color: 0x3399ff,
transparent: true,
opacity: 0.4,
bumpMap: waterNorm,
bumpScale: 0.05,
depthWrite: false
});
waterMesh = new THREE.Mesh(waterGeom, waterMat);
scene.add(waterMesh);
// Store originals for water
const wPos = waterGeom.attributes.position;
const wNorm = waterGeom.attributes.normal;
for (let i = 0; i < wPos.count; i++) {
waterOrig.push(new THREE.Vector3().fromBufferAttribute(wPos, i));
waterNorms.push(new THREE.Vector3().fromBufferAttribute(wNorm, i));
}
// Particle Field (magnetic/polar field look)
const pCount = 1200;
const pGeo = new THREE.BufferGeometry();
const pPos = new Float32Array(pCount * 3);
for (let i = 0; i < pCount; i++) {
const phi = Math.acos(2 * Math.random() - 1);
const theta = 2 * Math.PI * Math.random();
const r = THREE.MathUtils.lerp(1.4, 2.4, Math.random());
pPos[3*i] = r * Math.sin(phi) * Math.cos(theta);
pPos[3*i+1] = r * Math.sin(phi) * Math.sin(theta);
pPos[3*i+2] = r * Math.cos(phi);
}
pGeo.setAttribute('position', new THREE.BufferAttribute(pPos, 3));
const pMat = new THREE.PointsMaterial({
color: 0x88ccff, size: 0.01, opacity: 0.7, transparent: true
});
scene.add(new THREE.Points(pGeo, pMat));
// Handle window resize
window.addEventListener('resize', onResize);
// Explode Button
document.getElementById('explodeBtn')
.addEventListener('click', () => {
new TWEEN.Tween(params)
.to({ explosion: 1 }, 1200)
.easing(TWEEN.Easing.Quadratic.InOut)
.yoyo(true)
.repeat(1)
.start();
});
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function updateExplosion() {
const e = params.explosion * 0.6; // max explosion distance
// Earth
const posA = earthGeom.attributes.position;
for (let i = 0; i < posA.count; i++) {
const o = earthOrig[i];
const n = earthNorms[i];
posA.setXYZ(
i,
o.x + n.x * e,
o.y + n.y * e,
o.z + n.z * e
);
}
posA.needsUpdate = true;
// Water
const posW = waterGeom.attributes.position;
for (let i = 0; i < posW.count; i++) {
const o = waterOrig[i];
const n = waterNorms[i];
posW.setXYZ(
i,
o.x + n.x * e,
o.y + n.y * e,
o.z + n.z * e
);
}
posW.needsUpdate = true;
}
function updateWaterAnim() {
const t = Date.now() * 0.0003;
// gentle bump oscillation
waterMesh.material.bumpScale = 0.03 + Math.sin(t * 2) * 0.02;
// drift the bumpMap
waterMesh.material.bumpMap.offset.x += 0.0002;
waterMesh.material.bumpMap.offset.y += 0.0001;
}
function animate() {
requestAnimationFrame(animate);
controls.update();
TWEEN.update();
// rotate Earth + water
earthMesh.rotation.y += 0.0005;
waterMesh.rotation.y += 0.0007;
updateExplosion();
updateWaterAnim();
renderer.render(scene, camera);
}
</script>
</body>
</html>
Explanation of key parts:
• We build a high‐detail sphere for the land, capture its original vertex positions and normals, then displace vertices along normals on “explosion.”
• A second, slightly larger sphere with a water‐normal bump map simulates dynamic oceans.
• A simple Points field around the Earth evokes magnetic/particle lines.
• OrbitControls let you spin/zoom interactively.
• TWEEN.js smoothly animates the explosion parameter from 0→1→0.
Feel free to tweak parameters (segmentation, explosion distance, water opacity, particle count, etc.) to fit your taste! 🚀🌍