Skip to content

Commit

Permalink
Text
Browse files Browse the repository at this point in the history
  • Loading branch information
syanenko committed Dec 25, 2023
1 parent e10b154 commit ccf5f78
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 3 deletions.
Binary file modified examples/ex_axis.mlx
Binary file not shown.
9 changes: 6 additions & 3 deletions examples/ex_axis_utf8.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
% Llights

pl.include_begin('lights');
pl.light('location', [10 10 7], 'color', [3 3 3], 'shadowless', true);
pl.light('location', [-10 10 30], 'color', [3 3 3], 'shadowless', true);
pl.light('location', [10 10 7], 'color', [2 2 2], 'shadowless', true);
pl.light('location', [-10 10 30], 'color', [2 2 2], 'shadowless', true);
pl.include_end();
% Floor

Expand All @@ -37,7 +37,9 @@
pl.include("camera");
pl.include("lights");
pl.include("floor");

tex_green = pl.declare("tex_green", pl.texture('pigment', [0.0 0.3 0.0]));

pl.text('text', 'Axis', 'font', 'arial.ttf', 'thickness', 0, 'offset', 0, 'texture', tex_green ,'scale', [0.7 0.7 0.7], 'rotate', [ 90 0 135], 'translate', [1 -9 3]);
pl.axis('length', [5 5 4]);
pl.scene_end();
% Render and display
Expand All @@ -58,6 +60,7 @@
tex_pink = pl.declare("tex_pink", pl.texture('pigment', [0.8 0.2 0.3]*1.2));
tex_green = pl.declare("tex_green", pl.texture('pigment', [0.0 0.3 0.0]));

pl.text('text', 'Axis colored', 'font', 'arial.ttf', 'thickness', 0, 'offset', 0, 'texture', tex_pink ,'scale', [0.7 0.7 0.7], 'rotate', [ 90 0 135], 'translate', [1 -9 3]);
pl.axis('length', [5 5 4], 'radius', 0.07, 'tex_common', tex_gray, 'tex_x', tex_yellow, 'tex_y', tex_pink, 'tex_z', tex_green);
pl.scene_end();
% Render and display
Expand Down
Binary file added examples/ex_text.mlx
Binary file not shown.
38 changes: 38 additions & 0 deletions examples/ex_text_utf8.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
%% 'text' method usage example
% Common setup for all examples

ex_setup
% Start timer
tic

% Povlab object
pl = povlab( povray_version,...
povray_path, ...
povray_out_dir);

pl.scene_begin('scene_file', 'text.pov', 'image_file', 'text.png');
pl.light('location', [0 15 2], 'color', [1 1 1], 'shadowless', true);
pl.light('location', [0 0 30], 'color', [0.7 0.7 0.7], 'shadowless', true);

pl.camera('angle', 80, 'location', [-1 5 0], 'look_at', [0 0 0]);

% Walls
tex_plane = pl.declare("tex_plane", pl.texture('pigment_odd', [1.5 1.5 1.5], 'pigment_even', [0.1 0.1 0.1]));
pl.plane('normal', [1,0,0], 'texture', tex_plane', 'translate', [-10 0 1]);
pl.plane('normal', [0,0,1], 'texture', tex_plane', 'translate', [0 0 -5]);

% Texture
tex_green = pl.declare('tex_green', pl.texture('pigment', [0 1.8 0], ...
'finish', 'ambient 0.001 diffuse 0.3 reflection 0.04 specular 24.4 roughness 0.0004'));
pl.text('text', 'The quick brown', 'font', 'arial.ttf', 'thickness', 0.2, 'offset', 0, 'texture', tex_green ,'scale', [1 1 1], 'rotate', [90 0 180], 'translate', [4 0 1.4]);
pl.text('text', 'fox jumps over', 'font', 'arial.ttf', 'thickness', 0.2, 'offset', 0, 'texture', tex_green ,'scale', [1 1 1], 'rotate', [90 0 180], 'translate', [4 0 0]);
pl.text('text', 'the lazy dog', 'font', 'arial.ttf', 'thickness', 0.2, 'offset', 0, 'texture', tex_green ,'scale', [1 1 1], 'rotate', [90 0 180], 'translate', [4 0 -1.4]);

pl.scene_end();

% Render and display
image = pl.render();
imshow(image);

% Elapsed time
toc
39 changes: 39 additions & 0 deletions povLab.m
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,45 @@ function plot(o, varargin)
o.trans(scale, rotate, translate));
end

%
% Text
%
function text(o, varargin)
%
% Create a function text
%
% SYNTAX
% ...
%

p = inputParser;
addParameter(p,'text', '', @o.check_string);
addParameter(p,'font', 'arial.ttf', @o.check_string);
addParameter(p,'thickness', 0, @o.check_float);
addParameter(p,'offset', 0, @o.check_float);
addParameter(p,'texture', "tex_default", @o.check_string);
addParameter(p,'scale', [1 1 1], @o.check_vector3);
addParameter(p,'rotate', [0 0 0], @o.check_vector3);
addParameter(p,'translate', [0 0 0], @o.check_vector3);
parse(p,varargin{:});

text = p.Results.text;
font = p.Results.font;
thickness = p.Results.thickness;
offset = p.Results.offset;
texture = p.Results.texture;
scale = p.Results.scale;
rotate = p.Results.rotate;
translate = p.Results.translate;

% Write
fprintf(o.fh,['text { ttf "%s", "%s", %0.2f, %0.2f \n'...
' texture { %s }%s}\n'],...
font, text, thickness, offset,...
texture,...
o.trans(scale, rotate, translate));
end

%
% Surface2
%
Expand Down

0 comments on commit ccf5f78

Please # to comment.