4 Commits

Author SHA1 Message Date
SleepKiller
23e479ae51 fix flat normals not being handled 2019-11-24 16:03:13 +13:00
SleepKiller
bc388640ed Update reference_manual.md 2019-11-22 13:52:04 +13:00
SleepKiller
0db2f30ef3 Update reference_manual.md 2019-11-22 13:49:39 +13:00
SleepKiller
e2c0c42d88 update readme 2019-11-22 02:42:49 +13:00
4 changed files with 42 additions and 26 deletions

View File

@@ -1,20 +1,32 @@
# SWBF-msh-Blender-Export
WIP .msh (SWBF toolchain version) exporter for Blender 2.8
Currently capable of exporting the active scene without collision primitives or skinning information.
Currently capable of exporting the active scene without skinning information.
### Installing
You install it like any other Blender addon, if you already know how to do that then great! Grab the [latest release](https://github.com/SleepKiller/SWBF-msh-Blender-Export/releases/latest) (or if you're the adventerous type [clone from source](https://github.com/SleepKiller/SWBF-msh-Blender-Export/archive/master.zip)) and you'll be good to go.
> TODO: Install instructions.
However if you don't know how to install then read on!
These instructions are going to be for Windows. If you're on a different platform I'm sure some quick web searching can help provide you with answers.
First download and extract the addon [latest release](https://github.com/SleepKiller/SWBF-msh-Blender-Export/releases/latest).
Then open up Explorer and paste `%USERPROFILE%\AppData\Roaming\Blender Foundation\Blender\2.80\` into it's address bar. Then go into the `scripts` folder in that directory and copy the `addons` folder from the extracted addon into the scripts folder.
Next open up Blender, go into Edit > Preferences > Addons. Select "Community" tab and then search for ".msh". "Import-Export: SWBF .msh export" should come up, check the box next to it. The preferences window should look like this once you're done.
![Installed addon.](docs/images/blender_addon_installed.png)
If you've done that then the addon is installed and you should now find "SWBF msh" listed under Blender's export options.
### Reference Manual
Included in the repository is a [Reference Manual](https://github.com/SleepKiller/SWBF-msh-Blender-Export/blob/master/docs/reference_manual.md#reference-manual) of sorts. There is no need to read through it before using the addon but anytime you have a question about how something works or why an export failed it should hopefully have the answers.
### Work to be done
- [x] Raise an error when a .msh segment has more than 32767 vertices.
- [x] Convert from Blender's coordinate space to .msh cooordinate space.
- [x] Add support for exporting materials. Blender's materials are all based around it's own renderers, so possibly going to need custom UI and properties in order to provide something useful for .msh files.
- [x] Add support for collision primitives. Blender doesn't seam to support having basic boxes, cylinders or spheres so it's likely some wacky rules and conventions will need to be used by the modeler. "Add a 1m mesh primitive, have "sphere/box/cylinder" in the name and control the size with the object's scale." Less intuitive than I'd like but it might be the best course of action.
- [ ] Investigate and add support for exporting bones and vertex weights.
- [ ] Investigate and add support for exporting animations.
- [ ] Investigate if anything special needs to be done for lod/lowres exporting.
- [ ] Investigate and add support for editing and exporting SWBF2 cloth.
- [ ] Implement .msh importing. Currently you can use the 1.2 release of [swbf-unmunge](releases/tag/v1.2.0) to save out munged models to glTF 2.0 files if you need to open a model in Blender.
### What from [glTF-Blender-IO](https://github.com/KhronosGroup/glTF-Blender-IO) was used?

View File

@@ -103,7 +103,7 @@ def create_mesh_geometry(mesh: bpy.types.Mesh) -> List[GeometrySegment]:
for segment, material in zip(segments, mesh.materials):
segment.material_name = material.name
def add_vertex(material_index: int, vertex_index: int, loop_index: int) -> int:
def add_vertex(material_index: int, vertex_index: int, loop_index: int, use_smooth_normal: bool, face_normal: Vector) -> int:
nonlocal segments, vertex_remap
vertex_cache_miss_index = -1
@@ -111,19 +111,24 @@ def create_mesh_geometry(mesh: bpy.types.Mesh) -> List[GeometrySegment]:
cache = vertex_cache[material_index]
remap = vertex_remap[material_index]
def get_cache_vertex(vertex_index: int, loop_index: int):
vertex_normal: Vector
if use_smooth_normal or mesh.use_auto_smooth:
if mesh.has_custom_normals:
vertex_normal = mesh.loops[loop_index].normal
else:
vertex_normal = mesh.vertices[vertex_index].normal
else:
vertex_normal = face_normal
def get_cache_vertex():
yield mesh.vertices[vertex_index].co.x
yield mesh.vertices[vertex_index].co.y
yield mesh.vertices[vertex_index].co.z
if mesh.has_custom_normals:
yield mesh.loops[loop_index].normal.x
yield mesh.loops[loop_index].normal.y
yield mesh.loops[loop_index].normal.z
else:
yield mesh.vertices[vertex_index].normal.x
yield mesh.vertices[vertex_index].normal.y
yield mesh.vertices[vertex_index].normal.z
yield vertex_normal.x
yield vertex_normal.y
yield vertex_normal.z
if mesh.uv_layers.active is not None:
yield mesh.uv_layers.active.data[loop_index].uv.x
@@ -133,7 +138,7 @@ def create_mesh_geometry(mesh: bpy.types.Mesh) -> List[GeometrySegment]:
for v in mesh.vertex_colors.active.data[loop_index].color:
yield v
vertex_cache_entry = tuple(get_cache_vertex(vertex_index, loop_index))
vertex_cache_entry = tuple(get_cache_vertex())
cached_vertex_index = cache.get(vertex_cache_entry, vertex_cache_miss_index)
if cached_vertex_index != vertex_cache_miss_index:
@@ -146,11 +151,7 @@ def create_mesh_geometry(mesh: bpy.types.Mesh) -> List[GeometrySegment]:
remap[(vertex_index, loop_index)] = new_index
segment.positions.append(convert_vector_space(mesh.vertices[vertex_index].co))
if mesh.has_custom_normals:
segment.normals.append(convert_vector_space(mesh.loops[loop_index].normal))
else:
segment.normals.append(convert_vector_space(mesh.vertices[vertex_index].normal))
segment.normals.append(convert_vector_space(vertex_normal))
if mesh.uv_layers.active is None:
segment.texcoords.append(Vector((0.0, 0.0)))
@@ -165,9 +166,9 @@ def create_mesh_geometry(mesh: bpy.types.Mesh) -> List[GeometrySegment]:
for tri in mesh.loop_triangles:
polygons[tri.material_index].add(tri.polygon_index)
segments[tri.material_index].triangles.append([
add_vertex(tri.material_index, tri.vertices[0], tri.loops[0]),
add_vertex(tri.material_index, tri.vertices[1], tri.loops[1]),
add_vertex(tri.material_index, tri.vertices[2], tri.loops[2])])
add_vertex(tri.material_index, tri.vertices[0], tri.loops[0], tri.use_smooth, tri.normal),
add_vertex(tri.material_index, tri.vertices[1], tri.loops[1], tri.use_smooth, tri.normal),
add_vertex(tri.material_index, tri.vertices[2], tri.loops[2], tri.use_smooth, tri.normal)])
for segment, remap, polys in zip(segments, vertex_remap, polygons):
for poly_index in polys:

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -459,10 +459,13 @@ Sets the strength of the material's diffuse at the bottom of the "blink".
Speed of blinking, higher is faster.
### Materials.Texture Maps
All textures should be the names or paths to .tga files. SWBF's toolchain does not support .tga files with RLE (Run Length Encoding) compression or paletted .tga files. They should either be 8-bit greyscale, 24-bit RGB or 32-bit RGBA.
#### Materials.Texture Maps.Diffuse Map
The basic diffuse map for the material. The alpha channel is either the Transparency Map, Glow Map or Gloss Map, depending on the selected rendertype and flags.
Textures are not automatically copied over to the .msh file's folder on export at this time.
#### Materials.Texture Maps.Detail Map
Detail maps allow you to add in 'detail' to the Diffuse Map at runtime.