How to drag?

Software: Away3D 4.x

u6792345, Newbie
Posted: 04 September 2013 03:09 PM   Total Posts: 12

Hi, how to drag the model in this examples ?

package
{
 import away3d
.containers.*;
 
import away3d.controllers.*;
 
import away3d.debug.*;
 
import away3d.entities.*;
 
import away3d.events.*;
 
import away3d.library.assets.*;
 
import away3d.lights.*;
 
import away3d.loaders.*;
 
import away3d.loaders.misc.*;
 
import away3d.loaders.parsers.*;
 
import away3d.materials.*;
 
import away3d.materials.lightpickers.*;
 
import away3d.materials.methods.*;
 
import away3d.primitives.*;
 
import away3d.utils.*;
 
 
import flash.display.*;
 
import flash.events.*;
 
import flash.geom.*;
 
import flash.utils.*;
 
 
[SWF(backgroundColor="#000000"frameRate="30"quality="LOW")]
 
 
public class Basic_Load3DS extends Sprite
 {
  [Embed
(source="/../embeds/signature.swf"symbol="Signature")]
  
public static var SignatureSwf:Class;
  
  
[Embed(source="/../embeds/soldier_ant.jpg")]
  
public static var AntTexture:Class;
  
  
[Embed(source="/../embeds/soldier_ant.3ds",mimeType="application/octet-stream")]
  
public static var AntModel:Class;
  
  
[Embed(source="/../embeds/CoarseRedSand.jpg")]
  
public static var SandTexture:Class;
  
  private var 
_view:View3D;
  private var 
_cameraController:HoverController;
  
  private var 
_signature:Sprite;
  private var 
_signatureBitmap:Bitmap;
  
  private var 
_light:DirectionalLight;
  private var 
_lightPicker:StaticLightPicker;
  private var 
_direction:Vector3D;
  
  private var 
_groundMaterial:TextureMaterial;
  
  private var 
_loader:Loader3D;
  private var 
_ground:Mesh;
  
  private var 
_move:Boolean false;
  private var 
_lastPanAngle:Number;
  private var 
_lastTiltAngle:Number;
  private var 
_lastMouseX:Number;
  private var 
_lastMouseY:Number;
  
  public function 
Basic_Load3DS()
  
{
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
_view = new View3D();
   
_view.addSourceURL("srcview/index.html");
   
addChild(_view);
   
   
_view.camera.lens.far 2100;
   
   
_cameraController = new HoverController(_view.cameranull4520100010);
   
   
_light = new DirectionalLight(-1, -11);
   
_direction = new Vector3D(-1, -11);
   
_lightPicker = new StaticLightPicker([_light]);
   
_view.scene.addChild(_light);
   
   
Parsers.enableAllBundled();
   
   var 
assetLoaderContext:AssetLoaderContext = new AssetLoaderContext();
   
assetLoaderContext.mapUrlToData("texture.jpg", new AntTexture());
   
   
_groundMaterial = new TextureMaterial(Cast.bitmapTexture(SandTexture));
   
_groundMaterial.shadowMethod = new FilteredShadowMapMethod(_light);
   
_groundMaterial.lightPicker _lightPicker;
   
_groundMaterial.specular 0;
   
_ground = new Mesh(new PlaneGeometry(10001000), _groundMaterial);
   
_view.scene.addChild(_ground);
   
   
_loader = new Loader3D();
   
_loader.scale(300);
   
_loader.= -200;
   
_loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   
_loader.loadData(new AntModel(), assetLoaderContext);
   
_view.scene.addChild(_loader);
   
   
_signature = new SignatureSwf();
   
_signatureBitmap = new Bitmap(new BitmapData(_signature.width_signature.heighttrue0));
   
stage.quality StageQuality.HIGH;
   
_signatureBitmap.bitmapData.draw(_signature);
   
stage.quality StageQuality.LOW;
   
addChild(_signatureBitmap);
   
   
addChild(new AwayStats(_view));
   
   
addEventListener(Event.ENTER_FRAMEonEnterFrame);
   
stage.addEventListener(MouseEvent.MOUSE_DOWNonMouseDown);
   
stage.addEventListener(MouseEvent.MOUSE_UPonMouseUp);
   
stage.addEventListener(Event.RESIZEonResize);
   
onResize();
  
}
  
  
private function onEnterFrame(event:Event):void
  {
   
if (_move{
    _cameraController
.panAngle 0.3*(stage.mouseX _lastMouseX) + _lastPanAngle;
    
_cameraController.tiltAngle 0.3*(stage.mouseY _lastMouseY) + _lastTiltAngle;
   
}
   
   _direction
.= -Math.sin(getTimer()/4000);
   
_direction.= -Math.cos(getTimer()/4000);
   
_light.direction _direction;
   
   
_view.render();
  
}
  
  
private function onAssetComplete(event:AssetEvent):void
  {
   
if (event.asset.assetType == AssetType.MESH{
    
var mesh:Mesh event.asset as Mesh;
    
mesh.castsShadows true;
   
else if (event.asset.assetType == AssetType.MATERIAL{
    
var material:TextureMaterial event.asset as TextureMaterial;
    
material.shadowMethod = new FilteredShadowMapMethod(_light);
    
material.lightPicker _lightPicker;
    
material.gloss 30;
    
material.specular 1;
    
material.ambientColor 0x303040;
    
material.ambient 1;
   
}
  }
  
  
private function onMouseDown(event:MouseEvent):void
  {
   _lastPanAngle 
_cameraController.panAngle;
   
_lastTiltAngle _cameraController.tiltAngle;
   
_lastMouseX stage.mouseX;
   
_lastMouseY stage.mouseY;
   
_move true;
   
stage.addEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
  
  
private function onMouseUp(event:MouseEvent):void
  {
   _move 
false;
   
stage.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
 
  
private function onStageMouseLeave(event:Event):void
  {
   _move 
false;
   
stage.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
  
}
 
  
private function onResize(event:Event null):void
  {
   _view
.width stage.stageWidth;
   
_view.height stage.stageHeight;
   
_signatureBitmap.stage.stageHeight _signature.height;
  
}
 }

 

   

u6792345, Newbie
Posted: 06 September 2013 10:11 AM   Total Posts: 12   [ # 1 ]

Anyone know how to drag?

   

elemmiki, Newbie
Posted: 06 September 2013 02:34 PM   Total Posts: 10   [ # 2 ]

http://away3d.com/tutorials/Interactivity_and_Tweening
Take a look at that, it might help you out.

   

Avatar
Fabrice Closier, Administrator
Posted: 06 September 2013 05:26 PM   Total Posts: 1265   [ # 3 ]

There is a dedicated class to 3D drag stuff.
Its unexpected name: Drag3D.as smile
You can find it into the tools.utils package.

   

u6792345, Newbie
Posted: 07 September 2013 02:49 AM   Total Posts: 12   [ # 4 ]

Thanks for reply, but why when i run the drag3d.as, it’s got error “Error #2023: Class Drag3D$ must inherit from Sprite to link to the root.”
how to fix it?

   

Avatar
Fabrice Closier, Administrator
Posted: 08 September 2013 08:29 PM   Total Posts: 1265   [ # 5 ]

You need to instanciate the Drag3D class within your project.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X