1 Star 7 Fork 5

wangProgrammer/冰墩墩

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.html 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
wangProgrammer 提交于 2022-02-10 16:23 . 冰墩墩
<!DOCTYPE html>
<html lang="en">
<head>
<title>冰墩墩-itwangyang</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
html,body{
padding:0;
margin:0;
}
</style>
</head>
<body>
<script type="module">
import * as THREE from './js/three.module.js';
import { OrbitControls } from './js/OrbitControls.js';
import { GLTFLoader } from './js/GLTFLoader.js';
let camera, scene, renderer;
init();
render();
// init
function init() {
const container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
camera.position.set( 0, 0, 3 );
scene = new THREE.Scene();
const envMap = new THREE.TextureLoader().load( "model/env.jpg",function(texture){
const loader = new GLTFLoader().setPath( 'model/' );
loader.load( 'dwendwen.gltf', function ( gltf ) {
gltf.scene.traverse( function ( child ) {
if(child.name==="outer"||child.name==="mask"){
child.material.envMap = texture;
child.material.envMap.mapping = THREE.EquirectangularReflectionMapping;
child.material.envMapIntensity=2;
}else if(child.name==="body"){
let map = child.material.map;
child.material = new THREE.MeshToonMaterial({map:map});
}
} );
scene.add( gltf.scene );
render();
} );
});
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
const controls = new OrbitControls( camera, renderer.domElement );
controls.addEventListener( 'change', render ); // use if there is no animation loop
controls.minDistance = 2;
controls.maxDistance = 10;
controls.target.set( 0, 0, - 0.2 );
controls.update();
window.addEventListener( 'resize', onWindowResize );
}
//onWindowResize
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
render();
}
//render
function render() {
renderer.render( scene, camera );
}
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/itwangyang_coder/bing-dwen-dwen.git
git@gitee.com:itwangyang_coder/bing-dwen-dwen.git
itwangyang_coder
bing-dwen-dwen
冰墩墩
master

搜索帮助