three.js實(shí)現(xiàn)圓柱體
本文實(shí)例為大家分享了three.js繪制圓柱體的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>圓柱體</title> <style> #canvas{ width:1100px; height:600px; border:1px solid; } </style> <script type="text/javascript" src="js/three.js"></script> <script> // 渲染器 var renderer; function init_renderer(){ width = document.getElementById("canvas").clientWidth; height = document.getElementById("canvas").clientHeight; renderer = new THREE.WebGLRenderer({ //生成渲染對(duì)象 antialias : true //去鋸齒 }); renderer.setSize(width,height);//設(shè)置渲染的寬度和高度; document.getElementById("canvas").appendChild(renderer.domElement); renderer.setClearColor(0xEEEEEE,1);//設(shè)置渲染的顏色; } // 場(chǎng)景 var scene; function init_scene(){ scene = new THREE.Scene(); } // 圓柱體 var cylinder; function init_cylinder(){ var cylinder = new THREE.CylinderGeometry(80,50,300,50,50); var texture = THREE.ImageUtils.loadTexture("textures/2.jpg",null,function(t)//圖片地址可使用本地,同根目錄下文件夾即可 { }); var material = new THREE.MeshLambertMaterial({map:texture}); //材料 cube = new THREE.Mesh(cylinder,material); cube.position.set(0,0,5); //設(shè)置幾何體的位置(x,y,z) scene.add(cube); } // 相機(jī) var camera; function init_camera(){ // camera = new THREE.PerspectiveCamera(100,width/height,1,10000); //透視相機(jī) camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 1, 1000) //正投影相機(jī) // (可視角度,可視范圍的長寬比,相對(duì)于深度剪切面的近的距離 必須為正數(shù),相對(duì)于深度剪切面的遠(yuǎn)的距離 必須為正數(shù)) camera.position.x =600 camera.position.y = 100; camera.position.z = 100; camera.up.x = -2;//設(shè)置相機(jī)的上為「x」軸方向 camera.up.y = 2;//設(shè)置相機(jī)的上為「y」軸方向 camera.up.z = 0;//設(shè)置相機(jī)的上為「z」軸方向 camera.lookAt({x:0,y:0,z:0}); //設(shè)置視野的中心坐標(biāo) } // 光源 var light; function init_light(){ light = new THREE.DirectionalLight(0xffffff,1);//設(shè)置平行光源 (光顏色,光強(qiáng)度) light.position.set(200,100,50);//設(shè)置光源向量 (x,y,z) scene.add(light); } function ThreeJs_Main(){ init_renderer();//渲染 init_scene();//場(chǎng)景 init_cylinder();//圓柱體 init_camera();//相機(jī) init_light();//光源 renderer.clear(); animation() renderer.render(scene,camera); } function animation(){ //x,y,z為旋轉(zhuǎn)的軸 后邊數(shù)字為速度 // cube.rotation.x += 0.01; cube.rotation.y += 0.01; // cube.rotation.z += 0.01; renderer.render(scene,camera); requestAnimationFrame(animation); } </script> </head> <body onload="ThreeJs_Main()"> <div id="canvas"></div> </body> </html>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript實(shí)現(xiàn)QQ聊天室功能
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)QQ聊天室功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07JavaScript中數(shù)組雙重去重的方法總結(jié)
這篇文章主要為大家學(xué)習(xí)介紹了JavaScript中數(shù)組雙重去重的幾個(gè)常用方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-07-07在頁面中js獲取光標(biāo)/鼠標(biāo)的坐標(biāo)及光標(biāo)的像素坐標(biāo)
頁面JS光標(biāo)/鼠標(biāo)坐標(biāo),百度統(tǒng)計(jì)中有個(gè)熱點(diǎn)統(tǒng)計(jì)圖,我們要做的就是獲取光標(biāo)的像素坐標(biāo)2013-11-11

JavaScript?映射器?array.flatMap()

javascript基本數(shù)據(jù)類型和對(duì)象類型歸檔問題解析

詳解cesium實(shí)現(xiàn)大批量POI點(diǎn)位聚合渲染優(yōu)化方案

JS實(shí)現(xiàn)的簡(jiǎn)潔二級(jí)導(dǎo)航菜單雛形效果