package
{
import away3d.containers.View3D;
import away3d.entities.Mesh;
import away3d.events.MouseEvent3D;
import away3d.lights.DirectionalLight;
import away3d.lights.PointLight;
import away3d.materials.ColorMaterial;
import away3d.materials.TextureMaterial;
import away3d.materials.lightpickers.StaticLightPicker;
import away3d.materials.methods.FilteredShadowMapMethod;
import away3d.primitives.CubeGeometry;
import away3d.primitives.PlaneGeometry;
import away3d.utils.Cast; import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event; /**
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2015-9-23 下午3:27:28
*
*/
[SWF(width='800',height='600',frameRate="60", backgroundColor="0x000000")]
public class Away3dLight extends Sprite
{ //floor的贴图图片
[Embed(source = "assets/1.jpg")]
private static var FloorMaterial:Class;
//声明视口
private var _view:View3D;
//声明平面几何对象
private var _planeGeometry:PlaneGeometry;
//声明平面对象的贴图
private var _planeMaterial:TextureMaterial;
//声明平面几何对象的容器
private var _planeMesh:Mesh;
//控制旋转方向的变量
private var _direction:Boolean;
//声明cube对象
private var _cubeGeometry:CubeGeometry;
//声明cube对象容器
private var _cubeMesh:Mesh; //灯光
private var _directionalLight:DirectionalLight;
private var _pointLight:PointLight;
//灯光容器
private var _light:StaticLightPicker; public function Away3dLight()
{
if (stage) {
init();
}else {
this.addEventListener(Event.ADDED_TO_STAGE, init);
} }
private function init(e:Event=null):void {
//trace("舞台初始化完成!");
//设置舞台缩放模式和对齐方式
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
this.removeEventListener(Event.ADDED_TO_STAGE, init); //实例化视口
_view = new View3D();
addChild(_view);
//设置抗锯齿参数
_view.antiAlias = 6; //实例化一个长宽都是300的平面对象
_planeGeometry = new PlaneGeometry(300, 300);
//实例化贴图对象
_planeMaterial = new TextureMaterial(Cast.bitmapTexture(FloorMaterial));
//实例化平面几何对象的容器,第一个参数是平面几何对象,第二个参数是贴图数据
_planeMesh = new Mesh(_planeGeometry, _planeMaterial);
//设置容器可交互
_planeMesh.mouseEnabled = true;
//容器侦听鼠标点击事件
_planeMesh.addEventListener(MouseEvent3D.CLICK, clickHandler); //将容器添加到视口的场景中
_view.scene.addChild(_planeMesh); _cubeGeometry = new CubeGeometry();
_cubeMesh = new Mesh(_cubeGeometry, new ColorMaterial(0xcccccc));
_cubeMesh.mouseEnabled = true;
_cubeMesh.y = 150;
_cubeMesh.z = -40;
_view.scene.addChild(_cubeMesh); //添加平行光源
_directionalLight = new DirectionalLight();
_directionalLight.diffuse = .8;
_directionalLight.ambient = .3;
_directionalLight.castsShadows = true; //添加点光源
_pointLight = new PointLight();
_pointLight.ambient = 0.4;
//_pointLight.diffuse = 10; //实例化灯光容器
_light = new StaticLightPicker([_directionalLight,_pointLight]); //给地面添加阴影效果
_planeMaterial.shadowMethod = new FilteredShadowMapMethod(_directionalLight); //给两个模型的材质添加灯光
_planeMesh.material.lightPicker = _light;
_cubeMesh.material.lightPicker = _light; //将灯光添加到场景
_view.scene.addChild(_directionalLight); //设置摄像机的位置
_view.camera.z = -400;
_view.camera.y = 200; //可以把这个值改成1试试看,这样可以有更加直观的感受
//_view.camera.x = 90;
//设置摄像机始终指向平面
_view.camera.lookAt(_planeMesh.position);
//_view.camera.lookAt(new Vector3D()); this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(Event.RESIZE, onResize);
onResize();
} private function clickHandler(e:MouseEvent3D):void {
//鼠标点击变换运动方向
_direction = !_direction;
} private function onResize(e:Event = null):void {
//调整视口尺寸以适应新的窗口大小
_view.width = stage.stageWidth;
_view.height = stage.stageHeight;
} private function onEnterFrame(e:Event):void {
//判断方向旋转
_cubeMesh.rotationX += 1;
_cubeMesh.rotationY += 1;
if (!_direction) {
_planeMesh.rotationY += 1;
}else {
_planeMesh.rotationY -= 1;
}
//渲染3D世界
_view.render();
} }
}

[ActionScript 3.0] Away3D 灯光的使用的更多相关文章

  1. [ActionScript 3.0] Away3D 官网实例

    /* Dynamic tree generation and placement in a night-time scene Demonstrates: How to create a height ...

  2. [ActionScript 3.0] Away3D 非skybox的全景例子

    package { import away3d.containers.View3D; import away3d.controllers.HoverController; import away3d. ...

  3. [ActionScript 3.0] Away3D 天空盒(skybox)例子2

    所谓skybox就是六个面即六张图能够无缝的拼成一个正方体的盒子. package { import away3d.cameras.Camera3D; import away3d.cameras.le ...

  4. [ActionScript 3.0] Away3D 天空盒(skybox)例子

    /* SkyBox example in Away3d Demonstrates: How to use a CubeTexture to create a SkyBox object. How to ...

  5. [ActionScript 3.0] Away3D 旋转效果

    package { import away3d.containers.View3D; import away3d.entities.Mesh; import away3d.events.MouseEv ...

  6. ActionScript 3.0入门:Hello World、文件读写、数据存储(SharedObject)、与JS互调

    近期项目中可能要用到Flash存取数据,并与JS互调,所以就看了一下ActionScript 3.0,现把学习结果分享一下,希望对新手有帮助. 目录 ActionScript 3.0简介 Hello ...

  7. ActionScript 3.0 for the Lunder Algorithm

    package com.feiruo.Calendar.LunderCalendar { /* *@ClassName: package:com.feiruo.Calendar.LunderCalen ...

  8. [转]ActionScript 3.0入门:Hello World、文件读写、数据存储(SharedObject)、与JS互调

    本文转自:http://www.cnblogs.com/artwl/p/3396330.html 近期项目中可能要用到Flash存取数据,并与JS互调,所以就看了一下ActionScript 3.0, ...

  9. [ActionScript 3.0] AS3.0 动态加载显示内容

    可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...

随机推荐

  1. postfix

    http://www.postfix.org/ All programmers are optimists -- Frederick P. Brooks, Jr. 所有程序员都是乐天派

  2. unity, 查看.anim中的动画曲线(和帧)

    在场景里建一个gameObject,添加一个Animation组件,将.anim文件添加到Animation组件的Animations中,然后在Animation组件面板中选中.anim,然后 菜单- ...

  3. messagepcak 资料

    1,今天在hacknews上看到很多人对messagepack的争论.首先了解什么是MessagePack:MessagePack is a binary-based efficient object ...

  4. 决策树模型组合之(在线)随机森林与GBDT

    前言: 决策树这种算法有着很多良好的特性,比如说训练时间复杂度较低,预测的过程比较快速,模型容易展示(容易将得到的决策树做成图片展示出来)等.但是同时, 单决策树又有一些不好的地方,比如说容易over ...

  5. HTTP API 设计指南(中文版) restfull

    http://www.css88.com/archives/5121 目录 基础 总是使用TLS 在Accepts头中带上版本号 通过Etags支持缓存 用Request-Ids追踪请求 用Range ...

  6. C# 使用ffmpeg.exe进行音频转换完整demo

    今天在处理微信的开发接口时候,发现微信多媒体上传接口中返回的音频格式是amr.坑人的是现在大部分的web 播放器,不支持amr的格式播放.试了很多方法都不行. 没办法,只要找一个妥协的解决方案:将am ...

  7. 【jmeter】搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)

    一.环境准备: 1.JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.Jmeter:http://jme ...

  8. div的打开与关闭js

    <script type="text/javascript"> var BoxHeight=$('.t_c').css("height"); //$ ...

  9. (转)LitJson 遍历key

    本文转载自:http://blog.csdn.net/inlet511/article/details/47127579 用LitJson插件获取到的对象,如果想遍历对象中包含的子对象的key,可以用 ...

  10. 已跳过 'cache' -- 节点处于冲突状态

    svn resolved ./cache ./cache 为冲突文件路径“cache”的冲突状态已解决