Threejs 官網,threejs官網
Threejs 官網 - 入門指南(Getting Started)
太陽火神的美麗人生 (http://blog.csdn.net/opengl_es)
本文遵循“署名-非商業用途-保持一致”創作公用協議
轉載請保留此句:太陽火神的美麗人生 - 本部落格專註於 敏捷開發及移動和物聯裝置研究:iOS、Android、Html5、Arduino、pcDuino,否則,出自本部落格的文章拒絕轉載或再轉載,謝謝合作。
入門指南(Getting Started )chinedufn edited this page on 4 Mar 2013 · 9 revisions
Three.js 情境非常容易設定,只需要幾行代碼就能完成初始化工作。情境使用幾種不同類型的對象來構造:像機(camera)、燈光(light)和蒙皮(mesh)。
Three.js scenes are very easy to setup and only require a few lines of code to initialize. Scenes are constructed using a few different types of objects: cameras, lights, and meshes.
渲染 three.js 情境的第一步就是建立 WebGL 渲染對象。下面的代碼建立一個 800x640 像素的 HTML 畫布(cavas)對象,把它加入到文檔主體中,並初始化 three.js 的情境。
The first step in rendering a three.js scene is creating the WebGL renderer object. The following code creates an HTML canvas object 800x640 pixels, adds it to the document's body, and initializes a three.js scene.
var renderer = new THREE.WebGLRenderer();renderer.setSize( 800, 640 );document.body.appendChild( renderer.domElement );var scene = new THREE.Scene();
第二步定義像機,渲染對象在渲染中將會用到。
The second step is to define a camera which the renderer object will use in rendering.
var camera = new THREE.PerspectiveCamera( 35, // Field of view 800 / 640, // Aspect ratio .1, // Near 10000 // Far);camera.position.set( -15, 10, 15 );camera.lookAt( scene.position );
第一個參數決定了視圖 field 有多寬。
第二個參數是高寬比,通過視圖地區的寬除以高來計算。
第三個和第四個參數指定像機視角中對象(可視地區)的界限點。
如果對象離像機的距離未落在 NEAR 和 FAR 之間的範圍內,那麼這樣的對象就不會被渲染。(譯者註:這也是一種減少不必要渲染對 GPU 資源消耗,提高效率的內部機制吧!)。
最後一行代碼,設定像機 XYZ 座標分別為 -15, 10 和 15 。
The first parameter passed determines how wide the field of view is. The second parameter is the aspect ratio which is calculated by dividing the viewing area's width by its height. The third and fourth parameters specify cut-off points for objects in the camera's view. If an object's distance from the camera does not fall in the range between NEAR and FAR then that object is not rendered. The last line sets the camera's XYZ coordinates to -15, 10, and 15 respectively.
三步建立一個 5 個單位寬、高、深的立方體,添加 Lambert 材質,並把它加入到情境中。
Step three creates a cube that is 5 units wide, tall and deep, adds the Lambert material, and adds it to the scene.
// 譯者註:紮燈籠骨架var geometry = new THREE.CubeGeometry( 5, 5, 5 );// 譯者註:繪畫糊燈籠的紙,當然過年時,圖案畫得更喜慶為好var material = new THREE.MeshLambertMaterial( { color: 0xFF0000 } );// 譯者註:把畫好圖案的彩紙按燈籠的大小比量好,裁剪下來並糊到燈籠骨架上var mesh = new THREE.Mesh( geometry, material );// 譯者註:燈籠糊好了,可以掛到大門口讓別人看了,我們中國人就是愛展示我們最美好的一面scene.add( mesh );
設定情境的最後一步,建立一個黃色的光源,並添加到情境中。
For the last step in setting up a scene we create a yellow light source and add it to the scene.
// 譯者註:可別忘了這一步,得給燈籠準備根蠟燭var light = new THREE.PointLight( 0xFFFF00 );// 譯者註:把蠟燭放到燈籠裡,比量好位置,別把燈籠自個點著了,那可就白糊了,還容易失火喲light.position.set( 10, 0, 10 );// 譯者註:按比量好的位置把蠟燭固定在燈籠裡,當然了,紮燈籠骨架時,可能你已經考慮到預留插蠟燭的地方了scene.add( light );
最後渲染情境,該情境只顯示通過像機視角能看到的情境部分。
Finally we render the scene which displays our scene through the camera's eye.
// 譯者註:火柴呢?打火機呢?趕快點亮吧renderer.render( scene, camera );
使用最小 HTML 範本的運行樣本中的每一樣東西放在一下,就像下面的代碼這樣了:
Everything together in a working example with a minimal HTML template:
<!DOCTYPE html><html><head> <title>Getting Started with Three.js</title> <script src="three.min.js"></script> <script> window.onload = function() { var renderer = new THREE.WebGLRenderer(); renderer.setSize( 800, 600 ); document.body.appendChild( renderer.domElement ); var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera( 35, // Field of view 800 / 600, // Aspect ratio 0.1, // Near plane 10000 // Far plane ); camera.position.set( -15, 10, 10 ); camera.lookAt( scene.position ); var geometry = new THREE.CubeGeometry( 5, 5, 5 ); var material = new THREE.MeshLambertMaterial( { color: 0xFF0000 } ); var mesh = new THREE.Mesh( geometry, material ); scene.add( mesh ); var light = new THREE.PointLight( 0xFFFF00 ); light.position.set( 10, 0, 10 ); scene.add( light ); renderer.render( scene, camera ); }; </script></head><body></body></html>
15 行 Javascript 代碼初始化並渲染了一個情境。
15 lines of Javascript to initialize and render a scene.
webgl想要做六個球體在立方體的六個面上
建議用webgl架構吧,做起來很快。如果直接寫,就如同寫opengl,很費事。推薦threejs架構,寫立方體球體,然後座標定位,很快就出來了。
這是threejs官網 threejs.org/ 上面很多例子
一款好用的系統要可以用的先給10分回頭好用的我在追加分
XP下載:
www.namipan.com/...e0ad2b
只有納米盤的下載連結了……
Vista下載:
系統(OEM免啟用純淨版,注意選擇版本,別選錯了)
www.kpsky.cn/down/sp1.htm 或
Flashget://W0ZMQVNIR0VUXWZ0cDovL2twc2t5LmNuL2Rvd24vVklTVEFfU1AxX09FTV9DSFNfVUxUSU1BVEUuaXNvW0ZMQVNIR0VUXQ==&7365&1210076732
(快車專用) 或
soft.zt169.com/Software/Catalog152/7778.html
如果BIOS正確(即OEM廠商選擇正確)則不需要啟用,和正版系統完全一樣,不用擔心被封~~~