Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.8+ support #1

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
fa04c0e
2.8+ working importb3d
LabVaKars Aug 27, 2022
5ef60b9
block 28 fix
LabVaKars Aug 28, 2022
f403044
README
LabVaKars Aug 28, 2022
cbd6b51
import .way
LabVaKars Aug 28, 2022
a6e751d
8 block performance improved (bpy.ops)
LabVaKars Sep 17, 2022
0bd031b
improved 8 block + LOD detection
LabVaKars Sep 25, 2022
baaab19
Multiple b3d import
LabVaKars Sep 26, 2022
38f3a39
fixed triangulation
LabVaKars Sep 26, 2022
71a0e94
.raw import
LabVaKars Sep 28, 2022
2c95da8
block_to_import select
LabVaKars Oct 7, 2022
878133a
40 blok fix
LabVaKars Oct 8, 2022
d9830b6
uv override
LabVaKars Oct 10, 2022
746cd3a
hideLOD fix
LabVaKars Oct 15, 2022
d74df15
visible object copy
LabVaKars Oct 17, 2022
2c6b7cf
single add-on
LabVaKars Nov 10, 2022
6ec40c3
vertices/faces edit
LabVaKars Nov 22, 2022
5321164
b3dsplit
LabVaKars Nov 22, 2022
c9d2711
b3d refactor
LabVaKars Dec 24, 2022
8896fca
.res edit panel
LabVaKars Dec 26, 2022
cf56fd1
first successful export!
LabVaKars Dec 29, 2022
6c67956
export as-is(bad UV)
LabVaKars Jan 3, 2023
f37867e
block 33 import fix
LabVaKars Jan 6, 2023
80856c4
working export (unoptimized size)
LabVaKars Jan 6, 2023
708d0f8
cleanup + reporting
LabVaKars Jan 7, 2023
f70f1d1
various fixes
LabVaKars Jan 8, 2023
c26e892
empty name
LabVaKars Jan 8, 2023
1f1df40
group skip fix
LabVaKars Jan 8, 2023
1ce9a17
Update README.MD
LabVaKars Jan 9, 2023
e0f3a5b
more enums
LabVaKars Jan 14, 2023
8a7edb1
old getAllChildren
LabVaKars Jan 14, 2023
8cda37d
block 30 updated edit
LabVaKars Jan 15, 2023
7371ff5
b_28 fix
LabVaKars Jan 17, 2023
d42bae5
b3dsplit fix
LabVaKars Jan 17, 2023
fb45fdc
border sphere edit
LabVaKars Jan 22, 2023
5383f64
modal get operator
LabVaKars Jan 28, 2023
b0f1953
eng
LabVaKars Jan 28, 2023
00ca18d
various QoL fixes
LabVaKars Feb 1, 2023
0c55395
custom properties direct edit
LabVaKars Feb 4, 2023
17c7e4e
separate single block edit
LabVaKars Feb 4, 2023
94649cc
grouping + various fixes
LabVaKars Feb 5, 2023
0328ae6
b3dSqlite
LabVaKars Feb 11, 2023
a69f832
origin point + block11 + bound sphere export
LabVaKars Feb 11, 2023
35d93a9
no bound sphere property
LabVaKars Feb 11, 2023
b113b23
import simplify + block add
LabVaKars Feb 12, 2023
05239ca
enable way import
LabVaKars Feb 12, 2023
bf1280c
new version
LabVaKars Feb 12, 2023
f5085f3
v.2.3.1
LabVaKars Feb 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 33 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Blender-VWI
Плагины для форматов файлов игрового движка Virtual World Inventor.
Плагины для форматов файлов игрового движка Virtual World Inventor.
##### Текущие планы
* Доработка экспорта.
* Переход на Blender 2.9.
* Поддержка импорта и экспорта игровых ресурсов.
* Доработка экспорта b3d + .res.

## Поддерживаемые игры
| Название игры | Название игры (международное) | Год выхода |
Expand All @@ -12,32 +10,42 @@
| Дальнобойщики - 2 | Hard Truck 2 (King of the Road) | 2000 (2003)

## Поддерживаемые форматы файлов
| Расширение | Описание | Импорт | Экспорт |
| Расширение | Описание | Импорт | Экспорт |
|-----------|-----------------------|:----------:|:----------:|
| .b3d | Модели, логика, различные объекты | Да | Да |
| .way | Пути транспорта для ИИ | Да | Да |
| .tch/.tech | Параметры транспорта и динамических объектов | | Да |
| .res/.rmp | Архив игровых ресурсов | | в работе |
| .pro | Архив игровых ресурсов | | в работе |
| .b3d | Модели, логика, различные объекты | Да | Да |
| .b3d + .res | Модели, логика, различные объекты + текстуры | Да | Нет |
| .way | Пути транспорта для ИИ | Да | Нет |
| .tch/.tech | Параметры транспорта и динамических объектов | | Да |

## Файлы в проекте

#### Папка **src/2.79**
#### Папка **src/2.79**

Плагины для версии 2.79.

#### Папка **scenes**
#### Папка **src/2.80**

Плагины для версии 2.80+.
#### Папка **scenes**

Готовые сцены для экспорта в игру: **ht2-way.blend** - пути транспорта, **ht2-vehicle-export.blend** - транспорт, **ht2-env-module.blend** - карта

## Как установить плагины
#### Папка **utils**

Прочие полезные скрипты:
b3dsplit - извлечение из b3d-файла прочих моделей в отдельные файлы для импорта.
Пример: python b3dsplit.py ./TRUCKS.b3d ./split.txt

## Как установить плагины
1. Распаковать архив.
2. Поместить содержимое в папку Blender/2.79/scripts/addons/.
2. Поместить содержимое в папку Blender/2.79/scripts/addons/.
3. Открыть настройки в Blender (нажать LCtrl + Alt + U ), перейти во вкладку Addons.
4. Найти аддоны (b3d) и активировать их (галка на названии).

## Авторы
Юрий Гладышенко и Андрей Прожога.
Обновление: LabVaKars


## Ссылки
[Сообщество VK](https://vk.com/rnr_mods)
Expand All @@ -49,21 +57,19 @@
Hard Truck classic games (VWI engine) import/export plugins for Blender.

#### Roadmap
* Blender 2.9 support
* Add support for game resource files (.res/.rmp)
* .b3d + .res export support

## Supported games and formats

1. Hard Truck: Road to Victory (1998)

| Расширение | Описание | Import |
## Supported games
| Title | Title (ENG) | Release year |
|-----------|-----------------------|:----------:|
| .b3d | Models, game logic, various objects | Yes |
| Дальнобойщики: Путь к победе | Hard Truck: Road to Victory | 1998 |
| Дальнобойщики - 2 | Hard Truck 2 (King of the Road) | 2000 (2003)

2. Hard Truck: King Of The Road (2003)
## Supported formats

| Расширение | Описание | Import | Export |
| Extension | Description | Import | Export |
|-----------|-----------------------|:----------:|:----------:|
| .b3d | Models, game logic, various objects | Yes | Yes |
| .way | AI paths | Yes | Yes |
| .tch/.tech | Transport parameters | | Yes |
| .b3d | Models, game logic, various objects | Yes | Yes |
| .b3d + .res | Models, game logic, various objects + textures | Yes | No |
| .way | AI paths | Yes | No |
| .tch/.tech | Transport parameters | | Yes |
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*.py
128 changes: 64 additions & 64 deletions src/2.79/export_tch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,186 +25,186 @@ def read_tch(context, filepath, use_some_setting):
print("running read_tch...")
#file = open(filepath, 'r', encoding='utf-8')
#data = f.read()


file = open(filepath, 'r')

CollisionPlane = []

CPlanes_num = 0

field_ind = ""
field_x = ""
field_y = ""
field_z = ""
field_offset = ""

for line in file:
ColPlane_line = ""
if "CollisionPlane" in line:
CollisionPlane.append(line)
#CPlanes_num += 1
file.close()

#print(str(CollisionPlane))
ColPlane_vector = []


for i in range(len(CollisionPlane)):#(CPlanes_num):
if i < 10:
ColPlane_vector.append((CollisionPlane[i])[16:].split(" "))
else:
ColPlane_vector.append((CollisionPlane[i])[17:].split(" "))
#print(str(i))


print(str(ColPlane_vector))
# would normally load the data here
#print(data)

return {'FINISHED'}

def export_tch(context, filepath):
print("exporting tch...")
file = open(filepath, 'w')

global global_matrix
global_matrix = axis_conversion(to_forward="-Z",
to_up="Y",
).to_4x4() * Matrix.Scale(1, 4)

global CollisionPlane_num
CollisionPlane_num = 0

forChild(bpy.data.objects['tch'],True, file, CollisionPlane_num)

return {'FINISHED'}



def forChild(object, root, file, CollisionPlane_num):
if (not root):
if object.name == "Corner_Mark":
verticesL = []
uvs = []
faces = []

bm = bmesh.new()
bm.from_mesh(object.data)
bm.verts.ensure_lookup_table()
bm.faces.ensure_lookup_table()

bm.transform(global_matrix * object.matrix_world)

bm.to_mesh(object.data)


for v in bm.verts:
verticesL.append((v.co))

meshdata = object.data

for i, polygon in enumerate(meshdata.polygons):
for i1, loopindex in enumerate(polygon.loop_indices):
meshloop = meshdata.loops[loopindex]
faces.append(meshloop.vertex_index)

vLen = len(verticesL)

#for i,vert in enumerate(verticesL):
#file.write("CornerMark_" + str(i) + "=" + str(vert[0][0]) + " " + str(-vert[0][2]) + " " + str(vert[0][1]))
#file.write(str(object.data.vert[i][0][0]))
v_num = 0

v_num = 0

for vert in object.data.vertices:
v_num += 1
file.write("Corner_Mark_" + str(v_num) + "=" + str(round(vert.co.x, 6)) + " " + str(round(-vert.co.z, 6)) + " " + str(round(vert.co.y, 6)) + "\n")
#file.write(struct.pack("<f",vert.co.x))
#file.write(struct.pack("<f",vert.co.y))
#file.write(struct.pack("<f",vert.co.z))

if object.name == "Corner_Mark_W":
verticesL = []
uvs = []
faces = []

bm = bmesh.new()
bm.from_mesh(object.data)
bm.verts.ensure_lookup_table()
bm.faces.ensure_lookup_table()

bm.transform(global_matrix * object.matrix_world)

bm.to_mesh(object.data)


for v in bm.verts:
verticesL.append((v.co))

meshdata = object.data

for i, polygon in enumerate(meshdata.polygons):
for i1, loopindex in enumerate(polygon.loop_indices):
meshloop = meshdata.loops[loopindex]
faces.append(meshloop.vertex_index)

vLen = len(verticesL)
v_num = 0

v_num = 0

for vert in object.data.vertices:
v_num += 1
file.write("Corner_Mark_W" + str(v_num) + "=" + str(round(vert.co.x, 6)) + " " + str(round(-vert.co.z, 6)) + " " + str(round(vert.co.y, 6)) + "\n")

if object.name.find("CollisionPlane") != "Null" or "None":
if object.name != "CollisionPlane":
verticesL = []
uvs = []
faces = []

bm = bmesh.new()
bm.from_mesh(object.data)
bm.verts.ensure_lookup_table()
bm.faces.ensure_lookup_table()

bm.transform(global_matrix * object.matrix_world)

bm.to_mesh(object.data)


for v in bm.verts:
verticesL.append((v.co))

meshdata = object.data

for i, polygon in enumerate(meshdata.polygons):
for i1, loopindex in enumerate(polygon.loop_indices):
meshloop = meshdata.loops[loopindex]
faces.append(meshloop.vertex_index)
vLen = len(verticesL)

vLen = len(verticesL)

#vector = Vector(0,0,0)

#vector = mathutils.Vector((0.0, 0.0, 0.0))

vector_to_plane = Vector((0.0, 0.0, 0.0))

vector_to_plane = Vector((object.location.x, object.location.y, object.location.z))
#print(vector_to_plane.normalized())

vector_length = sqrt(vector_to_plane.x ** 2 + vector_to_plane.y ** 2 + vector_to_plane.z ** 2)
vector_to_plane = vector_to_plane.normalized()

#file.write("CollisionPlane" + str(v_num) + "=" + str(round(vert.co.x, 6)) + " " + str(round(-vert.co.z, 6)) + " " + str(round(vert.co.y, 6)) + "\n")
#print(vector_to_plane)
#file.write("CollisionPlane" + str(v_num) + "=" + str(vector_to_plane) + "\n")

#if (vector_to_plane.x != 0 and vector_to_plane.y != 0 and vector_to_plane.z != 0):
file.write("CollisionPlane" + str(CollisionPlane_num) + "=" + str(round(vector_to_plane.x, 6)) + " " + str(round(vector_to_plane.y, 6)) + " " + str(round(vector_to_plane.z, 6)) + " " + str(round(vector_length, 6)) + "\n")
CollisionPlane_num += 1

for child in object.children:
forChild(child,False,file, CollisionPlane_num)

Expand Down Expand Up @@ -250,7 +250,7 @@ class ImportTch(Operator, ImportHelper):
('OPT_B', "Second Option", "Description two")),
default='OPT_A',
)

class ExportTch(Operator, ExportHelper):
"""This appears in the tooltip of the operator and in the generated docs"""
bl_idname = "export_tch.some_data" # important since its how bpy.ops.import_tch.some_data is constructed
Expand All @@ -272,23 +272,23 @@ def execute(self, context):
# Only needed if you want to add into a dynamic menu
def menu_func_import(self, context):
self.layout.operator(ImportTch.bl_idname, text="Import KOTR tch")

def menu_func_export(self, context):
self.layout.operator(ExportTch.bl_idname, text="Export KOTR tch")


def register():
bpy.utils.register_class(ImportTch)
bpy.types.INFO_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.utils.register_class(ExportTch)
bpy.types.INFO_MT_file_export.append(menu_func_export)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)


def unregister():
bpy.utils.unregister_class(ImportTch)
bpy.types.INFO_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.utils.unregister_class(ExportTch)
bpy.types.INFO_MT_file_export.remove(menu_func_export)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)


if __name__ == "__main__":
Expand Down
Loading