Jump to content

Introducing morph targets


GameMonetize
 Share

Recommended Posts

Not going to prioritize over my work, but will add.  There are many things from my implementation which should help, like keeping track of Blender's vertices as they are being added.  The exporter, as you know, grabs things in material order & duplicates vertices at the borders where the material changes.

Part of the shapekey code can be kept, but think it needs to be reworked.  Your GPU implementation's restriction on having the exact same # of vertices is going to require shutting of groups.  I allow a group of the entire mesh, but it still tries to optimized out vertices which are un-affected.

Normals are not going to get passed though.  Am reading Shapekeys directly, not mesh posing like an armature for an action.  Shapekeys do not have normals themselves.  Normals are derivative data.  Have progressed from my own calculations of a targets normals to using @jerome's, which were faster than my own.  There are minor creases in some of my scenes with makehuman.  Think it is actually a makehuman issue.  Have a triangulation idea of as the vertex changed from the basis (direction), make the corresponding change to the basis normal.  Should be faster than calcing a normal too.  See creasing highlighted.

58ecf4e4e01d4_normalseems.thumb.JPG.b45b9f020c40408eeec5e52d9464ceb6.JPG

 

Link to comment
Share on other sites

I have looked at the TOB version of my code base.  I find in my ShapeKeyGroup.py file that I had broken out extracting the keys / targets from organizing them into groups.  This is a class called RawShapeKey.  I added the constructor arg, allowVertReduction, which when passed as False does not log how many vertices are actually different from the original value.

RawShapeKey could have a to_scene_file() added:

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def to_scene_file(self, file_handler):
        file_handler.write('{')
        ...
        file_handler.write('}')

This not going to be something I am going to do for a while.  I am in the process of finalizing Mesh.py unrelated to a .babylon.  Will adjust the logic to work with or without groups.  There are other things I am doing to close code for the mesh code, but when done will:

  • copy ShapeKeyGroup.py file to BJS repo, & hook it up in __init__.py
  • Merge the flow control to create either RawShapeKeys or RawShapeKeys  & ShapeKeyGroups in Mesh.py

That would leave the flow control in Mesh.to_scene_file() to write the keys.  This along with the actual writing, shown above.  This primarily a plumbing job.  I'll do it, but not for about a month or so.

Link to comment
Share on other sites

I have my own implementation of morphing, QueuedInterpolation extension, so not an authority on this new one.  Would say that positions, normals, UV1, UV2, vertex colors, matrix weights, matrix indices, ( matrix weights extra, and matrix indices extra for more than 4 influencers ) each also take up an attribute.

Link to comment
Share on other sites

Does anyone know how I can use Blender exporter for morph manager.  I tried 2 meshes with exact same vertex number but the exporter made one 9,350 vertices and the other 9,352 vertices so I can't use them with morph manager.  I'm not sure if the exported vertices are in the same order either.

Link to comment
Share on other sites

ok, I had to use the objLoader because that doesn't mess with the vertices.  I've got a demo here: http://punkoffice.com/weight

This is just a simple "weight gain" example.  This mesh has about 7,000 quads.  I've realised that for every blendshape I need to replicate another 7,000 quads.  This could get expensive!

Edit: I just realised the PBR material doesn't work with the morph target.  It just shows the original mesh shape.  Click on "Disable diffuse map" to see what I mean

Link to comment
Share on other sites

10 hours ago, Deltakosh said:

Does this one works?

https://www.babylonjs-playground.com/#HPV2TZ#6

 

if yes can you repro your issue in the PG?

Yes that works.

I've made a playground here using my mesh: http://www.babylonjs-playground.com/#28YUR5#201

I can't get it to compile.  I have to use an OBJ loader but this OBJ loader loads one of the meshes as twice the number of vertices as the first mesh.  I don't know any other way to load an OBJ in the playground

Link to comment
Share on other sites

2 minutes ago, Deltakosh said:

Not sure what mesh duplicates is? Can you explain? Perhaps I can help

I'm using the .OBJ file here http://preview.punkoffice.com/morph/weight.obj

In that .OBJ there are 2 meshes.  There's the normal girl.  Then what I did was simply "duplicate" her so I have a copy with exact same vertices, then I made her fat.  In Blender and when using SceneLoader it properly shows that they both have 7,405 vertices, but in the method I'm using in the playground one has 7,405 and the other has 14,810 (exactly double).  You can see in the console output

 

Link to comment
Share on other sites

I figured out what's wrong.  I get this crash on everything when I use the latest preview version of babylon.js (I downloaded it from GIThub 10 minutes ago).  I've applied that preview version to my old stuff that just displays a mesh from a .babylon file and it crashes at executeWhenReady().  They all do.  Fine in desktop browsers but crashes in iOS.  So its nothing to do with the morphing code that I'm using.  However, I don't get any errors when morphing in the playground.  Is the playground using a different version of babylon.js?

I've attached the output

shader_errors.jpg

Link to comment
Share on other sites

I found the problem with my coding.

I did this to check if webGL is supported:

function webgl_detect(return_context) {
    if (!!window.WebGLRenderingContext) {
        var names = ["webgl", "experimental-webgl", "moz-webgl", "webkit-3d"],
           context = false;

        for(var i=0;i<4;i++) {
            try {
                context = canvas.getContext(names[i]);
                if (context && typeof context.getParameter == "function") {
                    // WebGL is enabled
                    return true;
                }
            } catch(e) {}
        }

        // WebGL is supported, but disabled
        return false;
    }

    // WebGL not supported
    return false;
}

which is stupid because I can just use BABYLON.Engine.isSupported() instead.  But that code above gave all those errors with the preview release of babylon.js

So now if you go to http://punkoffice.com/weight you'll see that it works on desktop and mobile :D

 

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...