How to get MorphTarget from Blender export

Hello,

I create a simple Shape Key in Blender - that transforms a CUBE into a SPHERE (nothing else).

Export is successful and I see how to set up MorphTargetManager, but …

How to reference MorphTarget instance from Blender export?


DETAILS:

  • Here is the shape key setup: value 1, and the CUBE as a SPHERE.
    image
  • The target is named ‘KeyMorph1’

-The .babylon exports as expected:

"morphTargetManagers":[{"id":937964
,"targets":[{"name":"KeyMorph1"
,"positions":[-0.4394,-0.8788,...]
  • In the ImportMesh, this was the best attempt:
        nx.testBox = newMeshes[0];
        nx.testBox.position.copyFrom({x: 0, y: 10, z: 0});
        nx.testBox.isVisible = true;

        var manager = new BABYLON.MorphTargetManager();
        nx.testBox.morphTargetManager = manager;

        //HOW TO CORRECTLY INSTANTIATE MORPH TARGET from ShapeKey: KeyMorph1?
        nx.target1 = BABYLON.MorphTarget.FromMesh(nx.testBox, "KeyMorph1", 0.5);
        manager.addTarget(nx.target1);


Am I missing something? Searched everywhere, a good example might help others.

At runtime: nx.target1.influence = 1; //does nothing.

Thanks,

Maybe @JCPalmer

Export wise, you shouldn’t be exporting with a one on a key. The exporter writes the mesh with modifiers applied. Not sure what happens. You intend the mesh to be exported to be the same as basis, right?

You would get the MorphTargetManager already created in the mesh, I am pretty sure, and set targets by themselves or in combination to values 0-1. Nothing special about Blender being the source. There’s gotta be a doc page on that.

1 Like

You rock JCP as always.

I’m gonna jump into FORTNITE LIVE EVENT with my son… then I get to dig into this.

Thank you for being around.

UNDERSTOOD - did not EXPORT with it on value 1. Just to show the SUCCESS STATE.

Export is same as basis - correct. But TRUE - I could easily make that mistake.

MorphTargetManager already created in the mesh… ok I will double-check:

CONFIRMED (after import):

nx.testBox.morphTargetManager
null

nx.testBox.morphTargetManagers
undefined

So (as above) - creating morphTargetManager and applying to imported mesh.

CONFIRMED: Not in the Submeshes.

QUESTION:

Is it NOT BEING IMPORTED THROUGH ImportMesh???

QUESTION (not in docs and hard to find in PG):

Or, syntax to get the .babylon export “KeyMorph1” into BABYLON.MorphTarget instance?

Ah ha! ImportMesh is NOT IMPORTING MorphTargetManagers???

Blender .babylon exports them successfully, but it appears ImportMesh does not import…

I upgraded to v3.2. Was this something that was implemented after that?

Where should MorphTargetManagers be imported? Is it in parameter 4? Thx.

: )

SOLVED IT!!!

image

It was not easy. Just in case someone else is looking for example of how to IMPORT BLENDER SHAPEKEYS into BABYLON via MORPHTARGETMANAGER.

There were multiple points of difficulties.

The biggest was that ImportMesh was NOT IMPORTING. And the syntax to check if it is imported… I still have not seen. And it never did import.

The solution was this:

     BABYLON.SceneLoader.ImportMesh("", "./3d/", "minKeyMorph.babylon", nx.scene, function (newMeshes, particleSystems, skeletons) {
        nx.testBox = newMeshes[0];
        nx.testBox.position.copyFrom({x: -200, y: 50, z: -172.94191286506089});
        nx.testBox.position.y += 15;
        nx.testBox.isVisible = true;

        var manager = new BABYLON.MorphTargetManager();
        nx.testBox.morphTargetManager = manager;
                nx.target = new BABYLON.MorphTarget("key1", 0);
        
//forced to embed morphtarget-.
nx.target.setPositions([-0.4394,-0.8788,-0.8788,-0.8788,-0.8788,-0.4394,-0.5373,-1.0747,-0.5373,-0.8788,0.8788,-0.4394,-0.4394,0.8788,-0.8788,-0.5373,1.0747,-0.5373,0.8788,0.8788,-0.4394,0.8788,0.4394,-0.8788,1.0747,0.5373,-0.5373,-0.8788,0.4394,-0.8788,-0.5373,0.5373,-1.0747,-1.0747,0.5373,0.5373,-0.762,0.762,0.762,-0.8788,0.4394,0.8788,-0.5373,-0.5373,1.0747,-0.762,-0.762,0.762,-0.8788,-0.4394,0.8788
            ,-0.5883,0,1.1766,-0.5373,0.5373,1.0747,0.5883,0,1.1766,0,0.5883,1.1766,0.5373,0.5373,1.0747,0.4394,-0.8788,0.8788,0,-0.5883,1.1766,0.5373,-0.5373,1.0747,-1.1766,0,0.5883,-1.0747,-0.5373,0.5373,-1.1766,0,-0.5883,-1.1766,-0.5883,0,-1.0747,-0.5373,-0.5373,-1.1766,0.5883,0,-1.0747,0.5373,-0.5373,-0.5883,0,-1.1766,-0.8788,-0.4394,-0.8788
            ,-0.5373,-0.5373,-1.0747,0.5883,0,-1.1766,0,-0.5883,-1.1766,0.5373,-0.5373,-1.0747,0.4394,0.8788,-0.8788,0,0.5883,-1.1766,0.5373,0.5373,-1.0747,1.1766,0,-0.5883,0.8788,-0.4394,-0.8788,1.0747,-0.5373,-0.5373,1.1766,0,0.5883,1.1766,-0.5883,0,1.0747,-0.5373,0.5373,0.8788,0.8788,0.4394,1.1766,0.5883,0,1.0747,0.5373,0.5373,0,1.1766,-0.5883
            ,0.5373,1.0747,-0.5373,0,1.1766,0.5883,0.5883,1.1766,0,0.5373,1.0747,0.5373,-0.5373,1.0747,0.5373,-0.9317,0.9317,0,-0.5883,1.1766,0,-0.5373,-1.0747,0.5373,-0.9317,-0.9317,0,-0.8788,-0.8788,0.4394,0.5883,-1.1766,0,0,-1.1766,0.5883,0.5373,-1.0747,0.5373,0.5373,-1.0747,-0.5373,0,-0.9317,-0.9317,0,-1.1766,-0.5883,0,-1.3146,0
            ,0.9317,-0.9317,0,0.8788,-0.8788,-0.4394,0.4394,-0.8788,-0.8788,0,-0.9317,0.9317,0.8788,-0.8788,0.4394,0.762,-0.762,0.762,-0.4394,-0.8788,0.8788,-0.5883,-1.1766,0,0,1.3146,0,-0.4394,0.8788,0.8788,0,0.9317,0.9317,-0.8788,0.8788,0.4394,0.9317,0.9317,0,0.4394,0.8788,0.8788,0.762,0.762,0.762,0.762,0.762,-0.762,1.3146,0,0
            ,0.8788,0.4394,0.8788,0.9317,0,0.9317,0.8788,-0.4394,0.8788,0.762,-0.762,-0.762,0,0,-1.3146,0.9317,0,-0.9317,-0.762,-0.762,-0.762,-1.3146,0,0,-0.9317,0,-0.9317,-0.762,0.762,-0.762,0,0,1.3146,-0.9317,0,0.9317,0,0.9317,-0.9317]);

        manager.addTarget(nx.target);
        nx.target.influence = 0;

        //nx.target.influence = 1; //at runtime.
     });

This is the DOC I used to make the minimal shapekey…
easyblend.org/html/animation/shape_keys.html

Maybe trying it the easy way would be better. I am a little sick, and was answering from a tablet where I cannot really check things. ImportMesh / Append are calling Mesh.Parse() to load the JSON file. If there is a morfManagerTargetId, which you show as 937964 in your original post, then
mesh.morphTargetManager = scene.getMorphTargetManagerById(parsedMesh.morphTargetManagerId);

see Just use that.

1 Like

Oh SNAP! I try that…

… that code is great.

Hope you feel better.

Thanks JCP : )

1 Like

Digging deeper and deeper - and it is FASCINATING!

RESULTS of getMorphTargetManagerById

  • Very helpful fo someone (hard to find), for me the result is:

    nx.scene.getMorphTargetManagerById(435882) always returns null.
    

    And that is ok. Possibly a version issue, I’m on v3.0. Could try v3.1.

    But something else…

  • Blender Shape Keys had issues after export (surprise).

    a. Shape Key controls some verts it shouldn’t (wrongly back to Basis).

    b. And wrong offset position, relative to armature deform (not origin).

    Can try Non Relative Shape Key.

    Can try bones and vertex groups and… etc.

    Can try v3.1.

    OR…


We also see a way to manipulate the vertices directly with JS!!!

[Parent Objects off a HERO origin and interpolate]. So simple. Needs a TEST.

It causes extra work (re-doing POSE animations [always] <exclude EYE.), but, may result in

COMPLETE PROGRAMMATIC FREEDOM, (PERFORMANCE OPS) and ANM-PRECISION.


LIKE that potential very much! Going for it.

ANIMATION PRECISION is a GUIDING (DESIGN) PRINCIPLE.

We choose close-to-the-metal ANM~PRECISION methodology wherever we can get it!

It will FAIL! For unexpected reason… and that’s ok. Will push it through that door.

Prefer BABYLON logic over BLENDER logic (is an ongoing trend).


Thanks much! Confirm on null would be cool. Love MorphTargets.

Also, I’ll update (yet another) strange saga. As we try dangerous things!

That EYE had better moove!

orby2

PRECISELY (during full body armature deforms).

This eye is the reason for everything. : )

:eagle:

The getMorphTargetManagerById should be being called by the importMesh itself, and everything already setup. If not, it is probably a BUG. @Deltakosh, importMesh gets skeleton and materials. Shouldn’t it also get the morph manager?

Try scene.Append for now. All this other stuff is just confusing.

1 Like

Yeah importMesh gets extended over time but did not include the morphtarget. Not really a bug though

I agree, just use Append

1 Like

Awesome!

Will try…

SOLVED

Eye-Ball ANM, simultaneous to Body ANMs.

image

Zero Shape Keys (or Vertex Groups with Constraint complications).

Simple and clean - parent eye to body, then interpolate into relative position with JS.

image

EyeBallFactory

:eagle:

1 Like