1 Star 0 Fork 0

蔡鑫 / threejs_study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pump.html 3.44 KB
一键复制 编辑 原始数据 按行查看 历史
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
body {
margin: 0;
overflow: hidden;
}
</style>
<script src="../build/three.js"></script>
<script src="../build/Detector.js"></script>
<script src="../build/dat.gui.min.js"></script>
<script src="../build/stats.min.js"></script>
<script src="../build/OrbitControls.js"></script>
<script src="../build/GLTFLoader.js"></script>
<style>
#loading {
position: fixed;
top: 50%;
left: 50%;
color: #FFFFFF;
font-size: 20px;
margin-top: -30px;
margin-left: -40px;
}
</style>
</head>
<body>
<p id="loading">loading......</p>
<script>let scene, camera, renderer, controls, guiControls;
let stats = initStats();
/*场景*/
function initScene() {
scene = new THREE.Scene();
}
/* 相机*/
function initCamera() {
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 10000);
camera.position.set(5, 0, 10);
camera.lookAt(new THREE.Vector3(0, 0, 0));
}
/* 渲染器 */
function initRender() {
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x0E3866);
document.body.appendChild(renderer.domElement);
}
/* 灯光 */
function initLight() {
scene.add(new THREE.AmbientLight(0xffffff));
}
/* 控制器 */
function initControls() {
controls = new THREE.OrbitControls(camera, renderer.domElement);
}
function initGui() {
guiControls = new function () {
};
let controls = new dat.GUI({width: 200});
}
/* 导入 */
function initContent() {
let loader = new THREE.GLTFLoader();
loader.load('../pump/pump.gltf',function (obj) {
console.log(obj);
obj.scene.position.y = 1;
scene.add(obj.scene);
document.getElementById('loading').style.display = 'none';
},function (xhr) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},function (error) {
console.log('load error!'+error.getWebGLErrorMessage());
})
}
/* 插件 */
function initStats() {
let stats = new Stats();
document.body.appendChild(stats.domElement);
return stats;
}
/* 窗口 */
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function update() {
stats.update();
}
/*启动 */
function init() {
initScene();
initCamera();
initRender();
initLight();
initControls();
initContent();
initGui();
window.addEventListener('resize', onWindowResize, false);
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
update();
}
(function () {
console.log("three init start...");
init();
animate();
console.log("three init send...");
})();</script>
</body>
</html>
---------------------
JavaScript
1
https://gitee.com/cuteSeven/threejs_study.git
git@gitee.com:cuteSeven/threejs_study.git
cuteSeven
threejs_study
threejs_study
master

搜索帮助