FPreviewScene::~FPreviewScene() { // Stop any audio components playing in this scene if( GEngine && GEngine->GetAudioDevice() ) { GEngine->GetAudioDevice()->Flush( GetWorld(), false ); } // Remove all the attached components for( int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++ ) { UActorComponent* Component = Components[ ComponentIndex ]; if (bForceAllUsedMipsResident) { // Remove the mip streaming override on the mesh to be removed UMeshComponent* pMesh = Cast<UMeshComponent>(Component); if (pMesh != NULL) { pMesh->SetTextureForceResidentFlag(false); } } Component->UnregisterComponent(); } PreviewWorld->CleanupWorld(); GEngine->DestroyWorldContext(GetWorld()); }
int UAirBlueprintLib::GetMeshStencilID(const std::string& mesh_name) { FString fmesh_name(mesh_name.c_str()); for (TObjectIterator<UMeshComponent> comp; comp; ++comp) { // Access the subclass instance with the * or -> operators. UMeshComponent *mesh = *comp; if (mesh->GetName() == fmesh_name) { return mesh->CustomDepthStencilValue; } } return -1; }
void FPreviewScene::RemoveComponent(UActorComponent* Component) { Component->UnregisterComponent(); Components.Remove(Component); if (bForceAllUsedMipsResident) { // Remove the mip streaming override on the old mesh UMeshComponent* pMesh = Cast<UMeshComponent>(Component); if (pMesh != NULL) { pMesh->SetTextureForceResidentFlag(false); } } }
void FJavascriptInGameScene::Destroy() { if (bDestroyed) return; // Stop any audio components playing in this scene if (GEngine) { UWorld* World = GetWorld(); if (World) { if (FAudioDevice* AudioDevice = World->GetAudioDevice()) { AudioDevice->Flush(GetWorld(), false); } } } // Remove all the attached components for (int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++) { UActorComponent* Component = Components[ComponentIndex]; if (bForceAllUsedMipsResident) { // Remove the mip streaming override on the mesh to be removed UMeshComponent* pMesh = Cast<UMeshComponent>(Component); if (pMesh != NULL) { pMesh->SetTextureForceResidentFlag(false); } } Component->UnregisterComponent(); } if (GEngine) { PreviewWorld->CleanupWorld(); GEngine->DestroyWorldContext(GetWorld()); } bDestroyed = true; }
void FPreviewScene::AddComponent(UActorComponent* Component,const FTransform& LocalToWorld) { Components.AddUnique(Component); USceneComponent* SceneComp = Cast<USceneComponent>(Component); if(SceneComp && SceneComp->GetAttachParent() == NULL) { SceneComp->SetRelativeTransform(LocalToWorld); } Component->RegisterComponentWithWorld(GetWorld()); if (bForceAllUsedMipsResident) { // Add a mip streaming override to the new mesh UMeshComponent* pMesh = Cast<UMeshComponent>(Component); if (pMesh != NULL) { pMesh->SetTextureForceResidentFlag(true); } } GetScene()->UpdateSpeedTreeWind(0.0); }
/** * Attempts to apply the material to the specified actor. * * @param TargetActor the actor to apply the material to * @param MaterialToApply the material to apply to the actor * @param OptionalMaterialSlot the material slot to apply to. * * @return true if the material was successfully applied to the actor */ bool FActorFactoryAssetProxy::ApplyMaterialToActor( AActor* TargetActor, UMaterialInterface* MaterialToApply, int32 OptionalMaterialSlot ) { bool bResult = false; if ( TargetActor != NULL && MaterialToApply != NULL ) { ALandscapeProxy* Landscape = Cast<ALandscapeProxy>(TargetActor); if (Landscape != NULL) { UProperty* MaterialProperty = FindField<UProperty>(ALandscapeProxy::StaticClass(), "LandscapeMaterial"); Landscape->PreEditChange(MaterialProperty); Landscape->LandscapeMaterial = MaterialToApply; FPropertyChangedEvent PropertyChangedEvent(MaterialProperty); Landscape->PostEditChangeProperty(PropertyChangedEvent); bResult = true; } else { TArray<UActorComponent*> EditableComponents; FActorEditorUtils::GetEditableComponents( TargetActor, EditableComponents ); // Some actors could potentially have multiple mesh components, so we need to store all of the potentially valid ones // (or else perform special cases with IsA checks on the target actor) TArray<USceneComponent*> FoundMeshComponents; // Find which mesh the user clicked on first. TInlineComponentArray<USceneComponent*> SceneComponents; TargetActor->GetComponents(SceneComponents); for ( int32 ComponentIdx=0; ComponentIdx < SceneComponents.Num(); ComponentIdx++ ) { USceneComponent* SceneComp = SceneComponents[ComponentIdx]; // Only apply the material to editable components. Components which are not exposed are not intended to be changed. if( EditableComponents.Contains( SceneComp ) ) { UMeshComponent* MeshComponent = Cast<UMeshComponent>(SceneComp); if((MeshComponent && MeshComponent->IsRegistered()) || SceneComp->IsA<UDecalComponent>()) { // Intentionally do not break the loop here, as there could be potentially multiple mesh components FoundMeshComponents.AddUnique( SceneComp ); } } } if ( FoundMeshComponents.Num() > 0 ) { // Check each component that was found for ( TArray<USceneComponent*>::TConstIterator MeshCompIter( FoundMeshComponents ); MeshCompIter; ++MeshCompIter ) { USceneComponent* SceneComp = *MeshCompIter; bResult = FComponentEditorUtils::AttemptApplyMaterialToComponent(SceneComp, MaterialToApply, OptionalMaterialSlot); } } } } return bResult; }
void ADebugCameraHUD::PostRender() { Super::PostRender(); if (bShowHUD) { ADebugCameraController* DCC = Cast<ADebugCameraController>( PlayerOwner ); UFont* RenderFont = GEngine->GetSmallFont(); if( DCC != NULL ) { FFontRenderInfo FontRenderInfo = Canvas->CreateFontRenderInfo(false, true); Canvas->SetDrawColor(64, 64, 255, 255); FString MyText = TEXT("Debug Camera"); float xl, yl; Canvas->StrLen(RenderFont, MyText, xl, yl); float X = Canvas->SizeX * 0.05f; float Y = yl;//*1.67; yl += 2*Y; Canvas->DrawText(RenderFont, MyText, X, yl, 1.f, 1.f, FontRenderInfo); Canvas->SetDrawColor(200, 200, 128, 255); FVector const CamLoc = DCC->PlayerCameraManager->GetCameraLocation(); FRotator const CamRot = DCC->PlayerCameraManager->GetCameraRotation(); float const CamFOV = DCC->PlayerCameraManager->GetFOVAngle(); yl += Y; FString const LocRotString = FString::Printf(TEXT("Loc=(%.1f, %.1f, %.1f) Rot=(%.1f, %.1f, %.1f)"), CamLoc.X, CamLoc.Y, CamLoc.Z, CamRot.Pitch, CamRot.Yaw, CamRot.Roll); Canvas->DrawText(RenderFont, LocRotString, X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; FString const FOVString = FString::Printf(TEXT("HFOV=%.1f"), CamFOV); Canvas->DrawText(RenderFont, FOVString, X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; FString const SpeedScaleString = FString::Printf(TEXT("SpeedScale=%.2fx"), DCC->SpeedScale); Canvas->DrawText(RenderFont, SpeedScaleString, X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; FString const SpeedString = FString::Printf(TEXT("MaxSpeed=%.1f"), DCC->GetSpectatorPawn() && DCC->GetSpectatorPawn()->GetMovementComponent() ? DCC->GetSpectatorPawn()->GetMovementComponent()->GetMaxSpeed() : 0.f); Canvas->DrawText(RenderFont, SpeedString, X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; //Canvas->DrawText(FString::Printf(TEXT("CamLoc:%s CamRot:%s"), *CamLoc.ToString(), *CamRot.ToString() )); const TCHAR* CVarComplexName = TEXT("g.DebugCameraTraceComplex"); bool bTraceComplex = true; #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) bTraceComplex = CVarDebugCameraTraceComplex.GetValueOnGameThread() != 0; #endif FCollisionQueryParams TraceParams(NAME_None, bTraceComplex, this); FHitResult Hit; bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, CamLoc, CamRot.Vector() * 100000.f + CamLoc, ECC_Pawn, TraceParams); yl += Y; Canvas->DrawText(RenderFont, FString::Printf(TEXT("Trace info (%s = %d):"), CVarComplexName, bTraceComplex ? 1 : 0), X, yl, 1.f, 1.f, FontRenderInfo); if( bHit ) { AActor* HitActor = Hit.GetActor(); yl += Y; Canvas->DrawText(RenderFont, FString::Printf(TEXT("HitLoc:%s HitNorm:%s"), *Hit.Location.ToString(), *Hit.Normal.ToString() ), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->DrawText(RenderFont, FString::Printf(TEXT("HitDist: %f"), Hit.Distance), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->DrawText(RenderFont, FString::Printf(TEXT("HitActor: '%s'"), HitActor ? *HitActor->GetFName().ToString() : TEXT("<NULL>")), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->DrawText(RenderFont, FString::Printf(TEXT("HitComponent: '%s'"), Hit.Component.Get() ? *Hit.Component.Get()->GetFName().ToString() : TEXT("<NULL>")), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->DrawText(RenderFont, FString::Printf(TEXT("HitActor Class: '%s'"), HitActor && HitActor->GetClass() ? *HitActor->GetClass()->GetName() : TEXT("<Not Found>") ), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->DrawText(RenderFont, FString::Printf(TEXT("HitActorPath: '%s'"), HitActor ? *HitActor->GetPathName() : TEXT("<Not Found>")), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; bool bFoundMaterial = false; if ( Hit.Component != NULL ) { bFoundMaterial = DisplayMaterials( X, yl, Y, Cast<UMeshComponent>(Hit.Component.Get()) ); } else { TInlineComponentArray<UMeshComponent*> Components; GetComponents(Components); for ( int32 i=0; i<Components.Num(); i++ ) { UMeshComponent* MeshComp = Components[i]; if ( MeshComp->IsRegistered() ) { bFoundMaterial = bFoundMaterial || DisplayMaterials( X, yl, Y, MeshComp ); } } } if ( bFoundMaterial == false ) { yl += Y; Canvas->DrawText(RenderFont, "Material: NULL", X + Y, yl, 1.f, 1.f, FontRenderInfo ); } DrawDebugLine( GetWorld(), Hit.Location, Hit.Location+Hit.Normal*30.f, FColor::White ); } else { yl += Y; Canvas->DrawText( RenderFont, TEXT("No trace Hit"), X, yl, 1.f, 1.f, FontRenderInfo); } if ( DCC->bShowSelectedInfo && DCC->SelectedActor != NULL ) { yl += Y; Canvas->DrawText(RenderFont, FString::Printf(TEXT("Selected actor: '%s'"), *DCC->SelectedActor->GetFName().ToString()), X, yl, 1.f, 1.f, FontRenderInfo); DisplayMaterials( X, yl, Y, Cast<UMeshComponent>(DCC->SelectedComponent) ); } // controls display yl += Y*15; Canvas->SetDrawColor(64, 64, 255, 255); Canvas->DrawText(RenderFont, TEXT("Controls"), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->SetDrawColor(200, 200, 128, 255); Canvas->DrawText(RenderFont, TEXT("FOV +/-: ,/. or DPad Up/Down"), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->DrawText(RenderFont, TEXT("Speed +/-: MouseWheel or +/- or LB/RB"), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->DrawText(RenderFont, TEXT("Freeze Rendering: F or YButton"), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; Canvas->DrawText(RenderFont, TEXT("Toggle Display: BackSpace or XButton"), X, yl, 1.f, 1.f, FontRenderInfo); yl += Y; } } }
void Assignment::ApplyToMeshes() { UClass *refMeshClass= AStaticMeshActor::StaticClass(); UClass *refSkeletaMeshClass = ASkeletalMeshActor::StaticClass(); for (TObjectIterator<UObject> Itr; Itr; ++Itr) { if (Itr->GetClass()->IsChildOf(refMeshClass)) { UE_LOG(ModoMaterialImporter, Log, TEXT("Scan materials in: %s %s"), *Itr->GetName(), *Itr->GetClass()->GetDesc()); AStaticMeshActor *aMeshActor = dynamic_cast<AStaticMeshActor*> (*Itr); if (aMeshActor != NULL) { UMeshComponent* meshCompo = aMeshActor->GetStaticMeshComponent(); if (meshCompo != NULL) { for (int i = 0; i < meshCompo->GetNumMaterials(); i++) { UMaterialInterface* material = meshCompo->GetMaterial(i); // It seems a UE4 bug, GetNumMaterials contains NULL materials! if (material == NULL) continue; std::string strName = (TCHAR_TO_UTF8(*material->GetName())); std::map<std::string, UMaterial*>::iterator mat_itr = Materials.find(strName); if (mat_itr != Materials.end()) { UE_LOG(ModoMaterialImporter, Log, TEXT("Set Material: %s"), *material->GetName()); meshCompo->SetMaterial(i, mat_itr->second); } } } } } else if (Itr->GetClass()->IsChildOf(refSkeletaMeshClass)) { UE_LOG(ModoMaterialImporter, Log, TEXT("Scan materials in: %s %s"), *Itr->GetName(), *Itr->GetClass()->GetDesc()); ASkeletalMeshActor *aMeshActor = dynamic_cast<ASkeletalMeshActor*> (*Itr); if (aMeshActor != NULL) { UMeshComponent * meshCompo = aMeshActor->GetSkeletalMeshComponent(); for (int i = 0; i < meshCompo->GetNumMaterials(); i++) { UMaterialInterface* material = meshCompo->GetMaterial(i); // It seems a UE4 bug, GetNumMaterials contains NULL materials! if (material == NULL) continue; std::string strName = (TCHAR_TO_UTF8(*material->GetName())); std::map<std::string, UMaterial*>::iterator mat_itr = Materials.find(strName); if (mat_itr != Materials.end()) { UE_LOG(ModoMaterialImporter, Log, TEXT("Set Material: %s"), *material->GetName()); meshCompo->SetMaterial(i, mat_itr->second); } } } } } }