하나의 HTML 파일로 3D 메카 고질라 만들어
- User
하나의 HTML 파일로 3D 메카 고질라 만들어
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
하나의 HTML 파일로 3D 메카 고질라 만들어
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
네, 하나의 HTML 파일 안에 Three.js 라이브러리를 CDN으로 가져와서 3D 메카 고질라의 매우 단순화된 버전을 만드는 코드를 작성해 드리겠습니다.
외부 모델 파일(.obj, .gltf 등) 없이 HTML 파일만으로 복잡한 3D 모델을 만드는 것은 거의 불가능하기 때문에, 이 코드는 상자, 원통 등 기본적인 3D 도형을 조합하여 메카 고질라의 형태를 흉내 낸 것임을 미리 알려드립니다. 실제 메카 고질라와는 많이 다를 수 있습니다.
이 코드는 다음과 같은 내용을 포함합니다:
<!DOCTYPE html>, <html>, <head>, <body>).<style> 태그 안에 기본적인 CSS 스타일 (캔버스가 화면을 채우도록).<script> 태그 안에
<!DOCTYPE html>
<html>
<head>
<title>Simple 3D Mechagodzilla</title>
<style>
body { margin: 0; overflow: hidden; } /* 기본 마진 제거 및 스크롤바 숨김 */
canvas { display: block; } /* 캔버스 아래의 여백 제거 */
</style>
<!-- Three.js 라이브러리를 CDN에서 불러옴 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.159.0/three.min.js"></script>
</head>
<body>
<script>
// Three.js 기본 설정
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 }); // 부드러운 가장자리를 위해 antialias 추가
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement); // 렌더러의 캔버스 엘리먼트를 body에 추가
// 광원 설정
const ambientLight = new THREE.AmbientLight(0x404040); // 은은한 주변광
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); // 메인 광원
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);
// 메탈릭 느낌의 재질
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0x888888, // 회색 계열
metalness: 0.8, // 메탈 느낌 강도
roughness: 0.3, // 표면 거칠기 (낮을수록 반짝임)
flatShading: false // 부드러운 음영 적용
});
// 단순화된 메카 고질라 형태 만들기
const mechagodzillaGroup = new THREE.Group(); // 전체 모델을 담을 그룹
// 몸통 (Body)
const bodyGeometry = new THREE.BoxGeometry(1.5, 2, 1);
const body = new THREE.Mesh(bodyGeometry, metalMaterial);
mechagodzillaGroup.add(body);
// 머리 (Head)
const headGeometry = new THREE.BoxGeometry(0.8, 0.8, 0.8);
const head = new THREE.Mesh(headGeometry, metalMaterial);
head.position.y = 1.4; // 몸통 위에 위치
mechagodzillaGroup.add(head);
// 팔 (Arms) - 단순한 원통
const armGeometry = new THREE.CylinderGeometry(0.3, 0.3, 1.5, 8);
const leftArm = new THREE.Mesh(armGeometry, metalMaterial);
leftArm.position.set(-1, 0.5, 0);
leftArm.rotation.z = Math.PI / 2; // 옆으로 회전
mechagodzillaGroup.add(leftArm);
const rightArm = new THREE.Mesh(armGeometry, metalMaterial);
rightArm.position.set(1, 0.5, 0);
rightArm.rotation.z = -Math.PI / 2; // 옆으로 회전
mechagodzillaGroup.add(rightArm);
// 다리 (Legs) - 단순한 원통
const legGeometry = new THREE.CylinderGeometry(0.4, 0.4, 1.8, 8);
const leftLeg = new THREE.Mesh(legGeometry, metalMaterial);
leftLeg.position.set(-0.5, -1.9, 0);
mechagodzillaGroup.add(leftLeg);
const rightLeg = new THREE.Mesh(legGeometry, metalMaterial);
rightLeg.position.set(0.5, -1.9, 0);
mechagodzillaGroup.add(rightLeg);
// 어깨 또는 무기 (Optional Shoulder/Weapon) - 단순한 박스
const shoulderGeometry = new THREE.BoxGeometry(0.5, 0.5, 1.2);
const leftShoulder = new THREE.Mesh(shoulderGeometry, metalMaterial);
leftShoulder.position.set(-0.9, 1, 0);
mechagodzillaGroup.add(leftShoulder);
const rightShoulder = new THREE.Mesh(shoulderGeometry, metalMaterial);
rightShoulder.position.set(0.9, 1, 0);
mechagodzillaGroup.add(rightShoulder);
// 모델을 씬에 추가하고 위치 조정
scene.add(mechagodzillaGroup);
mechagodzillaGroup.position.y = -1; // 바닥에 서 있는 것처럼 보이도록 약간 내림
// 카메라 위치 설정
camera.position.z = 5;
camera.position.y = 1; // 약간 위에서 내려다보도록
// 애니메이션 루프
function animate() {
requestAnimationFrame(animate);
// 모델 회전 (예시: Y축 기준 회전)
mechagodzillaGroup.rotation.y += 0.005;
renderer.render(scene, camera); // 씬을 카메라 시점에서 렌더링
}
// 창 크기 변경 시 렌더러와 카메라 업데이트
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// 애니메이션 시작
animate();
</script>
</body>
</html>
사용 방법:
mechagodzilla_simple.html 과 같이 .html 확장자로 저장합니다.그러면 회색의 단순화된 로봇 형태(메카 고질라를 흉내 낸)가 화면에 나타나고 천천히 회전하는 것을 볼 수 있습니다.
참고:
.gltf 또는 .obj 같은 형식의 모델 파일을 로드하는 방법을 사용해야 합니다. 하지만 이는 하나의 HTML 파일만으로는 어렵습니다.OrbitControls 같은 기능을 사용해야 하지만, 이 또한 외부 스크립트를 가져오거나 코드를 직접 포함해야 하므로 이 예제에서는 생략했습니다.