-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrtbJitterVertices.m
47 lines (41 loc) · 1.44 KB
/
rtbJitterVertices.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function [scene, mappings] = rtbJitterVertices(scene, mappings, names, conditionValues, conditionNumber)
%% Jitter the XYZ position of each vertex in the scene by a few percent.
%
% This is an example of a "remodeler" function that we can use with
% RtbAssimpStrategy. It's a hook that will be on invoked during batch
% processing and gives us a chance to modify the mexximp scene.
%
% I this case, we truncate and squish each mesh a bit.
%
% 2016 [email protected]
% locate each mesh
for mm = 1:numel(scene.meshes)
mesh = scene.meshes(mm);
% break vertex positions into xyz components
x = mesh.vertices(1:3:end);
y = mesh.vertices(2:3:end);
z = mesh.vertices(3:3:end);
% get positions relative to mesh center
centerX = mean(x);
localX = x - centerX;
centerY = mean(y);
localY = y - centerY;
centerZ = mean(z);
localZ = z - centerZ;
% truncate vertex positions
clip = 0.8 * max(localX);
localX(localX > clip) = clip;
localX(localX < -clip) = -clip;
localY(localY > clip) = clip;
localY(localY < -clip) = -clip;
localZ(localZ > clip) = clip;
localZ(localZ < -clip) = -clip;
% move back to new global coordinates
x = localX + centerX;
y = localY + centerY;
z = localZ + centerZ;
% assign back to the scene
scene.meshes(mm).vertices(1:3:end) = x;
scene.meshes(mm).vertices(2:3:end) = y;
scene.meshes(mm).vertices(3:3:end) = z;
end