[x3d-public] Blender Python for exporting humanoid information

Brutzman, Donald (Don) (CIV) brutzman at nps.edu
Sat Sep 9 16:25:16 PDT 2023


Please do not post ChatGPT information, it is not authoritative and can be
completely wrong.

 

You can do whatever you want, but not at everyone else's expense.  Please do
not waste our time.

 

all the best, Don

-- 

Don Brutzman  Naval Postgraduate School, Code USW/Br        brutzman at nps.edu

Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA    +1.831.656.2149

X3D graphics, virtual worlds, navy robotics https://faculty.nps.edu/brutzman

 

From: x3d-public <x3d-public-bounces at web3d.org> On Behalf Of John Carlson
Sent: Friday, September 8, 2023 3:15 PM
To: GPU Group <gpugroup at gmail.com>; Joe D Williams <joedwil at earthlink.net>;
Michalis Kamburelis <michalis.kambi at gmail.com>; Nicholas Polys
<npolys at vt.edu>; X3D Graphics public mailing list <x3d-public at web3d.org>
Subject: [x3d-public] Blender Python for exporting humanoid information

 

ChatGPT says (I'll have to check accuracy later):

 

armature = None

for obj in bpy.context.scene.objects:

    if obj.type == 'ARMATURE':

      armature = obj

      break

 

if armature:

    for bone in armature.pose.bones:

         # Access bone name, location, rotation, and scale

         bone_name = bone.name
<https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbone.name%
2F&data=05%7C01%7Cbrutzman%40nps.edu%7Cd209707ee66644e8372008dbb0b933ec%7C6d
936231a51740ea9199f7578963378e%7C0%7C0%7C638298081722013666%7CUnknown%7CTWFp
bGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7
C3000%7C%7C%7C&sdata=k4hUP8YEo0FeVyTDMLqLxOsARfwjKt9pTcEnzetC6OQ%3D&reserved
=0> 

         bone_location = bone.location

         bone_rotation = bone.rotation_euler

         bone_scale = bone.scale

         # Do something with this bone information

         print(f"Bone: {bone_name}")

         print(f"Location: {bone_location}")

         print(f"Rotation: {bone_rotation}")

         print(f"Scale: {bone_scale}")

 

if armature:

    for obj in bpy.context.selected_objects:

           if obj.type == 'MESH':

                 mesh = obj.data

                 for vertex in mesh.vertices:

                       # Access vertex coordinates  

                       vertex_coords = vertex.co
<https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fvertex.co%
2F&data=05%7C01%7Cbrutzman%40nps.edu%7Cd209707ee66644e8372008dbb0b933ec%7C6d
936231a51740ea9199f7578963378e%7C0%7C0%7C638298081722013666%7CUnknown%7CTWFp
bGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7
C3000%7C%7C%7C&sdata=BuW3jan2ypuFOhl6mekZLUwaZanxAzj4Ihlyg4%2BKVfw%3D&reserv
ed=0> 

                       # Do something with this vertex information

                        print(f"Vertex Coordinates {vertex_coords}")

 

# Additionally,  getting skin coord information

 

# Replace 'YourMeshObjectName' with the actual name of your mesh object

 

mesh_obj = bpy.data.objects['YourMeshObjectName']

 

vertex_groups = mesh_obj.vertex_groups

for group in vertex_groups: l

    group_name = group.name
<https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fgroup.name
%2F&data=05%7C01%7Cbrutzman%40nps.edu%7Cd209707ee66644e8372008dbb0b933ec%7C6
d936231a51740ea9199f7578963378e%7C0%7C0%7C638298081722013666%7CUnknown%7CTWF
pbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%
7C3000%7C%7C%7C&sdata=oMf5JEitVRXGeURdZiRr4Iz%2Bn4SrvwbZUgzdpN4DZgY%3D&reser
ved=0> 

    for index, weight in group.weight_paint:

        # 'index' is the vertex index, and 'weight' is the weight value

        print(f"Group: {group_name}, Vertex Index: {index}, Weight:
{weight}")

 

Seems straightforward, if custom per model.  group_name is probably
analogous to joint name.  Combining scripts would probably be best.

 

Animations are another step.  I'm not sure how accessible this is because it
refers to selected_objects for one.  Also, one will have to convert bones to
Joints (hmm, look at an import script?)

 

Sorry, I couldn't read the Blender documentation or the ChatGPT English.
Just the facts, ma'am.

 

John

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230909/0d323007/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5464 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230909/0d323007/attachment-0001.p7s>


More information about the x3d-public mailing list