sandy.materials.Appearance;
sandy.materials.attributes.LightAttributes;
sandy.materials.attributes.LineAttributes;
sandy.materials.attributes.MaterialAttributes;
sandy.materials.ColorMaterial;
sandy.materials.Material;
- package
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.filters.ColorMatrixFilter;
- import sandy.core.Scene3D;
- import sandy.core.scenegraph.Camera3D;
- import sandy.core.scenegraph.Group;
- import sandy.core.scenegraph.Sprite3D;
- import sandy.materials.Appearance;
- import sandy.materials.attributes.LightAttributes;
- import sandy.materials.attributes.LineAttributes;
- import sandy.materials.attributes.MaterialAttributes;
- import sandy.materials.ColorMaterial;
- import sandy.materials.Material;
- import sandy.primitive.Box;
- public class Example002 extends Sprite
- {
- // 宣告3D場景及攝影機
- private var scene:Scene3D;
- private var camera:Camera3D;
- public function Example002()
- {
- camera = new Camera3D(300, 300);
- camera.z = -400;
- var root:Group = createScene();
- scene = new Scene3D("scene", this, camera, root);
- addEventListener(Event.ENTER_FRAME, enterFrameHandler);
- }
- private function createScene():Group
- {
- var g:Group = new Group();
- var box:Box = new Box("box", 100, 100, 100);
- // 產生材質屬性 MaterialAttributes
- // MaterialAttributes 可以擁有多個參數
- // 但每個參數都必需實作IAttributes這個介面
- // 而在 Sandy3D中,已經有3個類別實作了這個介面:
- // LineAttributes - 線屬性,其參數分別為厚度、顏色及透明度
- // LightAttributes- 燈光屬性,其參數分別為是否套用亮度設定及亮度的大小
- // 其值介於`0 ~ 1
- var materalAttr:MaterialAttributes = new MaterialAttributes(
- new LineAttributes(0.5, 0x2111BB, 0.4),
- new LightAttributes(true, 0.1)
- );
- // 產生色彩材質,並設定其屬性
- // 其參數分別為顏色、透明度及材質屬性
- var material:Material = new ColorMaterial(0xFFCC33, 1, materalAttr);
- // 設定此材質是否受外來光線影響
- material.lightingEnable = true;
- // 產生顯示物件的外觀物件
- // 其參數為材質,但可設定正面材質與背面材質
- var app:Appearance = new Appearance(material);
- // 將外觀物件套用到顯示物件 box
- box.appearance = app;
- box.rotateX 30;
- box.rotateY = 30;
- g.addChild(box);
- return g;
- }
- private function enterFrameHandler(evt:Event):void
- {
- scene.render();
- }
- }
- }
產出:
程式碼出處:http://www.flashsandy.org/tutorials/3.0/sandy_cs3_tut02
沒有留言:
張貼留言