`
wjlgryx
  • 浏览: 306855 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

o3d 文档原文

阅读更多

Basic Tasks
The basic tasks performed in an O3D program are the following:
1:Create the O3D object.
2:Assign values to global variables and initialize utility libraries.
3:Create the pack to manage O3D objects.
4:Create the render graph.
5:Set up the draw context (perspective and viewing transformations).
6:Create an effect and load the shader information into it.
7:Create the material and shape, set the material's draw list, and set up other material parameters.
8:Add the transforms and shapes to the transform graph.
9:Create the draw elements for the primitives.
10:Set the optional render callback function, if desired, to perform special tasks each time the 3D scene is rendered.
The following sections discuss how the Hello, Cube sample implements these tasks.

//-------------------------------------------------------------------------------------------------------------
HTML Document
An O3D application is contained in an HTML document. The main code for the O3D JavaScript application is contained in a <script> element inside the <head> element of the HTML document. In this example, when the HTML page is finished loading, the O3D init() function is called. The HTML page also sets up an onunload event, which calls the application's uninit() function to perform necessary cleanup, such as removing callback functions when the HTML page is unloaded..


<script type="text/javascript" src="o3djs/base.js"></script>
<script type="text/javascript">
o3djs.require('o3djs.util');
o3djs.require('o3djs.math');
o3djs.require('o3djs.rendergraph');

window.onload = init;
window.onunload = uninit;
  .
  .
  .

//---------------------------------------------------------------------------
Utility Libraries
O3D includes a number of utility libraries that simplify the coding of common tasks. If you use functions from one of these libraries, you also need to include that code in <script> tags at the beginning of your program as shown below. (The first <script> element defines the require
function, which is used thereafter to initialize the other utility libraries.):


<script type="text/javascript" src="o3djs/base.js"></script>
<script type="text/javascript">
o3djs.require('o3djs.util');
o3djs.require('o3djs.math');
o3djs.require('o3djs.rendergraph');

//--------------------------------------------------------------------------------
Creating the O3D Plug-in Object
In the code sample, the init() function calls the utility function o3djs.util.makeClients() to make the O3D objects. When this function returns, it invokes the callback function initStep2(). The user's browser must have scripting enabled in order for O3D HTML elements to be created.


function init() {
  o3djs.util.makeClients(initStep2)
}

//-------------------------------------------------------------------------------
Setting the Size of the Client Area on the Page
Use the o3djs.util.makeClients() function to create O3D objects in HTML that can be used across platforms. This function finds all <div> elements with an id that starts with the word "o3d" (for example o3d, o3d-element, and so on) and inserts a client area inside. The size of the client area is always set to 100 percent, which means the <div> must have its size set or managed by the browser. For example:
<!-- A div of a specific size -->
   <div id="o3d" style="width:800px; height:600px" />
  
<!-- A div that fills its containing element -->
   <div id="o3d" style="width:100%; height:100%" />
The makeClients() utility takes a callback function as one of its parameters. This callback is triggered once the O3D objects have been created.

//------------------------------------------------------------
Basic Setup for O3D
This code assigns values to global variables:


var o3dElement = clientElements[0];
g_client = o3dElement.client;
g_o3d = o3dElement.o3d;
g_math = o3djs.math;

//---------------------------------------------------------------------------
These variables have the following meaning:
o3dElement is the HTML O3D element, which is part of the DOM
g_client is the entry point of the O3D application
g_o3d is the namespace for O3D
g_math is the namespace for the math library

//------------------------------------------------
Creating the Pack
The pack contains all O3D objects and manages their lifetime.
  g_pack = g_client.createPack();

//---------------------------------------------------------
Creating the Render Graph
This example uses the utility function rendergraph.createBasicView() to create a standard render graph, as described in the Technical Overview. This render graph has two draw lists, one for draw elements with opaque materials (the performance draw list) and one for draw elements with transparent materials (the transparency draw list). A separate draw pass is performed for each draw list.
var viewInfo = o3djs.rendergraph.createBasicView(
    g_pack,
    g_client.root,
    g_client.renderGraphRoot);

//------------------------------------------------------------
Setting Up the Draw Context
The draw context specifies the view projection and the position of a virtual camera that is viewing the scene (the view transformation). The drawContext object is created by the utility function renderGraph.createBasicView(). Here is an example of setting its values:
// Set up a simple perspective view.
viewInfo.drawContext.projection = g_math.matrix4.perspective(
   g_math.degToRad(30), // 30 degree fov.
   g_client.width / g_client.height,
   1,                  // Near plane.
   5000);              // Far plane.

// Set up our view transformation to look towards the world origin where the
// cube is located.
viewInfo.drawContext.view = g_math.matrix4.lookAt([0, 1, 5],  // eye
                                                  [0, 0, 0],  // target
                                                  [0, 1, 0]); // up

//-----------------------------------------------------------------------------
Creating an Effect and Loading the Shaders
The vertex and pixel shaders are defined in the <textarea> element of the HTML document. The shaders control the calculations for the color of each pixel in each draw element. This code creates the effect (redEffect) and reads in the contents of the shaders:
var redEffect = g_pack.createObject('Effect');
       
// looks in the HTML document for an element named "effect"
var shaderString = document.getElementById('effect').value;
       
// loads the entire contents of the <textarea id="effect"> element into the redEffect object 
redEffect.loadFromFXString(shaderString);
Creating the Material and Shape
The red material for the cube is created in the initStep2() function and assigned to the performance draw list, which handles opaque materials. The following code also sets the material's effect to redEffect so that the graphics hardware can apply the proper shading to the cube. In this example, no shading calculations are performed. The simple color red is returned for all pixels. The createCube() function constructs the cube geometry, as described in Shapes, and uses the red material. An alternative to setting up the geometry within O3D, as shown in the Hello, Cube examples, is to import geometry constructed using an application such as SketchUp, 3ds Max, or Maya.
var redMaterial = g_pack.createObject('Material');
redMaterial.drawList = viewInfo.performanceDrawList;
redMaterial.effect = redEffect;

var cubeShape = createCube(redMaterial);
Setting Up the Transform Graph
The Hello, Cube example has a very simple transform graph. The following code creates one transform for the cube shape, adds the shape to the transform, and then adds the transform to the O3D root.
g_cubeTransform = g_pack.createObject('Transform');
g_cubeTransform.addShape(cubeShape);
g_cubeTransform.parent = g_client.root;
Creating Draw Elements
Every primitive has a draw element constructed for it that describes what material and effect to use when the primitive is rendered. The createDrawElements() function creates draw elements for all primitives in the specified shape and adds the draw elements to the draw list associated with the primitive's material. At render time, one draw pass is performed for each draw list, and all draw elements in the lists are rendered.
cubeShape.createDrawElements(g_pack, null);
Setting the Render Callback Function
The scene is automatically rendered each time the hardware refreshes the screen. In this example, setRenderCallback() sets a callback that updates the cube's transform values each time the scene is rendered. This update makes the cube spin.
g_client.setRenderCallback(renderCallback);

 

分享到:
评论

相关推荐

    O3D文档说明(主要关键字的说明及翻译)

    在O3D文档中,我们关注的是3D图形渲染的关键概念和术语,这些内容对于理解O3D框架的架构和工作原理至关重要。以下是对这些关键术语的详细解释: 1. **Draw Context 绘制上下文**:绘制上下文是3D渲染的核心组件,它...

    O3D 物体 编辑器

    在3D图形编程领域,O3D是一种开源的JavaScript库,它允许开发者在Web浏览器中创建和展示复杂的3D场景。"O3D 物体编辑器"是基于O3D库开发的一个工具,用于帮助用户在网页环境中设计、编辑和操作3D物体。这个编辑器...

    O3D学习笔记[一]素材准备*.3ds转成*.o3dtgz

    在本篇O3D学习笔记中,我们将探讨如何将3DS格式的三维模型转换为O3DTGZ格式,这是O3D系统所使用的专有格式。3DS是一种广泛使用的三维建模软件3ds Max导出的文件格式,而O3DTGZ是O3D(Open 3D Engine)框架下的压缩...

    O3D 实例 研究中

    `gettingstarted.html` 是 HTML 文档,用于设置页面结构,并加载 O3D 库及相关的 JavaScript 文件。其中,`&lt;script type="text/javascript" src="o3djs/base.js"&gt;&lt;/script&gt;` 是加载 O3DJS,这是 O3D 的辅助库,提供...

    google o3d例子3

    o3d是Google开发的基于web的3d编程API,因文件太大分三次上传

    google o3d 编程例子1

    google开发的web3d编程APT o3d.提供的各种3d效果例子,因文件太大,分三个包传上

    谷歌O3D的javascript源码

    谷歌O3D是一种由Google开发的JavaScript库,用于在Web浏览器中实现高性能的3D图形渲染。这个技术主要目标是让网页开发者能够轻松地在不借助插件的情况下创建丰富的、交互式的3D内容。O3D的核心是基于OpenGL的硬件...

    3D-o3d.zip

    在o3d-master子文件中,我们可以期待找到Objective-3D的源代码、文档、示例项目等资源。这些资源对于学习和理解如何使用这个引擎,以及如何进行3D游戏开发,都是非常宝贵的。通过深入研究和实践,开发者不仅可以掌握...

    o3d lib1 graph javascript ajax

    o3d lib1 graph javascript ajax

    o3d goolge javascript

    o3d goolge javascript texture graph

    野村综研O3W架构资料(内部)

    ### 野村综研O3W架构资料:深入解析与技术要点 #### 一、背景与挑战 在1980年代至1990年代初,日本许多企业开始进行核心业务系统的信息化改造,主要采用大型机为核心的专用系统。当时的终端设备主要是哑终端,仅能...

    google o3d 编程例子2

    o3d是Google开发的基于web的3d编程API,因文件太大分三次上传

    o3de.org:O3DE 网站

    此存储库包含 Open 3D Engine (O3DE) 的网站和文档。 在预览期间,站点和文档正在大量开发中 - 所以如果信息丢失或有时中断,请不要感到惊讶。 如果您想预览我们的官方网站,请直接联系我们获取信息。 如果您想构建...

    o3dv_0.8.3.zip

    "o3dv_0.8.3.zip" 是一个压缩包文件,包含了 Online3DViewer 的 0.8.3 版本。Online3DViewer 是一个基于 Web 的三维模型查看器,它允许用户在浏览器中查看和交互三维模型,无需安装任何额外的软件。这个工具主要利用...

    CaO-Al2O3和CaO-SiO2-Al2O3渣系中组元活度的计算 (2013年)

    根据分子和离子共存理论,建立了CaO-Al2O3 和CaO-SiO2-Al2O3 渣系的活度计算模型,并利用模型对渣中各组元的活度进行了计算,分析了 w (CaO )对渣中组元活度的影响.结果表明,在 CaO-Al2O3 渣系中,当w(CaO)小于45%时,...

    o3d:从 code.google.compo3d 导入

    2. **文档**:可能包含API参考、教程和示例说明,帮助开发者理解和使用O3D库。 3. **示例**:一系列预设的3D场景和应用,用于展示O3D库的功能和用法。 4. **资源文件**:纹理、模型和其他3D资源,供示例和应用使用。...

Global site tag (gtag.js) - Google Analytics