Threejs 官网 - 入门指南(Getting Started) 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循“署名-非商业用途-保持一致”创作公用协议 转载请保留此句:太阳火神的美丽人生 - 本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、HTML5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。 入门指南(Getting Started )chinedufn edited this page · 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.
第二步定义像机,渲染对象在渲染中将会用到。 The second step is to define a camera which the renderer object will use in rendering.
第一个参数决定了视图 field 有多宽。 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.
设置场景的最后一步,创建一个黄色的光源,并添加到场景中。 For the last step in setting up a scene we create a yellow light source and add it to the scene.
最后渲染场景,该场景只显示通过像机视角能看到的场景部分。 Finally we render the scene which displays our scene through the camera's eye.
使用最小 HTML 模板的运行示例中的每一样东西放在一下,就像下面的代码这样了: Everything together in a working example with a minimal HTML template:
15 行 JavaScript 代码初始化并渲染了一个场景。 15 lines of Javascript to initialize and render a scene. |
|