function [ handles ] = ADDCAD(axis,handles) % Mark Naves % m.naves@utwente.nl % 6-14-2017 %Just an example how to add cad data to spavisual % %In visualization part of dat-file: USERPLOT ADDCAD %Function requires stl2fv.m % %Check correct stl settings before saving. in save as => select .stl => %options => output as ASCII, unit as meters %% x_node = 5; %position node r_node = 6; %rotation node Color = [162 195 214]./255; Filename = 'cadfile'; %remember cad data to improve speed persistent V H %time step t = axis.anim.CurrentTimeStep; %time step for motion v = axis.anim.CurrentVibrStep; %time step for vibrations %spacar data lnp = axis.spacar.lnp; if strcmp(axis.anim.CurrentField,'CurrentTimeStep') || strcmp(axis.anim.CurrentField,'CurrentLoadStep') x = axis.spacar.x(:,t); else x = axis.anim.Modes.X(:,v); end %Position of the node x_pos = x(lnp(x_node,1:3)); q_pos = x(lnp(r_node,1:4)); R = quat2rotm(q_pos'); %plot/update cad data if strcmp(axis.handles.figure.Visible, 'off') [F,V] = stl2fv(Filename); H =patch('Faces', F, 'Vertices', V*R'+repmat((x_pos)',size(V,1),1),'FaceColor' ,Color,'EdgeAlpha',0); H.FaceVertexCData = repmat(Color,size(V,1),1); else H.Vertices = V*R'+repmat((x_pos)',size(V,1),1); end end