How to unwrap Spherical surface function

조회 수: 3 (최근 30일)
apops
apops 2022년 5월 10일
답변: VINAYAK LUHA 2023년 9월 27일
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

답변 (1개)

VINAYAK LUHA
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:
  1. Download the Wavefront OBJ Toolbox from MATLAB File exchange using the following link- https://in.mathworks.com/matlabcentral/fileexchange/27982-wavefront-obj-toolbox .
  2. Extract the “write_wobj.m” file in your current path.
  3. Save the “gcf” of your figure as a “.png” file to be used later for applying texture from image in blender.
  4. Create the “.obj” for the sphere plot as per the example given in the toolbox.
  5. Import the “.obj” file in blender.
  6. Select the object and create a new material for the object.
  7. Define a new material for the object and under “base color” select “image texture”.
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

카테고리

Help CenterFile Exchange에서 Vector Volume Data에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by