标题: sandy3d例子 [打印本页] 作者: 花街六少つ 时间: 2013-12-5 14:07 标题: sandy3d例子 import sandy.core.data.*;
import sandy.core.group.*;
import sandy.primitive.*;
import sandy.view.*;
import sandy.core.*;
import sandy.skin.*;
import sandy.util.*;
import sandy.core.transform.*;
import sandy.events.*;
// 定义一些有用的全局变量We define some useful global variables
var screen:ClipScreen; // 演示用表面Presentation surface
var world:World3D = World3D.getInstance(); // 我们的3维场景Our 3D world
//我们在init函数里初始化并渲染场景 In the init() function we initialize and render the world
function init( Void ):Void {
//创建clipScreen用作渲染3维世界的表面 Create a clipScreen as presentation surface for the World3D to draw on
screen = new ClipScreen( this.createEmptyMovieClip('screen', 1), 300, 300 );
// 创建一个摄影机,以便能够看到我们的世界 Create a camera, so we can see our world.
// 为他指定焦距和显示屏幕 Give it a focal distance ( equivalent ) and a reference to the viewing screen.
var cam:Camera3D = new Camera3D( 700, screen );
// 把摄影机定位到研z轴负方向。Position the camera at a negative distance along the z axis
// 默认它是观看坐标原点的 By default it is looking at the origin of the world coordinate system [0,0,0]
cam.setPosition(0,0,-500);
// 把摄影机付给场景 Attach the camera to the world
world.addCamera( cam );
//场景根组,用作场景中所有物体的支点 Create the root group, the branch node for all objects in our world
var bg:Group = new Group();
// 付给场景,该节点用来绘制其他子节点 and attach it to the world. this node is responsible
// for drawing all its ( possibly transformed child nodes
world.setRootGroup( bg );
// 创建场景并与根组关联 Create the scene and attach it to the rootGroup
createScene( bg );
// 最后开始渲染 场景Finally we start rendering the world
world.render();
}
//自定义创建场景函数
function createScene( bg:Group ):Void {
// 开始,创建一个长方体Start by creating a Box primitive.
// By setting all edges to 50 pixels, we'll get a cube
var cube:Object3D = new Box( 50, 50, 50, 'quad' );
//我们可以创建一个皮肤,使立方体看起来更好一些。 We can create a skin to make the cube look a little better
//这里我们使用一个混合皮肤,一个半透明绿色和黑细线 Here we use a mixed skin with a semi transparent green color and black thin lines
var skin:Skin = new MixedSkin( 0x00FF00, 80, 0, 100, 1 );
// 应用皮肤给立方体 Apply the skin to the cube.
cube.setSkin( skin );
// 添加立方体到rootGroup Add the cube as a child to the rootGroup
bg.addChild( cube );
}
init();