纳金网
标题:
Flash3D学习——Sandy学习笔记 [11]
[打印本页]
作者:
.
时间:
2012-8-24 10:17
标题:
Flash3D学习——Sandy学习笔记 [11]
之前根据教程,已经了解了Sandy的基本知识,可以说Sandy已经对我们敞开了大门,我们可以在Flash3D的世界里自由飞翔了。
接下来,要更加深入的对Sandy进行了解了,正式进入高级教程的部分。
这个章节是介绍关于Sandy 3D的精确显示。
这次使用的是Plane3D这个基元,这个形状是平面体,我把它理解为3D场景里的一张纸片。
public function Plane3D(p_sName:String = null, p_nHeight:Number = 100, p_nWidth:Number = 100, p_nQualityH:uint = 1, p_nQualityV:uint = 1, p_sType:String, p_sMode:String = null)
他的参数比较多:
p_sName:String (default = null) — 给实例命名
p_nHeight:Number (default = 100) — 平面体的高度
p_nWidth:Number (default = 100) — 平面体的宽度
p_nQualityH:uint (default = 1) — 横向的段数
p_nQualityV:uint (default = 1) — 纵向的段数
p_sType:String — 位平面体定向, ( XY_ALIGNED ( default ), YZ_ALIGNED or ZX_ALIGNED )
p_sMode:String (default = null) — 模式(tri 模式有3个顶点、quad 模式有4个顶点)
代码:
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.ui.*;
import sandy.core.Scene3D;
import sandy.core.data.*;
import sandy.core.scenegraph.*;
import sandy.materials.*;
import sandy.materials.attributes.*;
import sandy.primitive.*;
/**
* ...
* @author ever5u
*/
public class fuxi extends Sprite
{
private var scene:Scene3D;
private var camera:Camera3D;
private var tg:TransformGroup;
public function fuxi() {
//先创建摄像机
camera = new Camera3D( 300, 300 );
camera.z = -400;
camera.lookAt(0,0,0);
//创建 Group
var root:Group = createScene();
//创建场景
scene = new Scene3D( "scene", canvas, camera, root );
scene.rectClipping = ***e;
addEventListener( Event.ENTER_FRAME, enterFrameHandler );
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressedHandler);
}
private function createScene():Group {
var g:Group = new Group();
tg = new TransformGroup('myGroup');
//创建几个平面体,并定义坐标使其组合成为一个形状
var right:Shape3D = new Plane3D('right', 150, 100, 10, 10, Plane3D.YZ_ALIGNED,'quad');
right.moveLateraly(100);
right.moveForward(50)
var left:Shape3D = new Plane3D('left', 150, 100, 10, 10, Plane3D.YZ_ALIGNED,'quad');
left.moveLateraly(-100);
left.moveForward(50)
var back:Shape3D = new Plane3D('back', 100, 250, 10, 10, Plane3D.XY_ALIGNED,'quad');
back.moveForward(100);
var bottom:Shape3D = new Plane3D('bottom', 150, 250, 10, 10, Plane3D.ZX_ALIGNED,'quad');
bottom.moveForward(50);
bottom.moveUpwards( -50);
//着色设置
var materialAttr:MaterialAttributes = new MaterialAttributes(
new LineAttributes( 0.5, 0x2111BB, 0.4 ),
new LightAttributes( ***e, 0.1)
);
var material01:Material = new ColorMaterial( 0xFFCC33, 1, materialAttr );
material01.lightingEnable = false;
var material02:Material = new ColorMaterial( 0xFEA792, 1, materialAttr );
material02.lightingEnable = false;
var app01:Appearance = new Appearance( material01 );
var app02:Appearance = new Appearance( material02 );
//应用着色
right.enableBackFaceCulling = false;
right.appearance = app01;
left.enableBackFaceCulling = false;
left.appearance = app01;
back.enableBackFaceCulling = false;
back.appearance = app02;
bottom.enableBackFaceCulling = ***e;
bottom.appearance = app02;
//是否独立渲染
right.useSingleContainer = false;
left.useSingleContainer = false;
back.useSingleContainer = false;
bottom.useSingleContainer = false;
//组合到组
tg.addChild(right);
tg.addChild(left);
tg.addChild(back);
tg.addChild(bottom);
g.addChild(tg);
return g;
}
private function enterFrameHandler( event : Event ) : void {
scene.render();
}
private function keyPressedHandler(event:KeyboardEvent):void {
switch(event.keyCode) {
case Keyboard.UP:
tg.tilt +=2;
break;
case Keyboard.DOWN:
tg.tilt -=2;
break;
case Keyboard.RIGHT:
tg.pan +=2;
break;
case Keyboard.LEFT:
tg.pan -=2;
break;
}
}
}
}
效果:
http://www.blueidea.com/articleimg/2009/11/7221/Sandy_10.swf
作者:
她。
时间:
2012-11-2 09:25
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5