clear all
faces = csvread(‘handfaces.txt’);
V0 = csvread(‘handverts.txt’);
V0=V0’;
N = size(V0,1);
weights = csvread(‘handweights.txt’)
sk = loadbvh(‘HandBase.bvh’)
wmap = [1 2 3 4 0 15 16 17 0 5 6 7 0 8 9 10 0 11 12 13 0 14 0];
wzero = wmap==0;
W = sparse(weights(:,1)+1,weights(:,2)+1,weights(:,3));
W = full(W);
W = W(:,wmap+wzero);
W(:,wzero)=0;
V=V0*0;
cla
for i=1:length(sk)
if sk(i).parent
s=sk(i).t_xyz(:,j); sp = sk(sk(i).parent).t_xyz(:,j);
plot3([s(1) sp(1)],[s(2) sp(2)],[s(3) sp(3)],'r','LineWidth',5);
end
plot3(sk(i).t_xyz(1,j),sk(i).t_xyz(2,j),sk(i).t_xyz(3,j),'g.','MarkerSize',10);
if sk(i).Nchannels
plotax(sk(i).t_xyz(:,j)',sk(i).T(1:3,1:3,j)*sk(i).R0,15)
end
if sk(i).Nchannels
poseMatrix(:,:,i,j) = [(sk(i).T(1:3,1:3,j)*sk(i).R0) sk(i).t_xyz(:,j);0 0 0 1];
restMatrix(:,:,i) = [((sk(i).R0)) sk(i).head0 ;0 0 0 1];
M(:,:,j) = poseMatrix(:,:,i,j)*inv(restMatrix(:,:,i));
R = M(1:3,1:3,j);
t = M(1:3,4,j);
V = V + (R*V0 + repmat(t,1,length(V0))) * spdiags(W(:,i),0,length(V),length(V));
end
end
h = trisurf(faces+1,V(1,:),V(2,:),V(3,:),W(:,2)*0);
axis off;
axis equal
shading interp;
light
lighting phong
set(h,'FaceAlpha',0.8)
drawnow
end
运行结果是手臂手型不停地变换,这里只捕捉了两幅。