- Download the Wavefront OBJ Toolbox from MATLAB File exchange using the following link- https://in.mathworks.com/matlabcentral/fileexchange/27982-wavefront-obj-toolbox .
- Extract the “write_wobj.m” file in your current path.
- Save the “gcf” of your figure as a “.png” file to be used later for applying texture from image in blender.
- Create the “.obj” for the sphere plot as per the example given in the toolbox.
- Import the “.obj” file in blender.
- Select the object and create a new material for the object.
- Define a new material for the object and under “base color” select “image texture”.
How to unwrap Spherical surface function
8 次查看(过去 30 天)
显示 更早的评论
Hi,
I would like to unwrap a plotted sphere into a 2D image so it can be used as texture or import the 3D figure with colors to use in blender (colormap is important) I know matlab functions can be expoerted into stl or x3d files but when I open it in blender it is just a sphere without colors. Any help will be appreciated
0 个评论
回答(1 个)
VINAYAK LUHA
2023-9-27
Hi Apops,
I understand that you have plotted a sphere in MATLAB, and you want to export it along with its colormap and use it in Blender. Here is a workaround involving exporting the sphere in “.obj” format, which unlike “.stl” format, also supports color information:
You can now see a preview of the object with the colormap applied on it in the preview window.
Here is the code for generating “.obj” file and the “image texture” file your reference:
[x, y, z] = sphere(100);
c = hypot(x, y);
surf(x, y, z, c, 'FaceColor', 'interp', 'EdgeColor', 'none');
colormap jet;
colorbar;
OBJ.vertices = [x(:), y(:), z(:)];
OBJ.material = struct('type', 'newmtl', 'data', 'sphere_material');
OBJ.objects(1).type = 'g';
OBJ.objects(1).data = 'sphere_object';
OBJ.objects(2).type = 'usemtl';
OBJ.objects(2).data = 'sphere_material';
OBJ.objects(3).type = 'f';
OBJ.objects(3).data.vertices = surf2patch(x, y, z).faces;
filename = 'sphere.obj';
write_wobj(OBJ, filename);
filename = 'sphere_texture.png';
saveas(gcf, filename);
Explore the documentation of the following functions for more details:
Hope this helps.
Regards,
Vinayak Luha
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!