85 lines
2.6 KiB
Lua
85 lines
2.6 KiB
Lua
---@class BP_ItemCapture_C:AActor
|
|
---@field DirectionalLight UDirectionalLightComponent
|
|
---@field SceneCaptureComponent2D USceneCaptureComponent2D
|
|
---@field Camera UCameraComponent
|
|
---@field DisplayMesh UStaticMeshComponent
|
|
---@field DefaultSceneRoot USceneComponent
|
|
--Edit Below--
|
|
---@type BP_ItemCapture_C
|
|
local BP_ItemCapture = {};
|
|
|
|
BP_ItemCapture.DisplayMeshPath = nil;
|
|
BP_ItemCapture.ItemCaptureMaterial = nil;
|
|
BP_ItemCapture.ItemCaptureMaterialPath = "/Game/UGC/Materials/UGC_Material_ItemCapture.UGC_Material_ItemCapture";
|
|
|
|
function BP_ItemCapture:ReceiveBeginPlay()
|
|
self.SuperClass.ReceiveBeginPlay(self);
|
|
self.SceneCaptureComponent2D.ShowOnlyActors = { self };
|
|
end
|
|
|
|
--[[
|
|
function BP_ItemCapture:ReceiveTick(DeltaTime)
|
|
self.SuperClass.ReceiveTick(self, DeltaTime);
|
|
end
|
|
--]]
|
|
|
|
--[[
|
|
function BP_ItemCapture:ReceiveEndPlay()
|
|
self.SuperClass.ReceiveEndPlay(self);
|
|
end
|
|
--]]
|
|
|
|
--[[
|
|
function BP_ItemCapture:GetReplicatedProperties()
|
|
return
|
|
end
|
|
--]]
|
|
|
|
--[[
|
|
function BP_ItemCapture:GetAvailableServerRPCs()
|
|
return
|
|
end
|
|
--]]
|
|
|
|
function BP_ItemCapture:ReceiveDestroyed()
|
|
self.ItemCaptureMaterial = nil;
|
|
self.DisplayMeshPath = nil;
|
|
self.ItemCaptureMaterialPath = nil;
|
|
end
|
|
|
|
function BP_ItemCapture:CaptureSceneByMeshPath(Path)
|
|
local RenderTarget = KismetRenderingLibrary.CreateRenderTarget2D(self, 256, 256, ETextureRenderTargetFormat.RTF_RGBA16f);
|
|
if RenderTarget == nil then return; end
|
|
self.SceneCaptureComponent2D.TextureTarget = RenderTarget;
|
|
self:SetDisplayMesh(Path);
|
|
self.SceneCaptureComponent2D:CaptureScene();
|
|
self.ItemCaptureMaterial = LoadObject(self.ItemCaptureMaterialPath);
|
|
if self.ItemCaptureMaterial == nil then return end
|
|
local DisplayMaterial = KismetMaterialLibrary.CreateDynamicMaterialInstance(self, self.ItemCaptureMaterial);
|
|
if DisplayMaterial == nil then return end
|
|
DisplayMaterial:SetTextureParameterValue("MainTexture", RenderTarget);
|
|
return DisplayMaterial;
|
|
end
|
|
|
|
function BP_ItemCapture:SetDisplayMesh(Path)
|
|
local Mesh = LoadObject(Path);
|
|
if Mesh == nil then return end
|
|
--获取拍摄模型的大小,根据大小调整缩放和位置
|
|
self.DisplayMeshPath = Path;
|
|
local Bounds = Mesh:GetBounds();
|
|
|
|
if self.DisplayMesh and Bounds.BoxExtent.Z > 0 then
|
|
-- 调整缩放
|
|
local Scale = 75 / Bounds.BoxExtent.Z;
|
|
self.DisplayMesh:SetRelativeScale3D(Vector.New(Scale, Scale, Scale));
|
|
|
|
-- 调整位置
|
|
local OffsetZ = -Bounds.Origin.Z * Scale;
|
|
local Location = Vector.New(0, 0, OffsetZ);
|
|
self.DisplayMesh:K2_SetRelativeLocation(Location, false, {}, true);
|
|
|
|
self.DisplayMesh:SetStaticMesh(Mesh);
|
|
end
|
|
end
|
|
|
|
return BP_ItemCapture; |