Click doesn’t work on all the cube - only in its center

Software: Away3D 4.x

Fygo, Newbie
Posted: 21 April 2014 04:09 PM   Total Posts: 10

Hi everybody,

I have a cube in my scene. I would like to assign a click listener to it. This all works “fine” with one liiiittle problem - the cube is clickable only in its center area (let’s say an area of 100x100) If I click outside of this area, but still on the cube, nothing happens. The code I am using is this simple:

var texture:BitmapTexture = new BitmapTexture(new AntTexture().bitmapData);
var 
material:TextureMaterial = new TextureMaterial(texture);
cube = new Mesh(new CubeGeometry(400400400111false), material);
cube.mouseEnabled true;
cube.addEventListener(MouseEvent3D.CLICKcubeClickHandler);
cube.1500;
scene.addChild(cube);

....

private function 
cubeClickHandler(event:MouseEvent3D):void {
 navigateToURL
(new URLRequest("http://www.google.com"));

I have uploaded a picture that demonstrates the clickable area (yellow rectangle). All the rest of the cube does nothing. Why is that, what am I doing wrong? Thanks a lot!

 

   

Fygo, Newbie
Posted: 22 April 2014 05:45 PM   Total Posts: 10   [ # 1 ]

Example: http://tests.pixelhood.com/cube

   

gonchar, Newbie
Posted: 23 April 2014 11:36 PM   Total Posts: 7   [ # 2 ]

Which version of Away3D do you use?
I’ve tested your code with the latest version and it works well.

package {
 import away3d
.containers.View3D;
 
import away3d.entities.Mesh;
 
import away3d.events.MouseEvent3D;
 
import away3d.materials.ColorMaterial;
 
import away3d.primitives.CubeGeometry;

 
import flash.display.Sprite;
 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;
 
import flash.events.Event;

 public class 
TestClick extends Sprite {
  
private var _view:View3D;

  private var 
cube:Mesh;

  public function 
TestClick() {
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;

   
_view = new View3D();
   
addChild(_view);

   
cube = new Mesh(new CubeGeometry(400400400111false), new ColorMaterial(Math.random() * 0xffffff));
   
cube.mouseEnabled true;
   
cube.addEventListener(MouseEvent3D.CLICKcubeClickHandler);
   
cube.1500;
   
_view.scene.addChild(cube);

   
addEventListener(Event.ENTER_FRAME_onEnterFrame);
   
stage.addEventListener(Event.RESIZEonResize);
   
onResize();
  
}

  
private function cubeClickHandler(event:MouseEvent3D):void {
   cube
.material = new ColorMaterial(Math.random() * 0xffffff);
  
}

  
private function _onEnterFrame(e:Event):void {
   _view
.render();
  
}

  
private function onResize(event:Event null):void {
   _view
.width stage.stageWidth;
   
_view.height stage.stageHeight;
  
}
 }
   

Fygo, Newbie
Posted: 24 April 2014 04:11 PM   Total Posts: 10   [ # 3 ]

As far as I know I was using 4.1.6 (.as files, not swc). To be honest I cannot reproduce it anymore (I have changed to swc since then + proceeded with the project) but will try and post back if I find out something. Thanks for your reply!

   

Fygo, Newbie
Posted: 24 April 2014 05:06 PM   Total Posts: 10   [ # 4 ]

Sergey, I have just realized that this happens when I set

_view.camera.lens.far 0

Why is that? I get that nothing beyond the far plane of the frustrum should be rendered but the ray should still hit the front plane of the cube, shouldn’t it? Still it reacts only to the center part of the cube. I am a bit confused about this stuff…
Thanks!

EDIT: Oops, called you Sergey… well, I assume you are Sergey Gonchar, aren’t you?

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X