1 Star 0 Fork 0

siyuanzhou/three.js-style

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
index.html 2.31 KB
Copy Edit Raw Blame History
siyuanzhou authored 2024-09-02 07:56 . 绘制物体三要素之材质
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style lang="css">
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
overflow: hidden;
}
.canvas-box {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.cvs1,
.cvs2 {
border: 1px solid #ccc;
margin: 0 20px;
}
</style>
</head>
<body>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
// 1.创建一个场景
const scene = new THREE.Scene();
// 2.创建一个相机
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
// 移动相机位置
camera.position.set(0, 10, 20)
camera.lookAt(0, 0, 0)
// 3.创建一个渲染器
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// 创建材质几何体
const geometry = new THREE.SphereGeometry(2, 32, 32);
const loader = new THREE.TextureLoader();
// 创建材质 外观
const material = new THREE.MeshBasicMaterial({
color: 0xff000,
roughness: 0.5,
metalness: 0.5,
// map: loader.load('./4.png')
});
// 结构和材质组合,生成一个物体
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh)
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
function animate() {
requestAnimationFrame(animate);//requestAnimationFrame一直掉动画,如果去掉背景图片就没有了,需要在图片的load回调中调用render函数
controls.update()//更新轨道控制器
renderer.render(scene, camera);
}
// 6.渲染
animate();
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhou-siyuan-o/three.js-style.git
git@gitee.com:zhou-siyuan-o/three.js-style.git
zhou-siyuan-o
three.js-style
three.js-style
master

Search