代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<title>Verge3D webgl - morph targets - horse</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
<style>
body {
background-color: #f0f0f0;
color: #444;
}
a {
color: #08f;
}
</style>
</head>
<body>
<div id="info">
<a href="https://www.soft8soft.com/verge3d" target="_blank" rel="noopener">Verge3D</a> webgl - morph targets - horse<br/>
model by <a href="https://mirada.com/" target="_blank" rel="noopener">mirada</a> from <a href="http://www.ro.me" target="_blank" rel="noopener">rome</a>
</div>
<script type="module">
import * as v3d from '../build/v3d.module.js';
import Stats from './jsm/libs/stats.module.js';
import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
let container, stats;
let camera, scene, renderer;
let mesh, mixer;
const radius = 600;
let theta = 0;
let prevTime = Date.now();
init();
animate();
function init() {
container = document.createElement('div');
document.body.appendChild(container);
//
camera = new v3d.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.y = 300;
scene = new v3d.Scene();
scene.background = new v3d.Color(0xf0f0f0);
//
const light1 = new v3d.DirectionalLight(0xefefff, 1.5);
light1.position.set(1, 1, 1).normalize();
scene.add(light1);
const light2 = new v3d.DirectionalLight(0xffefef, 1.5);
light2.position.set(- 1, - 1, - 1).normalize();
scene.add(light2);
const loader = new GLTFLoader();
loader.load("models/gltf/Horse.glb", function(gltf) {
mesh = gltf.scene.children[0];
mesh.scale.set(1.5, 1.5, 1.5);
scene.add(mesh);
mixer = new v3d.AnimationMixer(mesh);
mixer.clipAction(gltf.animations[0]).setDuration(1).play();
});
//
renderer = new v3d.WebGLRenderer();
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputEncoding = v3d.sRGBEncoding;
container.appendChild(renderer.domElement);
//
stats = new Stats();
container.appendChild(stats.dom);
//
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
//
function animate() {
requestAnimationFrame(animate);
render();
stats.update();
}
function render() {
theta += 0.1;
camera.position.x = radius * Math.sin(v3d.MathUtils.degToRad(theta));
camera.position.z = radius * Math.cos(v3d.MathUtils.degToRad(theta));
camera.lookAt(0, 150, 0);
if (mixer) {
const time = Date.now();
mixer.update((time - prevTime) * 0.001);
prevTime = time;
}
renderer.render(scene, camera);
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。