MouseEvent over plane

Software: Away3D 4.x

parele, Jr. Member
Posted: 12 March 2013 04:47 AM   Total Posts: 43
Import Away3d.everything.*.

var 
plane = new Mesh(newPlaneGeometry(2500,2500,100,100,true),new TextureMaterial(Cast.bitmapTexture(groundMaterial))); 
plane.geometry.scaleUV(2525);
plane.castsShadows true;
plane.material.repeat true
plane
.mouseEnabled true

Above creates a plane, What im trying to do is get the mouse to grab on to closest vertex or on my over vertex of my mesh:

var vertex:Vector.<Number> = plane.geometry.subGeometries[0].vertexData


Anyway i get lost here: below is a picture of what im trying to achieve

 

   

parele, Jr. Member
Posted: 12 March 2013 01:33 PM   Total Posts: 43   [ # 1 ]

I realize i can get the vertex raw data but i dont have a clue how to translate it to the mouse position on the mesh

var index:Vector.<uint >  = plane.geometry.subGeometries[0].indexData;
var 
vertexData:Vector.<Number >  =  plane.geometry.subGeometries[0].vertexData;

for (var 
i:uint 0index.lengthi++)
{
 ind 
index[i] 3;

 
trace(vertex[ind] vertex[ind+1]vertex[ind 2]);

 

   

beers, Member
Posted: 12 March 2013 02:53 PM   Total Posts: 53   [ # 2 ]

I’ve used this technique to map a bounding box vertex list to screen space before - I assume it would work just as well for any vertex list.

yourMesh.sceneTransform.transformVectors(vertexlist,outputlist) where vertexlist is the vertex array from your example

view.project(outputlist…) go through the outputlist above and transform each vertex to screen space

beers

 

   

parele, Jr. Member
Posted: 12 March 2013 03:30 PM   Total Posts: 43   [ # 3 ]

I think i may understand, this is only a hobbie to me..
So far i have been looping example:

function moving_mouseOver_the_Plane(e:MouseEvent3D):void

for (var i:uint 0index.lengthi++)
{
 ind 
index[i] 3;
 if(
mymouse.position.==vertex[ind]){   anotherMesh.positi Vector3D(vertex[ind],vertex[ind+1],vertex[ind 2]);

 

 

   

parele, Jr. Member
Posted: 13 March 2013 12:18 AM   Total Posts: 43   [ # 4 ]

I cant get this to work, iv played around with this but i dont understand where the outputlist came from,

var gridOver = new WireframePlane(100,100,1,1,0xFF3C,2);
var 
plane = new Mesh(new PlaneGeometry(2500,2500,50,50,true),new TextureMaterial(Cast.bitmapTexture(groundMaterial)));
plane.geometry.scaleUV(2525);
plane.material.repeat true;
plane.mouseEnabled true;
plane.addEventListener(MouseEvent3D.MOUSE_DOWNMouseOverPlane);


var 
tiles_local;
var 
outputlist:Array = new Array(x,y,z)
var 
index:Vector.<uint >  = plane.geometry.subGeometries[0].indexData;
var 
vertex:Vector.<Number >  = plane.geometry.subGeometries[0].vertexData;

for (var 
i:uint 0index.lengthi++)
{
 ind 
index[i] 3;
 
vertexlist.push (vertex[ind] vertex[ind+1]vertex[ind 2]);
 
trace(vertex[ind] vertex[ind+1]vertex[ind 2]);
 
plane.sceneTransform.transformVectors(vertexlist,outputlist)
 
_container.project(outputlist)
}

function MouseOverPlane(e:MouseEvent3D):void
{  localPositi plane
.position ); 
 
 
tiles_local e.localPosition;//its a small plane Mesh  gridOver.positi plane mesh follows mouse
 
//Here i want mouse to tell me what vertex it hits or near
//either way i can use this,

By looking at the picture basically im trying to lock the green tile to the closest mouse position to the bigplane vertex along any x,z axis so when i place the item it will only be placed at the co-ordinates.

 

 

   

beers, Member
Posted: 13 March 2013 01:04 AM   Total Posts: 53   [ # 5 ]

outputlist is a Vector.<Number> array so you need to set it up that way:


var vertexlist:Vector.<Number >  = plane.geometry.subGeometries[0].vertexData;
var outputlist:Vector.<Number> = new <Number>[vertexlist.length];
plane.sceneTransform.transformVectors(vertexlist,outputlist);

now outputlist has all the transformed vertices. Use view.project on each vertex in that list in a loop , comparing the output to your mouse.x & mouse.y for the closest match. You’ll have to code the logic there.

Another technique is just do a racast, and find the face index you hit, and grab the vertices that way. Can’t help with that though, since im not an expert on away3d raycasting yet.

beers

 

   

parele, Jr. Member
Posted: 13 March 2013 04:34 AM   Total Posts: 43   [ # 6 ]

I appreciate the time you have giving me, i will get back to you soon with my outcome, thanks again

 

   

parele, Jr. Member
Posted: 13 March 2013 06:59 AM   Total Posts: 43   [ # 7 ]

Im doing something wrong here, my loop is giving me other values that have nothing to do with the vertices, iv attached an image:

var plane = new Mesh(new PlaneGeometry(500,500,20,20,true)
plane.geometry.scaleUV(2525);
plane.material.repeat true;
plane.mouseEnabled true;
plane.addEventListener(MouseEvent3D.MOUSE_DOWNhaha2);


var 
meshHolder:Array = new Array();
var 
vertexlist:Vector.<Number >  = plane.geometry.subGeometries[0].vertexData;
var 
outputlist:Vector.<Number> = new <Number>[vertexlist.length];
plane.sceneTransform.transformVectors(vertexlist,outputlist);
var 
index:Vector.<uint >  = plane.geometry.subGeometries[0].indexData;
var 
MeshHolder:Array = new Array();
var 
ind:uint 0;

for (var 
i:uint 0index.lengthi++)
{
 ind 
index[i] 1;
 
//trace(vertex[ind] , vertex[ind+1], vertex[ind + 2]);
 
  
var allLocations:Vector3D = new Vector3D(outputlist[ind+3],0,outputlist[ind+2]);
  var 
verticesPlane = new WireframePlane(100,100,1,1,0xFF3C,2);   
  
MeshHolder.push(verticesPlane);       verticesPlane.positi   
  MyView
.addChild(verticesPlane);
  
trace(outputlist[ind],outputlist[ind+1],outputlist[ind 2]);
// Think i need a loop inside this loop/

you will notice that my green planes (verticesPlane) are not correct over the mesh if everything is correct they should fill a Grid pattern over the whole mesh to represent where the vertices position are(x,y,z) on my plane

 

   

beers, Member
Posted: 13 March 2013 05:37 PM   Total Posts: 53   [ # 8 ]

This works for me. Snaps to the nearest vertex perfectly.

private var plane:Mesh;
private var 
dummy:Mesh;

private function 
initObjects():void
{
plane 
= new Mesh(new PlaneGeometry(5005002020true));
plane.mouseEnabled true;
plane.addEventListener(MouseEvent3D.MOUSE_DOWNtestDown);
scene.addChild(plane);
   
dummy=new Mesh( new CubeGeometry(3,3,3,1,1,1,true), new ColorMaterial0x00FF00) );
scene.addChild(dummy);
}

private function testDown(event:MouseEvent3D):void 

 
var dst:Number 1000;
 var 
idx:Number 0;
 var 
va:Vector3D;
 var 
vb:Vector3D = new Vector3D(stage.mouseXstage.mouseY0);
   
 var 
vertexlist:Vector.<Number> = plane.geometry.subGeometries[0].vertexData;
 var 
outputlist:Vector.<Number> = new Vector.<Number>(vertexlist.length);

 
plane.sceneTransform.transformVectors(vertexlistoutputlist);
   
 for (var 
c:Number 0outputlist.lengthc+=3)
 
{
  va 
view.project(new Vector3D(outputlist[c]outputlist[c 1]outputlist[c 2]));   
  
va.0;
  var 
tmp:Number Vector3D.distance(vavb);
  if (
tmp dst{ dst tmpidx c}   
}         dummy
.positi = new Vector3D(vertexlist[idx],vertexlist[idx+1],vertexlist[idx+2]);

 

   

parele, Jr. Member
Posted: 13 March 2013 11:50 PM   Total Posts: 43   [ # 9 ]

thank you, i think i have fixed it//

var vertexlist:Vector.<Number> = plane.geometry.subGeometries[0].vertexData;
 var 
outputlist:Vector.<Number> = new Vector.<Number>(vertexlist.length-1); // changed here

 
plane.sceneTransform.transformVectors(vertexlistoutputlist);
   
 for (var 
c:Number 0outputlist.length-2c+=1)// changed here
 
{
  va 
_view.project(new Vector3D(outputlist[c]0outputlist[c 2]));   //changed here 
  
va.0;
  var 
tmp:Number Vector3D.distance(vavb);
  if (
tmp dst{ dst tmpidx c}             dummy.positi Vector3D(vertexlist[idx],vertexlist[idx+1],vertexlist[idx+2]);
 
}
Thank you very much 

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X