Texture2DImage construction examplesΒΆ
Example 1: Create a Surface resource and add a Texture2DImage
sfc = steno3d.core.Surface;
sfc.Mesh = {'H1', ones(10, 1), 'H2', ones(10, 1)};
tex = steno3d.core.Texture2DImage;
tex.U = [10 0 0];
tex.V = [0 10 0];
pngFile = [tempname '.png'];
imwrite(imread('ngc6543a.jpg'), pngFile, 'png');
tex.Image = pngFile;
sfc.Textures = tex;
example1 = steno3d.core.Project( ...
'Title', 'Textures: Example 1', ...
'Resources', sfc ...
);
clear sfc tex pngFile;
Example 2: Create a Point resource and add multiple textures
pts = steno3d.core.Point( ...
'Mesh', {'Vertices', rand(1000, 3)} ...
);
pts.Textures = steno3d.core.Texture2DImage( ...
'U', 'X', ...
'V', 'Z', ...
'Image', 'ngc6543a.jpg' ...
);
pts.Textures{end+1} = steno3d.core.Texture2DImage( ...
'O', [.25 .25 .25], ...
'U', [.4 0 -.3], ...
'V', [.1 .2 .5], ...
'Image', 'ngc6543a.jpg' ...
);
example2 = steno3d.core.Project( ...
'Title', 'Textures: Example 2', ...
'Resources', pts ...
);
clear pts;
Example 3: Add a texture to a sphere to make it look like Earth
Note
The Texture2DImage constructor is called implicitly when constructing sfc by providing a cell array of input parameters.
fig = figure; [x, y, z] = sphere; surf(x, y, z);
h = findobj('Type', 'surface');
load earth; hemisphere = [ones(257,125),X,ones(257,125)];
set(h,'CData',flipud(hemisphere),'FaceColor','texturemap');
colormap(map); axis equal; view([90 0]);
fig.Position = [fig.Position(1:3) fig.Position(3)];
ax = gca; ax.Position = [0 0 1 1];
pngFile = [tempname '.png'];
print(fig, '-dpng', pngFile);
close(fig);
clear map X h hemisphere fig ax;
sfc = steno3d.core.Surface( ...
'Title', 'Hemisphere', ...
'Mesh', { ...
'Triangles', convhull(x(:), y(:), z(:)), ...
'Vertices', [x(:) y(:) z(:)] ...
}, ...
'Textures', { ...
'O', [-1 -1 -1], ...
'U', [2 0 0], ...
'V', [0 0 2], ...
'Image', pngFile ...
} ...
);
example3 = steno3d.core.Project( ...
'Title', 'Textures: Example 3', ...
'Resources', sfc ...
);
clear sfc x y z pngFile;
You can run the above examples with:
steno3d.examples.core.texture
Then plot the projects with:
example1.plot(); % etc...
See also steno3d.core.Texture2DImage, steno3d.core.Point, steno3d.core.Surface, steno3d.core.Project