Jump to content

mesh.lookAt hardcoded into .babylon (blender export)


Recommended Posts


Can mesh.lookAt be hardcoded into a .babylon file?

If so, how?

I have a few meshes in blender that I would like to use the 'Track To' constraint but I see that these are not supported for meshes in the exporter, whereas they are for cameras. I am hoping I can tweak the Blender > Bablyon exporter.

I appreciate I can do the same thing in the js script, but I'd rather have Blender and the exporter do it for me.


Link to comment
Share on other sites

I don't think we are calling mesh.lookAt during Babylon files loading.

We can think about adding a target property on mesh exportation and use this info (could be a vector3 or another node) to set the mesh.lookAt on it at loading time

Link to comment
Share on other sites

Thank you @Deltakosh,

I have got this to work and for anyone else looking to do the same, here goes:

in the Blender exporter mesh.py, I added this above # hasSkeleton detection & skeletonID determination:

        # constraint
        for constraint in object.constraints:
            if constraint.type == 'TRACK_TO':
                self.lockedTargetId = constraint.target.name

and this above # Sub meshes:

        # constraint
        if hasattr(self, 'lockedTargetId'):
            write_string(file_handler, 'lookAt', self.lockedTargetId, True)

You can now apply a constraint in Blender:


And here's a PG showing example: http://www.babylonjs-playground.com/#JJIEPB

There's probably a better / neater way of doing it but it works for me.

Link to comment
Share on other sites

Thanks.  As anyone who has ever did a PR knows, doing the first PR is more about figuring out the process than the change.  You did fine in that respect.

As far as the content, I think BillBoarding actually fully does this already.  I did not really pay attention to this topic till it was already solved.  I'll wait till @Deltakosh is back, but some other thoughts as well.

Camera.py also uses track to for ArcRotate & follow cameras, but of course a camera can only track one mesh (that's where billboarding came in)

Billboarding is implemented in the GAME Engine render, which has been removed for Blender 2.8.  I do not know if or how this is replaced in EEVEE.  There is a branch in the repo for 2.8, called EEVEE.  I have not done anything yet, but thought was going to initially just start ripping stuff out till it ran on a 2.8 build.  Kind of worried that I might be too early & some things might not be added back yet.  The result might inform as to your approach being required though.

If you wished to play with the ripping out on the EEVEE branch that would be great.  Just keep deleting (probably all of Materials) till it runs.  No need to be really careful, once we know what the full scope of what needs to change, that branch can just be trashed & recreated.  Just do not merge to Master, or your local repo will need to be rebuilt.

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.

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.


  • Recently Browsing   0 members

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