FThumbnailPreviewScene::FThumbnailPreviewScene() : FPreviewScene( ConstructionValues() .SetLightRotation( FRotator(304.736, 39.84, 0) ) .SetCreatePhysicsScene(false) .SetTransactional(false)) { // A background sky sphere UStaticMeshComponent* BackgroundComponent = NewObject<UStaticMeshComponent>(); BackgroundComponent->SetStaticMesh( GUnrealEd->GetThumbnailManager()->EditorSkySphere ); const float SkySphereScale = 2000.0f; const FTransform BackgroundTransform(FRotator(0,0,0), FVector(0,0,0), FVector(SkySphereScale)); FPreviewScene::AddComponent(BackgroundComponent, BackgroundTransform); // Adjust the default light DirectionalLight->Intensity = 0.2f; // Add additional lights UDirectionalLightComponent* DirectionalLight2 = NewObject<UDirectionalLightComponent>(); DirectionalLight->Intensity = 5.0f; AddComponent(DirectionalLight2, FTransform( FRotator(-40,-144.678, 0) )); UDirectionalLightComponent* DirectionalLight3 = NewObject<UDirectionalLightComponent>(); DirectionalLight->Intensity = 1.0f; AddComponent(DirectionalLight3, FTransform( FRotator(299.235,144.993, 0) )); // Add an infinite plane const float FloorPlaneScale = 10000.f; const FTransform FloorPlaneTransform(FRotator(-90.f,0,0), FVector::ZeroVector, FVector(FloorPlaneScale)); UStaticMeshComponent* FloorPlaneComponent = NewObject<UStaticMeshComponent>(); FloorPlaneComponent->SetStaticMesh( GUnrealEd->GetThumbnailManager()->EditorPlane ); FloorPlaneComponent->SetMaterial( 0, GUnrealEd->GetThumbnailManager()->FloorPlaneMaterial ); FPreviewScene::AddComponent(FloorPlaneComponent, FloorPlaneTransform); }
void AFlarePlanetarium::BeginPlay() { Super::BeginPlay(); FLOG("AFlarePlanetarium::BeginPlay"); TArray<UActorComponent*> Components = GetComponentsByClass(UStaticMeshComponent::StaticClass()); for (int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++) { UStaticMeshComponent* PlanetCandidate = Cast<UStaticMeshComponent>(Components[ComponentIndex]); if (PlanetCandidate) { // Apply a new dynamic material to planets so that we can control shading parameters UMaterialInstanceConstant* BasePlanetMaterial = Cast<UMaterialInstanceConstant>(PlanetCandidate->GetMaterial(0)); if (BasePlanetMaterial) { //FLOGV("AFlarePlanetarium::BeginPlay : found planet '%s'", *PlanetCandidate->GetName()); #if PLATFORM_LINUX int32 UseNormalAsLightingDirection = 1; #else int32 UseNormalAsLightingDirection = 0; #endif UMaterialInstanceDynamic* PlanetMaterial = UMaterialInstanceDynamic::Create(BasePlanetMaterial, GetWorld()); PlanetCandidate->SetMaterial(0, PlanetMaterial); PlanetMaterial->SetScalarParameterValue("UseNormalAsLightingDirection", UseNormalAsLightingDirection); } } } }
void UCarlaSettingsDelegate::SetAllRoads(UWorld* world, const float max_draw_distance, const TArray<FStaticMaterial> &road_pieces_materials) const { if(!world||!IsValid(world)||world->IsPendingKill()) return; AsyncTask(ENamedThreads::GameThread, [=](){ if(!world||!IsValid(world)||world->IsPendingKill()) return; TArray<AActor*> actors; UGameplayStatics::GetAllActorsWithTag(world, UCarlaSettings::CARLA_ROAD_TAG,actors); for(int32 i=0; i<actors.Num(); i++) { AActor* actor = actors[i]; if(!IsValid(actor) || actor->IsPendingKill()) continue; TArray<UActorComponent*> components = actor->GetComponentsByClass(UStaticMeshComponent::StaticClass()); for(int32 j=0; j<components.Num(); j++) { UStaticMeshComponent* staticmeshcomponent = Cast<UStaticMeshComponent>(components[j]); if(staticmeshcomponent) { staticmeshcomponent->bAllowCullDistanceVolume = (max_draw_distance>0); staticmeshcomponent->bUseAsOccluder = false; staticmeshcomponent->LDMaxDrawDistance = max_draw_distance; staticmeshcomponent->CastShadow = (max_draw_distance==0); if(road_pieces_materials.Num()>0) { TArray<FName> meshslotsnames = staticmeshcomponent->GetMaterialSlotNames(); for(int32 k=0; k<meshslotsnames.Num(); k++) { const FName &slotname = meshslotsnames[k]; road_pieces_materials.ContainsByPredicate( [staticmeshcomponent,slotname](const FStaticMaterial& material) { if(material.MaterialSlotName.IsEqual(slotname)) { staticmeshcomponent->SetMaterial( staticmeshcomponent->GetMaterialIndex(slotname), material.MaterialInterface ); return true; } else return false; }); } } } } } }); //,DELAY_TIME_TO_SET_ALL_ROADS, false); }
void AShaderPluginDemoCharacter::OnFire() { //Try to set a texture to the object we hit! FHitResult HitResult; FVector StartLocation = FirstPersonCameraComponent->GetComponentLocation(); FRotator Direction = FirstPersonCameraComponent->GetComponentRotation(); FVector EndLocation = StartLocation + Direction.Vector() * 10000; FCollisionQueryParams QueryParams; QueryParams.AddIgnoredActor(this); if (GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility, QueryParams)) { TArray<UStaticMeshComponent*> StaticMeshComponents = TArray<UStaticMeshComponent*>(); AActor* HitActor = HitResult.GetActor(); if (NULL != HitActor) { HitActor->GetComponents<UStaticMeshComponent>(StaticMeshComponents); for (int32 i = 0; i < StaticMeshComponents.Num(); i++) { UStaticMeshComponent* CurrentStaticMeshPtr = StaticMeshComponents[i]; CurrentStaticMeshPtr->SetMaterial(0, MaterialToApplyToClickedObject); UMaterialInstanceDynamic* MID = CurrentStaticMeshPtr->CreateAndSetMaterialInstanceDynamic(0); UTexture* CastedRenderTarget = Cast<UTexture>(RenderTarget); MID->SetTextureParameterValue("InputTexture", CastedRenderTarget); } } } // try and play the sound if specified if (FireSound != NULL) { UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); } // try and play a firing animation if specified if (FireAnimation != NULL) { // Get the animation object for the arms mesh UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance(); if (AnimInstance != NULL) { AnimInstance->Montage_Play(FireAnimation, 1.f); } } }
// Sets default values AKrofna_CPP::AKrofna_CPP() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; UStaticMeshComponent *Krofna = CreateDefaultSubobject<UStaticMeshComponent,UStaticMeshComponent>(TEXT("krofnica")); URotatingMovementComponent *Rotacija = CreateDefaultSubobject<URotatingMovementComponent, URotatingMovementComponent>(TEXT("rotaciona komponenta")); UPointLightComponent *Svetlo1 = CreateDefaultSubobject <UPointLightComponent, UPointLightComponent>(TEXT("Svetlo1")); UPointLightComponent *Svetlo2 = CreateDefaultSubobject <UPointLightComponent, UPointLightComponent>(TEXT("Svetlo2")); USphereComponent *Kolizija = CreateDefaultSubobject <USphereComponent, USphereComponent>(TEXT("Kolizija")); Kolizija->SetSphereRadius(65.f); Kolizija->Activate(true); Kolizija->bGenerateOverlapEvents = true; Kolizija->SetRelativeLocation(FVector(0,0,18.f)); this->RootComponent = Krofna; Kolizija->AttachTo(RootComponent); Svetlo1->AttachTo(RootComponent); Svetlo2->AttachTo(RootComponent); Svetlo1->SetRelativeLocation(FVector(0, 0, 65)); Svetlo2->SetRelativeLocation(FVector(0, 0, -45)); Svetlo1->SetLightColor(FLinearColor(0.65f, 1.f, 0.875f)); Svetlo2->SetLightColor(FLinearColor(0.45f, 1.f, 0.82f)); this->DisableComponentsSimulatePhysics(); Krofna->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap); static ConstructorHelpers::FObjectFinder<UStaticMesh> Krofna_SM(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Torus.Shape_Torus'")); Krofna->SetStaticMesh(Krofna_SM.Object); static ConstructorHelpers::FObjectFinder<UMaterial> Krofna_M(TEXT("Material'/Game/StarterContent/Materials/M_Metal_Gold.M_Metal_Gold'")); Krofna->SetMaterial(0, Krofna_M.Object); Rotacija->SetActive(true); Rotacija->RotationRate = FRotator(120,120,120); this->SetActorEnableCollision(true); OnActorBeginOverlap.AddDynamic(this, &AKrofna_CPP::OnBeginOverlap); }
void FComponentTypeRegistryData::AddBasicShapeComponents(TArray<FComponentClassComboEntryPtr>& SortedClassList) { FString BasicShapesHeading = LOCTEXT("BasicShapesHeading", "Basic Shapes").ToString(); const auto OnBasicShapeCreated = [](UActorComponent* Component) { UStaticMeshComponent* SMC = Cast<UStaticMeshComponent>(Component); if (SMC) { SMC->SetMaterial(0, LoadObject<UMaterial>(nullptr, TEXT("/Engine/BasicShapes/BasicShapeMaterial.BasicShapeMaterial"))); } }; { FComponentEntryCustomizationArgs Args; Args.AssetOverride = LoadObject<UStaticMesh>(nullptr, *UActorFactoryBasicShape::BasicCube.ToString()); Args.OnComponentCreated = FOnComponentCreated::CreateStatic(OnBasicShapeCreated); Args.ComponentNameOverride = LOCTEXT("BasicCubeShapeDisplayName", "Cube").ToString(); Args.IconOverrideBrushName = FName("ClassIcon.Cube"); Args.SortPriority = 2; { FComponentClassComboEntryPtr NewShape = MakeShareable(new FComponentClassComboEntry(BasicShapesHeading, UStaticMeshComponent::StaticClass(), true, EComponentCreateAction::SpawnExistingClass, Args)); SortedClassList.Add(NewShape); } { //Cube also goes in the common group FComponentClassComboEntryPtr NewShape = MakeShareable(new FComponentClassComboEntry(CommonClassGroup, UStaticMeshComponent::StaticClass(), false, EComponentCreateAction::SpawnExistingClass, Args)); SortedClassList.Add(NewShape); } } { FComponentEntryCustomizationArgs Args; Args.AssetOverride = LoadObject<UStaticMesh>(nullptr, *UActorFactoryBasicShape::BasicSphere.ToString()); Args.OnComponentCreated = FOnComponentCreated::CreateStatic(OnBasicShapeCreated); Args.ComponentNameOverride = LOCTEXT("BasicSphereShapeDisplayName", "Sphere").ToString(); Args.IconOverrideBrushName = FName("ClassIcon.Sphere"); Args.SortPriority = 2; { FComponentClassComboEntryPtr NewShape = MakeShareable(new FComponentClassComboEntry(BasicShapesHeading, UStaticMeshComponent::StaticClass(), true, EComponentCreateAction::SpawnExistingClass, Args)); SortedClassList.Add(NewShape); } { // Sphere also goes in the common group FComponentClassComboEntryPtr NewShape = MakeShareable(new FComponentClassComboEntry(CommonClassGroup, UStaticMeshComponent::StaticClass(), false, EComponentCreateAction::SpawnExistingClass, Args)); SortedClassList.Add(NewShape); } } { FComponentEntryCustomizationArgs Args; Args.AssetOverride = LoadObject<UStaticMesh>(nullptr, *UActorFactoryBasicShape::BasicCylinder.ToString()); Args.OnComponentCreated = FOnComponentCreated::CreateStatic(OnBasicShapeCreated); Args.ComponentNameOverride = LOCTEXT("BasicCylinderShapeDisplayName", "Cylinder").ToString(); Args.IconOverrideBrushName = FName("ClassIcon.Cylinder"); Args.SortPriority = 3; FComponentClassComboEntryPtr NewShape = MakeShareable(new FComponentClassComboEntry(BasicShapesHeading, UStaticMeshComponent::StaticClass(), true, EComponentCreateAction::SpawnExistingClass, Args)); SortedClassList.Add(NewShape); } { FComponentEntryCustomizationArgs Args; Args.AssetOverride = LoadObject<UStaticMesh>(nullptr, *UActorFactoryBasicShape::BasicCone.ToString()); Args.OnComponentCreated = FOnComponentCreated::CreateStatic(OnBasicShapeCreated); Args.ComponentNameOverride = LOCTEXT("BasicConeShapeDisplayName", "Cone").ToString(); Args.IconOverrideBrushName = FName("ClassIcon.Cone"); Args.SortPriority = 4; FComponentClassComboEntryPtr NewShape = MakeShareable(new FComponentClassComboEntry(BasicShapesHeading, UStaticMeshComponent::StaticClass(), true, EComponentCreateAction::SpawnExistingClass, Args)); SortedClassList.Add(NewShape); } }
void AFlarePlanetarium::SetupCelestialBody(CelestialBodyPosition* BodyPosition, double DisplayDistance, double DisplayRadius) { FVector PlayerShipLocation = FVector::ZeroVector; if (GetGame()->GetPC()->GetShipPawn()) { PlayerShipLocation = GetGame()->GetPC()->GetShipPawn()->GetActorLocation(); } #ifdef PLANETARIUM_DEBUG DrawDebugSphere(GetWorld(), FVector::ZeroVector, DisplayDistance /1000 , 32, FColor::Blue, false); PlayerShipLocation = FVector::ZeroVector; DisplayRadius /= 1000; DisplayDistance /= 1000; #endif BodyPosition->BodyComponent->SetRelativeLocation((DisplayDistance * BodyPosition->AlignedLocation.GetUnsafeNormal()).ToVector() + PlayerShipLocation); float Scale = DisplayRadius / 512; // Mesh size is 1024; BodyPosition->BodyComponent->SetRelativeScale3D(FPreciseVector(Scale).ToVector()); FTransform BaseRotation = FTransform(FRotator(0, 0 ,90)); FTransform TimeRotation = FTransform(FRotator(0, BodyPosition->TotalRotation, 0)); FQuat Rotation = (TimeRotation * BaseRotation).GetRotation(); // TODO Rotation float time interpolation BodyPosition->BodyComponent->SetRelativeRotation(FQuat::Identity); BodyPosition->BodyComponent->SetRelativeRotation(Rotation); // Apply sun direction to component UMaterialInstanceDynamic* ComponentMaterial = Cast<UMaterialInstanceDynamic>(BodyPosition->BodyComponent->GetMaterial(0)); if (!ComponentMaterial) { ComponentMaterial = UMaterialInstanceDynamic::Create(BodyPosition->BodyComponent->GetMaterial(0) , GetWorld()); BodyPosition->BodyComponent->SetMaterial(0, ComponentMaterial); } ComponentMaterial->SetVectorParameterValue("SunDirection", SunDirection.ToVector()); // Look for rings and orient them TArray<USceneComponent*> RingCandidates; BodyPosition->BodyComponent->GetChildrenComponents(true, RingCandidates); for (int32 ComponentIndex = 0; ComponentIndex < RingCandidates.Num(); ComponentIndex++) { UStaticMeshComponent* RingComponent = Cast<UStaticMeshComponent>(RingCandidates[ComponentIndex]); if (RingComponent && RingComponent->GetName().Contains("ring")) { // Get or create the material UMaterialInstanceDynamic* RingMaterial = Cast<UMaterialInstanceDynamic>(RingComponent->GetMaterial(0)); if (!RingMaterial) { RingMaterial = UMaterialInstanceDynamic::Create(RingComponent->GetMaterial(0), GetWorld()); RingComponent->SetMaterial(0, RingMaterial); } // Get world-space rotation angles for the ring and the sun float SunRotationPitch = FMath::RadiansToDegrees(FMath::Atan2(SunDirection.Z,SunDirection.X)) + 180; float RingRotationPitch = -BodyPosition->TotalRotation; // Feed params to the shader RingMaterial->SetScalarParameterValue("RingPitch", RingRotationPitch / 360); RingMaterial->SetScalarParameterValue("SunPitch", SunRotationPitch / 360); } } // Sun also rotates to track direction if (BodyPosition->Body == &Sun) { BodyPosition->BodyComponent->SetRelativeRotation(SunDirection.ToVector().Rotation()); } // Compute sun occlusion if (BodyPosition->Body != &Sun) { double OcclusionAngle = FPreciseMath::Asin(BodyPosition->Radius / BodyPosition->Distance); float BodyPhase = FMath::UnwindRadians(FMath::Atan2(BodyPosition->AlignedLocation.Z, BodyPosition->AlignedLocation.X)); float CenterAngularDistance = FMath::Abs(FMath::UnwindRadians(SunPhase - BodyPhase)); float AngleSum = (SunOcclusionAngle + OcclusionAngle); float AngleDiff = FMath::Abs(SunOcclusionAngle - OcclusionAngle); /*FLOGV("SetupCelestialBody %s BodyPhase = %f", *BodyPosition->Body->Name.ToString(), FMath::RadiansToDegrees(BodyPhase)); FLOGV("SetupCelestialBody %s SunPhase = %f", *BodyPosition->Body->Name.ToString(), FMath::RadiansToDegrees(SunPhase)); FLOGV("SetupCelestialBody %s OcclusionAngle = %f", *BodyPosition->Body->Name.ToString(), FMath::RadiansToDegrees(OcclusionAngle)); FLOGV("SetupCelestialBody %s SunOcclusionAngle = %f", *BodyPosition->Body->Name.ToString(), FMath::RadiansToDegrees(SunOcclusionAngle)); FLOGV("SetupCelestialBody %s AngleDiff = %f", *BodyPosition->Body->Name.ToString(), FMath::RadiansToDegrees(AngleDiff)); FLOGV("SetupCelestialBody %s CenterAngularDistance = %f", *BodyPosition->Body->Name.ToString(), FMath::RadiansToDegrees(CenterAngularDistance)); FLOGV("SetupCelestialBody %s AngleSum = %f", *BodyPosition->Body->Name.ToString(), FMath::RadiansToDegrees(AngleSum));*/ if (CenterAngularDistance < AngleSum) { // There is occlusion float OcclusionRatio; if (CenterAngularDistance < AngleDiff) { // Maximum occlusion OcclusionRatio = 1.0; } else { // Partial occlusion OcclusionRatio = (AngleSum - CenterAngularDistance) / (2* FMath::Min(SunOcclusionAngle, OcclusionAngle)); // OcclusionRatio = ((SunOcclusionAngle + OcclusionAngle) + FMath::Max(SunOcclusionAngle, OcclusionAngle) - FMath::Min(SunOcclusionAngle, OcclusionAngle)) / (2 * CenterAngularDistance); } //FLOGV("MoveCelestialBody %s OcclusionRatio = %f", *Body->Name, OcclusionRatio); // Now, find the surface occlusion float SunAngularSurface = PI*FMath::Square(SunOcclusionAngle); float MaxOcclusionAngularSurface = PI*FMath::Square(FMath::Min(SunOcclusionAngle, OcclusionAngle)); float MaxOcclusion = MaxOcclusionAngularSurface / SunAngularSurface; float Occlusion = OcclusionRatio * MaxOcclusion; /*FLOGV("SetupCelestialBody %s CenterAngularDistance = %f", *BodyPosition->Body->Name.ToString(), CenterAngularDistance); FLOGV("SetupCelestialBody %s SunOcclusionAngle = %f", *BodyPosition->Body->Name.ToString(), SunOcclusionAngle); FLOGV("SetupCelestialBody %s OcclusionAngle = %f", *BodyPosition->Body->Name.ToString(), OcclusionAngle); FLOGV("SetupCelestialBody %s SunAngularSurface = %f", *BodyPosition->Body->Name.ToString(), SunAngularSurface); FLOGV("SetupCelestialBody %s MaxOcclusionAngularSurface = %f", *BodyPosition->Body->Name.ToString(), MaxOcclusionAngularSurface); FLOGV("SetupCelestialBody %s MaxOcclusion = %f", *BodyPosition->Body->Name.ToString(), MaxOcclusion); FLOGV("SetupCelestialBody %s Occlusion = %f", *BodyPosition->Body->Name.ToString(), Occlusion);*/ if (Occlusion > SunOcclusion) { // Keep only best occlusion SunOcclusion = Occlusion; } } } }