• 大小: 3.78MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-30
  • 语言: Matlab
  • 标签: Z-Buffer  Matlab  obj  wrl  

资源简介

用Matlab实现的Z-Buffer算法,其中读取了一个wrl文件和obj文件

资源截图

代码片段和文件信息

function [vertexfacesnormallocationpicture] = read_obj(filenamepicturename)
 
% read_obj - load a .obj file.
%
%   [vertexfacenormal] = read_obj(filename);
%
%   faces    : list of facesangle elements
%   vertex  : node vertexinatates
%   normal : normal vector list
%
%   Copyright (c) 2008 Gabriel Peyre
 
fid = fopen(filename);
if fid<0
    error([‘Cannot open ‘ filename ‘.‘]);
end
 
frewind(fid);
a = fscanf(fid‘%c‘1);
if strcmp(a ‘P‘)
    % This is the montreal neurological institute (MNI) specific ASCII facesangular mesh data structure.
    % For FreeSurfer software a slightly different data input coding is
    % needed. It will be provided upon request.
    fscanf(fid‘%f‘5);
    n_points=fscanf(fid‘%i‘1);
    vertex=fscanf(fid‘%f‘[3n_points]);
    normal=fscanf(fid‘%f‘[3n_points]);
    n_faces=fscanf(fid‘%i‘1);
    fscanf(fid‘%i‘5+n_faces);
    faces=fscanf(fid‘%i‘[3n_faces])‘+1;
    fclose(fid);
    return;
end
 
frewind(fid);
vertex = [];
faces = [];
location = [];
normal = [];
while 1
    s = fgetl(fid);
    if ~ischar(s) 
        break;
    end
    if ~isempty(s) && strcmp(s(1) ‘f‘)
        % face
        af =  sscanf(s(3:end)‘%d/%d/%d %d/%d/%d %d/%d/%d‘);
        faces(:end+1) =af(1:3:end1);
%        faces(:end+1) = sscanf(s(3:end) ‘%d %d %d‘);
    end
    if ~isempty(s) && strcmp(s(1) ‘v‘)
        if strcmp(s(2) ‘ ‘)
            % vertex
            vertex(:end+1) = sscanf(s(3:end) ‘%f %f %f‘);
        elseif strcmp(s(2) ‘t‘)
            location(:end+1) = sscanf(s(4:end) ‘%f %f‘);
        elseif strcmp(s(2) ‘n‘)
            normal(:end+1) = sscanf(s(4:end) ‘%f %f %f‘);
        end
    end
end
fclose(fid);

picture = imread(picturename);
[highwidth~] = size(picture);
location(1:) = location(1:) * width;
location(2:) = high-1-location(2:) * high;
 


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     103625  2016-07-26 21:34  test\Angry\000.jpg

     文件    6607102  2016-07-25 15:17  test\Angry\000.wrl

     文件     687801  2013-07-27 20:36  test\bu4d_test\0000.jpg

     文件        211  2013-07-27 20:39  test\bu4d_test\0000.mtl

     文件    8566714  2013-07-27 20:26  test\bu4d_test\0000.obj

     文件       1840  2018-05-17 19:38  test\read_obj.m

     文件       1628  2018-05-16 22:01  test\read_wrl.m

     文件      56864  2018-05-17 20:24  test\result.png

     文件        671  2018-05-17 20:24  test\test_obj.m

     文件        653  2018-05-17 20:23  test\test_wrl.m

     文件       2921  2018-05-17 20:14  test\ZBuffer.m

    ..AD...         0  2018-05-17 20:26  test\Angry

     目录          0  2018-05-17 20:22  test\bu4d_test

     目录          0  2018-05-17 20:24  test

----------- ---------  ---------- -----  ----

             16030030                    14


评论

共有 条评论