- 浏览: 310678 次
- 性别:
- 来自: 北京
-
文章分类
最新评论
-
开发小菜:
支持IE9以下的吗?
HTML5+CSS3+JQuery打造自定义视频播放器 -
攻城使:
开发Html5必须得下载么,我用dw编写,把文件复制到myec ...
html5开发 myeclipse安装aptana插件 -
疾风鹰狼:
...
根据判断浏览器类型屏幕分辨率自动调用不同CSS的代码 -
sardodo:
你好,我想问下,导入例子中的.dae格式模型是可以看到旋转的小 ...
c3dl 初步认识 -
BIOHAZARDX:
下载学习,初学者膜拜一下。
html5 实现动画(三)
第1步:定义纹理坐标
下面的步骤操作和代码指定纹理坐标,将其添加到一个数组,并添加到数组的缓冲区。该setVertexStream ( )函数指定如何读取缓冲区,并设置了一个顶点缓冲流。
指定(u,v)纹理坐标为每个顶点,并将其添加到一个数组( texCoordsArray ):
view plaincopy to clipboardprint?
var texCoordsArray = [
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1,
1, 1,
0, 1,
0, 0,
1, 0,
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1
];
创建一个顶点缓冲区保存纹理坐标( texCoordsBuffer ) 。并在这个缓冲区设置纹理坐标数组:
view plaincopy to clipboardprint?
var texCoordsBuffer = g_pack.createObject('VertexBuffer');
var texCoordsField = texCoordsBuffer.createField('FloatField', 2);
texCoordsBuffer.set(texCoordsArray);
调用setVertexStream ()函数,将纹理坐标缓冲区和基元数据流银行关联起来。调用这个函数设置语义纹理坐标顶点流( TEXCOORD )以及有关如何读取数据流中数据的其他信息:
view plaincopy to clipboardprint?
streamBank.setVertexStream(
g_o3d.Stream.TEXCOORD, // 语意
0, // 语意索引
texCoordsField, // 域
0); // 起始索引
第2步 :创建纹理取样器
下面的步骤操作和代码创建纹理采样和确定其状态。
•调用Effect.createUniformParams ( )创建一个材料参数的每一个效果的统一的参数(即,参数,适用于原始作为一个整体) 。在这个例子中,有一个统一的参数,纹理取样器:
view plaincopy to clipboardprint?
cubeEffect.createUniformParameters(cubeMaterial);
•获取材料的采样参数:
view plaincopy to clipboardprint?
var samplerParam = cubeMaterial.getParam('texSampler0');
•创建纹理采样器,并设定其状态。该例子的缩小过滤器( minFilter )设置为各向异性ANISOTROPIC。从某一角度看,此值可以提高纹理的质量:
view plaincopy to clipboardprint?
g_sampler = g_pack.createObject('Sampler');
g_sampler.minFilter = g_o3d.Sampler.ANISOTROPIC;
g_sampler.maxAnisotropy = 4;
•将此纹理采样器赋值给材质采样器参数:
view plaincopy to clipboardprint?
samplerParam.value = g_sampler;
第3步:获取纹理
下面演示了初始化材质贴图文件的路径参数,并且当用户改变材质贴图文件时,这个路径参数会发生相应的改变。
• 初始化纹理网址(在 initStep2 ()函数中)
view plaincopy to clipboardprint?
var path = window.location.href;
var index = path.lastIndexOf('/');
path = path.substring(0, index+1) + 'assets/texture_b3.jpg';
var url = document.getElementById("url").value = path;
•每当用户指定一个新的纹理,在changeTexture ( )函数获取一个新的纹理文件。
view plaincopy to clipboardprint?
function changeTexture() {
var textureUrl = document.getElementById('url').value;
try {
o3djs.io.loadTexture(g_pack, textureUrl, function(texture) {
// Remove the currently used texture from the pack so that when it's not
// referenced anymore, it can get destroyed.
if (g_sampler.texture)
g_pack.removeObject(g_sampler.texture);
// Set the texture on the sampler object to the newly created texture
// object returned by the request.
g_sampler.texture = texture;
// We can now safely add the cube transform to the root of the
// transform graph since it now has a valid texture. If the transform
// is already parented under the root, the call will have no effect.
g_cubeTransform.parent = g_client.root;
.
.
.//Error handling calls here.
}
这个函数使用util.loadTexture ( )从指定的地址加载纹理。此实用工具,反过来,调用createFileRequest ()函数。根据预设, createFileRequest ( )创建了一套mipmaps时加载纹理。如果您知道您不会使用mipmapping ,您可以明确要求加载纹理文件,并指定generateMipmaps属性FileRequest为FALSE 。
•在<body>的HTML网页,添加用户输入框和按钮,使用户可以指定一个新的纹理:
view plaincopy to clipboardprint?
<body>
<h1>Hello Cube: Textures</h1>
This example shows how to texture map a cube using an image fetched from a URL.
<br/>
<!-- Start of O3D plugin -->
<div id="o3d" style="width: 600px; height: 600px;"></div>
<!-- End of O3D plugin -->
<br />
Image URL: <input type="text" id="url" size="100">
<input type="button" onclick="changeTexture();" value="Update Texture"><BR>
第4步:创建着色器
在这个例子中, <textarea>元素包含的代码顶点和像素着色器。输入属性的顶点着色器的位置,有语义的立场,有语义的TEXCOORD0 。顶点着色器转换成均匀顶点位置剪辑空间。在这里,立场载于positionsBuffer和纹理坐标载于texCoordsBuffer 。顶点着色器通过纹理坐标值( TEXCOORD0 )通过不变( output.tex = input.tex ; ) 。支持Pixel Shader然后在查询中每个像素的原始和效益的颜色相应位的纹理贴图。以下是代码的顶点和像素着色器:
view plaincopy to clipboardprint?
<textarea id="effect">
// World View Projection matrix that will transform the input vertices
// to screen space.
float4x4 worldViewProjection : WorldViewProjection;
// The texture sampler is used to access the texture bitmap in the fragment
// shader.
sampler texSampler0;
// input for our vertex shader
struct VertexShaderInput {
float4 position : POSITION;
float2 tex : TEXCOORD0; // Texture coordinates
};
// input for our pixel shader
struct PixelShaderInput {
float4 position : POSITION;
float2 tex : TEXCOORD0; // Texture coordinates
};
/**
* The vertex shader simply transforms the input vertices to screen space.
*/
PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
PixelShaderInput output;
// Multiply the vertex positions by the worldViewProjection matrix to
// transform them to screen space.
output.position = mul(input.position, worldViewProjection);
output.tex = input.tex;
return output;
}
/**
* Given the texture coordinates, our pixel shader grabs the corresponding
* color from the texture.
*/
float4 pixelShaderFunction(PixelShaderInput input): COLOR {
return tex2D(texSampler0, input.tex);
}
// Here we tell our effect file *which* functions are
// our vertex and pixel shaders.
// #o3d VertexShaderEntryPoint vertexShaderFunction
// #o3d PixelShaderEntryPoint pixelShaderFunction
// #o3d MatrixLoadOrder RowMajor
下面的步骤操作和代码指定纹理坐标,将其添加到一个数组,并添加到数组的缓冲区。该setVertexStream ( )函数指定如何读取缓冲区,并设置了一个顶点缓冲流。
指定(u,v)纹理坐标为每个顶点,并将其添加到一个数组( texCoordsArray ):
view plaincopy to clipboardprint?
var texCoordsArray = [
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1,
1, 1,
0, 1,
0, 0,
1, 0,
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1,
0, 0,
1, 0,
1, 1,
0, 1
];
创建一个顶点缓冲区保存纹理坐标( texCoordsBuffer ) 。并在这个缓冲区设置纹理坐标数组:
view plaincopy to clipboardprint?
var texCoordsBuffer = g_pack.createObject('VertexBuffer');
var texCoordsField = texCoordsBuffer.createField('FloatField', 2);
texCoordsBuffer.set(texCoordsArray);
调用setVertexStream ()函数,将纹理坐标缓冲区和基元数据流银行关联起来。调用这个函数设置语义纹理坐标顶点流( TEXCOORD )以及有关如何读取数据流中数据的其他信息:
view plaincopy to clipboardprint?
streamBank.setVertexStream(
g_o3d.Stream.TEXCOORD, // 语意
0, // 语意索引
texCoordsField, // 域
0); // 起始索引
第2步 :创建纹理取样器
下面的步骤操作和代码创建纹理采样和确定其状态。
•调用Effect.createUniformParams ( )创建一个材料参数的每一个效果的统一的参数(即,参数,适用于原始作为一个整体) 。在这个例子中,有一个统一的参数,纹理取样器:
view plaincopy to clipboardprint?
cubeEffect.createUniformParameters(cubeMaterial);
•获取材料的采样参数:
view plaincopy to clipboardprint?
var samplerParam = cubeMaterial.getParam('texSampler0');
•创建纹理采样器,并设定其状态。该例子的缩小过滤器( minFilter )设置为各向异性ANISOTROPIC。从某一角度看,此值可以提高纹理的质量:
view plaincopy to clipboardprint?
g_sampler = g_pack.createObject('Sampler');
g_sampler.minFilter = g_o3d.Sampler.ANISOTROPIC;
g_sampler.maxAnisotropy = 4;
•将此纹理采样器赋值给材质采样器参数:
view plaincopy to clipboardprint?
samplerParam.value = g_sampler;
第3步:获取纹理
下面演示了初始化材质贴图文件的路径参数,并且当用户改变材质贴图文件时,这个路径参数会发生相应的改变。
• 初始化纹理网址(在 initStep2 ()函数中)
view plaincopy to clipboardprint?
var path = window.location.href;
var index = path.lastIndexOf('/');
path = path.substring(0, index+1) + 'assets/texture_b3.jpg';
var url = document.getElementById("url").value = path;
•每当用户指定一个新的纹理,在changeTexture ( )函数获取一个新的纹理文件。
view plaincopy to clipboardprint?
function changeTexture() {
var textureUrl = document.getElementById('url').value;
try {
o3djs.io.loadTexture(g_pack, textureUrl, function(texture) {
// Remove the currently used texture from the pack so that when it's not
// referenced anymore, it can get destroyed.
if (g_sampler.texture)
g_pack.removeObject(g_sampler.texture);
// Set the texture on the sampler object to the newly created texture
// object returned by the request.
g_sampler.texture = texture;
// We can now safely add the cube transform to the root of the
// transform graph since it now has a valid texture. If the transform
// is already parented under the root, the call will have no effect.
g_cubeTransform.parent = g_client.root;
.
.
.//Error handling calls here.
}
这个函数使用util.loadTexture ( )从指定的地址加载纹理。此实用工具,反过来,调用createFileRequest ()函数。根据预设, createFileRequest ( )创建了一套mipmaps时加载纹理。如果您知道您不会使用mipmapping ,您可以明确要求加载纹理文件,并指定generateMipmaps属性FileRequest为FALSE 。
•在<body>的HTML网页,添加用户输入框和按钮,使用户可以指定一个新的纹理:
view plaincopy to clipboardprint?
<body>
<h1>Hello Cube: Textures</h1>
This example shows how to texture map a cube using an image fetched from a URL.
<br/>
<!-- Start of O3D plugin -->
<div id="o3d" style="width: 600px; height: 600px;"></div>
<!-- End of O3D plugin -->
<br />
Image URL: <input type="text" id="url" size="100">
<input type="button" onclick="changeTexture();" value="Update Texture"><BR>
第4步:创建着色器
在这个例子中, <textarea>元素包含的代码顶点和像素着色器。输入属性的顶点着色器的位置,有语义的立场,有语义的TEXCOORD0 。顶点着色器转换成均匀顶点位置剪辑空间。在这里,立场载于positionsBuffer和纹理坐标载于texCoordsBuffer 。顶点着色器通过纹理坐标值( TEXCOORD0 )通过不变( output.tex = input.tex ; ) 。支持Pixel Shader然后在查询中每个像素的原始和效益的颜色相应位的纹理贴图。以下是代码的顶点和像素着色器:
view plaincopy to clipboardprint?
<textarea id="effect">
// World View Projection matrix that will transform the input vertices
// to screen space.
float4x4 worldViewProjection : WorldViewProjection;
// The texture sampler is used to access the texture bitmap in the fragment
// shader.
sampler texSampler0;
// input for our vertex shader
struct VertexShaderInput {
float4 position : POSITION;
float2 tex : TEXCOORD0; // Texture coordinates
};
// input for our pixel shader
struct PixelShaderInput {
float4 position : POSITION;
float2 tex : TEXCOORD0; // Texture coordinates
};
/**
* The vertex shader simply transforms the input vertices to screen space.
*/
PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
PixelShaderInput output;
// Multiply the vertex positions by the worldViewProjection matrix to
// transform them to screen space.
output.position = mul(input.position, worldViewProjection);
output.tex = input.tex;
return output;
}
/**
* Given the texture coordinates, our pixel shader grabs the corresponding
* color from the texture.
*/
float4 pixelShaderFunction(PixelShaderInput input): COLOR {
return tex2D(texSampler0, input.tex);
}
// Here we tell our effect file *which* functions are
// our vertex and pixel shaders.
// #o3d VertexShaderEntryPoint vertexShaderFunction
// #o3d PixelShaderEntryPoint pixelShaderFunction
// #o3d MatrixLoadOrder RowMajor
发表评论
-
bufferData
2011-07-21 14:30 1101/*void*/ bufferData //缓冲区数 ... -
导入支持的格式(Import)
2011-05-31 16:54 2468导入对话框选择格式,你会看到众多导入的格式。3ds m ... -
法线贴图
2011-05-13 11:48 1920本文转自:http://yumi08.jimdo.co ... -
法线向量
2011-05-13 10:20 2531面法线的计算相对来 ... -
ShowWebGL 强大的3D模型查看器
2011-04-12 14:01 6157ShowWebGL http://showwebgl.com ... -
o3d 创建一个平面
2011-03-29 15:27 879var vertexInfo = o3djs.primitiv ... -
o3d 常见几何图形创建
2011-03-29 15:25 11261、基本形状包括: o3djs.primitives.cre ... -
o3D 材质-定义透明材质
2011-03-29 15:20 1098//定义一个为白色并且是透明材质 var material = ... -
o3D 光照设定材质的光反射系数
2011-03-29 15:19 9811、创建材质 2、设定效果 3、创建光源的位置 4、设置材质环 ... -
O3D程序基本结构
2011-03-29 15:13 830创建一个O3D对象 设置全局变量初始化通用库 创建一个O3D ... -
Google 三维 JavaScript API
2011-03-28 15:59 900O3D 是一个开源的Web API,其可以创建相当牛X的基于浏 ... -
3D引擎CopperLicht(二)
2011-03-28 15:14 1431在上一个课程的基础上 ... -
3D引擎CopperLicht
2011-03-28 15:09 1736WebGL是一种3D绘图标准, ... -
o3d 文档原文
2011-03-18 18:00 875Basic TasksThe basic tasks perf ... -
WebGL的框架
2011-03-18 16:23 3923WebGL的框架 WebGL http://www.khro ... -
c3dl 官方教程(二)
2011-03-18 16:13 1899教程#2:一个简单的场景本教程将展示C3DL)的基础知识使用三 ... -
C3DL 官方教程(一)
2011-03-18 15:57 1560本文笔者翻译,如有错误请留言。 教程#1:Web ... -
3D模型导入 CanvasMatrix.js引擎 demo(一)
2011-03-17 17:51 3055为广大html5 3d开发的朋友们演示 代码贴图,请下载附 ... -
c3dl 可以直接导入3dmax文件的3D引擎
2011-03-17 17:41 1201c3dl可以直接在网页代码中使用.dae格式的3dma ... -
o3d 模型导入引擎CanvasMatrix.js
2011-03-17 16:09 1636最近研究3d引擎在html5中的效果实现,需求当然是 ...
相关推荐
O3D库包含了一系列的类和方法,如几何体创建、材质应用、光照设置、相机控制等,支持开发者构建丰富的网络3D应用。 2. **3D物体编辑**:O3D 物体编辑器允许用户创建、修改和管理3D模型。用户可以导入现有的3D模型...
google开发的web3d编程APT o3d.提供的各种3d效果例子,因文件太大,分三个包传上
o3d是Google开发的基于web的3d编程API,因文件太大分三次上传
在本篇O3D学习笔记中,我们将探讨如何将3DS格式的三维模型转换为O3DTGZ格式,这是O3D系统所使用的专有格式。3DS是一种广泛使用的三维建模软件3ds Max导出的文件格式,而O3DTGZ是O3D(Open 3D Engine)框架下的压缩...
o3d是Google开发的基于web的3d编程API,因文件太大分三次上传
6. **纹理和光照**:为了使3D模型看起来更真实,O3D支持纹理贴图和光照模型。理解如何应用纹理和设置光照参数对于创建逼真的3D场景至关重要。 7. **性能优化**:由于O3D依赖于硬件加速,因此了解如何有效地利用GPU...
**O3D 实例研究详解** O3D 是一个开源的 JavaScript 库,它允许开发者在 Web 浏览器中创建高性能的三维图形应用。这个实例可能是为了展示 O3D 的基本用法和功能,帮助用户快速入门。下面我们将深入探讨 O3D 的核心...
在O3D文档中,我们关注的是3D图形渲染的关键概念和术语,这些内容对于理解O3D框架的架构和工作原理至关重要。以下是对这些关键术语的详细解释: 1. **Draw Context 绘制上下文**:绘制上下文是3D渲染的核心组件,它...
在3D-o3d.zip这个压缩包中,我们看到的是Objective-3D视频游戏引擎的相关资料,这是一个专门用于3D游戏开发的工具。 Objective-3D游戏引擎,以其强大的功能和灵活性,为开发者提供了构建逼真3D游戏环境的可能性。它...
o3d lib1 graph javascript ajax
o3d goolge javascript texture graph
离心力场中Al2O3纤维多孔体中的过临界渗透现象的研究涉及了多孔介质的渗透理论、液态金属在多孔介质中的流动行为、以及离心力场对流体渗透行为的影响等多个方面。本文将详细介绍这些知识点。 首先,多孔介质的渗透...
### 野村综研O3W架构资料:深入解析与技术要点 #### 一、背景与挑战 在1980年代至1990年代初,日本许多企业开始进行核心业务系统的信息化改造,主要采用大型机为核心的专用系统。当时的终端设备主要是哑终端,仅能...
"o3dv_0.8.3.zip" 是一个压缩包文件,包含了 Online3DViewer 的 0.8.3 版本。Online3DViewer 是一个基于 Web 的三维模型查看器,它允许用户在浏览器中查看和交互三维模型,无需安装任何额外的软件。这个工具主要利用...
根据分子和离子共存理论,建立了CaO-Al2O3 和CaO-SiO2-Al2O3 渣系的活度计算模型,并利用模型对渣中各组元的活度进行了计算,分析了 w (CaO )对渣中组元活度的影响.结果表明,在 CaO-Al2O3 渣系中,当w(CaO)小于45%时,...
01_mesh_sphere_ball.py:球面和立方体表面三角化示例程序。 02_trimesh_slz.py:三棱柱模型可视化,并将trimesh.Trimesh对象转换为open3d的o3d.geometry.TriangleMesh对象。 03_trimesh_o3d.py:三棱柱模型可视化,...