ROS講座90 gazeboモデルでメッシュを使う、テクスチャを使う
環境
この記事は以下の環境で動いています。
項目 | 値 |
---|---|
CPU | Core i5-8250U |
Ubuntu | 20.04 |
ROS | Noetic |
Gazebo | 11.9.0 |
インストールについてはROS講座02 インストールを参照してください。
またこの記事のプログラムはgithubにアップロードされています。ROS講座11 gitリポジトリを参照してください。
概要
今まで単純な立体で模様の無いgazebo modelを作ってきました。今回はメッシュの使い方、テクスチャの適用の仕方を説明します。
メッシュの使い方(stlファイルを使う)
room1というモデルの形状でroom_mesh.stl
というメッシュを使います。stlファイルは以下のようにroom1モデルのディレクトリの直下に置きます。
sim3_lecture/
├── models/
│ └── room1/
│ ├── model.config
│ ├── model.sdf
│ └── room_mesh.stl
└── worlds/
└── world_test3.world
ソースコード
<?xml version='1.0'?>
<sdf version="1.4">
<model name="room1">
<pose>0 0 0.5 0 0 0</pose>
<link name="link">
<inertial>
<mass>1.0</mass>
<inertia>
<ixx>0.083</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>0.083</iyy>
<iyz>0.0</iyz>
<izz>0.083</izz>
</inertia>
</inertial>
<collision name="collision">
<geometry>
<mesh>
<uri>model://room1/room_mesh.stl</uri>
</mesh>
</geometry>
</collision>
<visual name="visual">
<geometry>
<mesh>
<uri>model://room1/room_mesh.stl</uri>
</mesh>
</geometry>
</visual>
</link>
</model>
</sdf>
このように<geometry>
要素の中の<mesh>
要素の中の<uri>
要素でファイルを指定します。model://(モデル名)/(ファイル名)
のように指定します。
テクスチャを張る
以下のようにモデルの中のmaterialstディレクトリの下に画像とテクスチャ用のORGEスクリプトを入れます。
sim3_lecture/
├── models/
│ ├── box2/
│ │ ├── materials/
│ │ │ ├── test_texture.material
│ │ │ └── texture1.png
│ │ ├── model.config
│ │ └── model.sdf
└── worlds/
└── world_test3.world
ソースコード
以下がOGREスクリプトです(OGREはRvizの描画エンジンです)。TestTextureという名前のテクスチャを定義してテクスチャのファイルとscaleを選択しています。
material TestTexture
{
technique
{
pass
{
texture_unit
{
// Relative to the location of the material script
texture texture1.png
// Repeat the texture over the surface (4 per face)
scale 0.5 0.5
}
}
}
}
-
TestTexture
がこのテクスチャの名前です(modelのsdfファイル中で使います。) -
scale
は1面あたりに何枚分貼るかという指定です。以下の様に記述すると1つの面に2x2で張られます。分割数で指定するので、大きい面には大きくテクスチャが張られます。
以下が本体のsdfファイルです。
<?xml version='1.0'?>
<sdf version="1.4">
<model name="box2">
<pose>0 0 0.5 0 0 0</pose>
<link name="link">
<inertial>
<mass>1.0</mass>
<inertia>
<ixx>0.083</ixx>
<ixy>0.0</ixy>
<ixz>0.0</ixz>
<iyy>0.083</iyy>
<iyz>0.0</iyz>
<izz>0.083</izz>
</inertia>
</inertial>
<collision name="collision">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
</collision>
<visual name="visual">
<geometry>
<box>
<size>1 1 1</size>
</box>
</geometry>
<material>
<script>
<uri>model://box2/materials/test_texture.material</uri>
<name>TestTexture</name>
</script>
</material>
</visual>
</link>
</model>
</sdf>
<material>
要素の中の<script>
要素の中で<uri>
でOGREスクリプトのファイル名を指定して<name>
でテクスチャの名前を指定します。
実行
以下のように表示されます。各ターミナルごとに実行前にsource ~/catkin_ws/devel/setup.bash
を実行する必要があります。
roslaunch gazebo_ros empty_world.launch world_name:=world_test3.world
コメント
stlファイルにテクスチャを適用しようとするとうまく表示されません。この場合はdaeファイルを作ってその中でテクスチャを適用する必要があります。
参考
Gazebo: Color And Texture Models
textureの使い方
目次ページへのリンク
Author And Source
この問題について(ROS講座90 gazeboモデルでメッシュを使う、テクスチャを使う), 我々は、より多くの情報をここで見つけました https://qiita.com/srs/items/8b0c00b1c409efd995cc著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .