1、
o3djs.rendergraph.createBasicView( !o3d.Pack pack
!o3d.Transform treeRoot
!o3d.RenderNode opt_parent
!o3djs.math.Vector4 opt_clearColor
number opt_priority
!o3djs.math.Vector4 opt_viewport )
参数:
pack
管理生成对象的Pack包.
treeRoot 视图的根节点.
opt_parent 视图的渲染节点.
opt_clearColor 视图的颜色,[0.1,0.2,0.3,0.4],分别表示[红,绿,蓝,黑],每个值介于0到1之间。
opt_priority 生成对象的优先级。
opt_viewport 视窗设置,例如[0.1,0.1,0.9,0.9],分别表示[左,上,右,下],每个值介于0到1之间,左和右值相加不能大于1,上和下值相加不能大于1
返回值:
!o3djs.rendergraph.ViewInfo. 创建的所有对象的视图信息.
例如,
var viewBackgroundColor=[0.2,0.5,0.6,0.7];
var viewPort = [0.1,0.1,0.9,0.9];
g_viewInfo = o3djs.rendergraph.createBasicView(
g_pack,
g_client.root,
g_client.renderGraphRoot,
viewBackgroundColor,
1,
viewPort
);
2、创建材质 o3djs.material.createBasicMaterial ()
view plaincopy to clipboardprint?
!o3d.Material o3djs.material.createBasicMaterial (
!o3d.Pack pack ,
!o3djs.rendergraph.ViewInfo viewInfo ,
(!o3djs.math.Vector4|!o3d.Texture) colorOrTexture ,
boolean opt_transparent )
参数:
pack 管理创建对象的包(Pack)。
viewInfo API函数o3djs.rendergraph.createBasicView创建的视窗信息。
colorOrTexture 颜色矩阵[r, g, b, a]或者一个o3d纹理贴图。
opt_transparent 材质是否是透明的。默认情况下是非透明的。
返回:
!o3d.Material.生成的材质。
示例代码:
view plaincopy to clipboardprint?
<html><body>
<mce:script type="text/javascript" src="o3djs/all.js" mce_src="o3djs/all.js"><!--
// --></mce:script>
<mce:script type="text/javascript"><!--
window.onload = init;
function init() {
o3djs.base.makeClients(initStep2);
}
function initStep2(clientElements) {
var clientElement = clientElements[0];
var client = clientElement.client;
var pack = client.createPack();
var viewInfo = o3djs.rendergraph.createBasicView(
pack,
client.root,
client.renderGraphRoot);
var material = o3djs.material.createBasicMaterial(
pack,
viewInfo,
[1, 0, 0, 1]); // red
var shape = o3djs.primitives.createCube(pack, material, 10);
var transform = pack.createObject('Transform');
transform.parent = client.root;
transform.addShape(shape);
o3djs.camera.fitContextToScene(client.root,
client.width,
client.height,
viewInfo.drawContext);
}
// --></mce:script>
<div id="o3d" style="width: 600px; height: 600px"></div>
</body></html>
o3djs.rendergraph.createBasicView( !o3d.Pack pack
!o3d.Transform treeRoot
!o3d.RenderNode opt_parent
!o3djs.math.Vector4 opt_clearColor
number opt_priority
!o3djs.math.Vector4 opt_viewport )
参数:
pack
管理生成对象的Pack包.
treeRoot 视图的根节点.
opt_parent 视图的渲染节点.
opt_clearColor 视图的颜色,[0.1,0.2,0.3,0.4],分别表示[红,绿,蓝,黑],每个值介于0到1之间。
opt_priority 生成对象的优先级。
opt_viewport 视窗设置,例如[0.1,0.1,0.9,0.9],分别表示[左,上,右,下],每个值介于0到1之间,左和右值相加不能大于1,上和下值相加不能大于1
返回值:
!o3djs.rendergraph.ViewInfo. 创建的所有对象的视图信息.
例如,
var viewBackgroundColor=[0.2,0.5,0.6,0.7];
var viewPort = [0.1,0.1,0.9,0.9];
g_viewInfo = o3djs.rendergraph.createBasicView(
g_pack,
g_client.root,
g_client.renderGraphRoot,
viewBackgroundColor,
1,
viewPort
);
2、创建材质 o3djs.material.createBasicMaterial ()
view plaincopy to clipboardprint?
!o3d.Material o3djs.material.createBasicMaterial (
!o3d.Pack pack ,
!o3djs.rendergraph.ViewInfo viewInfo ,
(!o3djs.math.Vector4|!o3d.Texture) colorOrTexture ,
boolean opt_transparent )
参数:
pack 管理创建对象的包(Pack)。
viewInfo API函数o3djs.rendergraph.createBasicView创建的视窗信息。
colorOrTexture 颜色矩阵[r, g, b, a]或者一个o3d纹理贴图。
opt_transparent 材质是否是透明的。默认情况下是非透明的。
返回:
!o3d.Material.生成的材质。
示例代码:
view plaincopy to clipboardprint?
<html><body>
<mce:script type="text/javascript" src="o3djs/all.js" mce_src="o3djs/all.js"><!--
// --></mce:script>
<mce:script type="text/javascript"><!--
window.onload = init;
function init() {
o3djs.base.makeClients(initStep2);
}
function initStep2(clientElements) {
var clientElement = clientElements[0];
var client = clientElement.client;
var pack = client.createPack();
var viewInfo = o3djs.rendergraph.createBasicView(
pack,
client.root,
client.renderGraphRoot);
var material = o3djs.material.createBasicMaterial(
pack,
viewInfo,
[1, 0, 0, 1]); // red
var shape = o3djs.primitives.createCube(pack, material, 10);
var transform = pack.createObject('Transform');
transform.parent = client.root;
transform.addShape(shape);
o3djs.camera.fitContextToScene(client.root,
client.width,
client.height,
viewInfo.drawContext);
}
// --></mce:script>
<div id="o3d" style="width: 600px; height: 600px"></div>
</body></html>