目录
Meshlab生成webots物体包络体bounding box
导入物体visual模型
-
首先将之前生成的物体外观模型导入到一个文件夹中,包含obj、mtl、jpg文件,分别对应几何描述、材料纹理描述、图片纹理素材
-
扫描仪扫描的物体单位是mm,需要将单位变成m,并且将扫描的物体几何中心放置在坐标原点,运行以下代码脚本进行处理即可,生成处理之后的目标模型文件output.obj
python scale_obj.py
# scale_obj.py import numpy as np # Read in the vertex coordinates from the OBJ file vertices = [] with open('cleansing_foam/cleansing_foam.obj', 'r') as f: for line in f: if line.startswith('v '): parts = line.split() x = float(parts[1]) / 1000.0 y = float(parts[2]) / 1000.0 z = float(parts[3]) / 1000.0 vertices.append([x, y, z]) # Compute the geometric center of the vertices center = np.mean(vertices, axis=0) # Shift all vertices so that the geometric center is at the origin vertices = [v - center for v in vertices] # Write out the modified OBJ file with shifted vertices with open('cleansing_foam/output.obj', 'w') as f: with open('cleansing_foam/cleansing_foam.obj', 'r') as f_in: for line in f_in: if line.startswith('v '): parts = line.split() x, y, z = vertices.pop(0) f.write('v {} {} {}\n'.format(x, y, z)) else: f.write(line)
-
处理之后得到output.obj文件,可以观察到vertex数值变成了m为度量的数值
生成物体包络模型作为WEBOTS碰撞体
- 打开meshlab,打开output.obj文件
- 选择filter中的simplification选项简化模型
- 通过减少target number of faces用于简化模型体,例如简化到100个面
- 点击apply应用简化,可以看到我们得到了一个简化后的模型可以用于形成bounding box
- 最后export mesh as存储为collision.obj
导入物体visual模型到webots
- 在webots中新建一个Robot或solid节点,在节点children里面进行模型导入
- 添加一个CadShape节点
- 从CadShape节点里面编辑url,选择output.obj的路径
导入物体collision模型到webots
- 类似于导入visual模型,在bounding_box中添加一个mesh,在mesh的url里面选取collision.obj的文件路径即可
- 导入之后可以看到物体能够正常显示也能看到包络mesh的大致形状
测试WEBOTS物体导入
- 添加physics性质使得我们的节点具备碰撞模拟和重力模拟
- 保存world,开启仿真运行,看一下物体是否自由掉落,是否不发生碰撞穿模