0%

04 - ARCSim

1. 下载与安装

下载链接:

先安装需要的库:

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo apt-get install gcc
sudo apt-get install make
sudo apt-get install g++
sudo apt-get install libboost-all-dev
sudo apt-get install freeglut3-dev
sudo apt-get install gfortran
sudo apt-get install liblapacke-dev
sudo apt-get install libpng-dev
sudo apt-get install libpng++-dev
sudo apt-get install scons
sudo apt-get install libatlas-base-dev
sudo apt-get install ctags
sudo apt-get install libopenblas-dev

2. 环境配置

2.1 boost 库(手动配置)

在 HYLC 的 CMAKEList.txt 文件中需要该版本的库,建议选择 1.55.0 版本(其实在 1. 中已经安装了 boost 库) :

screenShot.png

参考文章:

1
2
3
4
5
6
7
8
9
wget http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz

tar -xzvf boost_1_55_0.tar.gz

cd boost_1_55_0

./bootstrap.sh --prefix=/usr/local

./b2 install --with=all

boost库被安装在 /usr/local/lib 下面

2.3 scons(手动配置)

JsonCPP 类库需要 Scons 编译器来编译,而 Scons 需要 Python 安装了才能使用。

下载链接

将压缩包 scons-local-4.0.1.tar.gz 在文件目录 /arcsim-0.2.1/dependencies/jsoncpp/ 下解压:

1
sudo tar -xf scons-local-4.0.1.tar.gz

可以手动安装 scons ,后面 make 的过程也会进行一次该步骤 test 一下:

1
python3 scons.py platform=linux-gcc Gnu C++

具体查阅 /arcsim-0.2.1/dependencies/jsoncpp/README.txt

2.4 SConstruct 文件修改

python2 to python3

arcsim-0.2.1/dependencies/jsoncpp/SConstruct 文件中使用的 python2 代码编写,如果环境是 python3 ,则需要更改 /arcsim-0.2.1/dependencies/jsoncpp/SConstruct 一部分代码。

2.4.1 print

给所有的 print 添加括号。

2.4.2 commands

其中 commands 模块在 python3.x 被 subprocess 取代,点开:

screenShot.png

1
2
import commands
version = commands.getoutput('%s -dumpversion' %CXX)

line 28,29 换成:

1
2
import subprocess
version = subprocess.getoutput('%s -dumpversion' %CXX)

2.4.3 name ‘apply’ is not defined

参考方案:
https://blog.csdn.net/hellenlee22/article/details/90906476

1
apply( self.env.SrcDist, (self.env['SRCDIST_TARGET'],) + args, kw )

将 Line 144 代码改成:

1
self.env.SrcDist( *(self.env['SRCDIST_TARGET'],) + args, **kw )

2.5 make 依赖项(/dependencies/)

arcsim-0.2.1/dependencies/ 文件夹下进行 make :

1
make

当第二次 make 输出结果是如下时,说明成功:

screenShot.png

2.6 make arcsim

2.6.1 预处理

参考文章:

修改代码文件 /arcsim-0.2.1/src/sparse.hpp 的 Line 118 :

  • << file 更改为 << std::endl

将代码文件 /arcsim-0.2.1/src/sparse.hpp 的 Line 805 811 注释掉:

1
2
[805] extern int isnan(double);
[811] extern int isinf(double);

修改文件 /arcsim-0.2.1/Makefile

  • 将三个 -mt 删掉;
  • CXXFLAGSLDFLAGS 添加下载的 boost 库的路径 (如果是按前面操作安装的boost,则路径为 /usr/local/lib

screenShot.png

Line 7,14 的代码为:

1
2
3
4
5
6
7
8
CXXFLAGS := -Idependencies/include -I/opt/local/include -I/usr/local/include

ifdef NO_OPENGL
CXXFLAGS := $(CXXFLAGS) -DNO_OPENGL
endif
CXXFLAGS_DEBUG := -Wall -g -Wno-sign-compare
CXXFLAGS_RELEASE := -O3 -Wreturn-type -fopenmp
LDFLAGS := -Ldependencies/lib -L/opt/local/lib -L/usr/local/lib -lpng -lz -ltaucs -llapack -lblas -ljson -lgomp -lalglib -lboost_filesystem -lboost_system -lboost_thread

参考文章:

2.6.2 进行 make

/arcsim-0.2.1/ 目录下进行 make ,如果是以下显示,说明 make 成功:

screenShot.png

测试一下:

1
./bin/arcsim simulate conf/sphere.json

s 进行 step 。

3. 使用方法

参考文章:

3.1 使用命令

在控制台输入命令:

1
bin/arcsim <command> [<args>]

可以做个软连接:

1
sudo ln -s <arcsim path>/arcsim /bin/

这时可以全局直接调用命令:

1
arcsim <command> [<args>]
命 令
simulate <scene-file> [<out-dir>] 读取 <scene-file> 中给出的 .json 文件(尝试 conf / sphere.json ,然后参见下面的 “场景文件” ),并在显示结果的同时运行模拟 OpenGL 窗口。按住 Space 键运行,或按一次 s 可向前移动一个时间步。如果给出 <out-dir> ,则模拟结果将保存在该目录中。输出的格式在 “输出文件” 中描述。
simulateoffline <scene-file> [<out-dir>] 离线渲染,与 simulate 相同,但没有OpenGL显示。(并且您不必按 Space 键即可开始模拟。)对于通过SSH在远程服务器上运行非常有用。
resume <out-dir> <resume-frame> 恢复 <out-dir> 中保存的未完成模拟,从给定的帧号 <resume-frame> 开始。(请注意,如果自首次运行模拟以来原始场景文件已更改,则在恢复的模拟中不会考虑这些更改。)
resumeoffline <out-dir> <resume-frame> resume 相同,但没有 OpenGL 显示。
replay <out-dir> [<sshot-dir>] 重放存储在 <out-dir> 中的模拟结果(保证该目录下存在 conf.json 文件 )。按 Space 键播放, 在帧之间移动;Shift + Alt + 分别跳过 10 帧和 100 帧。按空格键可以尽可能快地播放所有帧。 Home 关键点返回到第 0 帧。如果给定了 <sshot-dir> ,则播放时渲染的图像也会保存在那里。
merge
split
test
tri2obj
debug

3.2 OpenGL 界面操作

操 作
Space 开始模拟 / 播放
鼠标左键 旋转
鼠标中键 位移
鼠标滑轮 缩放
Esc 退出

3.3 场景配置文件(.json)

场景配置文件以 JSON语法 编写。

conf/ 目录中提供了许多示例场景:

  • conf/sphere.json :球体交互示例,是一个很好的 “hello world” 场景,用于检查模拟器是否正在工作;
  • 场景文件由单个 JSON 对象组成,其中包含许多描述模拟参数和内容的 key/value 对。
  • conf/sphere-annotated.json :有关所有选项的完整描述,是 conf/sphere.json 的一个带有大量注释的版本,描述了所有可以使用的设置。

conf/sphere-annotated.json

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
"frame_time": 0.04, // 必填项:每帧的长度
"frame_steps": 8, // 可选,默认值为1:每帧的 substep 数
"end_time": 10, // 可选,默认无穷大:模拟的时间长度
// "end_frame": <frame_num> // 可选,默认为无穷大:
// // 模拟长度(以帧数为单位)
// 模拟将一直运行到 END_TIME 或 END_FRAME ,以先到者为准

"cloths": [{ // 必填项:Cloth 对象列表
"mesh": "meshes/square4.obj", // Required: Initial mesh
// See "Creating cloth meshes" in README
"transform": { // Optional, default identity: Initial pose of mesh
"translate": [-0.5, -1, 0.5] // Optional
// "rotate": [<angle>, <axis_x>, <axis_y>, <axis_z>] // Optional
// "scale": <scale> // Optional
},
"materials": [{ // Required: List of material properties for each cloth.
// This is a list because different patches of the
// same mesh are allowed to have different materials,
// but this functionality is not used very much.
// Just make a list of one element and be done with it.
"data": "materials/gray-interlock.json", // Required: material data
// see materials/README
// "density_mult": <d> // Optional: Multiply density by a factor
// "stretching_mult": <s> // Optional: Multiply stretching stiffness
// "bending_mult": <b>, // Optional: Multiply bending stiffness
"thicken": 2 // Optional: Multiply all of the above
// "damping": <damp> // Optional: Stiffness-proportional damping
// "strain_limits": [<min>, <max>] // Optional, default [0.9, 1.1]
// Actually this is 1 + strain
// "yield_curv": <kappa> // Optional, units of 1/length
// "weakening": <g> // Optional: reduce stiffnesses upon yielding
}],
"remeshing": { // Required: Remeshing parameters
"refine_angle": 0.3, // Required: Max allowed change in normals
"refine_compression": 0.005, // Required: Max allowed compression
"refine_velocity": 0.5, // Required: Max allowed change in velocity
"size": [10e-3, 200e-3], // Required: Bounds on size of triangles
"aspect_min": 0.2 // Required: Lower bound on triangle aspect ratio
}
}],

"motions": [[ // Optional: List of motions for handles and/or obstacles.
// Each motion is a list of keyframed transformations.
// Motion is interpolated using a cubic Hermite spline
// with Catmull-Rom derivatives at keyframes;
// derivatives at first and last keyframe are zero
{
"time": 0, // Required: Keyframe time
"transform": { // Required: Keyframe transformation
"scale": 0.1, // Same format as transform in cloth:
"translate": [0,0,0] // translation, rotation, scaling
}
},
{"time": 1, "transform": {"scale": 0.1, "translate": [0,0,0]}},
{"time": 2, "transform": {"scale": 0.1, "translate": [0,0,0]}},
{"time": 3, "transform": {"scale": 0.1, "translate": [0,-1.5,0]}},
{"time": 4, "transform": {"scale": 0.1, "translate": [0,0,0]}},
{"time": 5, "transform": {"scale": 0.1, "translate": [0,1.5,0]}},
{"time": 6, "transform": {"scale": 0.1, "translate": [0,0,0]}},
{"time": 7, "transform": {"scale": 0.1, "translate": [0,-0.4,0]}}
]],
// Alternatively, the value of "motions" can be an object as follows:
// "motions": { // If an object not a list, refers to motion data in file
// "motfile": <filename>, // Required, see e.g. meshes/dance.mot
// "fps": <fps>, // Required: frame rate of motion keyframes
// "transform": <transform> // Optional: overall transformation
// // applied to motion sequence
// },

"handles": [{ // List of "handles" i.e. sets of constrained vertices
// "cloth": <i> // Optional, default 0: Vertices of <i>th cloth
"vertices": [2,3], // Required: Indices of vertices under this handle.
// Must be boundary vertices in initial mesh,
// otherwise they may be deleted by remeshing
// "motion": <j> // Optional: Index of motion to attach to
// If omitted, handle does not move
// "start_time": <time> // Optional, default 0: When handle activates
"end_time": 7 // Optional, default infinity: When handle deactivates
}],

"obstacles": [{ // List of static or scripted obstacles
"mesh": "meshes/sphere.obj", // Required: Obstacle geometry
// "transform": <transform> // Optional
"motion": 0 // Optional: Index of motion for obstacle frame
}],
// Alternatively, "obstacles" can be a printf-style format string with one
// field for an integer. This specifies as many obstacles as there exist
// files named printf(obstacles, i) for i = 0, 1, 2, ...
// The ith obstacle is automatically assigned the ith motion.
// See karate.json or dress-*.json for why this is useful.

"gravity": [0, 0, -9.8], // Optional, default 0: Acceleration due to gravity

// "wind": { // Optional. By default, everything experiences air resistance
// in the normal direction due to still air.
// For windy scene, set nonzero velocity.
// For vacuum, set density to zero.
// // "density": <rho> // Optional, default 1: Air density
// "velocity": [7.5, 0, 0] // Optional, default 0: Wind velocity
// // "drag": <drag> // Optional, default 0: Tangential drag due to air
// }

// "friction": <mu> // Optional, default 0.6: Coeff. of cloth-cloth friction
// "obs_friction": <mu> // Optional, default 0.3: Cloth-obstacle friction

// "disable": ["strainlimiting", "remeshing"] // Optional, default []
// List of modules to disable. choose any or all of: "proximity",
// "physics", "strainlimiting", "collision", "remeshing", "separation"

"magic": {"repulsion_thickness": 5e-3, "collision_stiffness": 1e6}
// magic numbers to make the simulation behave
}

3.4 创建仿真网格

// TODO

3.5 输出文件

文件名
conf.json 是用于运行模拟的场景文件的副本。用于 resumereplay 和一般未来参考。
<frame>_<i>.obj 是指定帧数 <frame> 的 第 <i> 个布料的网格。模拟可以有多件布料,例如踢腿角色的裤子、T恤和背心。
obs_<j>.obj 是第 <j> 个障碍物在其参考姿势下的几何体的副本。
<frame>obs<j>.txt 是描述指定帧数 <frame><j> 个障碍的变换的 XML 片段。它仅用于在渲染时插入 Mitsuba 场景文件。在恢复( resume )和重播( replay )代码时会忽略它,而是根据 conf.json 中的规范重新构建障碍运动。
timing 在模拟的每个 routine 的每个时间步花费的挂钟计算时间的转储。