请马上登录,朋友们都在花潮里等着你哦:)
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 马黑黑 于 2025-5-16 07:49 编辑
八面缓冲几何体(OctahedronGeometry)是一个用于生成八面体的类。构造器:
OctahedronGeometry(radius : Float, detail : Integer)
其中:
radius — 八面体的半径,默认值为 1
detail — 默认值为0,将这个值设为一个大于0的数将会为它增加一些顶点,使其不再是一个八面体
以下代码演示各面颜色为道奇蓝的八面体在光源作用下呈现出各面明暗不同的效果(平行光光源从xyz轴的右上前出发):
<script type="module">
/* 八面缓冲几何体 OctahedronGeometry */
import * as THREE from 'https://esm.sh/three';
const scene = new THREE.Scene;
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 10);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const geometry = new THREE.OctahedronGeometry(1.2, 0); // 八面体
const material = new THREE.MeshLambertMaterial({ color: 0x1e90ff }); // 朗伯特材质
const ico = new THREE.Mesh(geometry, material); // 创建网格Mess对象(图像=几何体+材质)
scene.add(ico); // 图像添加到场景成形
const ambientLight = new THREE.AmbientLight(0xffeeee, 1); // 环境光 : 改善场景视觉
scene.add(ambientLight);
const dirLight = new THREE.DirectionalLight(0xffd700, 2.5); // 平行光(方向光) : 角度照亮
dirLight.position.set(20,20,20); // 光来自右上靠近观者
dirLight.target = ico; // 光作用的对象 : 八面体图像
scene.add(dirLight);
const animate = () => {
requestAnimationFrame(animate);
ico.rotation.x += 0.01;
ico.rotation.y += 0.01;
renderer.render(scene, camera);
};
window.onresize = () => renderer.setSize(window.innerWidth, window.innerHeight);
animate();
</script>
|