This action will force synchronization from Leon/ComputerGraphics, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
// Fill out your copyright notice in the Description page of Project Settings.#include "DynamicTextureComponent.h"#include "Components/StaticMeshComponent.h"// Sets default values for this component's propertiesUDynamicTextureComponent::UDynamicTextureComponent(){// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features// off to improve performance if you don't need them.PrimaryComponentTick.bCanEverTick = true;Width = 1920;Height = 1080;DataLocked = nullptr;// ...}// Called when the game startsvoid UDynamicTextureComponent::BeginPlay(){Super::BeginPlay();if (Width > 0 && Height > 0){Texture = UTexture2D::CreateTransient(Width, Height);FTexture2DMipMap& Mip = Texture->PlatformData->Mips[0];FColor* Data = (FColor*)Mip.BulkData.Lock(LOCK_READ_WRITE);FMemory::Memzero(Data, Width * Height * sizeof(FColor));Mip.BulkData.Unlock();bDirty = true;Mesh = Cast<UStaticMeshComponent>(GetOwner()->GetComponentByClass(UStaticMeshComponent::StaticClass()));if (ensure(Mesh)){Mesh->CreateDynamicMaterialInstance(0)->SetTextureParameterValue(TEXT("Tex"), Texture);Mesh->SetRelativeScale3D(FVector(Width, Height, 1));}}}// Called every framevoid UDynamicTextureComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction){Super::TickComponent(DeltaTime, TickType, ThisTickFunction);if (bDirty){Texture->UpdateResource();bDirty = false;}}// https://www.ue4community.wiki/legacy/dynamic-textures-a5iczbuybool UDynamicTextureComponent::SetPixel(int X, int Y, FColor Color){if (Texture && ensure(X < Width && Y < Height)){FTexture2DMipMap& Mip = Texture->PlatformData->Mips[0];FColor* Data = (FColor*)Mip.BulkData.Lock(LOCK_READ_WRITE);Data[Y * Texture->GetSizeX() + X] = Color;Mip.BulkData.Unlock();bDirty = true;return true;}return false;}bool UDynamicTextureComponent::SetPixel(int X, int Y, FLinearColor Color){return SetPixel(X, Y, Color.ToFColor(true));}bool UDynamicTextureComponent::SetPixelWithoutLock(int X, int Y, FColor Color){if (Texture && ensure(X < Width && Y < Height) && DataLocked){DataLocked[Y * Texture->GetSizeX() + X] = Color;return true;}return false;}bool UDynamicTextureComponent::SetPixelWithoutLock(int X, int Y, FLinearColor Color){return SetPixelWithoutLock(X, Y, Color.ToFColor(true));}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。