irajsb / UE4_Assimp

Assimp mesh importer for Unreal Engine
MIT License
136 stars 29 forks source link

Substantial change to be a more 1:1 import of Assimp data. #29

Closed sfjohnston closed 1 year ago

sfjohnston commented 1 year ago

Removed code that tried to swap from right-handed y-up to left-handed z-up coordinate systems and that applied scale factors.

Added GetUnitScaleFactor blueprint method.

Users can adjust scale by applying Unit Scale Factor to the root component, and can rotate from y-up to z-up with a -90 x-rotation of root component.

Users can also apply Assimp global scale at load time with the Post Process Global Scale Factor flag, and use the "Convert to Left Handed" flag.

Moved mesh loading from UAINode::Setup to UAIScene::InternalConstructNewScene alongside materials, lights and cameras. (It wasn't ASync anyway.)

Calculation of "WorldTransform" was incorrect in a few places. It is now kicked off with an Identity matrix scaled by the UnitScaleFactor when running Setup on the root node. (WorldTransform isn't really needed anymore, since users can build a tree and pull the world transform out of the tree on blueprint side. I've confirmed that they match.)

Added ImportScene (singular) for cases where users don't want to load multiple scenes at the same time.

Changed AssimpFunctionLibrary.h to use the macro definitions from the Assimp header, rather than the hex values. (In case assimp changes them.)

irajsb commented 1 year ago

Hi , This is really great. does it solve the wrong transform entirely ?

irajsb commented 1 year ago

https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Buggy/glTF-Binary/Buggy.glb https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/Corset/glTF-Binary/Corset.glb Try these models . seem to be in wrong orientation.

sfjohnston commented 1 year ago

These two models match between Blender and Unreal when I load them. The "Corset" model is very small and needs to be scaled in both apps to make it visible.

The blueprint I use does a -90 x rotation on the actor the model is attached to to complete the switch from right-handed y-up to left-handed z-up. The flags I have active (currently) are: MakeLeftHanded, OptimizeMeshes, and TargetRealtimeQuality.

Corset_blender

Corset_unreal

Buggy_blender

Buggy_unreal

irajsb commented 1 year ago

Can we fix -90 x rotation needed for models so user doesn't have to do any manual work ?

sfjohnston commented 1 year ago

My thought was that the tree contains the transforms given by the assimp file "as-is" and that this rotation belongs on the object to which that tree is attached.

We could modify that thought and apply the -90 rotation to the root node of the assimp data and could also apply the unitscalefactor. This would change the root node values away from the assimp file, so I'd want an argument to importscene to enable/disable.

Alternatively, we could create an actor (scene component) that stores this value, but this creates scene objects rather than having the user create them on the blueprint side. One of the things I like about UE4_Assimp is that the scene object creation is all on the blueprint side.

A third option would be to have a transform generator that just returns a transform for the scene that has -90 x-axis and scale by unit-scale-factor. If the user wants, they can "set relative transform" on their actor with this transform, but wouldn't be required to do so.

I'll throw in the first option and you can see if you like it.

On Sun, Jan 22, 2023 at 12:08 AM iraj mohtasham @.***> wrote:

Can we fix -90 x rotation needed for models so user doesn't have to do any manual work ?

— Reply to this email directly, view it on GitHub https://github.com/irajsb/UE4_Assimp/pull/29#issuecomment-1399426486, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADNVAYS22VETBCVM7VS7PVTWTTTGXANCNFSM6AAAAAAUA4BRKE . You are receiving this because you authored the thread.Message ID: @.***>

irajsb commented 1 year ago

First option seems to be best which should be enabled by default for beginner users so they can use the project as is . More advanced users can read the comments and disable that feature if they need raw unedited data.

sfjohnston commented 1 year ago

I've implemented in the first option. Novice users will have some "Auto Space Changes" activated. Currently this includes adding the flags for "realtime quality", "make left-handed" and adding a transform to the root with unitscalefactor and a 90 degree rotation on x to correct the expected space differences. Advanced users can disable this and control everything manually.