, Jr. Member
Working from the Der Schmale Blog, here is a version of last summer’s ShallowWaterDemo migrated to the Dev API. I always try to upgrade this one with every change, not because it is the best tutorial code example,, but because it is one of the most impressive demos of Away3d capabiltiies.
package
{
import away3d.containers.View3D;
import away3d.core.math.Matrix3DUtils;
import away3d.debug.AwayStats;
import away3d.lights.LightBase;
import away3d.lights.PointLight;
// import away3d.materials.BitmapMaterial;
import away3d.materials.ColorMaterial;
import away3d.materials.TextureMaterial;
import away3d.materials.lightpickers.StaticLightPicker;
import away3d.materials.methods.BasicDiffuseMethod;
import away3d.materials.methods.EnvMapMethod;
import away3d.materials.methods.FogMethod;
// import away3d.materials.utils.CubeMap;
import away3d.primitives.Cube;
import away3d.primitives.Plane;
import away3d.primitives.SkyBox;
import away3d.textures.BitmapCubeTexture;
import away3d.textures.BitmapTexture;
import com.li.away3d.camera.MKSOCameraController;
import com.li.fluids.shallow.DisturbanceBrush;
import com.li.fluids.shallow.FluidDisturb;
import com.li.fluids.shallow.ShallowFluid;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.ColorTransform;
import flash.geom.Matrix3D;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.utils.Timer;
import uk.co.soulwire.gui.SimpleGUI;
// TODO: Finish native mouse implementation - waiting for resolution of mouse occlusion topic.
[SWF(width=“1024”, height=“576”, frameRate=“60”, backgroundColor=“0x000000”)]
public class ShallowWaterDemo extends Sprite
{
// // Image used as height info for the terrain (generated in prefab).
// [Embed(source=“terrainPerlin1.jpg”)]
// private var HeightMapAsset:Class;
// Environment map.
[Embed(source=”../embeds/envMap/snow_positive_x.jpg”)]
private var EnvPosX : Class;
[Embed(source=”../embeds/envMap/snow_positive_y.jpg”)]
private var EnvPosY : Class;
[Embed(source=”../embeds/envMap/snow_positive_z.jpg”)]
private var EnvPosZ : Class;
[Embed(source=”../embeds/envMap/snow_negative_x.jpg”)]
private var EnvNegX : Class;
[Embed(source=”../embeds/envMap/snow_negative_y.jpg”)]
private var EnvNegY : Class;
[Embed(source=”../embeds/envMap/snow_negative_z.jpg”)]
private var EnvNegZ : Class;
// Liquid image assets.
[Embed(source=”../embeds/assets.swf”, symbol=“ImageClip”)]
private var ImageClip : Class;
[Embed(source=”../embeds/assets.swf”, symbol=“ImageClip1”)]
private var ImageClip1 : Class;
[Embed(source=”../embeds/assets.swf”, symbol=“ImageClip2”)]
private var ImageClip2 : Class;
// Signature asset.
[Embed(source=”../embeds/assets.swf”, symbol=“AwaySignature”)]
private var AwaySignature : Class;
// Disturbance brushes.
[Embed(source=”../embeds/assets.swf”, symbol=“Brush1”)]
private var Brush1 : Class;
[Embed(source=”../embeds/assets.swf”, symbol=“Brush2”)]
private var Brush2 : Class;
[Embed(source=”../embeds/assets.swf”, symbol=“Brush3”)]
private var Brush3 : Class;
[Embed(source=”../embeds/assets.swf”, symbol=“Brush4”)]
private var Brush4 : Class;
[Embed(source=”../embeds/assets.swf”, symbol=“Brush5”)]
private var Brush5 : Class;
[Embed(source=”../embeds/assets.swf”, symbol=“Brush6”)]
private var Brush6 : Class;
public var mouseBrushStrength : Number = 5;
public var rainBrushStrength : Number = 10;
public var mouseBrushLife : uint = 0;
public var fluid : ShallowFluid;
private var _view : View3D;
private var _cameraController : MKSOCameraController;
private var _plane : Plane;
private var _pressing : Boolean;
private var _light : LightBase;
private var _dropTmr : Timer;
private var _fluidDisturb : FluidDisturb;
private var _cubeMap : BitmapCubeTexture; // CubeMap;
public var brushClip1 : Sprite;
public var brushClip2 : Sprite;
public var brushClip3 : Sprite;
public var brushClip4 : Sprite;
public var brushClip5 : Sprite;
public var brushClip6 : Sprite;
public var brushClips : Array;
private var _activeMouseBrushClip : Sprite;
private var _rainBrush : DisturbanceBrush;
private var _imageBrush : DisturbanceBrush;
private var _mouseBrush : DisturbanceBrush;
private var _liquidShading : Boolean = true;
private var _showingLiquidImage : Boolean;
private var _showingLiquidImage1 : Boolean;
private var _showingLiquidImage2 : Boolean;
private var _gui : SimpleGUI;
private var _rain : Boolean;
private var _inverse : Matrix3D = new Matrix3D();
private var _projX : Number, _projY : Number;
public var hx : Number, hy : Number, hz : Number;
private var _min : Number;
private var _max : Number;
private var _colorMaterial : ColorMaterial;
private var _liquidMaterial : ColorMaterial;
public function ShallowWaterDemo() : void
{
// Init stage.
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.frameRate = 60;
// Init 3D core.
_view = new View3D();
addChild(_view);
// Show Away3D stats.
var stats : AwayStats = new AwayStats(_view);
stats.x = stage.stageWidth - stats.width;
addChild(stats);
// Signature.
var sig : Sprite = new AwaySignature() as Sprite;
sig.y = stage.stageHeight;
sig.useHandCursor = sig.buttonMode = true;
sig.getChildByName(“awayHit”).addEventListener(MouseEvent.CLICK, logoClickHandler);
sig.getChildByName(“liHit”).addEventListener(MouseEvent.CLICK, liClickHandler);
sig.getChildByName(“davidHit”).addEventListener(MouseEvent.CLICK, davidClickHandler);
addChild(sig);
// Init camera controller.
_view.camera.z = -250;
_view.camera.y = 200;
_view.camera.lens.far = 5000000;
_view.backgroundColor = 0x000000;
s
_cam