O3D笔记

  • 格式:docx
  • 大小:314.54 KB
  • 文档页数:9

O3D简介 一、结构

主要包括三个部分 1) JavaScript应用程序 2) O3D JavaScript API(C++写的、开源) 3) O3D与系统硬件(GPU)之间通讯通过OpenGL 和 Direct3D 。

二、三维模型导入 O3D提供直接创建shape的方法(point list, line list, triangle list, triangle strip, triangle fan). 通过COLLADA格式可以将Autodesk 3ds Max, Maya, and Google SketchUp等三维模型导入。 三、Scene graph API Scene Graph API被用作创建a transform graph 和 a render graph. The transform graph 存储 the position, size, shapes, materials, and shaders. Transform包含一个矩阵控制shapes的位置和大小。

Shapes A shape 定义了geometry(包含position和size的结合体)。For example, if you were creating a table with four identical legs, you would 1) model the shape for the leg 2) and then reference it four times in four transforms that specify the positions for the four table legs. 3) Then you would create the table top 4) and reference it in a transform that places it on top of its four legs. 5) Finally, you would create a parent transform for the table unit to move the entire grouping to its desired location.

The basic transform graph for the transforms and shapes that make up this table would look like this: Materials 每一个初始的模型包含一个material参数。一个material可以被多个primitive share.

Effects A material contains a parameter for an effect and a parameter for an optional state. The effect, in turn, contains a vertex shader and a fragment (pixel) shader, which together specify how to color the pixels that make up the shape. The parameters of the material, such as its diffuse color, specular color, ambient color, and so on, are used by the effect it refers to. 什么是场景API? O3D场景API被用来创建一个转换图和一个渲染图,转换图保存对象的位置,尺寸,阴影,材质和3D程序最基础的着色信息。渲染图存储这些3D对象是如何转变为实际的像素并显示在用户的屏幕上的信息,渲染图作用于以下几个方面: 1.渲染图包含视图中隐藏的3D形状。 2.渲染图可以穿过转换图来绘制原始图元。 3.渲染图可以通过处理复杂的计算来达到特殊的渲染效果,如透明,多视角和模糊 编写的应用程序首先应该为3D世界构建一个转换图和一个为绘图细节准备的基础渲染图。然后O3D将穿过渲染图去显示3D内容,当然渲染图的信息是来之于转换图的。这种方法与那些发出绘制命令并立即执行的快速模式截然不同。 转换图 转换包含一个矩阵,其详述了在三维空间中如何关联已经定义位置和尺寸的形状。转换图是一个已安排在父/子层中的转变的有序集合。应用程序的变换图在树形目录的顶端有一个根本转变,任何其他的子变换排列都将排在根目录的分支上。转换有一个累计效应,也就是说高一级的变换可以作用于此低一级的分支上。 形状 转换可以有一个或多个形状与它相关。一个形状可以定义一块已经定义位置和尺寸的几何图像作为一个图元。反过来,形状是每一个都有不同材质的原始图元组成。形状被独立定义,然后与一个定义在局部坐标空间的转换交互。例如,如果你想建一个具有四条腿桌子的模型,您将先创建桌子腿的模型,然后你在四个定义好的位置对桌腿进行转换。接着,您将创建桌面并在四条腿的上方进行一次转换。最后,您将为整个桌子模型创建一个根转换,然后移动到合适的位置。

The render graph stores information about how these 3D objects are converted into the actual pixels that are displayed on the user's screen. The render graph主要功能: 1) 3D shapes are hidden from view的信息 2) it traverses the transform graph to assemble primitives to be drawn.对transform graph做渲染 3) transparency, multiple views of the same world, and heads-up displays等渲染参数的设置

Creating the Transform Graph 1 外部导入 COLLADA文件为中间格式导入其他三位格式。 Using this sample converter as a model, you can also write your own importer and reader for files in any other format. 2 自己创建。提供vertex data on position, normals, color, and effects。尤其如何在3D space中确定position。 Packs for memory management 当创建一个object,他自动加到pack中,为了确保不被误删。Pack本身带有一个reference. pack.removeObject function releases an individual reference to an object, pack.destroy releases all references in that pack. 当您创建一个O3D对象 ,它会自动添加到一个包中以保证对象不会被意外删除。对象被引用一次,此引用数就会自增一;包也会保存一个到该对象的引用。pack.removeObject函数释放一个无效的对象引用。Pack.destroy函数释放包中所有的对象引用。

Creating the Render Graph O3D provides a DrawContext object that is used to define the view matrix and projection matrix. The view matrix converts vertices from world coordinates to view coordinates. The projection matrix is a transformation that converts view coordinates to clipspace coordinates. Any 3D content that falls outside of the viewing frustum is discarded, or clipped. This matrix is usually an orthographic or perspective transformation. The DrawContext is shared by the DrawPass objects and the TreeTraversal object. The TreeTraversal object uses it for culling, and the DrawPass object uses it during rendering. You can specify these matrices explicitly, or if you're importing models from other sources, O3D can obtain the camera information contained in the imported content. The createDrawElements() function walks the transform graph and generates a draw element for each primitive in the transform graph. A draw element is basically an instruction to "Draw this primitive." Without draw elements, nothing is drawn. Draw elements allow O3D to efficiently draw the same primitive multiple times (for example, once as the actual shape and once as the shadow for that shape). In some cases, the draw element uses the material assigned to the primitive. In other cases, the draw element may have its own material assigned to it (for example, for shadows). In cases where both the primitive and the draw element have materials assigned to them, the material assigned to the draw element overrides the material assigned earlier to the primitive. O3D提供了一个DrawContext对象用来定义视图模型和投影模型。视图模型表示从世界坐标到视图坐标的转变。投射模型表示了从视图坐标到剪裁空间模型的转变。超出可视范围的3D内容将被裁剪或者省略。这种矩阵通常是正字法或透视变换。DrawContext是被DrawPass对象和TreeTraversal对象分享。TreeTraversal对象使用它裁剪,而DrawPass对象在渲染时使用他。你可以明确指定这些模型,或你从其他地方导入模型, O3D可以获得保存在导入内容中的摄影信息。 createDrawElements函数通过遍历转换图为每一个原始图元生成一个可绘制单元。可绘制图元本质上是一个绘制原始图元的指示命令,如果没有可绘制图元,就没有图形可绘。可绘制图元允许O3D对同一原始图元进行多次绘制(例如,一次作为实际图形,另一次用作影子的形成)。在某些情况下,可绘制图元分配材质给原始图元。在其他情况下,可绘制图元可能将自己的材质分配给它(例如,阴影)。万一同时有材质分配给原始图元和可绘制图元,那么分配给可绘制图元的材质将会覆盖分配给原始图元的材质。