castle-engine / castle-model-viewer

Viewer for many 3D and 2D model formats: glTF, X3D, VRML, Collada, 3DS, MD3, Wavefront OBJ, STL, Spine JSON, sprite sheets in Cocos2D and Starling XML formats
https://castle-engine.io/castle-model-viewer
90 stars 18 forks source link

HAnim conversion to xml inverts rotations #8

Open andreasplesch opened 6 years ago

andreasplesch commented 6 years ago

Converting the Lucy model from http://www.seamless3d.com/browser_test/lucy_test0.x3dvz to X3D XML encoding with 3.18 results in this file: https://raw.githubusercontent.com/andreasplesch/x3dom/HAnim_work/test/functional/HAnim/Lucy_test0.x3d

It seems during conversion the rotations somehow get inverted.

Here is X3D XML encoded scene: https://raw.githubusercontent.com/andreasplesch/x3dom/HAnim_work/test/functional/HAnim/Lucy_test0b.x3d converted by http://doc.instantreality.org/tools/x3d_encoding_converter/ It has correct rotations.

michaliskambi commented 6 years ago

A workaround, until I find and fix it, seems to be to use command-line conversion:

view3dscene lucy_test0.x3dv --write > new2_lucy_test0.x3dv
view3dscene lucy_test0.x3dv --write --write-encoding=xml > new2_lucy_test0.x3d

These result in correct files, it seems.

See https://castle-engine.io/view3dscene.php#section_converting .

I do not yet have a solution for interactive conversion, I'll debug it. I can confirm that opening + saving http://www.seamless3d.com/browser_test/lucy_test0.x3dvz results in a file that has something weird with rotations :)

Note that saving X3D from view3dscene is like saving the current DOM tree from HTML browser: You save the current state of everything, e.g. all Transform.rotation have values in the middle of the animation. It may be considered a feature or a bug :), but technically, we don't have any choice: we only keep the current X3D graph in memory, we don't try to remember the original graph. To avoid it, disable events before opening the model (menu item "Animation -> Process VRML/X3D Events"). Or use command-line (view3dscene or tovrmlx3d) to convert the model.

However:

  1. It should not cause weirdness (like inverted rotations).

  2. In this case, I tested opening + saving lucy model when "Process VRML/X3D Events" was disabled. And the resulting file still has weird (inverted) rotations. So the engine is processing something even with "Process VRML/X3D Events" disabled. I'll debug and see what is it:)

andreasplesch commented 6 years ago

Thanks. Although it is always nice to fix a problem, it may suffice to modify saving from view3dscene so it just calls the command-line, probably in a whole separate process, or add as an option. Just a thought.