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); }
// Sets default values AMotherActor::AMotherActor() { // 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; UBoxComponent* Box = CreateDefaultSubobject<UBoxComponent>(TEXT("RootComponent")); RootComponent = Box; Box->InitBoxExtent(FVector(20.0f, 20.0f, 20.0f)); UBoxComponent* Box1 = CreateDefaultSubobject<UBoxComponent>(TEXT("Box")); Box1->InitBoxExtent(FVector(60.0f, 60.0f, 60.0f)); Box1->RelativeLocation = FVector(100.0f, 0.0f, 0.0f); USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere")); SphereComponent->InitSphereRadius(60.0f); SphereComponent->RelativeLocation = FVector(100.0f, 0.0f, 0.0f); UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation")); static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere")); if (SphereVisualAsset.Succeeded()) { SphereVisual->SetStaticMesh(SphereVisualAsset.Object); SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -100.0f)); SphereVisual->SetWorldScale3D(FVector(0.8f)); } Box1->AttachTo(RootComponent); SphereVisual->AttachTo(RootComponent); SphereComponent->AttachTo(RootComponent); UChildActorComponent * ChildActor = CreateDefaultSubobject<UChildActorComponent>(TEXT("InventoryCamera")); ChildActor->SetChildActorClass(AOrbitalActor::StaticClass()); ChildActor->CreateChildActor(); FVector position = GetActorLocation(); ChildActor->SetRelativeTransform(FTransform(position)); }
// Sets default values ACollidingPawn::ACollidingPawn() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; // Tutorial code // Our root component will be a sphere that reats to Physics USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent")); RootComponent = SphereComponent; SphereComponent->InitSphereRadius(40.0f); SphereComponent->SetCollisionProfileName(TEXT("Pawn")); // Creating and correctly Positioning the Mesh component so that it fits the sphere collision UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation")); SphereVisual->AttachTo(RootComponent); static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere")); if (SphereVisualAsset.Succeeded()) { SphereVisual->SetStaticMesh(SphereVisualAsset.Object); SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f,-40.0f)); SphereVisual->SetWorldScale3D(FVector(0.8f)); } // Particle system Creation, Positioning (Offset) OurParticleSystem = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MovementParticles")); OurParticleSystem->AttachTo(SphereVisual); OurParticleSystem->bAutoActivate = false; OurParticleSystem->SetRelativeLocation(FVector(-20.0f,0.0f,0.0f)); static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticleAsset(TEXT("/Game/StarterContent/Particles/P_Fire.P_Fire")); if (ParticleAsset.Succeeded()) { OurParticleSystem->SetTemplate(ParticleAsset.Object); } // SpringArm creation for a smooth and fast Camera Experience ( We could have just avoided this springArm ) but for the sake of smoothness USpringArmComponent* SpringArm = CreateAbstractDefaultSubobject<USpringArmComponent>(TEXT("CameraAttachmentArm")); SpringArm->AttachTo(RootComponent); SpringArm->RelativeRotation = FRotator(-45.0f,0.0f,0.0f); SpringArm->TargetArmLength = 400.0f; SpringArm->bEnableCameraLag = true; SpringArm->CameraLagSpeed = 3.0f; // Easy to create the Camera component and attach it to the built in Socket at the end of springArm UCameraComponent* ActualCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("ActualCamera")); ActualCamera->AttachTo(SpringArm, USpringArmComponent::SocketName); // Take control of the default player AutoPossessPlayer = EAutoReceiveInput::Player0; // creating an instance of our movement component, and telling it to update the root. OurMovementComponent = CreateDefaultSubobject<UCollidingPawnMovementComponent>(TEXT("CustomMovementComponent")); OurMovementComponent->UpdatedComponent = RootComponent; }
// Sets default values APawnCharacter::APawnCharacter() { // Stats moveSpeed = 300.0f; dodgeSpeed = 800.0f; // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; // Our root component will be a sphere that reacts to physics USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent")); RootComponent = SphereComponent; SphereComponent->InitSphereRadius(40.0f); SphereComponent->SetCollisionProfileName(TEXT("Pawn")); // Create and position a mesh component so we can see where our sphere is UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation")); SphereVisual->AttachTo(RootComponent); static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere")); if (SphereVisualAsset.Succeeded()) { SphereVisual->SetStaticMesh(SphereVisualAsset.Object); SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f)); SphereVisual->SetWorldScale3D(FVector(0.8f)); } // Use a spring arm to give the camera smooth, natural-feeling motion. USpringArmComponent* SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraAttachmentArm")); SpringArm->AttachTo(RootComponent); SpringArm->RelativeRotation = FRotator(-75.f, 0.f, 0.f); SpringArm->TargetArmLength = 800.0f; SpringArm->bEnableCameraLag = true; SpringArm->CameraLagSpeed = 5.0f; // Create a camera and attach to our spring arm UCameraComponent* Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("ActualCamera")); Camera->AttachTo(SpringArm, USpringArmComponent::SocketName); // Take control of the default player AutoPossessPlayer = EAutoReceiveInput::Player0; // Create an instance of our movement component, and tell it to update the root. OurMovementComponent = CreateDefaultSubobject<UPawnCharacterMovementComponent>(TEXT("CustomMovementComponent")); OurMovementComponent->UpdatedComponent = RootComponent; OurMovementComponent->setMoveSpeed(moveSpeed); }
void SStaticMeshEditorViewport::UpdatePreviewMesh(UStaticMesh* InStaticMesh) { { const int32 SocketedComponentCount = SocketPreviewMeshComponents.Num(); for(int32 i = 0; i < SocketedComponentCount; ++i) { UStaticMeshComponent* SocketPreviewMeshComponent = SocketPreviewMeshComponents[i]; if( SocketPreviewMeshComponent ) { PreviewScene.RemoveComponent(SocketPreviewMeshComponent); } } SocketPreviewMeshComponents.Empty(); } if (PreviewMeshComponent) { PreviewScene.RemoveComponent(PreviewMeshComponent); PreviewMeshComponent = NULL; } PreviewMeshComponent = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass()); PreviewMeshComponent->SetStaticMesh(InStaticMesh); PreviewScene.AddComponent(PreviewMeshComponent,FTransform::Identity); const int32 SocketCount = InStaticMesh->Sockets.Num(); SocketPreviewMeshComponents.Reserve(SocketCount); for(int32 i = 0; i < SocketCount; ++i) { UStaticMeshSocket* Socket = InStaticMesh->Sockets[i]; UStaticMeshComponent* SocketPreviewMeshComponent = NULL; if( Socket && Socket->PreviewStaticMesh ) { SocketPreviewMeshComponent = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass()); SocketPreviewMeshComponent->SetStaticMesh(Socket->PreviewStaticMesh); SocketPreviewMeshComponent->SnapTo(PreviewMeshComponent, Socket->SocketName); SocketPreviewMeshComponents.Add(SocketPreviewMeshComponent); PreviewScene.AddComponent(SocketPreviewMeshComponent, FTransform::Identity); } } EditorViewportClient->SetPreviewMesh(InStaticMesh, PreviewMeshComponent); }
// Sets default values APawnWithCamera::APawnWithCamera() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; // Our root component will be a sphere that reacts to physics USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent")); RootComponent = SphereComponent; SphereComponent->InitSphereRadius(40.0f); SphereComponent->SetCollisionProfileName(TEXT("Pawn")); // Create and position a mesh component so we can see where our sphere is UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation")); SphereVisual->AttachTo(RootComponent); static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere")); if (SphereVisualAsset.Succeeded()) { SphereVisual->SetStaticMesh(SphereVisualAsset.Object); SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f)); SphereVisual->SetWorldScale3D(FVector(0.8f)); } //Create our camera sprinf OurCameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm")); OurCameraSpringArm->AttachTo(RootComponent); OurCameraSpringArm->SetRelativeLocationAndRotation(FVector(4.0f, 0.0f, 30.0f), FRotator(-60.0f, 0.0f, 0.0f)); OurCameraSpringArm->TargetArmLength = 300.f; OurCameraSpringArm->bEnableCameraLag = true; OurCameraSpringArm->CameraLagSpeed = 3.0f; OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera")); OurCamera->AttachTo(OurCameraSpringArm, USpringArmComponent::SocketName); OurMovementComponent = CreateDefaultSubobject<UCollidingPawnMovementComponent>(TEXT("CustomMovementComponent")); OurMovementComponent->UpdatedComponent = RootComponent; //Take control of the default Player AutoPossessPlayer = EAutoReceiveInput::Player0; speenIncrease = 2.0f; speed = 100.f; }
void SStaticMeshEditorViewport::UpdatePreviewSocketMeshes() { UStaticMesh* const PreviewStaticMesh = PreviewMeshComponent ? PreviewMeshComponent->StaticMesh : NULL; if( PreviewStaticMesh ) { const int32 SocketedComponentCount = SocketPreviewMeshComponents.Num(); const int32 SocketCount = PreviewStaticMesh->Sockets.Num(); const int32 IterationCount = FMath::Max(SocketedComponentCount, SocketCount); for(int32 i = 0; i < IterationCount; ++i) { if(i >= SocketCount) { // Handle removing an old component UStaticMeshComponent* SocketPreviewMeshComponent = SocketPreviewMeshComponents[i]; PreviewScene.RemoveComponent(SocketPreviewMeshComponent); SocketPreviewMeshComponents.RemoveAt(i, SocketedComponentCount - i); break; } else if(UStaticMeshSocket* Socket = PreviewStaticMesh->Sockets[i]) { UStaticMeshComponent* SocketPreviewMeshComponent = NULL; // Handle adding a new component if(i >= SocketedComponentCount) { SocketPreviewMeshComponent = ConstructObject<UStaticMeshComponent>(UStaticMeshComponent::StaticClass()); PreviewScene.AddComponent(SocketPreviewMeshComponent, FTransform::Identity); SocketPreviewMeshComponents.Add(SocketPreviewMeshComponent); } else { SocketPreviewMeshComponent = SocketPreviewMeshComponents[i]; } SocketPreviewMeshComponent->SetStaticMesh(Socket->PreviewStaticMesh); SocketPreviewMeshComponent->SnapTo(PreviewMeshComponent, Socket->SocketName); } } } }
// 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); }
bool SMaterialEditorViewport::SetPreviewAsset(UObject* InAsset) { if (!MaterialEditorPtr.Pin()->ApproveSetPreviewAsset(InAsset)) { return false; } // Unregister the current component if (PreviewMeshComponent != nullptr) { PreviewScene.RemoveComponent(PreviewMeshComponent); PreviewMeshComponent = nullptr; } FTransform Transform = FTransform::Identity; if (UStaticMesh* StaticMesh = Cast<UStaticMesh>(InAsset)) { // Special case handling for static meshes, to use more accurate bounds via a subclass UStaticMeshComponent* NewSMComponent = NewObject<UMaterialEditorMeshComponent>(GetTransientPackage(), NAME_None, RF_Transient); NewSMComponent->SetStaticMesh(StaticMesh); PreviewMeshComponent = NewSMComponent; // Update the toolbar state implicitly through PreviewPrimType. if (StaticMesh == GUnrealEd->GetThumbnailManager()->EditorCylinder) { PreviewPrimType = TPT_Cylinder; } else if (StaticMesh == GUnrealEd->GetThumbnailManager()->EditorCube) { PreviewPrimType = TPT_Cube; } else if (StaticMesh == GUnrealEd->GetThumbnailManager()->EditorSphere) { PreviewPrimType = TPT_Sphere; } else if (StaticMesh == GUnrealEd->GetThumbnailManager()->EditorPlane) { // Need to rotate the plane so that it faces the camera Transform.SetRotation(FQuat(FRotator(0, 90, 0))); PreviewPrimType = TPT_Plane; } else { PreviewPrimType = TPT_None; } } else if (InAsset != nullptr) { // Fall back to the component asset broker if (TSubclassOf<UActorComponent> ComponentClass = FComponentAssetBrokerage::GetPrimaryComponentForAsset(InAsset->GetClass())) { if (ComponentClass->IsChildOf(UMeshComponent::StaticClass())) { PreviewMeshComponent = NewObject<UMeshComponent>(GetTransientPackage(), ComponentClass, NAME_None, RF_Transient); FComponentAssetBrokerage::AssignAssetToComponent(PreviewMeshComponent, InAsset); PreviewPrimType = TPT_None; } } } // Add the new component to the scene if (PreviewMeshComponent != nullptr) { PreviewScene.AddComponent(PreviewMeshComponent, Transform); } // Make sure the preview material is applied to the component SetPreviewMaterial(PreviewMaterial); return (PreviewMeshComponent != nullptr); }
// Sets default values AMyDrone::AMyDrone() { // 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; // Our root component will be a sphere that reacts to physics SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent")); RootComponent = SphereComponent; SphereComponent->InitSphereRadius(20.0f); SphereComponent->BodyInstance.SetCollisionEnabled(ECollisionEnabled::QueryOnly); SphereComponent->BodyInstance.SetResponseToAllChannels(ECR_Overlap); OnActorBeginOverlap.AddDynamic(this, &AMyDrone::OnOverlapBegin); // Create and position a mesh component to fuselage UStaticMeshComponent* fuselageMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation")); fuselageMesh->AttachTo(RootComponent); static ConstructorHelpers::FObjectFinder<UStaticMesh> FuselageVisualAsset(TEXT("/Game/unreal_fuselage.unreal_fuselage")); if (FuselageVisualAsset.Succeeded()) { fuselageMesh->SetStaticMesh(FuselageVisualAsset.Object); fuselageMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f)); // no translation for now fuselageMesh->SetWorldScale3D(FVector(1.0f)); // no scaling for now } // find elevon in assets library static ConstructorHelpers::FObjectFinder<UStaticMesh> ElevonVisualAsset(TEXT("/Game/elevon.elevon")); // Create and position a mesh component to elevon 1 elevon1Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Elevon1Mesh")); elevon1Mesh->AttachTo(RootComponent); if (ElevonVisualAsset.Succeeded()) { elevon1Mesh->SetStaticMesh(ElevonVisualAsset.Object); elevon1Mesh->SetRelativeLocation(FVector(-12.0f, 12.0f, 0.0f)); // no translation for now elevon1Mesh->SetWorldScale3D(FVector(1.0f)); // no scaling for now } // Create and position a mesh component to elevon 2 elevon2Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Elevon2Mesh")); elevon2Mesh->AttachTo(RootComponent); if (ElevonVisualAsset.Succeeded()) { elevon2Mesh->SetStaticMesh(ElevonVisualAsset.Object); elevon2Mesh->SetRelativeLocation(FVector(-12.0f, -12.0f, 0.0f)); // no translation for now elevon2Mesh->SetWorldScale3D(FVector(1.0f)); // no scaling for now } // Create a particle system that we can activate or deactivate DroneParticleSystem = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("MovementParticles")); DroneParticleSystem->AttachTo(fuselageMesh); DroneParticleSystem->bAutoActivate = false; DroneParticleSystem->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f)); static ConstructorHelpers::FObjectFinder<UParticleSystem> ParticleAsset(TEXT("/Game/StarterContent/Particles/P_Fire.P_Fire")); if (ParticleAsset.Succeeded()) { DroneParticleSystem->SetTemplate(ParticleAsset.Object); } // inyit cvs table handlers UCurveTable* expTable; static ConstructorHelpers::FObjectFinder<UCurveTable> expTable_BP(TEXT("CurveTable'/Game/Data/testtable.testtable'")); expTable = expTable_BP.Object; // not sure what this is, but it seems necessary static const FString ContextString(TEXT("GENERAL")); // here we link curves to experimental position CSV data curveX = expTable->FindCurve(*FString::Printf(TEXT("X")), ContextString); curveY = expTable->FindCurve(*FString::Printf(TEXT("Y")), ContextString); curveZ = expTable->FindCurve(*FString::Printf(TEXT("Z")), ContextString); // here we link curves to experimental quaternion CSV data curveQ0 = expTable->FindCurve(*FString::Printf(TEXT("Q0")), ContextString); curveQ1 = expTable->FindCurve(*FString::Printf(TEXT("Q1")), ContextString); curveQ2 = expTable->FindCurve(*FString::Printf(TEXT("Q2")), ContextString); curveQ3 = expTable->FindCurve(*FString::Printf(TEXT("Q3")), ContextString); // here we link curves to experimental elevon CSV data curveD1 = expTable->FindCurve(*FString::Printf(TEXT("D1")), ContextString); curveD2 = expTable->FindCurve(*FString::Printf(TEXT("D2")), ContextString); }