Skip to content

Upgrade FBX files to modern version compatible with Blender import #175

Description

@iwanPlays

One of the complicated things about r1 modding and mapmaking is that its fbx 3d models use vertex colors and an old fbx format that is incompatible with blender imports.

If you try to import R1's FBX files into Blender, you get this error:

Report: Error
Version 6000 unsupported, must be 7100 or later

Image

As far as I can tell, Autodesk's FBX 2013 Converter for Windows and Mac works without issue on Windows at least, it's just that its installation file annoyingly requires admin rights (but you can just unzip it to skip that).

I only tested it a little bit so far, but the files seem to work the same in Unity after conversion. Also Blender can then import the files and one script in Blender is then able to make it so the vertex colors are visible.

Would it be reasonable to aim for updating all FBX files in both the normal assets and the unity project assets folders?

I ran one experiment with just the Unity project FBX files and some of them would not convert:

Image Image Image

Turns out these were already newer (version 7500) than the Autodesk tool supports (it exports version 7300) and import into Blender fine:

  • ceiling_turret.fbx
  • LevelTileGuideFBX.fbx
  • all in Gun Range/ (except SteelTarget.fbx)

I used the following sh script in git bash for windows to replace all old fbx that had been converted in the Unity project.

#!/usr/bin/env bash

# Recursively find all "FBX 2013" directories
find . -type d -name "FBX 2013" -print0 | while IFS= read -r -d '' dir; do
    parent_dir="$(dirname "$dir")"

    # Find all .fbx files inside the folder (case-insensitive)
    find "$dir" -maxdepth 1 -type f \( -iname "*.fbx" \) -print0 | \
    while IFS= read -r -d '' file; do
        filename="$(basename "$file")"
        target="$parent_dir/$filename"

        echo "Moving:"
        echo "  From: $file"
        echo "  To:   $target"

        # Move and overwrite existing file
        mv -f "$file" "$target"
    done
done

CC0/no copyright

As far as I can tell the game looks the same.

Steam testing branch:
Image

FBX upgraded version played in Unity:
Image

Regarding getting vertex colors to work in Blender, I used the following:

import bpy

# Material name to reuse/create
MAT_NAME = "VertexColorMaterial"

# Create or get material
mat = bpy.data.materials.get(MAT_NAME)

if mat is None:
    mat = bpy.data.materials.new(name=MAT_NAME)
    mat.use_nodes = True

    nodes = mat.node_tree.nodes
    links = mat.node_tree.links

    # Clear default nodes
    nodes.clear()

    # Create nodes
    output = nodes.new(type="ShaderNodeOutputMaterial")
    bsdf = nodes.new(type="ShaderNodeBsdfPrincipled")
    vcol = nodes.new(type="ShaderNodeVertexColor")

    # Position nodes
    vcol.location = (-400, 0)
    bsdf.location = (-100, 0)
    output.location = (200, 0)

    # Use active vertex color layer
    vcol.layer_name = ""

    # Connect nodes
    links.new(vcol.outputs["Color"], bsdf.inputs["Base Color"])
    links.new(bsdf.outputs["BSDF"], output.inputs["Surface"])

# Assign material to all selected mesh objects
for obj in bpy.context.selected_objects:
    if obj.type != 'MESH':
        continue

    mesh = obj.data

    # Ensure object has a color attribute
    if not mesh.color_attributes:
        print(f"{obj.name}: No vertex colors found")
        continue

    # Assign material
    if mat.name not in [m.name for m in obj.data.materials]:
        obj.data.materials.append(mat)
    else:
        # Replace first slot with material if desired
        obj.material_slots[0].material = mat

    print(f"{obj.name}: Vertex color material assigned")

print("Done.")

CC0/no copyright

I don't know whether that [the blender script] is the right thing to do yet if the plan is to build/remix existing maps, but it's enough to get a few nice renders.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions