1 Star 0 Fork 9

DanielLeefu/3D教程

forked from liujiboy/3D教程 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
08.Materials(MeshLambertMaterial).html 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
liujiboy 提交于 2021-07-01 19:17 . 08-09完成
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>08.Materials(MeshLambertMaterial)</title>
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<script src="build/three.js"></script>
<script>
//生成场景
const scene = new THREE.Scene();
//设置相机
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
//设置渲染器
const renderer = new THREE.WebGLRenderer({antialias:true});
//renderer.setClearColor(0xFFFFFF);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
//生成模型
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshLambertMaterial({ color: 0x00ff00 });
const cube = new THREE.Mesh(geometry, material);
const wireframeMaterial = new THREE.MeshLambertMaterial({ color: 0xff0000,wireframe:true });
const cubeWireframe = new THREE.Mesh(geometry, wireframeMaterial);
//设置场景
const group=new THREE.Group()
group.add(cube)
group.add(cubeWireframe)
scene.add(group);
//设置光照
const light = new THREE.AmbientLight( 0x111111 );
scene.add(light);
const pointLight = new THREE.PointLight( 0xFFFFFF, 1, 100 );
pointLight.position.set( 5, 5, 10 );
scene.add( pointLight );
function animate(){
group.rotation.x+=0.005;
group.rotation.y+=0.005;
group.rotation.z+=0.005;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
//开始动画
animate()
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/danielleefu/threed-tutorial.git
git@gitee.com:danielleefu/threed-tutorial.git
danielleefu
threed-tutorial
3D教程
master

搜索帮助