Below is an example HTML file that uses Three.js (via the provided CDN) to create an animated 3D scene containing a stylized “moose” being lifted by a UFO’s beam over a forest. You can save the code into an HTML file and open it in your browser to see the scene.
Note: This example uses simple geometries (boxes, spheres, cylinders, and cones) to “suggest” a moose, a UFO, its beam, and trees. You can further enhance the models with textures, more refined geometries, or even imported models to achieve a more detailed visualization.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Moose in Forest with Alien Spaceship</title>
<!-- Load three.js from CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.174.0/three.tsl.js"></script>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000;
}
</style>
</head>
<body>
<script>
// Set up scene, camera, and renderer
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x000000, 0.02);
const camera = new THREE.PerspectiveCamera(
60,
window.innerWidth / window.innerHeight,
0.1,
1000
);
camera.position.set(0, 10, 25);
camera.lookAt(0, 5, 0);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Add ambient and directional light
const ambientLight = new THREE.AmbientLight(0x888888);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(10, 20, 10);
scene.add(directionalLight);
// --- Create a ground plane ---
const groundGeometry = new THREE.PlaneGeometry(100, 100);
const groundMaterial = new THREE.MeshPhongMaterial({ color: 0x223322 });
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2;
scene.add(ground);
// --- Create a simple forest ---
function addTree(x, z) {
// Trunk
const trunkGeometry = new THREE.CylinderGeometry(0.25, 0.3, 2, 8);
const trunkMaterial = new THREE.MeshPhongMaterial({ color: 0x8b4513 });
const trunk = new THREE.Mesh(trunkGeometry, trunkMaterial);
trunk.position.set(x, 1, z);
// Foliage (a cone)
const foliageGeometry = new THREE.ConeGeometry(1, 3, 8);
const foliageMaterial = new THREE.MeshPhongMaterial({ color: 0x228b22 });
const foliage = new THREE.Mesh(foliageGeometry, foliageMaterial);
foliage.position.set(x, 3.5, z);
scene.add(trunk);
scene.add(foliage);
}
// Randomly scatter trees over the ground
for (let i = 0; i < 50; i++) {
const x = (Math.random() - 0.5) * 80;
const z = (Math.random() - 0.5) * 80;
addTree(x, z);
}
// --- Create the "moose" ---
const mooseGroup = new THREE.Group();
// Body (an elongated ellipsoid)
const bodyGeometry = new THREE.SphereGeometry(1.5, 16, 16);
bodyGeometry.scale(1.5, 1, 0.7);
const bodyMaterial = new THREE.MeshPhongMaterial({ color: 0x654321 });
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.position.y = 1.5;
mooseGroup.add(body);
// Head (a smaller sphere)
const headGeometry = new THREE.SphereGeometry(0.8, 16, 16);
const head = new THREE.Mesh(headGeometry, bodyMaterial);
head.position.set(1.5, 2, 0);
mooseGroup.add(head);
// Antlers: two simple branches (thin cylinders)
function createAntler(offsetX, offsetZ, angleY) {
const antlerGeometry = new THREE.CylinderGeometry(0.05, 0.1, 1, 8);
const antlerMaterial = new THREE.MeshPhongMaterial({ color: 0x8b4513 });
const antler = new THREE.Mesh(antlerGeometry, antlerMaterial);
antler.position.set(0.5 * offsetX, 0.3, offsetZ);
antler.rotation.z = Math.PI / 6;
antler.rotation.y = angleY;
return antler;
}
head.add(createAntler(1, 0.2, 0.3));
head.add(createAntler(1, -0.2, -0.3));
// Four legs (cylinders)
function createLeg(x, z) {
const legGeometry = new THREE.CylinderGeometry(0.15, 0.15, 2, 8);
const legMaterial = new THREE.MeshPhongMaterial({ color: 0x654321 });
const leg = new THREE.Mesh(legGeometry, legMaterial);
leg.position.set(x, 1, z);
return leg;
}
mooseGroup.add(createLeg(0.8, 0.5));
mooseGroup.add(createLeg(-0.8, 0.5));
mooseGroup.add(createLeg(0.8, -0.5));
mooseGroup.add(createLeg(-0.8, -0.5));
// Start the moose at ground level
mooseGroup.position.set(0, 0, 0);
scene.add(mooseGroup);
// --- Create the alien spaceship (UFO) ---
const spaceshipGroup = new THREE.Group();
const spaceshipY = 12; // altitude of the spaceship
// UFO base - a flattened cylinder
const baseGeometry = new THREE.CylinderGeometry(2.5, 2.5, 0.5, 32);
const baseMaterial = new THREE.MeshPhongMaterial({
color: 0x888888,
flatShading: true,
});
const ufoBase = new THREE.Mesh(baseGeometry, baseMaterial);
ufoBase.position.set(0, spaceshipY, 0);
spaceshipGroup.add(ufoBase);
// UFO dome - a dome on top of the UFO
// We create a hemisphere by restricting the phi length of a sphere.
const domeGeometry = new THREE.SphereGeometry(1.5, 32, 16, 0, Math.PI * 2, 0, Math.PI / 2);
const domeMaterial = new THREE.MeshPhongMaterial({
color: 0x00ffff,
transparent: true,
opacity: 0.6,
});
const ufoDome = new THREE.Mesh(domeGeometry, domeMaterial);
ufoDome.position.set(0, spaceshipY + 0.5, 0);
spaceshipGroup.add(ufoDome);
scene.add(spaceshipGroup);
// --- Create the UFO beam ---
// We’ll use a cone geometry that we later scale in the Y-direction to cover the gap
const beamGeometry = new THREE.ConeGeometry(1.8, 1, 32, 1, true);
// The beam material is emissive and semi-transparent
const beamMaterial = new THREE.MeshPhongMaterial({
color: 0x55ffff,
emissive: 0x55ffff,
transparent: true,
opacity: 0.4,
side: THREE.DoubleSide,
});
const beam = new THREE.Mesh(beamGeometry, beamMaterial);
// Initially, set its geometry with height=1. We will scale it later.
// Rotate the cone so that its tip is pointing downward.
beam.rotation.x = Math.PI;
scene.add(beam);
// --- Animate the scene ---
let clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
let elapsed = clock.getElapsedTime();
// Animate moose gently floating upward (with a sine wave)
// so it appears to be carried by the UFO beam.
const floatHeight = 0.5 * Math.sin(elapsed * 1.5) + 2; // oscillates between 1.5 and 2.5
mooseGroup.position.y = floatHeight;
// Keep the spaceship fixed; if desired, you could also add a slight rotation
spaceshipGroup.rotation.y += 0.005;
// Update the beam to stretch from the UFO to the moose.
let startY = spaceshipY - 0.25; // bottom of the UFO base
let endY = mooseGroup.position.y + 1.5; // top of the moose body
let beamLength = startY - endY;
// Avoid a negative or zero scale.
beamLength = Math.max(beamLength, 0.1);
// To avoid regenerating geometry, we set the beam's scale and position.
// The original cone points downward with a height of 1.
beam.scale.y = beamLength;
// Position the beam midway between the UFO and the moose:
beam.position.set(0, endY + beamLength / 2, 0);
renderer.render(scene, camera);
}
animate();
// --- Adjust for window resizing ---
window.addEventListener("resize", function () {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
});
</script>
</body>
</html>
Explanation
-
Scene Setup:
A scene with fog, a perspective camera, and basic ambient/directional lighting is created.
-
Forest Creation:
A large ground plane is added, and then a loop scatters a number of simple trees (using a brown cylinder for the trunk and a green cone for the foliage) over the plane.
-
Moose Model:
The moose is built as a group of meshes. Its body, head, legs, and a pair of antlers (represented with thin cylinders) form a stylized moose. The moose group is animated along the Y-axis with a sine function to simulate a floating motion.
-
Spaceship and Beam:
The UFO is modeled as a flat cylinder (the base) with a semi-transparent dome on top. A downward-pointing cone (with a transparent, emissive material) is used as the beam. In the animation loop, the beam is scaled and repositioned in the vertical direction so that it connects the bottom of the UFO to the rising moose.
-
Animation:
The animation loop updates the moose’s vertical position and adjusts the beam’s scale and position accordingly, while also adding a subtle rotation to the spaceship.
Feel free to modify colors, geometry parameters, or add textures and shaders to make the scene even “visually cool.” Enjoy your extraterrestrial forest rescue!