I have a quick question about texture mapping in MATLAB. I have a 3D triangular mesh and I need to texture map onto the model in MATLAB.
I understand that texture mapping is possible for Surface object using 'surf(...)' command. For 3D triangular mesh model, I am using 'patch(...)' but I am unable to find a way to texture map with this method.
My question is, is there a way to texture map a 3D triangular mesh object?
Any help is very much appreciated.
Thank You.
Bruno
Since TRIMESH and TRISURF both return handles to patch objects, they won't behave any differently than PATCH with respect to texture mapping. Using SURF is the only way to do texture mapping. I know there is a SURF2PATCH function to convert surfaces to patches, but I don't know if there is any code to do the reverse. I'd look around the FEX first to see if anyone has tackled this problem already.
Ken
did you succeed on doing so ? If so , please reply.
Ran.
From a created patch you can use the xdata, ydata, and zdata to create
a surface of the same shape.
patchobject = patch(fv);
xdata = get(patchobject,'xdata')
ydata = get(patchobject,'ydata')
zdata = get(patchobject,'zdata')
surf(xdata,ydata,zdata)
I realize this is not the most efficient, since you have to create the
actual graphics patch just to get the data for the surface, but I
couldn't find a better way. It seems that there should be a
patch2surf to go along with surf2patch.
If anybody finds a better solution to this, let me know.
Nick
I believe only surf allows you to texture map a surface with an image of a different size from the vertices arrays.
If you can't use surf for your problem (because your mesh is not regular), then there are two ways round this (that I can see):
1. Split each triangle up, down to the size of the pixels of your texture map image, then use trisurf(x, y, z, c) for interpolated shading. If your image is larger than your mesh (in terms of number of pixels/vertices) then you'll have more triangles to plot, which will slow the rendering down.
2. Add more points to your mesh to make it regular, then use surf. Again, this will slow down the rendering, assuming it is possible, which it might not be.
As an alternative to 2., you could use:
http://www.mathworks.com/matlabcentral/fileexchange/14646
to approximate your mesh to a regular grid, then texture map that. I don't know how straightforward it will be to compute the new texture coordinates though.
Olly