当前位置: 首页> 教育> 培训 > 表白网页设计代码大全_网站设计与系统的区别_免费网站怎么申请_郑州疫情最新消息

表白网页设计代码大全_网站设计与系统的区别_免费网站怎么申请_郑州疫情最新消息

时间:2025/7/10 8:15:32来源:https://blog.csdn.net/guang2586/article/details/144660110 浏览次数:0次
表白网页设计代码大全_网站设计与系统的区别_免费网站怎么申请_郑州疫情最新消息

Three.js 顶点着色学习
https://threehub.cn/#/codeMirror?navigation=ThreeJS&classify=basic&id=gradientTriangle

在这里插入图片描述

import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'const box = document.getElementById('box')const scene = new THREE.Scene()const camera = new THREE.PerspectiveCamera(75, box.clientWidth / box.clientHeight, 0.1, 1000)camera.position.set(0, 0, 500)const renderer = new THREE.WebGLRenderer()renderer.setSize(box.clientWidth, box.clientHeight)new OrbitControls(camera, renderer.domElement)window.onresize = () => {renderer.setSize(box.clientWidth, box.clientHeight)camera.aspect = box.clientWidth / box.clientHeightcamera.updateProjectionMatrix()}box.appendChild(renderer.domElement)initObject();
function initObject() {let geometry = new THREE.BufferGeometry(); // 使用BufferGeometrylet vertices = new Float32Array([0, 0, 0, // 顶点p10, 200, 0, // 顶点p2200, 0, 0 // 顶点p3]);geometry.setAttribute('position', new THREE.BufferAttribute(vertices, 3));let colors = [1.0, 0.0, 0.0, // 颜色1 (红色)0.0, 1.0, 0.0, // 颜色2 (绿色)0.0, 0.0, 1.0  // 颜色3 (蓝色)];// 创建顶点颜色属性let colorAttribute = new THREE.BufferAttribute(new Float32Array(colors), 3);geometry.setAttribute('color', colorAttribute);// 定义索引,创建三角形面let indices = [0, 1, 2 // 索引0, 1, 2 表示顶点数组中的p1, p2, p3];let indexAttribute = new THREE.BufferAttribute(new Uint16Array(indices), 1);geometry.setIndex(indexAttribute);let material = new THREE.MeshBasicMaterial({vertexColors: true,side: THREE.DoubleSide,wireframe: false});let obj = new THREE.Mesh(geometry, material);scene.add(obj);
}
function animate() {requestAnimationFrame(animate)renderer.render(scene, camera)}animate()/*** 名称: 渐变三角形* 作者: giser2017 https://gitee.com/giser2017
*/
关键字:表白网页设计代码大全_网站设计与系统的区别_免费网站怎么申请_郑州疫情最新消息

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: