File size: 3,460 Bytes
07aae38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---

title: Besiege Machine Generator
emoji: 🎮
colorFrom: purple
colorTo: blue
sdk: gradio
sdk_version: 4.44.1
app_file: app.py
pinned: false
license: mit
---


# 🎮 Besiege Machine Generator

使用 AI 生成你的 Besiege 机器设计!这个应用使用 DeepSeek AI 模型来理解你的描述,并生成可以直接在 Besiege 游戏中使用的 .bsg 文件。

## ✨ 特性

- 🤖 **AI 生成**:使用自然语言描述你想要的机器,AI 会自动生成
- 🔄 **手动转换**:如果你已经有 JSON 数据,可以直接转换为 .bsg 文件
- 💾 **一键下载**:生成后直接下载 .bsg 文件
- 🎨 **现代界面**:美观易用的用户界面

## 🚀 使用方法

### AI 生成模式

1. 在文本框中描述你想要创建的机器
   - 例如:"创建一个四轮车,带有旋转块驱动"
2. (可选)调整高级设置
   - Temperature:控制创意程度
   - Max Tokens:控制生成长度
3. 点击"生成机器"按钮
4. 等待 AI 生成完成
5. 下载生成的 .bsg 文件

### 手动转换模式

1. 粘贴你的 JSON 机器数据
2. 点击"转换为 XML"按钮
3. 下载生成的 .bsg 文件

## 📋 JSON 格式说明

JSON 格式应该包含机器的方块信息,例如:

```json

[

    {"id": "0", "order_id": 0, "parent": -1, "bp_id": -1},

    {"id": "1", "order_id": 1, "parent": 0, "bp_id": 0},

    ...

]

```

### 字段说明:

- `id`: 方块类型 ID
- `order_id`: 方块的顺序编号
- `parent`: 父方块的 order_id(-1 表示根方块)

- `bp_id`: 连接到父方块的建造点 ID

对于线性方块(如橡皮筋,id=9):

```json

{"id": "9", "order_id": 2, "parent_a": 0, "bp_id_a": 0, "parent_b": 1, "bp_id_b": 2}

```

## 🎮 可用方块类型

- `0`: Starting Block(起始方块)
- `1`: Wooden Block(木块)
- `2`: Powered Wheel(动力轮)
- `15`: Small Wooden Block(小木块)
- `16`: Spring(弹簧)
- `22`: Rotating Block(旋转块)
- `30`: Container(容器)
- `35`: Ballast(配重)
- `36`: Boulder(巨石)
- `41`: Wooden Rod(木棒)
- `63`: Log(原木)
- `9`: Rubber Band(橡皮筋,线性方块)

## 🔧 技术栈

- **Frontend**: Gradio
- **AI Model**: DeepSeek-R1-Distill-Llama-8B
- **Backend**: Python
- **Libraries**: NumPy, SciPy, Hugging Face Hub

## ⚙️ 本地运行

1. 克隆仓库
```bash

git clone <your-repo-url>

cd BesiegeField-MachineGenerator

```

2. 安装依赖
```bash

pip install -r requirements.txt

```

3. 设置环境变量(可选,用于访问 HF 模型)
```bash

export HF_TOKEN=your_huggingface_token

```

4. 运行应用
```bash

python app.py

```

## 📝 注意事项

1. **生成质量**:AI 生成的机器可能需要在游戏中进行调整
2. **尺寸限制**   - 长度(Z): ≤ 17
   - 宽度(X): ≤ 17
   - 高度(Y): ≤ 9.5
3. **方块连接**:新方块必须连接到现有方块的可建造点
4. **坐标系统**:使用左手坐标系,Y+ 向上,Z+ 向前,X+ 向右

## 🤝 贡献

欢迎提交 Issue 和 Pull Request!

## 📄 许可证

MIT License

## 🙏 致谢

- [Besiege](https://store.steampowered.com/app/346010/Besiege/) - 精彩的物理建造游戏
- [DeepSeek AI](https://huggingface.co/deepseek-ai) - 强大的 AI 模型
- [Gradio](https://gradio.app/) - 快速构建 ML 应用界面