Download

C++ noob Assimp library usage

Hi,

I’ve been writing a plugin to import a Collada file using the Assimp library. The plugin itself is now working and loads the Collada file. I can even get the name of the light in the file.

What I now want to achieve is set the transformation of the light but since Assimp uses its own types and UE4 too, I need to do a type conversion from ‘aiVector3D’ to ‘FVector’. And since these are my first steps into C++, I’m not really sure how to do this.

So my first question is, how can I do the type conversion, so I can set the transform?

And my second question is, what would be a great resource to get more up to speed with c++? Would a generic c++ training/book/reference be sufficient? Or are there more UE4 specific resources? I know Tom Looman’s survival game series and will surely follow that as well. I also read the WIKI pages about writing plugins and getting started with c++ in UE4. But since my current goal is more towards the plugin and editor part, there might be other resources that will help.

Thanks!

Ok, So I figured some stuff out. A light in a collada file has a named node reference which stores the location and rotation of the light, as it does for all kinds of nodes. So in order to get the translation information for a light, you have to find the corresponding node and read its translation like so:



    if(pScene->HasLights()){
        for (unsigned int nAssimpLight = 0; nAssimpLight < pScene->mNumLights; nAssimpLight++) 
        {
            const aiLight cAssimpLight = *pScene->mLights[nAssimpLight];
            aiNode* LightNode = pScene->mRootNode->FindNode(cAssimpLight.mName);
                        
            // mTransformation[0] = scaling
            // mTransformation[1] = rotation
            // mTransformation[2] = position




            FTransform ActorTransform = FTransform::Identity;            
            const FTransform LightPosition = FTransform(
                FRotator(
                    LightNode->mTransformation[1][0],
                    LightNode->mTransformation[1][1],
                    LightNode->mTransformation[1][2]
                ),
                FVector(
                    LightNode->mTransformation[2][0] * 100, 
                    LightNode->mTransformation[2][1] * 100, 
                    LightNode->mTransformation[2][2] * 100
                )
            );
                 }
        }


Although not yet completely accurate (the position value do not correspond with the source file), I’m able to use the values and add a light in the editor!

Ok, finally got some time again to work on this. Most of it is working, but I have a problem with the rotation of the lights. They seem to be off by 90 degrees, but not always on the same axis.

Does anyone know how to approach this? Here’s my latest code:


if(pScene->HasLights()){
		for (unsigned int nAssimpLight = 0; nAssimpLight < pScene->mNumLights; nAssimpLight++) 
		{
			aiVector3D nodeScale, nodePos;
			aiQuaternion nodeQuat;
			const aiLight cAssimpLight = *pScene->mLights[nAssimpLight];
            
			
			// Get rootNode
			aiNode* rootNode = pScene->mRootNode;

            // Get LightNode by asset name
			aiNode* LightNode = pScene->mRootNode->FindNode(cAssimpLight.mName);
						
			LightNode->mTransformation.Decompose(nodeScale, nodeQuat, nodePos);

			FQuat lightQuat = FQuat(nodeQuat.x, nodeQuat.y, nodeQuat.z, nodeQuat.w);

			FRotator lightRot = FRotator::MakeFromEuler(lightQuat.Euler());

			const FTransform LightPosition = FTransform(
				lightRot,
				FVector(
					nodePos.x * 100,
					nodePos.y * 100, 
					nodePos.z * 100
				)
			);

			ASpotLight* SpotLight = Cast<ASpotLight>(GEditor->AddActor(GEditor->GetEditorWorldContext().World()->GetCurrentLevel(), ASpotLight::StaticClass(), LightPosition));

			SpotLight->SetActorLabel(*FString(cAssimpLight.mName.C_Str()));
			SpotLight->SetLightColor(FLinearColor(cAssimpLight.mColorAmbient.r, cAssimpLight.mColorAmbient.g, cAssimpLight.mColorAmbient.b));

			FRotator currentRotation = SpotLight->GetActorRotation();
			SpotLight->SetActorRelativeRotation(FRotator::MakeFromEuler(FVector(currentRotation.Roll + 90, currentRotation.Pitch, currentRotation.Yaw + 90)));

		
		}
	}

As you can see, I already tried to add 90 degrees to roll and yaw, but that doesn’t solve the issue. I think my main problem is the translation between the XYZ euler in Blender3D to the Collada transform matrix to UE4 FRotator.

I Hope someone can point me in the right direction.

Thanks.

How to add rotation of -90 to the Y axis in a quaternion

ok, getting closer! The only thing I think is left is the fact that a light in UE4 is default rotated around the Y axis by -90. So I now need to figure out how to add that rotation to my imported light.
I think the nodeQuat.y in the line below needs to get the transformation, but I’m not sure how to add it.


FQuat lightQuat = FQuat(nodeQuat.x, nodeQuat.y, nodeQuat.z, nodeQuat.w);

Any ideas?