Files
Mujoco_WASM/plugin/sdf/README.md
T
chenlin b45b15d153
build / setup (compute matrix) (push) Has been cancelled
build / ${{ matrix.label }} (push) Has been cancelled
build / macos-15-arm64-studio (push) Has been cancelled
build / ubuntu-24.04-clang-18-studio (push) Has been cancelled
build / ubuntu-24.04-gcc-14-studio (push) Has been cancelled
build / windows-2025-ninja-studio (push) Has been cancelled
build / ubuntu-24.04-clang-18-wasm (push) Has been cancelled
build / ubuntu-24.04-clang-18-mjx (push) Has been cancelled
add chinese
2026-08-19 17:14:37 +08:00

99 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<h1>
<a href="#"><img alt="MuJoCo" src="../../banner.png" width="100%"/></a>
</h1>
## 符号距离函数(SDF)插件
这些是第一方插件,使用符号距离函数(Signed Distance Functions, SDF)实现隐式几何体。它们可以应用于 **geoms**(几何体)和 **meshes**(网格,在 **asset** 资产部分)。示例模型可在[此文件夹](../../model/plugin/sdf/)中找到。
### 螺栓(Bolt
在 [bolt.cc](bolt.cc) 中实现。使用示例见 [nutbolt.xml](../../model/plugin/sdf/nutbolt.xml)。
该插件实现了一个带有六角头的螺栓,类似于 https://www.shadertoy.com/view/XtffzX。
参数:
- `radius` [m]:螺栓半径(默认 `0.26`)。
### 碗(Bowl
在 [bowl.cc](bowl.cc) 中实现。使用示例见 [bowl.xml](../../model/plugin/sdf/bowl.xml)。
该插件实现了来自 https://www.shadertoy.com/view/7tVXRt 的被切割中空球体。
参数:
- `height` [m]:切割平面的位置(默认 `0.4`)。
- `radius` [m]:球体半径(默认 `1`)。
- `thickness` [m]:碗的壁厚(默认 `0.02`)。
### 齿轮(Gear
在 [gear.cc](gear.cc) 中实现。使用示例见 [gear.xml](../../model/plugin/sdf/gear.xml)。
该插件实现了来自 https://www.shadertoy.com/view/3lG3WR 的 2D 齿轮几何体的 3D 拉伸挤出。
参数:
- `alpha` [m]:齿轮的初始旋转角度(默认 `0`)。
- `diameter` [m]:齿轮直径(默认 `2.8`)。
- `teeth` []:齿数(默认 `25`)。
### 螺母(Nut
在 [nut.cc](nut.cc) 中实现。使用示例见 [nutbolt.xml](../../model/plugin/sdf/nutbolt.xml)。
该插件实现了一个六角螺母,与来自 https://www.shadertoy.com/view/XtffzX 的螺栓头部相同。
参数:
- `radius` [m]:螺母半径(默认 `0.26`)。
### 圆环体(Torus
在 [torus.cc](torus.cc) 中实现。使用示例见 [torus.xml](../../model/plugin/sdf/torus.xml)。
该插件实现了一个圆环体。
参数:
- `radius1` [m]:主半径/大半径(默认 `0.35`)。
- `radius1` [m]:次半径/小半径(默认 `0.15`)。
### 如何创建自定义 SDF
在当前 README 所在的 SDF 文件夹中创建您的 `MySDF.h``MySDF.cc` 文件。使用以下接口实现您的 SDF:
```cpp
struct MySDFAttribute {
static constexpr int nattribute =
/* 填入属性数量 */;
static constexpr char const* names[nattribute] =
/* 与 SDF 类中属性数组顺序相同的属性名称数组 */;
static constexpr mjtNum defaults[nattribute] =
/* 属性的默认值数组 */;
};
class MySDF {
public:
// 创建新的 MySDF 实例,失败时返回 null。
static std::optional<MySDF> Create(const mjModel* m, mjData* d, int instance);
MySDF(MySDF&&) = default;
~MySDF() = default;
// 在查询点返回 SDF 距离及其梯度的函数
mjtNum Distance(const mjtNum point[3]) const;
void Gradient(mjtNum grad[3], const mjtNum point[3]) const;
// 需要在 register.cc 中添加对此函数的调用
static void RegisterPlugin();
// 与上述结构体中顺序相同的属性数组
mjtNum attribute[MySDFAttribute::nattribute];
private:
MySDF(const mjModel* m, mjData* d, int instance);
};
```