|
GiGBiG, Member
Posted: 06 July 2012 04:58 PM Total Posts: 57
Hi,
I am trying to create a 3d table for a casino game, and I would need to put several clickable areas on it: the best way would be to use a single movieclip containing the areas representing the clickable areas: is it possible? The areas should animate (just change alpha) on mouseover too. I think this is possible using MovieMaterial, right?
I haven’t tried yet as I encountered a problem with MouseEvent3D: it doesn’t work! I enable a mesh (mouseEnabled) for MouseEvents, I assign a MouseEvent3D listener but nothing happens.
Just the regular MouseEvent works, and it tells me I am clicking a Sprite, I think the Main class (that is the only Sprite on stage), but this shouldn’t be a problem, as it shouldn’t cover the 3dscene, right?
What is the problem?
|
Richard Olsson, Administrator
Posted: 06 July 2012 09:09 PM Total Posts: 1192
[ # 1 ]
First of all, what version of Away3D are you using? You’ve indicated that you’re using 4.0, but there’s no MovieMaterial in Away3D 4.0.
If you are indeed using 4.0, you need to reconsider a little bit because the MovieMaterial approach of drawing the contents of a MovieClip to a bitmap and using that as a texture doesn’t transfer well to the GPU. At least not if it’s supposed to be animated and interactive.
Consider laying out plane meshes in the places where you want your clickable areas, and just use the same texture as the background. Fading them in (by animating their material’s alpha property) should be efficient enough.
Regarding your mouse issue, what version of the codebase are you using? Consider switching over to the release branch from the GitHub repository, which contains a recent refactor of the mouse picking system that should work better than the old one.
|
GiGBiG, Member
Posted: 07 July 2012 12:09 AM Total Posts: 57
[ # 2 ]
Yes, Away3D 4, I don’t remember now if I picked the local libraries or the GitHub ones, I will check on Monday, but I think I will refresh them anyway
I started using Away3D/Physics about 2 weeks ago, and it is the first time I use a 3D library to code, even if I have a good background in 3D graphic, so don’t be pissed off if I will ask stupid questions, please
The single meshes approach for the selectable areas was my first idea, but I excluded it because it would be (it will be) a pain in the ass if they ask me to modify the layout of the table. Anyway if you tell me it is the right choice I will go for it.
|
GiGBiG, Member
Posted: 09 July 2012 01:16 PM Total Posts: 57
[ # 3 ]
I have updated Away3D libs with the latest ones from GitHub, but the problem persists: MouseEvent3D does not work. I have put the code in a zip: the main class is as follows
package { import flash.display.Sprite; import flash.events.Event; import flash.geom.Vector3D; import flash.utils.getQualifiedClassName; import away3d.core.raycast.MouseHitMethod; import away3d.entities.Mesh; import away3d.core.base.Geometry; import away3d.cameras.lenses.OrthographicLens; import away3d.containers.View3D; import away3d.lights.DirectionalLight; import away3d.materials.lightpickers.StaticLightPicker; import away3d.materials.TextureMaterial; import away3d.textures.BitmapTexture; import away3d.events.MouseEvent3D; import models.fichemodel.FicheModel; public class Main extends Sprite { private var _view : View3D; private var _sunLight : DirectionalLight; private var _lightPicker : StaticLightPicker; private var fiche : Mesh; // a fiche [Embed(source="../embeds/ficheBase.png")] private static const ficheBaseSkin : Class; public function Main() { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null) : void { removeEventListener(Event.ADDED_TO_STAGE, init); stage.frameRate = 30; initView(); initFiches(); stage.addEventListener(Event.ENTER_FRAME, updateRender); stage.dispatchEvent(new Event(Event.RESIZE)); } private function initView(): void { _view = new View3D(); _view.antiAlias = 2; this.addChild(_view); _sunLight = new DirectionalLight(0, -100, -50); _sunLight.color = 0xfffdc5; _sunLight.ambient = 0.5; _view.scene.addChild(_sunLight); _lightPicker = new StaticLightPicker([_sunLight]); _view.camera.lens = new OrthographicLens(1670); _view.camera.lens.far = 3500; _view.camera.position = new Vector3D(-550, 2000, -1430); _view.camera.rotationY = 10; _view.camera.rotationX = 52; } private function initFiches() : void { var ficheGeometry: Geometry = new FicheModel().meshes[0].geometry; ficheGeometry.scale(300); var t: TextureMaterial = new TextureMaterial(new BitmapTexture(new ficheBaseSkin().bitmapData)); t.specular = 0; t.lightPicker = _lightPicker; fiche = new Mesh(ficheGeometry, t); fiche.mouseEnabled = true; _view.scene.addChild(fiche); //fiche.mouseHitMethod = MouseHitMethod.MESH_ANY_HIT; fiche.addEventListener(MouseEvent3D.MOUSE_UP, traceSomething); fiche.addEventListener(MouseEvent3D.MOUSE_OVER, traceSomething); } private function updateRender(e: Event = null): void { _view.render(); } private function traceSomething(e: MouseEvent3D): void { trace("FICHE"); trace(getQualifiedClassName(e.target)); } } }
I can’t find where the problem is…
File Attachments
test.zip (File Size: 272KB - Downloads: 170)
|
Fabrice Closier, Administrator
Posted: 09 July 2012 01:41 PM Total Posts: 1265
[ # 4 ]
By latest you probably mean “master”. As Richard suggested, you should update to “release” as several mouse issues were fixed. The “master” branch is actually Beta 4.0.
On git page, select “release”. This is the branch that will become “master” once we are officially 4.0. Note that you may need to update/change a few lines here and there.
Here a custom example of a MouseEvent3D.
The class has comments/doc depending the target for deployment. On IOS the underneath example would not be a good idea because it rely on PixelBender.
Note that by default you do not need to set the pickingCollider type.
m.mouseEnabled = true;
m.shaderPickingDetails = false;
m.pickingCollider = PickingColliderType.PB_FIRST_ENCOUNTERED;
m.addEventListener(MouseEvent3D.MOUSE_DOWN, doSomething);
|
GiGBiG, Member
Posted: 09 July 2012 02:15 PM Total Posts: 57
[ # 5 ]
Nice! Now it works! Thank you!
But, do I have to render all frames to intercept MouseEvent3Ds? If I remove the rendering on ENTER_FRAME MouseMove does not fire anymore.
Now I have to create all the table areas…
P.S.: do you use PixelBender3D?
|
Fabrice Closier, Administrator
Posted: 09 July 2012 03:39 PM Total Posts: 1265
[ # 6 ]
Yes, you need to render. Otherwize if you want to manage mousepicking on a still image, you can transform the bounds and project them in 2d from the last updated matrices. (see camera unproject/project) and rest is classical flash (bimapdata’s, rectangles. Whatever fits your project best).
Unless I’m mistaking, PB3D is more or less a dead egg…
|