Project Goal: Create an interactive 3D web application using Three.js to demonstrate advanced procedural spider animation.
Core Requirements:
Procedurally Animated Spider:
Create a spider model composed of a body and eight multi-jointed legs.
Implement a procedural animation system where the spider's legs automatically adapt to the ground beneath them.
Allow the user to control the spider's movement direction with keyboard inputs (W, A, S, D).
Implement a mouse-controlled orbital camera to view the spider from any angle.
Test Environment:
-Generate a simple, non-flat ground plane with varied heights (hills and valleys) so the animation can be properly tested.
-Scatter a few basic obstacles (like spheres or boxes) on the terrain.
Output as one unified .html file.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Below is a unified .html file that fulfills the requirements of your project. This implementation uses Three.js to create an interactive 3D web application with a procedurally animated spider, user-controlled movement, and a mouse-controlled orbital camera. The terrain includes hills, valleys, and basic obstacles.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Procedural Spider Animation</title>
<style>
body { margin: 0; overflow: hidden; }
canvas { display: block; }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r146/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.146/examples/js/controls/OrbitControls.js"></script>
<script>
// Scene, Camera, Renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Orbit Controls
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(10, 10, 10);
scene.add(directionalLight);
// Terrain
const terrainGeometry = new THREE.PlaneGeometry(100, 100, 100, 100);
const terrainMaterial = new THREE.MeshStandardMaterial({ color: 0x8B4513, wireframe: false });
const terrain = new THREE.Mesh(terrainGeometry, terrainMaterial);
terrain.rotation.x = -Math.PI / 2;
// Add random height variations to terrain vertices
const positionAttribute = terrain.geometry.attributes.position;
for (let i = 0; i < positionAttribute.count; i++) {
positionAttribute.setY(i, Math.sin(i * 0.1) * 2 + Math.random() * 3);
}
terrain.geometry.computeVertexNormals();
scene.add(terrain);
// Obstacles
const obstacleGeometry = new THREE.BoxGeometry(2, 2, 2);
const obstacleMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
for (let i = 0; i < 5; i++) {
const obstacle = new THREE.Mesh(obstacleGeometry, obstacleMaterial);
obstacle.position.set(Math.random() * 40 - 20, 1, Math.random() * 40 - 20);
scene.add(obstacle);
}
// Spider Model
const spiderBodyGeometry = new THREE.SphereGeometry(1, 16, 16);
const spiderBodyMaterial = new THREE.MeshStandardMaterial({ color: 0x000000 });
const spiderBody = new THREE.Mesh(spiderBodyGeometry, spiderBodyMaterial);
spiderBody.position.y = 1;
const legs = [];
const legLength = 2;
const jointCount = 3;
for (let i = 0; i < 8; i++) {
const leg = [];
for (let j = 0; j < jointCount; j++) {
const segmentGeometry = new THREE.CylinderGeometry(0.1, 0.1, legLength / jointCount, 8);
const segmentMaterial = new THREE.MeshStandardMaterial({ color: 0x000000 });
const segment = new THREE.Mesh(segmentGeometry, segmentMaterial);
if (j > 0) {
leg[j - 1].add(segment);
segment.position.y = -legLength / jointCount;
} else {
scene.add(segment);
}
leg.push(segment);
}
legs.push(leg);
}
// Position legs around the spider body
const legAngles = [0, Math.PI / 4, Math.PI / 2, 3 * Math.PI / 4, Math.PI, 5 * Math.PI / 4, 3 * Math.PI / 2, 7 * Math.PI / 4];
legs.forEach((leg, index) => {
leg[0].position.set(Math.cos(legAngles[index]) * 1.5, 0, Math.sin(legAngles[index]) * 1.5);
leg[0].rotation.z = legAngles[index] - Math.PI / 2;
});
// Spider Movement
let moveDirection = new THREE.Vector3();
const speed = 0.1;
const keys = {};
document.addEventListener('keydown', (event) => {
keys[event.key.toLowerCase()] = true;
});
document.addEventListener('keyup', (event) => {
keys[event.key.toLowerCase()] = false;
});
function updateSpiderPosition(deltaTime) {
moveDirection.set(0, 0, 0);
if (keys['w']) moveDirection.z -= speed * deltaTime;
if (keys['s']) moveDirection.z += speed * deltaTime;
if (keys['a']) moveDirection.x -= speed * deltaTime;
if (keys['d']) moveDirection.x += speed * deltaTime;
if (moveDirection.lengthSq() > 0) {
moveDirection.normalize().multiplyScalar(speed * deltaTime);
spiderBody.position.add(moveDirection);
// Align legs with terrain
legs.forEach((leg) => {
const groundHeight = getGroundHeight(leg[0].getWorldPosition(new THREE.Vector3()));
leg[0].position.y = groundHeight + 0.5;
});
}
}
function getGroundHeight(position) {
const raycaster = new THREE.Raycaster(position.clone(), new THREE.Vector3(0, -1, 0), 0, 10);
const intersects = raycaster.intersectObject(terrain);
return intersects.length > 0 ? intersects[0].point.y : 0;
}
// Animation Loop
function animate() {
requestAnimationFrame(animate);
const deltaTime = clock.getDelta();
updateSpiderPosition(deltaTime);
controls.update();
renderer.render(scene, camera);
}
// Initial Setup
camera.position.set(10, 10, 10);
camera.lookAt(spiderBody.position);
const clock = new THREE.Clock();
animate();
// Handle Window Resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>
Explanation:
Terrain: A PlaneGeometry is used to create a terrain with random height variations using sine waves and random offsets.
Obstacles: Simple red cubes are scattered across the terrain.
Spider Model: The spider consists of a spherical body and eight legs, each composed of three joints.
Procedural Animation: The legs adapt to the terrain by casting rays downward to determine the ground height.
User Controls: Keyboard inputs (W, A, S, D) control the spider's movement, while the mouse controls the orbital camera.
Responsive Design: The application adjusts to window resizing.
Save this code as an .html file and open it in a browser to see the interactive 3D spider animation.