clear 
clc
exVScale = 1;
bNoninversion = 1;

DataPath = './hippo/'; % <-------- update with your YALMIP path
OBJFile = 'mesh.obj';
nVt = 2387;

% DataPath = './test3D/'; % <-------- update with your YALMIP path
% OBJFile = 'sphere.obj';
% nVt = 1061;

addpath(genpath(DataPath));

rawExV = importdata('targetconstraints.txt');
rawExR = importdata('exrotation.txt');    % maybe the rotation matrices need to be transposed

sizeExV = size(rawExV, 1)/4;
sizeExR = size(rawExR, 1)/10;
%n = size(G,2);
n = nVt*3;
m = sizeExR;

VList = zeros(nVt,3);
FList = zeros(m,4);
fp = fopen( OBJFile, 'r' );
for i=1:nVt
    fscanf( fp, '%s', 1 );
    VList(i,:) = fscanf( fp, '%f %f %f');
end
for i=1:m
    fscanf( fp, '%s', 1 );
    FList(i,:) = fscanf( fp, '%d %d %d %d');
end
fclose( fp );

G = extractG3D(VList, FList);

indices = zeros(3*sizeExV,1);
exV = zeros(n, 1);
for i=1:sizeExV
    indices(3*i-2) = 3*(rawExV(4*i-3)+1)-2; %0-based --> 1-based
    indices(3*i-1) = 3*(rawExV(4*i-3)+1)-1; %0-based --> 1-based
    indices(3*i)   = 3*(rawExV(4*i-3)+1); %0-based --> 1-based
    
    exV(3*(rawExV(4*i-3)+1)-2) = rawExV(4*i-2);
    exV(3*(rawExV(4*i-3)+1)-1) = rawExV(4*i-1);
    exV(3*(rawExV(4*i-3)+1))   = rawExV(4*i);
end

exV = exV / exVScale;

exR = zeros(9*sizeExR,1);
for i=1:sizeExR
    for c=0:1:8
         exR(9*i-c) = rawExR(10*i-c);
    end
end





