Deltakosh

Introducing morph targets

28 posts in this topic

3 hours ago, Deltakosh said:

I'm pleased to announce the availability of morph targets!

Shape keys finally arriving !!;)

cheers, gryff :)

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

That's cool. I was waiting for this feature for a long time. it's nice to see. 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

OMG YES!!!  I no longer have to have my avatars moving around with blank expressions on their faces :D

jessepmason likes this

Share this post


Link to post
Share on other sites

"Please be aware that most of the browsers are limited to 16 attributes per mesh. Adding a single morph target to a mesh add 2 new attributes (position + normal). "

So this means we can only have max 8 morph targets?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I'm using an iPhone 6+ with iOS 10.3.1 and its breaking.  I've attached the console output

 

ios_errors.jpg

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I think I need to wait for an upgrade to the Blender exporter and OBJ loader cos at the moment none of them are supporting mesh duplicates properly

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
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

 

gryff likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.