View3D blocks MouseEvents

Software: Away3D 4.x

GiGBiG, Member
Posted: 02 August 2012 03:14 PM   Total Posts: 57

Hi, I am still working on the dice game, and I am now adding the player interface, a toolbar.

The structure is as follows:
Main class Client (a Sprite)
View3D with the selectable areas is addedChild to Client’s stage
GameUI is a container movieclip for 2D interface, with pushable toolbar

Now:
- if I addChild GameUI to stage MouseEvents work, but prevents MouseEvent3D from working
- if I addChild GameUI to the Client main class MouseEvents do not work anymore, but MouseEvent3Ds work

I need that both 3D selectable areas and toolbar are interactive at the same time.
I have a big problem…

I have just read in another topic that Away3D adds an invisible layer for MouseEvent3D detection, and that addChild order for 3D and 2D matters (even if 3D should stay behind everything): this is a very big problem, because a lot of the games I will have to create have 3D interactive content behind a 2D interactive interface

   

Richard Olsson, Administrator
Posted: 02 August 2012 05:13 PM   Total Posts: 1192   [ # 1 ]

As mentioned in another thread (probably the one you’re referring to) the fact that display objects steal mouse input from View3D even though they’re disabled for mouse-input is a bug. It has been logged, and will be fixed ASAP.

You can track it’s progress here:
https://github.com/away3d/away3d-core-fp11/issues/378

 

   

Avatar
Alejandro Santander, Administrator
Posted: 08 August 2012 04:04 PM   Total Posts: 414   [ # 2 ]

Hey, I had a look at this and it seems to me that the current behaviour is the expected behaviour - if a 2d sprite is over the view and is mouseEnabled, it “steals” events from the 3d view and causes rolls from one to the other ( 2d element to 3d element ), if the 2d element is not mouse enabled, the 3d view catches all events.

 

   

GiGBiG, Member
Posted: 29 October 2012 04:58 PM   Total Posts: 57   [ # 3 ]

Any progress on this issue?

 

   

GiGBiG, Member
Posted: 30 October 2012 10:57 AM   Total Posts: 57   [ # 4 ]

Here it is, a simple test to show the problem.

On stage I have the 3D interactive model and overlay2D above it.
In overlay2D I have a Sprite containing a red BMP that partly covers the 3D model: the Sprite is mouse-disabled, but the overlay2D still obstructs the interactivity in the area of the red bitmap
I should avoid to mouse-disable the whole overlay2D, as it could contain interactive elements.

 

File Attachments
overlay_test.zip  (File Size: 347KB - Downloads: 303)
   

Avatar
oladitan, Member
Posted: 20 August 2014 03:37 PM   Total Posts: 71   [ # 5 ]
GiGBiG - 02 August 2012 03:14 PM

Hi, I am still working on the dice game, and I am now adding the player interface, a toolbar.

The structure is as follows:
Main class Client (a Sprite)
View3D with the selectable areas is addedChild to Client’s stage
GameUI is a container movieclip for 2D interface, with pushable toolbar

Now:
- if I addChild GameUI to stage MouseEvents work, but prevents MouseEvent3D from working
- if I addChild GameUI to the Client main class MouseEvents do not work anymore, but MouseEvent3Ds work

I need that both 3D selectable areas and toolbar are interactive at the same time.
I have a big problem…

I have just read in another topic that Away3D adds an invisible layer for MouseEvent3D detection, and that addChild order for 3D and 2D matters (even if 3D should stay behind everything): this is a very big problem, because a lot of the games I will have to create have 3D interactive content behind a 2D interactive interface

Hi GiGBiG what seemed to work for me was to change the index of the View3D:

stage.setChildIndex(view,0); 

 

   

GiGBiG, Member
Posted: 20 August 2014 05:26 PM   Total Posts: 57   [ # 6 ]

Hi oladitan!
Thank you for your reply, but I fixed the problem… at the end of 2012, I don’t even remember how, maybe it was an Away3D bug-fix, maybe I changed the index as you suggested.

But… the method you suggest puts the view3D in the deepest level of the stage, I am pretty sure that in the old Away3Ds this caused the mouse 2D/3D conflict.

 

   

Avatar
oladitan, Member
Posted: 21 August 2014 02:53 PM   Total Posts: 71   [ # 7 ]
GiGBiG - 20 August 2014 05:26 PM

Hi oladitan!
Thank you for your reply, but I fixed the problem… at the end of 2012, I don’t even remember how, maybe it was an Away3D bug-fix, maybe I changed the index as you suggested.

But… the method you suggest puts the view3D in the deepest level of the stage, I am pretty sure that in the old Away3Ds this caused the mouse 2D/3D conflict.

Ok. I have run into the same problem then. How do you suppose That I fix it without compromising 2D or 3D mouse detection? thanks.

 

   

Avatar
oladitan, Member
Posted: 21 August 2014 02:56 PM   Total Posts: 71   [ # 8 ]
GiGBiG - 20 August 2014 05:26 PM

Hi oladitan!
Thank you for your reply, but I fixed the problem… at the end of 2012, I don’t even remember how, maybe it was an Away3D bug-fix, maybe I changed the index as you suggested.

But… the method you suggest puts the view3D in the deepest level of the stage, I am pretty sure that in the old Away3Ds this caused the mouse 2D/3D conflict.

actually there is not conflict. Thanks.

 

   

GiGBiG, Member
Posted: 21 August 2014 03:22 PM   Total Posts: 57   [ # 9 ]

Which A3D version are you using? I found the problem when compiling with… maybe 4.0.1 or something like that. It was one of the first v4 releases.

 

   

GiGBiG, Member
Posted: 03 September 2014 10:14 AM   Total Posts: 57   [ # 10 ]

I can’t find the 3D model, please can you specify a path to view one?
Anyway… which version of Away3D are you using?

 

   

Shaedo, Newbie
Posted: 25 February 2015 01:15 AM   Total Posts: 9   [ # 11 ]

The problem still persists… but here is what’s happening…

Richard Olsson - 02 August 2012 05:13 PM

As mentioned in another thread (probably the one you’re referring to) the fact that display objects steal mouse input from View3D even though they’re disabled for mouse-input is a bug. It has been logged, and will be fixed ASAP.

You can track it’s progress here:
https://github.com/away3d/away3d-core-fp11/issues/378

Unfortunately this was closed without being solved as no-one was able to isolate the issue. I’ve posted an example on Github now (on the closed thread) but I thought I’d post it here for people, so they can understand the error if it happens to them and they are searching for a solution:

It’s probably easier to just run the standalone code which demonstrates the error - than to understand my explanation, but in a nutshell if you have the following:

1) 2dContainer.mouseEnabled==true;
2) 2dcontainedObject.mouseEnabled=false;
3) container added AFTER the ‘view’
4) now 2dcontainedObject stops the ‘view’ receiving mouse events

....For me I want to add 2D labels to some 2D menu buttons, but not have the labels interfere with interacting with 3D objects. My workarounds for this are getting quite a bit messy, so any elegant solutions welcome. In the meantime I’m adding things to the stage that really shouldn’t be there :(

package
{
    import away3d
.containers.View3D;
 
import away3d.containers.ObjectContainer3D;
    
import away3d.entities.Mesh;
    
import away3d.materials.ColorMaterial;
    
import away3d.primitives.*;
 
import away3d.lights.*; //Pointlight
 
import away3d.materials.lightpickers.StaticLightPicker//
    
import flash.display.*;
    
import flash.events.*;
 
import flash.geom.*;
 
import flash.text.TextField;
  
import away3d.events.MouseEvent3D;
 
    public class 
Main extends Sprite
    {
        
private var view:View3D;
  private var 
lightPicker:StaticLightPicker;
  private var 
directionalLight:DirectionalLight;
  private var 
sphereMesh:Mesh
  private var 
containedObject:TextField;
  private var 
container1:Sprite// added before the view
  
private var container2:Sprite// added after the view
  
private var container3:Sprite// added after the view AND mouseEnabled==false;
  
        
public function Main():void
        {
   container1
=new Sprite();// container1.mouseEnabled=true;
   
container2=new Sprite();// container2.mouseEnabled=true;
   
container3=new Sprite(); container3.mouseEnabled=false;
   
   
containedObject=createTextField('added to stage before the view - works fine',10,10,0x0000aa);
   
addChild(containedObject);

   
containedObject=createTextField('added to a container - container added BEFORE the view - works fine',200,10,0x00aa00);
   
container1.addChild(containedObject); 
   
   
addChild(container1);
   
            
view=new View3D();
   
view.camera.z=-1000;
            
addChild(view);
   
   
addChild(container2);
   
addChild(container3);
   
   
containedObject=createTextField('added to stage after the view - works fine',10,150,0xaaaa00);
   
container1.addChild(containedObject); 
   
   
containedObject=createTextField('added to a container - container added AFTER the view - FAIL',200,150,0xaa0000);
   
container1.addChild(containedObject); 
   
   
containedObject=createTextField('added to a container - container added AFTER the view - container.mouseEnabled=false. Works Fine',10,300,0x00aa00);
   
container3.addChild(containedObject); 
   
   
directionalLight=new DirectionalLight();
   
lightPicker=new StaticLightPicker([directionalLight]);
   
view.scene.addChild(directionalLight);
   
   
initSphere(); // nothing to do with the example, just to show everything is working
   
addEventListener(Event.ENTER_FRAME,render3D,false,50,true);   
   
view.addEventListener(MouseEvent.MOUSE_DOWN,viewMouseDown,false,50,true);   
   
stage.addEventListener(MouseEvent.MOUSE_DOWN,stageMouseDown,false,50,true); /*Begin Drag/Rotate*/
   
sphereMesh.addEventListener(MouseEvent.MOUSE_DOWN,sphereMouseDown,false,50,true); 
   
containedObject.addEventListener(MouseEvent.MOUSE_DOWN,textMouseDown,false,50,true); 
  
}
  
function initSphere():void
  {
            
var sphereGeometry:SphereGeometry=new SphereGeometry(50);
            var 
sphereMaterial:ColorMaterial=new ColorMaterial(0x00FF00,1);
   
sphereMaterial.lightPicker=lightPicker;
            
sphereMesh=new Mesh(sphereGeometrysphereMaterial);
   
sphereMesh.mouseEnabled=true;
   
sphereMesh.addEventListener(MouseEvent3D.MOUSE_DOWN,sphereMouseDown);
   
sphereMesh.name='sphereMesh';
            
view.scene.addChild(sphereMesh); 
        
}
  
function createTextField(s:String,_x:int,_y:int,c:int):TextField
  {
   
var t:TextField=new TextField();
   
t.mouseEnabled=false;
   
t.textColor=0xFFFFFF;
   
t.text=s;
   
t.x=_x;
   
t.y=_y;
   
t.wordWrap=true;
   
t.multiline=true;
   
t.background=true;
   
t.backgroundColor=c;
   return(
t);
  
}
  
private function render3D(e:Event):void
  {
//render view, rotate/drag objects if mouse is down
   
view.render();
  
}
  
private function viewMouseDown(e:MouseEvent):void
  {
   trace
('view MouseDown');   
  
}
  
private function stageMouseDown(e:MouseEvent):void
  {
   trace
('stage MouseDown');   
  
}
  
private function textMouseDown(e:MouseEvent):void /*Note never called as all text fields are mouseEnabled=false*/
  
{
    trace
('text MouseDown');   
  
}
  
private function sphereMouseDown(e:MouseEvent3D):void
  {
   trace
(e.target.name ' MouseDown');   
  
}
    }

 

   

Sean72, Newbie
Posted: 08 March 2015 09:06 PM   Total Posts: 28   [ # 12 ]

Whether or not this is a bug, I found I can control it via

stage.setChildIndexmyView3D); // use this to lower your 3D stage behind all 2D layers

stage.setChildIndexmyView3D10 ); // use this to raise your 3D stage above e.g. the first 10 2D layers 

So, if you keep track of all your layers, you could place your non-feedback HUD e.g. at index = 0, then your View3D at index = 1, then your interactive 2D control button layer at index = 2.

I also read elsewhere that you can e.g. place an object on the top of its parent’s layer using this statement

myButton.parent.setChildIndex(myButtonmyButton.parent.numChildren 1); 

Away3D is awesome, but it not always intuitive.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X