Jump to content

Blender > .babylon Vertex Groups


Recommended Posts

Hello,

For anyone that may be interested, I have been messing with mesh.py to get it to export Vertex Groups along with their associated indices and have attached it.

I think @adam and @ozRocker have both asked about this and I'd definitely make good use of it. I'd be grateful if you could let me know if this works for you or not, please.

It currently adds them under the 'meshes' as 'vertexGroups'

Massive disclaimer: I am not good with Python!

Thank you

Problem: it duplicates indices.

mesh.py

Edited by babbleon
Problem
Link to comment
Share on other sites

Saw the pg, and downloaded last file, but did not diff it to the repos.  As it is the largest source file in the add-on, I would need to diff to find the lines added / changed.  Not a big deal in Netbeans.  I do not a use for right now in my own work, but now that I know it is an option uses might come up.

If you are thinking about a PR, a checkbox in the custom properties (default false) would definitely be needed, since if you are not using, it could really increase the size of the export file. 

Link to comment
Share on other sites

Thank you @ozRocker, do let me know if you have problems with it.

@JCPalmer, I have now added checkbox as you suggested. I have a problem which is beyond my understanding of python and would be grateful if you could help please. You may recall we added the 'Track To' constraint which adds this to metadata. I cannot work out how not to overwrite metadata when we have both 'Vertex Groups' & 'Track To'. I attach the latest mesh.py though I can do a PR if you prefer.

mesh.py

Link to comment
Share on other sites

7 hours ago, ozRocker said:

Just wondering, with the Blender export, is vertex order preserved?

Not at all.  Even worse, if you desired that, the vertices are not even directly consulted.  A feature in Blender that allows you to get a temp copy of geometry, with modifiers applied is used.  So if you were using a modifier like mirror, then twice the vertices would be exported than were actually be in the mesh.

Inside of using the mesh copy, vertices are indexed in the export for compactness & that is how BJS loads them to gl context.

Link to comment
Share on other sites

I look at your mesh.py.  I refactored it creating a small class called BJSVertexGroup, since you were doing an array of arrays, then indexing into it with loop, and also including a matching name.  It is very small, and looks a lot like the SubMesh class:

class BJSVertexGroup:
    def __init__(self, group):
        self.name = group.name
        self.groupIdx = group.index
        self.indices = []
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def to_scene_file(self, file_handler):
        file_handler.write('\n{')
        write_string(file_handler, 'name', self.name, True)
        write_array(file_handler, 'indices', self.indices)
        file_handler.write('}')

This adds functionality, so I bumped the version to 5.7.  I ran it in against a blend with armature of 25 bones, but one of the meshes is only affected by 2 bones (vertex groups are used for bones too).  It correctly only matched for 2 vertex groups. Data looked reasonable.

I do not have code to playing with this once  in BJS though.   Please run this  mesh.py against your .blends to verify, before I push up the new .zip file.  Also, please add an announcement topic illustrating, since this is the only change for 5.7

Link to comment
Share on other sites

Hi @JCPalmer, this all seems to work fine thank you. Something's not quite right with the indices.. I will have a look when I have time & post back.

I will post a further amended mesh.py soon which enabled you to export animated vertex positions so once that is sorted and you're happy to include - it can go to 5.7 too.

Thank you.

Edited by babbleon
correction
Link to comment
Share on other sites

Might be you wrote it out this way:

write_array(file_handler, 'indices', list(set(self.vertexGroups[indexgroups])))

I was not sure what that did.  Looking at this entire topic, it was probably for duplicates.  That could be put into the to_scene_file().  Duplicates can also just be avoided by moving up & indenting the code that appends them only when the vertex is added for the first time.

Duplicates are created automatically for the vertices which border a material change, but those are not implemented through indices, but actual duplicate vertices.

On your animation of vertices, this can get really expensive file size wise.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...