Plane with Vertices Movement on touch

Hi All,

I have one plane with texture applied.My need is mouse drag of plane,plane shape should be change dynamically.i need only x and y axis vertices movement…

i dont want change size.With in that size plane shape should change depends on mouse drag…

Is anybody explain how to do???

Thanks

This is a bit tricky, so I’ve attached an example script. The first step is to detect the point in space where the touch contacts with the mesh. This is usually done with a physics raycast against the object’s collider, but there is also a very useful plane raycast which is more efficient and more suitable in this particular case. Next, you need to find the vertex closest to the clicked point. This is done by transforming the point into the object’s local space and then searching the mesh vertex array. Having found the right vertex, you just need to keep doing raycasts against the plane and moving the vertex to the new position each frame.

I suspect that this won’t do exactly what you need, but it should give you something to work from. Ask again if you need any help modifying the script.

363853–12639–$vertdrag_162.js (1.71 KB)

Its really very nice to seeing this type of reference code here.But now i am facing little bit difficulty to achieve my expectation.My problem is if i drag an image in the right or down direction its working ok,but there is no smoothness.
At the same time if i drag an image left side or up direction,its hiding the image.
Another problem is if i try to drag any corner of the image the particular portion was not displayed properly.How do i rectify these problems.Please refer the following url for exact my expectation : http://www.warmi.net/tmp/Image.mov
below i attached the figures for reference what i am getting.

Thanks,



A few things:

  1. You need to make your mesh (grid) continuous - meaning a collection of shared vertices.
  2. When modifying vertex ( or uv coordinates - both will work) you need to come up with some sort of function which will scale your drag influence over the grid.

For instance in the video you listed I am using something like this ( this is C++ code and it is not using Unity but the idea is pretty much the same)

Here is the code for handling user input…
There are essentially 3 modes:

  1. first touch.
  2. dragging
  3. releasing ( which in my case kicks a bounce-back type of animation)
bool RubberyImageApp::handleMouseEvent(const InputMouseEntry &entry)
{
	bool alreadyHandled=Application::handleMouseEvent(entry);
	if(!alreadyHandled)
	{
		if(entry.getState()==InputState::Up)
		{
			mState=Animating;
			((RenderablePrimitiveGridSmooth*)mGrid)->copyBuffers(0,2);
			mAnimationTime=0.5f;
			mCurrentTime=0;
		}
		else if(entry.getState()==InputState::smile:own)
		{		
			mAPoint.x=(float)entry.getPosX();
			mAPoint.y=(float)entry.getPosY();
			mState=Dragging;
		}
		else
		{
			if(mState==Dragging)
				handleDrag(Vector2((float)entry.getPosX(),(float)entry.getPosY()));
		}
	}
	return alreadyHandled;	
}

Here is the handleDrag method:

void RubberyImageApp::handleDrag(const Vector2 &cPoint)
{
	size_t numVertices;
	short *posPtr=0;
	unsigned int vStride;

	RenderablePrimitiveGridSmooth *gSmooth=(RenderablePrimitiveGridSmooth *)mGrid;

	VertexBuffer *vBuf=gSmooth->getVertexBuffer();
	VertexAttribute *vAttVertex=vBuf->Attributes.findAttribute(VertexAttribute::AttVertex);

	if(vAttVertex==0)
		return ;	

	posPtr=(short*)(vBuf->VertexData+vAttVertex->mOffset);

	vStride=mGrid->getVertexBuffer()->Attributes.mStride/sizeof(unsigned short);
	numVertices=mGrid->getVertexBuffer()->VertexCount;

	int origDataOffset=gSmooth->getCopyByteOffset()/sizeof(short);

	Vector2 displacement=cPoint-mAPoint;
	Vector2 rPoint=cPoint;


	while(numVertices)
	{
		const Vector2 pVec((float)*(posPtr+origDataOffset),(float)*(posPtr+origDataOffset+1));

		float influence=1.0f-MathUtils::Clamp1(pVec.distance(mAPoint)/mMaxInfluence);		
		influence=influence*influence;
		*posPtr = (short)(pVec.x + displacement.x*influence);
		*(posPtr+1) = (short)(pVec.y + displacement.y*influence);

		posPtr+=vStride;
		--numVertices;
	}
}

Hi,

Thanks for your reply.i will try and tell u the result.

good work , your question saved my life :slight_smile: