1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

第2回: 障害物を設置してみた!Genesisでリムル様の試練

Posted at

はじめに

こんにちは、しゅんです! 重要事項:マジで遊んでるだけ
前回はGenesisにリムル様を追加し、シンプルな動作確認を行いました。今回は壁を設置するだけな記事になります。


壁の設置とシミュレーションコード

/your_path/rimuru.obj

適切なパスに置き換えすること

壁をシーンに追加し、スライムの挙動をシミュレートします。

コード:

# 壁を追加
scene.add_entity(
    morph=gs.morphs.Box(
        pos=(0.3, 0.3, 0.0),
        size=(0.1, 1.0, 0.15),
    ),
    material=gs.materials.Rigid(rho=1000, friction=0.5)
)

シミュレーションのコード全体は以下:

import numpy as np
import genesis as gs

# 初期化
gs.init(seed=0, precision='32', logging_level='debug')

# シーンの作成
scene = gs.Scene(
    sim_options=gs.options.SimOptions(
        substeps=10,
        gravity=(0, 0, -9.8),
    ),
    mpm_options=gs.options.MPMOptions(
        dt=5e-4,
        lower_bound=(-1.0, -1.0, -0.2),
        upper_bound=(1.0, 1.0, 1.0),
    ),
    viewer_options=gs.options.ViewerOptions(
        camera_pos=(1.5, 0, 0.8),
        camera_lookat=(0.0, 0.0, 0.0),
        camera_fov=40,
    )
)

# 地面を追加
scene.add_entity(
    morph=gs.morphs.Plane(),
    material=gs.materials.Rigid(
        rho=1000,
        friction=0.5
    )
)
# 壁を追加
scene.add_entity(
    morph=gs.morphs.Box(
        pos=(0.3, 0.3, 0.0),  # 壁の位置
        size=(0.1, 1.0, 0.15),  # 壁の大きさ(幅, 奥行き, 高さ)
    ),
    material=gs.materials.Rigid(
        rho=1000,  # 密度
        friction=0.5  # 摩擦係数
    )
)

# スライムを追加
slime = scene.add_entity(
    morph=gs.morphs.Mesh(
        file='your_path/rimuru.obj',
        pos=(0.0, 0.0, 0.2),  # スライムの初期位置
        scale=0.05,
        euler=(90, 0, 0),
    ),
    material=gs.materials.MPM.Muscle(
        E=1e4,
        nu=0.39,
        rho=800.,
        model='neohooken',
    )
)


# シーンを構築
scene.build()

# シミュレーションを実行
scene.reset()
# while True:
for i in range(1000):
    scene.step()

最後

なんとか壁作れた。階段も作りたかったが深夜でこれ以上頭使いたくなかったため、やめました。次回はjump機能です。それとわざとリムル様の座標と重ねて壁を降ろしたらリムル様が潰れた。。。悲しい
最後まで見てくれてありがとうございます。またよろしくお願いします。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?