How to determine the "Natural" forward axis or forward vector of a Static Mesh

Hello and thank you for any input,

I have as yet cannot determine from code (C++), the “natural” forward axis, or forward vector of a Static mesh. i.e. a Static Mesh of a Car, has a natural “front” or “rear” of the car. The Root Actor, or Root Component, have a forward vector, but this does not reflect the “natural forward vector/axis” of the attached static mesh.

Has anyone figured out how to determine, the “natural” forward vector/axis of a Static Mesh?

.

link:

Hey jayice-

You should be able to use the GetForwardVector() function to get the forward vector of your static mesh. If you want to change/update what is considered as the forward vector, you would want to do this in the modeling program used to create the static mesh.

Cheers

,

Thank you for the response, very much appreciated. All I am after is to be able to “align” an arbitrary mesh to the forward direction of the owning Actor.

yet, when I look here

G:\ue4launcher\Epic Games\4.10\Engine\Source\Runtime\Engine\Classes\Engine\StaticMesh.h

I find no function GetForwardVector().

Not trying to be argumentative at all, it’s just not there, and getting the forward vector, from the StaticMeshComponent, doesn’t supply the answer. It just gives, the default values (assuming that the component has not be rotated), with X-axis as forward, Y-Axis as right, and Z-Axis as up.

I have chased this forever, and just cannot seem to find it. My plugin is not in control of the Static Mesh, applied to a SMC, attached to an actor, it’s all arbitrary to my code, and if someone using the plugin, brought the mesh in, and it was rotated 90 degrees off the X-Axis, I just simply want to be able to detect this, and then rotate it back, instead of telling a customer, well you have to back to the modeling program and re-export, etc. Because there is no guarantee, that they have the knowledge of how to do this.

Of course I can put in a parameter for the product, to just do a rotation of hte actor, but that just opens up another kettle of fish, especially in terms of usability of the product.

I do thank you very much,

After you newest comment i am a bit confused. Which rotation are you actually talking about?

“and it was rotated 90 degrees off the X-Axis, I just simply want to be able to detect this, and then rotate it back”
So you want to do something like staticMesh.SetRotation(0,0,0)?

“to be able to align an arbitrary mesh to the forward direction of the owning Actor”
So, you want to have their Rotation face the same direction? like staticMesh.setRotation(parent.getRotation())?

Just to have the naming clarified:

The Forward Vector is the direction the Mesh/Actor is CURRENTLY facing on a specific Axis with a given Rotation. Its like if you stand up and point forward, then this is your current forward vector. If you turn 90 degrees and point forward, now this is your new forward vector.

The Rotation is basically set to 0, 0, 0 when you import a mesh into the engine. This is equivalent to the rotation / orientation the mesh had when exporting it from the modeling app. If i.e. in 3dsmax you rotate the mesh by 90 degrees, export and import it, you will see the changed orientation but the rotation will still be 0, 0, 0 as this is the base when importing it.

Hope this helps a bit :slight_smile:

Cheers,

hello !

UE4, likes forward to be the X axis (1,0,0, if we think of a Vector), right to be the Y axis (0, 1, 0, again a vector), and up to be Z axis. I’m only stating this, to make sure we are on the same page, and that nomenclature is not getting in the way.

So we have a actor / world, that likes (1,1,1), but when the mesh was created, and brought into UE4, then the Y axis (we’ll assume it’s 90 degrees off the X axis), was used as the forward axis.

I’m looking for something, that I can determine programmatically (C++), that will tell me, that the “natural” forward/facing vector/direction is the Y-Axis, or that it’s A Degrees off the X-Axis, so that the mesh or the mesh component, or the Actor itself, after the component is attached to the actor, can be rotated, causing the “Natural” forward vector of the mesh, to “align” to the actor’s forward direction.

If one looks, at the Static Mesh for the VehicleGame project, that mesh for the vehicle is aligned to what UE4 likes, i.e. the X-Axis, is aligned with the natural forward axis of the static mesh itself. (The vehicle’s “front” will be in front of the vehicles’s “rear”, as it moves forward on the X-Axis).

If we look at the InfinityBlade Adversaries pack, and look at those static mesh’s, they were brought in rotated 90 degrees. Such that when the Static Mesh Component (Or skeletal mesh) is moved forward on the X-Axis. The “actual face” of the mesh, is looking sideways, and it makes the static mesh appear to be “strafing” in it’s movement.

Thank you for your response,

Ok, i think we are slowly getting into the right direction :wink:

“but when the mesh was created, and brought into UE4, then the Y axis (we’ll assume it’s 90 degrees off the X axis), was used as the forward axis.”
In other words you mean that there was a rotation applied on import if i got it right? Since i cant remember that there is another way to change the forward orientation of a mesh on import (of course could be wrong here).

If thats the case, you will need to get the actual static mesh, which should have some properties from the import itself; If i remember right these were called “build rotation” “build scale” and so on. Just try to find it directly in the Editor first: Open a static mesh in the SM Editor and look through the properties; You may need to get them using UProperty getters.

Though, my personal opinion would be, give the user the possibility to rotate the mesh/component/actor/whatever themselves. Even if you know the actual forward vector / rotation the mesh had in the original 3d editor like 3dsmax, you can never be sure that it was the correct one, and in fact the user always must have a chance to override this behaviour and rotate it himself. But thats just my 2c.

Cheers,

,

The mesh may have had it’s axis changed on import, it may have been created like that, etc. It really makes no difference how it happened. I just wish to be able to deal with it.

I have no control over the mesh’s orientation, as to what axis the “natural forward direction is”. This is a product for UE4, that has to deal with arbitrary mesh’s (no matter what the component is). I mean of course I can say, sure go back to the Modeling software, and rotate to where X axis is “forward”, but I really don’t wish to do that

I much prefer, that the user ( in this case UE4 game developers, level designers, architectgs, city designers, etc), don’t have to do anything, I just determine the “natural forward” direction, and adjust. Yet I’m not sure that is possible.

I’m currently thinking, of putting in a bit of code, that puts a value into the “asset”, that gives me a value I can query, and then based off it, rotate the component/actor (whatever), such that the “natural front” is moving “forward”. This way, I don’t have to tell a customer,

“Ummmmmm, yeah, that’s just UE4, it likes the X-Axis, and sorry that you have 500 static meshes you have to do that too”

To me that is just not acceptable. If I put in a little routine, to update the “tag/asset” with an identifier, well then the static meshes all become usable in seconds. I prefer a runtime solution, but will take this route, if there is no other.

Thank you for your input, and any other thoughts you have!!!

.

Hello jayice,

There is no such “natural” forward vector for a given Unreal Engine static mesh. The actual forward vector for a given mesh is defined by the x-axis when exporting the mesh from your 3D package. If your mesh has a natural front and back, ensure that your mesh is centered around the x-axis and that that it’s front is facing in the positive x-direction and the rear is facing in the negative x-direction.

If you’re wondering how to detect the front/rear of an object once the static mesh has been imported into UE4, regardless of the forward vector created on export (as described above), then I wish you the best of luck, as I doubt many people have discovered a solution for this. Identifying the actual front and rear of an object using code will vary greatly depending on the mesh used, as one would have to develop a process for identifying topological features of the mesh. If you do manage to figure this out, I would love to see the result.

Best of Luck,

Austin

DesertEagle,

I really doubt there is a way, to determine the “front”, when looking at StaticMesh.h, there just is not enough information there to determine anything. There maybe some form of information in a FBX file, but I don’t have the time, nor inclination to dig into that right now.

As I have to work with arbitrary Static Meshs, which I don’t control, and never will. I’m thinking the best thing to do, is to set up some form of asset tag, that can be retrieved at runtime, that the user can set, saying, rotate this,Actor/Component by X degrees. This is something a end user could do quickly, and make sense to them. Then I could just include some little piece of code, that would go through, and set the rotation value, en mass for all assets in a directory, or other filters, and be done with it.

Thank you!

.