0
$\begingroup$

I used the blender add-on Sapling Tree Gen to generate a tree, then I added an armature and deleted the mesh, this yields the following:

enter image description here

That's basically what I want. So now I want to export this set of vertices and edges as an obj. To that effect I tried doing export to obj.

However the resulting obj file has no vertices and no edges.

How do I export the skeleton?

$\endgroup$
2
  • $\begingroup$ Just to clarify - Are you trying to export an Armature as OBJ with each bone being converted to two vertices connected by an edge? $\endgroup$ Commented Dec 23, 2023 at 7:56
  • $\begingroup$ @RumenBelev Exactly, I just want the graph $\endgroup$
    – Makogan
    Commented Dec 23, 2023 at 8:09

1 Answer 1

1
$\begingroup$

Here is a simple script that you can try.

Paste this script in a new Text in your Text Editor

import bpy
import bmesh

# Selected Armature in Object Mode Required
obj = bpy.context.active_object
view_layer = bpy.context.view_layer

if obj.type == 'ARMATURE':
    # Create new mesh object to contain the converted bones
    mData = bpy.data.meshes.new( obj.name + "_Data" )
    mObj = bpy.data.objects.new( obj.name + "_OBJ", mData )
    
    # Link to current View Layer active Collection (link to scene)
    view_layer.active_layer_collection.collection.objects.link(mObj)

    # Using BMesh
    bm = bmesh.new()
    bm.from_mesh(mData)   # initialize from mData
    # Read Armature's Bones Data and assign each head and tail to vertices of a new edge
    for bone in obj.data.bones:
        bm.edges.new((bm.verts.new(bone.head_local), bm.verts.new(bone.tail_local)))

    # Convert BMesh data to Mesh Data and rewrite mData
    bm.to_mesh(mData)
    bm.free()  # no longer needed

Select your Armature object and run the script by pressing the Run button. It will convert the bones to edges. Note there will be duplicate vertices where bones connect. You can merge vertices if needed in Edit mode. The object is of type Mesh which you can now export as an OBJ file.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .