Good evening,
I have problem with getting vertices from plane.
I’m trying to make buoyancy and make ship float but when I try to get vertex height then I have 0 always.
Can someone help me do it? Or even point me how to do it correctly.
Here is code I have so far
// Fill out your copyright notice in the Description page of Project Settings.
#include "HeightMapReader.h"
#include <Runtime/Engine/Classes/Engine/Engine.h>
#include <Runtime/Engine/Classes/Engine/StaticMeshActor.h>
#include <Runtime/Engine/Classes/Components/StaticMeshComponent.h>
#include <Runtime/Engine/Classes/Engine/StaticMesh.h>
/* Update ALL verticles (that will be slow, depending on verts ammount...) Returns true on succes or null on fail */
bool AHeightMapReader::UpdateBuffer(AStaticMeshActor * AStaticMesh) {
// Clear First
StaticMeshActor = nullptr;
StaticMeshComponent = nullptr;
VertexBuffer = NULL;
VertexCount = NULL;
SideVertexCount = NULL;
// Save & Get Component
StaticMeshActor = AStaticMesh;
StaticMeshComponent = AStaticMesh->GetStaticMeshComponent();
// Check
if (!IsValidLowLevel()) return NULL;
if (!StaticMeshComponent) return NULL;
if (!StaticMeshComponent->StaticMesh) return NULL;
if (!StaticMeshComponent->StaticMesh->RenderData) return NULL;
if (StaticMeshComponent->StaticMesh->RenderData->LODResources.Num() > 0)
{
VertexBuffer = &StaticMeshComponent->StaticMesh->RenderData->LODResources[0].VertexBuffers.PositionVertexBuffer;
if (VertexBuffer)
{
VertexCount = VertexBuffer->GetNumVertices(); // Whole static mesh vertices count
SideVertexCount = sqrt(VertexCount); // Side of the static mesh rectangle vertex count
}
else
UE_LOG(LogTemp, Error, TEXT("VertexBuffer is NULL or something!"));
}
else
UE_LOG(LogTemp, Error, TEXT("No vertices found (or failed access)!?"));
// Return NULL on Error
return NULL;
}
/* Get's postion from point depending on Array. Requires UpdateBuffer working...! */
FVector AHeightMapReader::GetPoinFromVertexesArray(float x, float y) {
int X = x;
int Y = y;
if (X > SideVertexCount) return { NULL, NULL, NULL };
if (Y > SideVertexCount) return { NULL, NULL, NULL };
VertexLocation = { 0, 0, 0 };
int Index = Y * SideVertexCount - SideVertexCount + X; // May be incorrect
// Check if Index is not bigger then max vertives ammount so it don't crash but just return NULL as error
if (Index > VertexCount)
return { NULL, NULL, NULL };
if (Index <= 0)
return { NULL, NULL, NULL };
UE_LOG(LogTemp, Warning, TEXT("Vertices Count: %d"), VertexCount);
UE_LOG(LogTemp, Warning, TEXT("Number of Current vertex: %d"), Index);
UE_LOG(LogTemp, Warning, TEXT("X: %d"), VertexLocation.X);
UE_LOG(LogTemp, Warning, TEXT("Y: %d"), VertexLocation.Y);
UE_LOG(LogTemp, Warning, TEXT("Z: %d"), VertexLocation.Z);
return { NULL, NULL, NULL };
}
Thanks for any info :)!