dragging a mesh with arrow handles

Software: Away3D 4.x

hfeist, Jr. Member
Posted: 02 January 2013 07:14 PM   Total Posts: 37

I’m working on a game that asks the player to reassemble a sculpture that has fallen apart by dragging the sculpture’s sub meshes back to where they belong.

However I’m having difficulty understanding how to access the location of each mesh in the scene space.
What I’d like to do is attach arrows on each side of the mesh much like the way it is done in Prefab where elements may be moved on the axes in the scene by dragging on the arrows with the mouse.

I’ve tried, unsuccessfully, things like
arrow.x=mesh.x
arrow.position=mesh.position
arrow.position=mesh.sceneTransform.position

I could probably manage using drag3D but i feel players would find it much too awkward. Arrows seem more intuitive.

Any ideas?

If I can get this working I’ll most likely be back asking how to rotate the mesh with some curved arrows perhaps

   

rthompson, Newbie
Posted: 03 January 2013 10:36 PM   Total Posts: 9   [ # 1 ]

Having each piece as submeshes would make things more difficult..you’d need a custom dragging solution most likely.

If you separated each piece into its own mesh, you could just add it to a container, add the arrow meshes to the container as well, position the arrows appropriately.  Then create a Drag3D set the target to the container, add event listeners to each arrow and update the drag3d only when the arrows are clicked.  Remember you’ll need to set the Drag3D plane based on which arrow was manipulated XYZ.  Rotation would be more difficult.

I’d probably just skip the Drag3D and try to use simple mouse deltas to move, and that would also make rotation simple. The MouseEvent class has a scenePosition property, so you can get a start position, and then during a MOUSE_MOVE you can get the current scenePosition which I’d assume you’d need to cast a ray tangent to the same axis as the arrow..

   

hfeist, Jr. Member
Posted: 04 January 2013 04:03 PM   Total Posts: 37   [ # 2 ]

Thanks very much for your response.

rthompson - 03 January 2013 10:36 PM

...If you separated each piece into its own mesh, you could just add it to a container, add the arrow meshes to the container as well, position the arrows appropriately.

That’s precisely where I’m stuck. I can’t find the way to position the container directly over the mesh. It always appears somewhere else in the scene. I’m missing a basic bit of knowledge—the relationship between the mesh space and the scene space.

rthompson - 03 January 2013 10:36 PM

.
I’d probably just skip the Drag3D

I had expected that Drag3D would work but it’s Achilles heel, for me, is on MOUSE_UP where the dragging keeps on going when the mouse is not over the target when released. Need something like the old RELEASE,RELEASE_OUTSIDE.

rthompson - 03 January 2013 10:36 PM

.
I’d probably just skip the Drag3D and try to use simple mouse deltas to move, and that would also make rotation simple. The MouseEvent class has a scenePosition property, so you can get a start position, and then during a MOUSE_MOVE you can get the current scenePosition which I’d assume you’d need to cast a ray tangent to the same axis as the arrow..

This sounds attractive but I’m afraid I don’t understand the terminology—“mouse deltas”? Example?

 

   

Avatar
80prozent, Sr. Member
Posted: 04 January 2013 04:22 PM   Total Posts: 430   [ # 3 ]

Hi

to create a Objectcontainer as parent of a existing object do this:

var newCon:ObjectContainer3D = new ObjectContainer3D();
newCon.transform originalObject.transform;
newCon.addChild(originalObject);
originalObject.tranform = new Matrix3D(); 

with mousedelta he means the length of the mousemovement. in mathematics delta always stands for difference.
e.g. : mouseX1= mouse.x when mouse is clicked
      mouseX2= mouse.x when mouse is released
      mouseDeltaX = mouseX2 - mouseX1

hope that helps

 

 Signature 

sorry…i hope my actionscript is better than my english…

   

rthompson, Newbie
Posted: 04 January 2013 04:33 PM   Total Posts: 9   [ # 4 ]

The way I’ve described won’t work if your pieces are submeshes (which are contained in a Mesh). Split the submeshes out into their own Mesh objects, then add each piece to a container, as well as 3 arrow meshes…there is no positioning the container.

What I’d do is have a class that extends ObjectContainer3D; then add it to your scene:

public class SculpturePiece extends ObjectContainer3D 
{

public var xAxisArrow:Mesh;
public var 
yAxisArrow:Mesh;
public var 
zAxisArrow:Mesh;
public var 
sculpturePiece:Mesh;

public function 
SculpturePiece():void{

 create
/load arrow meshes here, and add them to this and position appropriately

 load sculpture piece 
and add them to this

 setup drag3d 
or mouse events on the arrow meshesbut have them target and manipulate this


}

You issue with Drag3D not “releasing”, sounds like you might not be using the drag3d.update() method properly?  You should be able to have a global variable like dragPiece:Boolean = false and then on MOUSE_DOWN (of the arrow) set it to true, and on MOUSE_UP (of the stage) set dragPiece to false.  Then in your loop only call drag3d.update() if dragPiece is true. 

I might be misunderstanding you though.

As for what I meant by the deltas bit.  Basically you just get the position of the mouse down and then use the distance from that to the current position to move your object.  Any of the Away3D examples where you can drag the camera around do this, albeit not in 3D.

 

   

hfeist, Jr. Member
Posted: 04 January 2013 10:58 PM   Total Posts: 37   [ # 5 ]

“MOUSE_UP (of the stage)” was what I needed to fix Drag3D.

Still digesting all the other suggestions…

   

hfeist, Jr. Member
Posted: 07 January 2013 08:50 PM   Total Posts: 37   [ # 6 ]
private function drag3DEnterFrame(e:Event):void
  {
   
if (dragging)
   
{
    drag3D
.plane=dragPlane;
    
    if(
currentPiece.x>600){
     currentPiece
.x=600;
    
}
    
if(currentPiece.x<-600){
     currentPiece
.x=-600;
    
}
    
if(currentPiece.y>600){
     currentPiece
.y=600;
    
}
    
if(currentPiece.y<50){
     currentPiece
.y=50;
    
}
    
if(currentPiece.z<0){
     currentPiece
.z=10;
    
}
    
if(currentPiece.z>600){
     currentPiece
.z=600;
    
}
    txtFld
.text=("x/y/z="+Math.round(currentPiece.x).toString()+"/"+Math.round(currentPiece.y).toString()+"/"+Math.round(currentPiece.z).toString())+"\n";
    
    
drag3D.updateDrag();
    
    
view.render();
   
}
  } 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X