Mesh line shape

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Legars2101
Posts: 8
Joined: Fri Mar 07, 2008 11:34 am
Location: Rouen, FR

Mesh line shape

Post by Legars2101 »

Hello everyone,

I am working on the displaying of a 3D mesh which is the result of a 3D hardware scanning.
The result gives me an obj file.
I can load it, turn around, zoom, and select a triangle.
The next step is to be able to select a line following the shape of the model. To be more visual : immagine a laser line projected on body. The line on the body will not be straight but will follow distortion of the body.
I would like to have the same result on my model...
The problem is that I just know I may use collision (as for a triangle selector) but that's all...

If someone have an idea, a starting point or already did it, it will be great !
doqkhanh
Posts: 158
Joined: Sat Mar 01, 2008 3:14 am
Location: Tokyo, Japan
Contact:

Re: Mesh line shape

Post by doqkhanh »

Your requirement seems to match this tutorial:
http://irrlicht.sourceforge.net/tut007.html
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Do you want a laser which comes from the camera and points onto the car and shows you the collision point from the camera to the car?

Or do you want a line which is projected onto the car and lies on the surface of the car, taking its shape, like projective texturing..? Like this sort of thing:

Image

where the texture get projected onto the surfaces and gets distorted based on those surfaces, much like how a projector would work if you projected the image onto a non-flat surface instead of a wall.
Image Image Image
Legars2101
Posts: 8
Joined: Fri Mar 07, 2008 11:34 am
Location: Rouen, FR

Post by Legars2101 »

Or do you want a line which is projected onto the car and lies on the surface of the car, taking its shape
That's it !

I finally have some working but limited to vertex's point. I have to do some clean up in the code, and i will post it with a screenshot. It might help.. ;)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

the ideal way to do this would be with projective texturing. It's a bit elusive in irrlicht, hard to do, but someone (can't remember who) is working on a fixed function pipeline version (possibly only opengl currently) which means you can do it without shaders. Other people have done shader versions before i think.
Image Image Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

BlindSide is preparing something.
Legars2101
Posts: 8
Joined: Fri Mar 07, 2008 11:34 am
Location: Rouen, FR

Post by Legars2101 »

This is not a perfect solution, but it works well. It's limited on mesh vertices.

Currently this is how I do (Every optimisation is welcome :) ) :

Create this object :

Code: Select all

scene::ISceneManager* _smgr;
core::triangle3df tri_selected;
core::vector3df inter;
scene::ITriangleSelector* tri_selector;
core::line3df line;
Associate with the mesh of interest :

Code: Select all

tri_selector = _smgr->createOctTreeTriangleSelector(_mesh->getMesh(0), _meshSN);
In the render loop :

Code: Select all

// Get line between mouse and screen
line = _smgr->getSceneCollisionManager()->getRayFromScreenCoordinates(_device->getCursorControl()->getPosition());

// If intersection, draw things
if(_smgr->getSceneCollisionManager()->getCollisionPoint(line, tri_selector, inter, tri_selected))
   DrawMouseEffect(true, tri_selected);
with :

Code: Select all

void DrawMouseEffect(bool doI, core::triangle3df triSelected)
{
	if(doI)
	{
		int i;
		std::list<video::S3DVertex> lsVerticesX;
		std::list<video::S3DVertex> lsVerticesY;

		float myX = triSelected.pointA.X;
		float myY = triSelected.pointA.Y;

		video::S3DVertex* vertices = (video::S3DVertex*)_meshMB->getVertices();

		int nVertex = _meshMB->getVertexCount();

		// Add vectors of interest
		for(i = 0; i < nVertex; i++)
		{
			if(vertices[i].Pos.X == myX)
				lsVerticesX.push_back(vertices[i]);

			if(vertices[i].Pos.Y == myY)
				lsVerticesY.push_back(vertices[i]);
		}

		// Draw X curve
		this->DrawCurve(lsVerticesX);

		// Draw Y curve
		this->DrawCurve(lsVerticesY);
	}
}
And then :

Code: Select all

void DrawCurve(std::list<video::S3DVertex> lsVertex)
{
	core::vector3df deb, fin;
	std::list<video::S3DVertex>::iterator it;
	
	it = lsVertex.begin();

	while(it != lsVertex.end())
	{
		deb = (*it++).Pos;
		if(it != lsVertex.end())
		{
			fin = (*it).Pos;
			_driver->draw3DLine(deb, fin, video::SColor(0, 123, 45, 78));
		}
	}
}
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Cool, glad you got it working, any chance of a screenshot or executable to play around with?
Image Image Image
Legars2101
Posts: 8
Joined: Fri Mar 07, 2008 11:34 am
Location: Rouen, FR

Post by Legars2101 »

I would like to put a picture of the result, but I don't know how... I don't have webspace to put pictures on...
doqkhanh
Posts: 158
Joined: Sat Mar 01, 2008 3:14 am
Location: Tokyo, Japan
Contact:

Post by doqkhanh »

Legars2101 wrote:I would like to put a picture of the result, but I don't know how... I don't have webspace to put pictures on...
Email it to me, REMOVESPAMnguoidanongvidai@REMOVESPAMgmail.com, I glad to store your screenshot !
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I use photobucket for uploading images, pretty good in my opinion!
Image Image Image
Legars2101
Posts: 8
Joined: Fri Mar 07, 2008 11:34 am
Location: Rouen, FR

Post by Legars2101 »

Thanks, I send it to you.

I test it with other model than one from my 3d scan, it don't work very well or at all.

I my case, vertex are align in X and Y so finally it's easy to get line shape from the meshbuffer.

Second step is too find another solution which permit the same things for any model...

I'll keep working on :)
Legars2101
Posts: 8
Joined: Fri Mar 07, 2008 11:34 am
Location: Rouen, FR

Post by Legars2101 »

JP wrote:I use photobucket for uploading images, pretty good in my opinion!
Great idea, I will use it from now !
doqkhanh
Posts: 158
Joined: Sat Mar 01, 2008 3:14 am
Location: Tokyo, Japan
Contact:

Post by doqkhanh »

Legars2101's screenshot:
Image
Image
Post Reply