Jump to content

Light animation & other additions to babylonFileLoader.js


JCPalmer
 Share

Recommended Posts

I should have realized that going on the assumption that babylonFileLoader.js was static when building the to_javascript() methods of each of my python classes(World, Mesh, SubMesh, Node, Bone, Skeleton, MultiMaterial, Camera, Light, ShadowGenerator, Texture, Material, Animation & its subclass VectorAnimation) was incorrect.  I am now diffing all changes since June 1st, & io_export_babylon.py changes too.

 

Found light animation was added to babylonFileLoader, but io_export_babylon.py had not been updated to send it.  I had actually wondered about adding this myself, but quickly put it out of my mind, as I thought it would have just been ignored in the .babylon.  Might be kind of cool for like a POW camp game with search lights.

 

Guess I should add it, though I am not going to maintain io_export_babylon.py.  I am going to ignore any changes to babylonFileLoader.js related to working with an alternatively loaded file, as it has no meaning on the Blender side.  Will try sync up TOB with all else, and use this thread to ask questions.

 

Gryff, are you up to working in another animation type to one of the testing .blends, please?

 

Jeff

 

Link to comment
Share on other sites

Deltakosh:

To do positional animation, like camera in the python script, one might just copy the section from Camera(lines 146-158) and paste after line 204. See no reason anything else would need to be done.

 

Cannot paste from TOB back to original, since it is now object oriented.  Constructors make blender data babylon friendly, to_scene_file() & to_javascript() write to their respective outputs in later passes.

 

Further than that, I have just made a new python class: FCurveAnimatable.  It has 3 subclasses (Mesh, Camera, & Light).  It is based on the code that got ripped out of Mesh, since Mesh supports rotation, position, and scaling  animation.  Summary is:

class FCurveAnimatable:    def __init__(self, object, supportsRotation, supportsPosition, supportsScaling):                 # just because a sub-class can be animatable does not mean it is        self.animationsPresent = object.animation_data and object.animation_data.action                . . .    def to_scene_file(self, file_handler):             if (self.animationsPresent):            . . .            def to_javascript(self, file_handler, jsVarName, indent):         if (self.animationsPresent):            . . .

Mesh sets all 3 supports args to True.  I saw no reason that camera that should be limited to just positional, so its constructor is:

class Camera(FCurveAnimatable):    def __init__(self, camera):                 super().__init__(camera, True, True, False)        . . .

Light should also be rotatable, depending on the light:

class Light(FCurveAnimatable):    def __init__(self, light):              super().__init__(light, light.data.type != 'POINT', True, False)        . . .

So you see that modularizing with classes, & multi-pass make it not backward compatible.  I even have 2 new python classes in development: ShapeKey & ShapeKeyGroup.  Definitely going to need many passes processing that.

 

gryff:

Looking impressive, when ready I need the actual .blend, as you obviously know.  Let's use this thread for that from now on.  The other one started out with a completely different topic.

 

Jeff

Link to comment
Share on other sites

Looking impressive, when ready I need the actual .blend, as you obviously know.  Let's use this thread for that from now on.  The other one started out with a completely different topic.

 

NP Jeff. I'm looking to package 3, maybe 4, blend files for you with an explanation of each one so you can step through them.

 

I saw no reason that camera that should be limited to just positional,

 

That was the problem I ran into - I could not keep the camera perpendicular to the path it was traveling as the babylon file only contained positional data for the camera - so I had to use the parent option to a mesh that followed the path. And the lights were all over the place ;-)

 

Expect some files and explanation on the weekend.

 

cheers, gryff :)

 

 

Link to comment
Share on other sites

DK, the issue I would like solved is when you have two or more different objects that are animated with different animation lengths. Currently if you export such a babylon file then they default to the start and end positions shown in the Blender timeline interface at the time of export.

 

I looked at the exporter code (don't faint ;) ) and I found this line:

Export_babylon.write_int(file_handler, "autoAnimateTo", bpy.context.scene.frame_end - bpy.context.scene.frame_start + 1)

It seems to be getting the end of the animation for all animations from whatever is currently scene_frame_start and scene_frame_end in the timeline window. All animations exported  then have the same end frame - which may not be true.

 

Now I know all animations can be stopped when the scene loads then restarted with the correct length, or different animated objects can be imported as separate meshes,  but for more than a couple of objects it seems tedious.

 

If it is not a major rewrite and you have the time - I think it would be an improvement.

 

cheers, gryff :)

 

 

 

 

Link to comment
Share on other sites

Here are the 4 blend files Jeff you can  use for the light/camera animation

 

4_light_cam_269A, 4_light_cam_269B, 4_light_cam_269C, 4_light_cam_269D

 

4_light_cam_269A is just the starting file with all the objects, The other 3 files are the step-by-step processes necessary to animate the cube.

 

There is a small text file included that, hopefully, explains the steps (fromA-D) taken and you should be able to follow.

 

If you are not bothered with doing the steps yourself then use 4_light_cam_269C or 4_light_cam_269D (reduced keyframes) blend files

 

Cam_Anim.zip

 

To get the animation of the "Cube" to drive the "Point" Light and "Camera" - you have to parent these two objects to the "Cube".

 

cheers, gryff :)

 

 

Link to comment
Share on other sites

gryff,

Received, and starting to it look over.  Wondering, since TOB can do camera rotation & light positioning / rotation for not point light, what would I do to test that?  Delete the cube?  Then what, click the camera & add the follow the path constraint?  Then the Same with the light?

 

Jeff

Link to comment
Share on other sites

since TOB can do camera rotation & light positioning / rotation for not point light, what would I do to test that?  Delete the cube?  Then what, click the camera & add the follow the path constraint?  Then the Same with the light?

 

Jeff, I know that would work for the "Camera" - as I did that with the .babylon exporter (except of course the rotation gets ignored). The "Point" light does not need rotation of course.

 

Thinking about it quickly, the only issue would be that you probably would end up with two identical sets of animation data - inflating the file. Might be better to just do the camera then parent the light to it. But I don't know how you handle parenting in TOB.

 

cheers, gryff :)

Link to comment
Share on other sites

Technically, camera rotation SHOULD work in a .babylon.  The issue is not on the the Babylon side,  it will animate any property that an JS object has.  The old exporter is just not sending it.  If you are keeping up the use of the cube just for the .babylon and not old exporter, then it should be un-needed.  Will test and let you know.

Link to comment
Share on other sites

The old exporter is just not sending it.  If you are keeping up the use of the cube just for the .babylon and not old exporter, then it should be un-needed.  Will test and let you know.

 

Good luck with the testing - I've been spectacularly unsuccessful with getting any rotations to export from Blender 2.69 or 2.71. The exporter I use  is the latest one from github.

 

As for the "Cube" - you might want some mesh there anyway - think the Train in the demo, or a roller coaster car in some vomit-inducing ride :o

 

cheers, gryff :)

Link to comment
Share on other sites

Gryff,

Remember, Tower of Babel, TOB,  exports BOTH .js & .babylon.  This is the .babylon I will be testing, not the one io_export_babylon.py produces.  I see camera rotation in TOB's .babylon. TOB's .babylon is usually 8-10 % smaller in size too, but in this case, the size reduction will not be achieved, since more data is being written.

 

So far, found lots of little bugs!  Great test file!  Like I need to change the names of meshes to legal JS names, since they end up as class names.  4Cylinder.001 has 2 problems:  you must start with an alphabetic & '.' is not allowed.  Code like this errors:

new 4Cylinder.001("4Cylinder.001", scene);

 

Must be changed to:

new Cylinder_001("4Cylinder.001", scene);

 

The one in quotes is just the Mesh.name property & can be anything.  Not sure if I want to change this one too.  Still solving this problem.  I cannot even get the browser to load the .js to fix the other problems I am eye balling.  FYI, might be a while before I show output.  I liked the way you use dropbox as a cheapo web server.  Need to figure that out too.

 

Jeff

Link to comment
Share on other sites

Like I need to change the names of meshes to legal JS names

 

Well Jeff,  the ".00X" is common with Blender if you duplicate stuff, and will also  occur  if you are sloppy with material/texture names too. Also in rigs you can find the "." - often the names of bones can be something like "Hand.L" and "Hand.R" - useful for mirroring changes to the rig.

 

I set the names up deliberately so that the Scene Outliner was easy for you to read ;)  (And in case you do not know, right click on object in the Outliner ->Rename).

 

I hope one day we all get a chance to run your exporter too.

 

cheers, gryff :)

 

 

 

 

Link to comment
Share on other sites

Yes, I know it's a JS problem, and by extension TOB's.  Fixed.  No need to make names JS capable.  Shape keys names is another matter.

 

After I get thru this test, I will resume shape key development.  Not going to put out a public version without it.  So may be a while.

Link to comment
Share on other sites

I have generated a running .js (.babylon too, but not checked it yet).  It is animating the camera, not the cube, which I deleted.  Kind of dark, since I have not parented the point light to the camera yet.  The "big" (well for me) problem is the camera is pointing down & flying over like some helicopter.  Did I miss a step, or is my code bad? 

 

Also, I seem to have found a bug that is even in io_export_babylon.py.  On Linux & OSX, it is not copying any image files to the destination directory.  Side stepped for now by copying myself.  This works on windows, right?

Link to comment
Share on other sites

Well, no actual error with the texture file copy.  Blender was looking for /home/EasyPHP-DevServer-14.1VC9/data/localweb/webgl/jcp/tmage512.png as the source.  This path was saved into the blend file.  Guess you have to be careful, that .blend files referencing image textures may not copy them if things are moved.

 

Tried using '.' as the path, but blender would have none of it.  I remapped it to where it is on my machine.  It copied fine.  TOB at least does not fail silently.  An error is still not fatal, but with the log file the error is now recorded.

Link to comment
Share on other sites

It is animating the camera, not the cube, which I deleted.  Kind of dark, since I have not parented the point light to the camera yet.  The "big" (well for me) problem is the camera is pointing down & flying over like some helicopter.

 

Jeff, if you add a new camera to a blender scene it will be facing down. If you select the camera in the file ".... 269A" file I sent you, just to the right of 3d window under "Transform" you will see that the camera has been rotated by 90 degrees on the X axis. So somehow I think that has been missed.  Does the camera animation look normal in blender ?

 

As for darkness, select the Hemi and a "Hemi" shaped button appears below the scene outliner. Select that button and increase the intensity (currently set at 0.1).

 

As for the texture issue, I must remember to pack the texture into the blend file - that might help. Never worried about it before as once the file gets exported by babylon exporter, it assumes the texture is in the same directory as the babylon file.

 

cheers, gryff :)

 

 

Link to comment
Share on other sites

Gryff,

 

I went back to your 4_light_cam_296C version that moved the cube, and exported.  Here is the comparison of the rotation with that of the cameras (shown in JS, since it is easier to read):

 

Cube:

animation = new BABYLON.Animation("rotation animation", "rotation", 30, 1, 1);animation.setKeys([{frame: 0, value: new BABYLON.Vector3(-0,2.2994,0)},{frame: 1, value: new BABYLON.Vector3(-0,2.2994,0)},{frame: 2, value: new BABYLON.Vector3(-0,2.2743,0)},{frame: 3, value: new BABYLON.Vector3(-0,2.2492,0)},. . .

Camera:

animation = new BABYLON.Animation("rotation animation", "rotation", 30, 1, 1);animation.setKeys([{frame: 0, value: new BABYLON.Vector3(-1.5708,2.2994,0)},{frame: 1, value: new BABYLON.Vector3(-1.5708,2.2994,0)},{frame: 2, value: new BABYLON.Vector3(-1.5708,2.2743,0)},{frame: 3, value: new BABYLON.Vector3(-1.5708,2.2492,0)},. . .

The first element is not 0 for camera.  Looked at how the rotation property is defined for mesh & camera, and they are different.

 

Mesh:

loc, rot, scale = world.decompose()self.rotation = scale_vector(rot.to_euler("XYZ"), -1)

Camera:

self.rotation = mathutils.Vector(-camera.rotation_euler[0] + math.pi / 2, camera.rotation_euler[1], -camera.rotation_euler[2])

This difference is probably why no rotation animation was never made.  1.5708 * 2 == pi.  Hmm, the wheels are spinning.

Link to comment
Share on other sites

Camera Rotation now works!  Fixed using the constructor of FCurveAnimatable adding xOffsetForRotation arg with default of 0:

class FCurveAnimatable:    def __init__(self, object, supportsRotation, supportsPosition, supportsScaling, xOffsetForRotation = 0):  . . .class Camera(FCurveAnimatable):    def __init__(self, camera):                 super().__init__(camera, True, True, False, math.pi / 2)

Also, dropped "rotation" animation from Light.  First it is "direction", and second it is not a vector, but a 3x3 matrix.

 

On the extra artificial frames front.  I see a problem if there are multiple types animation for a single object, eg. position & rotation.  Unless multiple FCurves for object must have the same range.  AutoAnimate "plays" both concurrently.

Link to comment
Share on other sites

AutoAnimate "plays" both concurrently.

 

Jeff, my issue with the autoanimate is that all animations in a scene end up with the same autoanimate - not an autoanimate that reflects the different lengths of keys frames for each individual animated object. 

 

 

Hmm, the wheels are spinning.

 

Camera Rotation now works!

 

Naw, its the Camera that is spinning now. ;)

 

cheers, gryff :)

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