Skip to content

Commit

Permalink
fixed debug display errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJerez committed Oct 23, 2024
1 parent a29a762 commit 92ed2b5
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ ndMatrix ndShapeCompound::CalculateInertiaAndCenterOfMass(const ndMatrix& alignM

ndFloat32 invVolume = ndFloat32(1.0f) / volume;
centerOfMass = centerOfMass.Scale(invVolume);
centerOfMass.m_w = ndFloat32(1.0f);
inertiaII = inertiaII.Scale(invVolume);
crossInertia = crossInertia.Scale(invVolume);
ndMatrix inertia(ndGetIdentityMatrix());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,14 @@ ndMatrix ndShapeConvex::CalculateInertiaAndCenterOfMass(const ndMatrix& alignMat
scaledMatrix = alignMatrix * scaledMatrix;

ndFloat32 volume = CalculateMassProperties(scaledMatrix, inertiaII, crossInertia, centerOfMass);
if (volume < D_MAX_MIN_VOLUME) {
if (volume < D_MAX_MIN_VOLUME)
{
volume = D_MAX_MIN_VOLUME;
}

ndFloat32 invVolume = ndFloat32(1.0f) / volume;
centerOfMass = centerOfMass.Scale(invVolume);
centerOfMass.m_w = ndFloat32(1.0f);
inertiaII = inertiaII.Scale(invVolume);
crossInertia = crossInertia.Scale(invVolume);
ndMatrix inertia(ndGetIdentityMatrix());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ void UNewtonCollision::SetWireFrameColor(const FLinearColor& color)

ndShapeInstance* UNewtonCollision::CreateInstanceShape() const
{
// implicit shape does use unreal scale, for rendering
ndShapeInstance* const instance = new ndShapeInstance(m_shape);
return instance;
}
Expand All @@ -241,6 +242,7 @@ ndShapeInstance* UNewtonCollision::CreateBodyInstanceShape(const ndMatrix& bodyM
{
ndShapeInstance* const instance = CreateInstanceShape();

// implicit set the scale and local transform to the instance
const FVector uScale(GetComponentTransform().GetScale3D());
const ndVector scale(ndFloat32(uScale.X), ndFloat32(uScale.Y), ndFloat32(uScale.Z), ndFloat32(1.0f));

Expand All @@ -252,6 +254,21 @@ ndShapeInstance* UNewtonCollision::CreateBodyInstanceShape(const ndMatrix& bodyM
return instance;
}

ndVector UNewtonCollision::GetVolumePosition(const ndMatrix& bodyMatrix) const
{
ndVector posit(0.0f);
ndShapeInstance* const instance = CreateBodyInstanceShape(bodyMatrix);
if (instance)
{
const ndMatrix inertia(instance->CalculateInertia());
posit = inertia.m_posit;

posit.m_w = instance->GetVolume();
delete instance;
}
return posit;
}

void UNewtonCollision::ApplyPropertyChanges()
{
m_propertyChanged = false;
Expand Down Expand Up @@ -309,23 +326,4 @@ void UNewtonCollision::ApplyPropertyChanges()
MarkRenderDynamicDataDirty();
NotifyMeshUpdated();
}
}

ndVector UNewtonCollision::GetVolumePosition() const
{
ndVector posit(0.0f);
ndShapeInstance* const instance = CreateInstanceShape();
if (instance)
{
//const FVector uScale(GetComponentTransform().GetScale3D());
//const ndVector scale(ndFloat32(uScale.X), ndFloat32(uScale.Y), ndFloat32(uScale.Z), ndFloat32(0.0f));
instance->SetScale(ndVector(1.0f));

const ndMatrix inertia(instance->CalculateInertia());
posit = inertia.m_posit;

posit.m_w = instance->GetVolume();
delete instance;
}
return posit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class UNewtonCollision : public UDynamicMeshComponent
public:
// Sets default values for this component's properties
UNewtonCollision();
virtual ndVector GetVolumePosition() const;
virtual void SetWireFrameColor(const FLinearColor& color);
virtual ndVector GetVolumePosition(const ndMatrix& bodyMatrix) const;
virtual void InitStaticMeshCompoment(const USceneComponent* const meshComponent);

protected:
Expand All @@ -44,7 +44,6 @@ class UNewtonCollision : public UDynamicMeshComponent
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
virtual void BuildNewtonShape();
virtual void ApplyPropertyChanges();
//virtual UStaticMesh* FindStaticMesh() const;

virtual ndShape* CreateShape() const;
virtual long long CalculateHash() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UNewtonCollisionConvexApproximate::ConvexVhacdGenerator : public ndConvexA
,m_progressBar(nullptr)
,m_acc(0.0f)
{
#ifdef SHOW_VHACD_PROGRESS_BAR
#ifdef SHOW_VHACD_PROGRESS_BAR
// for some reason the progress bar invalidate some UClasses
// I need to report this some day to unreal.
// for now just do not report progress.
Expand Down Expand Up @@ -63,6 +63,7 @@ UNewtonCollisionConvexApproximate::UNewtonCollisionConvexApproximate()
Generate = false;
MaxConvexes = 16;
Tolerance = 0.0f;
NumberOfConvex = 0;
HighResolution = false;
MaxVertexPerConvex = 32;
}
Expand Down Expand Up @@ -328,14 +329,31 @@ ndShapeInstance* UNewtonCollisionConvexApproximate::CreateInstanceShape() const
return instance;
}

ndVector UNewtonCollisionConvexApproximate::GetVolumePosition(const ndMatrix& bodyMatrix) const
{
ndVector posit(0.0f);
ndShapeInstance* const instance = CreateInstanceShape();
if (instance)
{
instance->SetScale(ndVector(1.0f));

const ndMatrix inertia(instance->CalculateInertia());
posit = inertia.m_posit;

posit.m_w = instance->GetVolume();
delete instance;
}
return posit;
}

void UNewtonCollisionConvexApproximate::ApplyPropertyChanges()
{
FnewtonModule* const plugin = FnewtonModule::GetPlugin();
check(plugin);
long long meshHash = CalculateStaticMeshHash();
if ((m_meshHash != meshHash) || Generate && !m_generateFlipFlop)
{
TSharedPtr<ndConvexHullSet> convexHullSet (plugin->FindConvexHull(meshHash));
TSharedPtr<ndConvexHullSet> convexHullSet(plugin->FindConvexHull(meshHash));
if (convexHullSet == nullptr)
{
convexHullSet = TSharedPtr<ndConvexHullSet>(CreateConvexApproximationShapes());
Expand All @@ -347,6 +365,7 @@ void UNewtonCollisionConvexApproximate::ApplyPropertyChanges()
m_convexHullSet = plugin->FindConvexHull(meshHash);
m_debugVisualIsDirty = true;
}
NumberOfConvex = m_convexHullSet ? m_convexHullSet->Num() : 0;
MarkRenderDynamicDataDirty();
NotifyMeshUpdated();

Expand All @@ -355,4 +374,4 @@ void UNewtonCollisionConvexApproximate::ApplyPropertyChanges()
Generate = false;
BuildNewtonShape();
Super::ApplyPropertyChanges();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,37 @@ class UNewtonCollisionConvexApproximate : public UNewtonCollision
virtual void InitStaticMeshCompoment(const USceneComponent* const meshComponent) override;

protected:
virtual void ApplyPropertyChanges();
virtual ndShape* CreateShape() const;
virtual long long CalculateHash() const;
virtual ndShapeInstance* CreateInstanceShape() const;
virtual ndShapeInstance* CreateBodyInstanceShape(const ndMatrix& bodyMatrix) const;

virtual void ApplyPropertyChanges() override;
virtual ndShape* CreateShape() const override;
virtual long long CalculateHash() const override;
virtual ndShapeInstance* CreateInstanceShape() const override;
virtual ndVector GetVolumePosition(const ndMatrix& bodyMatrix) const override;
virtual ndShapeInstance* CreateBodyInstanceShape(const ndMatrix& bodyMatrix) const override;

long long CalculateStaticMeshHash() const;
ndConvexHullSet* CreateConvexApproximationShapes() const;
const FStaticMeshLODResources* GetRenderLOD() const;
ndConvexHullSet* CreateConvexApproximationShapes() const;

virtual void Serialize(FArchive& ar) override;
void SerializeLoadRevision_firstVersion(FArchive& ar);

UPROPERTY(EditAnywhere, Category = Newton)
bool Generate = false;
bool Generate;

UPROPERTY(EditAnywhere, Category = Newton)
bool HighResolution = false;
bool HighResolution;

UPROPERTY(VisibleAnywhere, Category = Newton)
int NumberOfConvex;

UPROPERTY(EditAnywhere, Category = Newton, meta = (ClampMin = 1, ClampMax = 128))
int MaxVertexPerConvex = 32;
int MaxVertexPerConvex;

UPROPERTY(EditAnywhere, Category = Newton, meta = (ClampMin = 1, ClampMax = 128))
int MaxConvexes = 16;
int MaxConvexes;

UPROPERTY(EditAnywhere, Category = Newton, meta = (ClampMin = 0.0, ClampMax = 1.0))
float Tolerance = 0.0f;
float Tolerance;

long long m_meshHash;
TSharedPtr<ndConvexHullSet> m_convexHullSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ void UNewtonJoint::ClearDebug()
m_propertyChanged = true;
}

void UNewtonJoint::ActivateDebug()
{
ShowDebug = true;
m_propertyChanged = true;
}

void UNewtonJoint::CreateJoint(ANewtonWorldActor* const)
{
m_transfrom = GetComponentTransform();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class UNewtonJoint : public USceneComponent
UNewtonJoint();

void ClearDebug();
void ActivateDebug();

// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

Expand Down
Loading

0 comments on commit 92ed2b5

Please sign in to comment.