This took me longer than it should have. Some rudimentary camera controls are on the player 1 and player 2 buttons (rotation/translation). Depending on settings this glitches alot.
3D-Model: low poly cat by xavab29 Creative Commons - Attribution - Share Alike
Published on May 28, 2015
www.thingiverse.com/thing:853358
STL to lua Matlab script:
mesh = stlread('chatlowpoly.stl'); fid = fopen('stl.lua','wt'); fprintf(fid, 'stl = { '); for i=1:length(mesh.vertices)-1 fprintf(fid, ['{ ', num2str(mesh.vertices(i,1)), ', ', num2str(mesh.vertices(i,2)),', ',num2str(mesh.vertices(i,3)), ' },\n']); end fprintf(fid, ['{ ', num2str(mesh.vertices(length(mesh.vertices),1)), ', ', num2str(mesh.vertices(length(mesh.vertices),2)),', ',num2str(mesh.vertices(length(mesh.vertices),3)), ' }\n']); fprintf(fid, '}'); fclose(fid); |
using STL file reader by Eric Johnson
https://de.mathworks.com/matlabcentral/fileexchange/22409-stl-file-reader
and here is the Matlab prototype I used
global c c = [0 0 -1]; %camera trans mesh = stlread('chatlowpoly.stl'); figure for n=1:3:length(mesh.vertices) tri3d= [mesh.vertices(n,:); mesh.vertices(n+1,:); mesh.vertices(n+2,:)]; tri2d = project_triangle(tri3d); plot_triangle(tri2d) end function [tri2d] = project_triangle(tri3d) tri2d(1,:) = project_point(tri3d(1,:)); tri2d(2,:) = project_point(tri3d(2,:)); tri2d(3,:) = project_point(tri3d(3,:)); end function [b] = project_point(a) b(1) = a(1)/a(3); b(2) = a(2)/a(3); end function [] = plot_triangle(tri2d) % x = [tri2d(1,1) tri2d(2,1)]; % y = [tri2d(1,2) tri2d(2,2)]; % plot(x,y); % x = [tri2d(2,1) tri2d(3,1)]; % y = [tri2d(2,2) tri2d(3,2)]; % plot(x,y); % % x = [tri2d(3,1) tri2d(1,1)]; % y = [tri2d(3,2) tri2d(1,2)]; % plot(x,y); %plot([tri2d(1,1) tri2d(2,1)],[tri2d(1,2) tri2d(2,2)],[tri2d(2,1) tri2d(3,1)],[tri2d(2,2) tri2d(3,2)],[tri2d(3,1) tri2d(1,1)],[tri2d(3,2) tri2d(1,2)]); line([tri2d(1,1) tri2d(2,1)],[tri2d(1,2) tri2d(2,2)]); line([tri2d(2,1) tri2d(3,1)],[tri2d(2,2) tri2d(3,2)]); line([tri2d(3,1) tri2d(1,1)],[tri2d(3,2) tri2d(1,2)]); end function [out] = get_rot_x(angle) out = [ 1 0 0; 0 cos(angle) -sin(angle); 0 sin(angle) cos(angle) ]; end function [out] = get_rot_y(angle) out = [ cos(angle) 0 sin(angle); 0 1 0; -sin(angle) 0 cos(angle) ]; end function [out] = get_rot_z(angle) out = [ cos(angle) -sin(angle) 0; sin(angle) cos(angle) 0; 0 0 1 ]; end |
[Please log in to post a comment]