away3d4.0 基础demo一则

学3d其实是一件简单的事情,通过一个星期的学习,我了解了下面的几个概念后,就可以上手做东西了,东西很简单,使用away3d做的。但是麻雀虽小五脏俱全。给大家展示一下。


1.视口
2.相机
3.基础模型:立方体,球,圆锥
4.光照:
5.材质:

package
{
import away3d.containers.ObjectContainer3D;
import away3d.containers.View3D;
import away3d.lights.DirectionalLight;
import away3d.lights.PointLight;
import away3d.materials.BitmapMaterial;
import away3d.materials.ColorMaterial;
import away3d.materials.DefaultMaterialBase;
import away3d.materials.SegmentMaterial;
import away3d.primitives.Cube;

import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Vector3D;

[SWF(width='500',height='500',frameRate="60")]
public class Main extends Sprite
{
private var view:View3D = new View3D();
private var cube:Cube;
[Embed(source='embeds/crossColor.jpg')]
private var IImage:Class;

public function Main()
{
this.addEventListener(Event.ADDED_TO_STAGE,init);
}

private function init(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE,init);

this.stage.scaleMode = 'noScale';
this.stage.align = 'top_left';

view.width = 300;
view.height = 300;
view.x = 100;
view.y = 100;
view.backgroundColor = 0xcccccc;
this.addChild(view);

var light:DirectionalLight = new DirectionalLight();
light.x = -1000;
light.y = 1000;
light.z = -1000;
var material:BitmapMaterial = new BitmapMaterial(new IImage().bitmapData);
material.lights = [light];

cube = new Cube(material,200,200,200);
view.scene.addChild(cube);
view.scene.addChild(light);

this.addEventListener(Event.ENTER_FRAME, _handleEnterFrame);
}

private function _handleEnterFrame(ev : Event) : void
{
cube.rotationX += 0.5;
cube.rotationY += 0.5;
cube.rotationZ += 0.5;
view.render();
}
}
}



你可能感兴趣的:(demo)