diff --git a/newton-4.00/applications/ndSandbox/main.cpp b/newton-4.00/applications/ndSandbox/main.cpp index 9f84176e9..8da176a86 100644 --- a/newton-4.00/applications/ndSandbox/main.cpp +++ b/newton-4.00/applications/ndSandbox/main.cpp @@ -45,6 +45,15 @@ int main(int, char**) //index.SetCount(xxxx.GetCount()); //ndInt32 vertexCount = ndVertexListToIndexList(&xxxx[0].m_x, sizeof(ndVector), 3, ndInt32(xxxx.GetCount()), &index[0], ndFloat32(1.0e-6f)); + //ndVector points[5]; + //points[0] = ndVector(-1.0f, -1.0f, 0.0f, 0.0f); + //points[1] = ndVector( 1.0f, -1.0f, 0.0f, 0.0f); + //points[2] = ndVector(1.2f, 0.6f, 0.0f, 0.0f); + //points[3] = ndVector(0.9f, 0.9f, 0.0f, 0.0f); + //points[4] = ndVector(-1.0f, 1.0f, 0.0f, 0.0f); + //ndArray triangles; + //ndTriangulatePolygon(points, 5, triangles); + ndDemoEntityManager demos; demos.Run(); return 0; diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Binaries/ThirdParty/newtonLibrary/Win64/ExampleLibrary.dll b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Binaries/ThirdParty/newtonLibrary/Win64/ExampleLibrary.dll index f84c880ed..9430d8164 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Binaries/ThirdParty/newtonLibrary/Win64/ExampleLibrary.dll and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Binaries/ThirdParty/newtonLibrary/Win64/ExampleLibrary.dll differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary.vcxproj b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary.vcxproj index 0c3296f1b..31d3bafe1 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary.vcxproj +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary.vcxproj @@ -109,6 +109,7 @@ + @@ -257,6 +258,7 @@ + diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary.vcxproj.filters b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary.vcxproj.filters index 32512f4c8..bee1baa83 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary.vcxproj.filters +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary.vcxproj.filters @@ -420,6 +420,9 @@ thirdParty + + dCore + @@ -869,6 +872,9 @@ thirdParty + + dCore + diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary/x64/Release/vc143.pdb b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary/x64/Release/vc143.pdb index aa419e986..6a780155b 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary/x64/Release/vc143.pdb and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/ExampleLibrary/x64/Release/vc143.pdb differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndCore.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndCore.h index ace27e49f..d00f1177e 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndCore.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndCore.h @@ -71,6 +71,7 @@ #include #include #include +#include #include #include #include diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.cpp new file mode 100644 index 000000000..0e2c10b93 --- /dev/null +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.cpp @@ -0,0 +1,73 @@ +/* Copyright (c) <2003-2022> +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* +* 3. This notice may not be removed or altered from any source distribution. +*/ + +#include "ndCoreStdafx.h" +#include "ndPolyhedra.h" +#include "ndTriangulatePolygon.h" + +void ndTriangulatePolygon(ndVector* const points, ndInt32 count, ndArray& triangles) +{ + triangles.SetCount(0); + if (count < 3) + { + return; + } + if (count == 3) + { + triangles.PushBack(0); + triangles.PushBack(1); + triangles.PushBack(2); + return; + } + + ndInt32 index[256]; + ndFixSizeArray vertexBuffer; + for (ndInt32 i = 0; i < count; ++i) + { + index[i] = i; + vertexBuffer.PushBack(points[i]); + } + + ndPolyhedra polyhedra; + polyhedra.BeginFace(); + polyhedra.AddFace(count, index); + polyhedra.EndFace(); + + ndPolyhedra leftOversOut; + polyhedra.Triangulate(&vertexBuffer[0].m_x, sizeof(ndBigVector), &leftOversOut); + + ndInt32 mark = polyhedra.IncLRU(); + ndPolyhedra::Iterator it(polyhedra); + for (it.Begin(); it; it++) + { + ndEdge* const edge = &it.GetNode()->GetInfo(); + if (edge->m_mark != mark && (edge->m_incidentFace > 0)) + { + ndAssert(edge == edge->m_next->m_next->m_next); + edge->m_mark = mark; + edge->m_next->m_mark = mark; + edge->m_next->m_next->m_mark = mark; + triangles.PushBack(edge->m_incidentVertex); + triangles.PushBack(edge->m_next->m_incidentVertex); + triangles.PushBack(edge->m_next->m_next->m_incidentVertex); + } + } +} diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.h new file mode 100644 index 000000000..27f8e933e --- /dev/null +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/Public/dCore/ndTriangulatePolygon.h @@ -0,0 +1,31 @@ +/* Copyright (c) <2003-2022> +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* +* 3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __ND_TRIANGULATE_POLYGON_H__ +#define __ND_TRIANGULATE_POLYGON_H__ + +#include "ndCoreStdafx.h" +#include "ndArray.h" +#include "ndVector.h" + +D_CORE_API void ndTriangulatePolygon(ndVector* const vertexCloud2d, ndInt32 count, ndArray& triangles); + +#endif diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.dll b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.dll index f84c880ed..9430d8164 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.dll and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.dll differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.lib b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.lib index 2f3dac11d..3cc928150 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.lib and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.lib differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.pdb b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.pdb index 68966eca9..c052c121e 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.pdb and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/ExampleLibrary.pdb differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/hacd.lib b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/hacd.lib index 89f2d7c41..6f775c915 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/hacd.lib and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/hacd.lib differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/hacd.pdb b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/hacd.pdb index b720da04b..7067facbf 100644 Binary files a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/hacd.pdb and b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/ThirdParty/newtonLibrary/x64/Release/hacd.pdb differ diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollision.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollision.cpp index 27b546e0e..0bc9e94b7 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollision.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollision.cpp @@ -21,7 +21,6 @@ UNewtonCollision::UNewtonCollision() BestFit = false; CastShadow = 0; - m_savedMeshComponent = nullptr; bExplicitShowWireframe = true; m_visualMesh = TSharedPtr(nullptr); @@ -45,13 +44,34 @@ void UNewtonCollision::OnUnregister() m_shape = nullptr; } m_hash = 0; - m_savedMeshComponent = nullptr; m_visualMesh = TSharedPtr(nullptr); } -void UNewtonCollision::SetGeometryMesh(USceneComponent* const staticMesh) +//void UNewtonCollision::SetGeometryMesh(USceneComponent* const staticMesh) +//{ +// m_savedMeshComponent = staticMesh; +//} + +void UNewtonCollision::SetTransform(const USceneComponent* const meshComponent) { - m_savedMeshComponent = staticMesh; + const AActor* const owner = GetOwner(); + check(owner); + const FTransform bodyTransform(owner->GetRootComponent()->GetComponentToWorld()); + const FTransform globalTransform(meshComponent->GetComponentToWorld()); + const FTransform localTransform(globalTransform * bodyTransform.Inverse()); + + SetComponentToWorld(globalTransform); + + // for some reason, this does not work in the unreal editor + //SetRelativeTransform(localTransform); + SetRelativeScale3D_Direct(localTransform.GetScale3D()); + SetRelativeRotation_Direct(FRotator(localTransform.GetRotation())); + SetRelativeLocation_Direct(localTransform.GetLocation()); +} + +void UNewtonCollision::InitStaticMeshCompoment(const USceneComponent* const meshComponent) +{ + check(0); } void UNewtonCollision::PostLoad() @@ -184,11 +204,13 @@ void UNewtonCollision::ApplyPropertyChanges() m_points.PushBack(faceArray[i] * m_scale); } - for (ndInt32 i = 2; i < vertexCount; ++i) + ndArray triangles; + ndTriangulatePolygon(&m_points[0], vertexCount, triangles); + for (ndInt32 i = 0; i < ndInt32 (triangles.GetCount()); i+=3) { - m_index.PushBack(baseIndex); - m_index.PushBack(baseIndex + i - 0); - m_index.PushBack(baseIndex + i - 1); + m_index.PushBack(baseIndex + triangles[i + 0]); + m_index.PushBack(baseIndex + triangles[i + 1]); + m_index.PushBack(baseIndex + triangles[i + 2]); } } @@ -290,39 +312,22 @@ void UNewtonCollision::ApplyPropertyChanges() } } -UStaticMesh* UNewtonCollision::FindStaticMesh() const -{ - if (m_savedMeshComponent) - { - UStaticMeshComponent* const staticMesh = Cast(m_savedMeshComponent); - return staticMesh ? staticMesh->GetStaticMesh().Get() : (UStaticMesh*) nullptr; - } - - const UStaticMeshComponent* const mesh = Cast(GetAttachParent()); - if (mesh && mesh->GetStaticMesh().Get()) - { - return mesh->GetStaticMesh().Get(); - } - - return nullptr; -} - -void UNewtonCollision::SetGlobalTransform() -{ - UStaticMesh* const staticMesh = FindStaticMesh(); - if (staticMesh && m_savedMeshComponent) - { - //const ANewtonSceneActor* const owner = Cast(GetOwner()); - const AActor* const owner = GetOwner(); - check(owner); - const FTransform bodyTransform(owner->GetRootComponent()->GetComponentToWorld()); - const FTransform globalTransform(m_savedMeshComponent->GetComponentToWorld()); - const FTransform localTransform(globalTransform * bodyTransform.Inverse()); - - SetRelativeTransform(localTransform); - SetComponentToWorld(globalTransform); - } -} +//UStaticMesh* UNewtonCollision::FindStaticMesh() const +//{ +// if (m_savedMeshComponent) +// { +// UStaticMeshComponent* const staticMesh = Cast(m_savedMeshComponent); +// return staticMesh ? staticMesh->GetStaticMesh().Get() : (UStaticMesh*) nullptr; +// } +// +// const UStaticMeshComponent* const mesh = Cast(GetAttachParent()); +// if (mesh && mesh->GetStaticMesh().Get()) +// { +// return mesh->GetStaticMesh().Get(); +// } +// +// return nullptr; +//} ndVector UNewtonCollision::GetVolumePosition() const { diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollision.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollision.h index 5c50abcbb..672eaefcf 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollision.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollision.h @@ -25,11 +25,9 @@ class UNewtonCollision : public UDynamicMeshComponent public: // Sets default values for this component's properties UNewtonCollision(); - - virtual void SetGlobalTransform(); virtual ndVector GetVolumePosition() const; - void SetGeometryMesh(USceneComponent* const staticMesh); virtual void SetWireFrameColor(const FLinearColor& color); + virtual void InitStaticMeshCompoment(const USceneComponent* const meshComponent); protected: UPROPERTY(EditAnywhere, Category = Newton) @@ -43,20 +41,19 @@ class UNewtonCollision : public UDynamicMeshComponent virtual void BeginDestroy() override; virtual bool ShouldCreatePhysicsState() const override; virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override; - virtual void BuildNewtonShape(); virtual void ApplyPropertyChanges(); - virtual UStaticMesh* FindStaticMesh() const; + //virtual UStaticMesh* FindStaticMesh() const; virtual ndShape* CreateShape() const; virtual long long CalculateHash() const; virtual ndShapeInstance* CreateInstanceShape() const; virtual ndShapeInstance* CreateBodyInstanceShape(const ndMatrix& bodyMatrix) const; + void SetTransform(const USceneComponent* const meshComponent); //public: long long m_hash; ndShape* m_shape; - USceneComponent* m_savedMeshComponent; TSharedPtr m_visualMesh; UMaterial* m_transparentMaterial; bool m_propertyChanged; diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionBox.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionBox.cpp index 15af4e919..888a67cea 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionBox.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionBox.cpp @@ -20,6 +20,34 @@ ndShape* UNewtonCollisionBox::CreateShape() const return new ndShapeBox(SizeX * UNREAL_INV_UNIT_SYSTEM, SizeY * UNREAL_INV_UNIT_SYSTEM, SizeZ * UNREAL_INV_UNIT_SYSTEM); } +void UNewtonCollisionBox::InitStaticMeshCompoment(const USceneComponent* const meshComponent) +{ + const UStaticMeshComponent* const staticMeshComponent = Cast(meshComponent); + check(staticMeshComponent); + const UStaticMesh* const staticMesh = staticMeshComponent->GetStaticMesh().Get(); + const UBodySetup* const bodySetup = staticMesh->GetBodySetup(); + const FKAggregateGeom& aggGeom = bodySetup->AggGeom; + check(aggGeom.BoxElems.Num() == 1); + const FKBoxElem& box = aggGeom.BoxElems[0]; + + SetTransform(meshComponent); + const FTransform localTransformOffset(box.GetTransform()); + const FTransform globalTransform(localTransformOffset * GetComponentToWorld()); + SetComponentToWorld(globalTransform); + + const AActor* const owner = GetOwner(); + const FTransform bodyTransform(owner->GetRootComponent()->GetComponentToWorld()); + const FTransform localTransform(globalTransform * bodyTransform.Inverse()); + + SetRelativeScale3D_Direct(localTransform.GetScale3D()); + SetRelativeRotation_Direct(FRotator(localTransform.GetRotation())); + SetRelativeLocation_Direct(localTransform.GetLocation()); + + SizeX = box.X; + SizeY = box.Y; + SizeZ = box.Z; +} + long long UNewtonCollisionBox::CalculateHash() const { long long hash = ndCRC64(ndShapeBox::StaticClassName(), strlen(ndShapeBox::StaticClassName()), 0); diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionBox.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionBox.h index dcaf52b4a..72593d5e5 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionBox.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionBox.h @@ -20,6 +20,7 @@ class UNewtonCollisionBox : public UNewtonCollision public: // Sets default values for this component's properties UNewtonCollisionBox(); + virtual void InitStaticMeshCompoment(const USceneComponent* const meshComponent) override; protected: virtual void ApplyPropertyChanges(); diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionConvexHull.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionConvexHull.cpp index 71b4c8138..312d035bf 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionConvexHull.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionConvexHull.cpp @@ -66,55 +66,57 @@ ndShape* UNewtonCollisionConvexHull::CreateShape() const void UNewtonCollisionConvexHull::ApplyPropertyChanges() { - if (m_proceduralData.Num() == 0) - { - m_debugVisualIsDirty = true; - - const UStaticMesh* const staticMesh = FindStaticMesh(); - if (staticMesh) - { - const ANewtonSceneActor* const owner = Cast(GetOwner()); - if (owner && m_savedMeshComponent) - { - const FTransform bodyTransform(owner->GetRootComponent()->GetComponentToWorld()); - const FTransform meshTransform(m_savedMeshComponent->GetComponentToWorld()); - const FTransform transform(meshTransform * bodyTransform.Inverse()); - SetComponentToWorld(transform); - } - - const FStaticMeshRenderData* const renderData = staticMesh->GetRenderData(); - const FStaticMeshLODResourcesArray& renderResource = renderData->LODResources; - - const FVector uScale(GetComponentTransform().GetScale3D()); - const ndVector scale(ndFloat32(uScale.X), ndFloat32(uScale.Y), ndFloat32(uScale.Z), ndFloat32(0.0f)); - const ndVector bakedScale(scale.Scale(UNREAL_INV_UNIT_SYSTEM)); + check(0); + //if (m_proceduralData.Num() == 0) + //{ + // m_debugVisualIsDirty = true; + // + // const UStaticMesh* const staticMesh = FindStaticMesh(); + // if (staticMesh) + // { + // const ANewtonSceneActor* const owner = Cast(GetOwner()); + // if (owner && m_savedMeshComponent) + // { + // const FTransform bodyTransform(owner->GetRootComponent()->GetComponentToWorld()); + // const FTransform meshTransform(m_savedMeshComponent->GetComponentToWorld()); + // const FTransform transform(meshTransform * bodyTransform.Inverse()); + // SetComponentToWorld(transform); + // } + // + // const FStaticMeshRenderData* const renderData = staticMesh->GetRenderData(); + // const FStaticMeshLODResourcesArray& renderResource = renderData->LODResources; + // + // const FVector uScale(GetComponentTransform().GetScale3D()); + // const ndVector scale(ndFloat32(uScale.X), ndFloat32(uScale.Y), ndFloat32(uScale.Z), ndFloat32(0.0f)); + // const ndVector bakedScale(scale.Scale(UNREAL_INV_UNIT_SYSTEM)); + // + // const FStaticMeshLODResources& renderLOD = renderResource[0]; + // const FStaticMeshVertexBuffers& staticMeshVertexBuffer = renderLOD.VertexBuffers;; + // const FPositionVertexBuffer& positBuffer = staticMeshVertexBuffer.PositionVertexBuffer; + // + // ndArray points; + // for (int i = positBuffer.GetNumVertices() - 1; i >= 0; --i) + // { + // const FVector3f p(positBuffer.VertexPosition(i)); + // const ndVector q(ndFloat32(p.X), ndFloat32(p.Y), ndFloat32(p.Z), ndFloat32(0.0f)); + // points.PushBack(q * bakedScale); + // } + // ndConvexHull3d convexHull(&points[0].m_x, sizeof(ndBigVector), points.GetCount(), Tolerance, MaxVertexCount); + // const ndArray& convexVertex = convexHull.GetVertexPool(); + // + // ndHullOutput hullMesh; + // for (ndInt32 i = convexVertex.GetCount() - 1; i >= 0; --i) + // { + // ndHullPoint p; + // p.m_x = convexVertex[i].m_x; + // p.m_y = convexVertex[i].m_y; + // p.m_z = convexVertex[i].m_z; + // hullMesh.PushBack(p); + // } + // SetProceduralData(hullMesh); + // } + //} - const FStaticMeshLODResources& renderLOD = renderResource[0]; - const FStaticMeshVertexBuffers& staticMeshVertexBuffer = renderLOD.VertexBuffers;; - const FPositionVertexBuffer& positBuffer = staticMeshVertexBuffer.PositionVertexBuffer; - - ndArray points; - for (int i = positBuffer.GetNumVertices() - 1; i >= 0; --i) - { - const FVector3f p(positBuffer.VertexPosition(i)); - const ndVector q(ndFloat32(p.X), ndFloat32(p.Y), ndFloat32(p.Z), ndFloat32(0.0f)); - points.PushBack(q * bakedScale); - } - ndConvexHull3d convexHull(&points[0].m_x, sizeof(ndBigVector), points.GetCount(), Tolerance, MaxVertexCount); - const ndArray& convexVertex = convexHull.GetVertexPool(); - - ndHullOutput hullMesh; - for (ndInt32 i = convexVertex.GetCount() - 1; i >= 0; --i) - { - ndHullPoint p; - p.m_x = convexVertex[i].m_x; - p.m_y = convexVertex[i].m_y; - p.m_z = convexVertex[i].m_z; - hullMesh.PushBack(p); - } - SetProceduralData(hullMesh); - } - } BuildNewtonShape(); Super::ApplyPropertyChanges(); } diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionLandscape.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionLandscape.cpp index a22408992..4734d399e 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionLandscape.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionLandscape.cpp @@ -36,20 +36,20 @@ void UNewtonCollisionLandscape::Serialize(FArchive& ar) ar << m_heightfield; } -void UNewtonCollisionLandscape::SetGlobalTransform() -{ - if (m_savedMeshComponent) - { - const AActor* const owner = GetOwner(); - check(owner); - const FTransform bodyTransform(owner->GetRootComponent()->GetComponentToWorld()); - const FTransform globalTransform(m_savedMeshComponent->GetComponentToWorld()); - const FTransform localTransform(globalTransform * bodyTransform.Inverse()); - - SetRelativeTransform(localTransform); - SetComponentToWorld(globalTransform); - } -} +//void UNewtonCollisionLandscape::SetGlobalTransform() +//{ +// if (m_savedMeshComponent) +// { +// const AActor* const owner = GetOwner(); +// check(owner); +// const FTransform bodyTransform(owner->GetRootComponent()->GetComponentToWorld()); +// const FTransform globalTransform(m_savedMeshComponent->GetComponentToWorld()); +// const FTransform localTransform(globalTransform * bodyTransform.Inverse()); +// +// SetRelativeTransform(localTransform); +// SetComponentToWorld(globalTransform); +// } +//} long long UNewtonCollisionLandscape::CalculateHash() const { @@ -67,63 +67,64 @@ long long UNewtonCollisionLandscape::CalculateHash() const void UNewtonCollisionLandscape::ApplyPropertyChanges() { - if (m_savedMeshComponent && (m_heightfield.Num() == 0)) - { - const ULandscapeHeightfieldCollisionComponent* const tile = Cast(m_savedMeshComponent); - check(tile); - - const ULandscapeHeightfieldCollisionComponent::FHeightfieldGeometryRef* const heightfieldRef = tile->HeightfieldRef; - const Chaos::FHeightField* const mapData = heightfieldRef->HeightfieldGeometry; - check(mapData); - const Chaos::FHeightField::FData& elevationData = mapData->GeomData; - - const Chaos::FVec3 elevationScale(elevationData.Scale); - // this is not a bug, y and z are swapped after the mapping - ndFloat32 xScale = elevationScale[0] * UNREAL_INV_UNIT_SYSTEM; - ndFloat32 zScale = elevationScale[1] * UNREAL_INV_UNIT_SYSTEM; - - ndShapeHeightfield* const heightfield = new ndShapeHeightfield( - ndInt32(mapData->GetNumCols()), ndInt32(mapData->GetNumRows()), - ndShapeHeightfield::m_normalDiagonals, xScale, zScale); - - ndReal minValue = elevationData.MinValue; - ndReal highScale = elevationData.HeightPerUnit; - - const ndShape* const shape = heightfield; - const ndShapeInfo info(shape->GetShapeInfo()); - ndInt8* const attributes = info.m_heightfield.m_atributes; - ndReal* const dstHeigh = info.m_heightfield.m_elevation; - ndReal yScale = ndReal(elevationScale[2] * UNREAL_INV_UNIT_SYSTEM); - - ndInt32 dstRow = 0; - ndInt32 srcRow = (ndInt32(elevationData.NumRows) - 1) * elevationData.NumCols; - for (ndInt32 row = ndInt32(elevationData.NumRows) - 1; row >= 0; --row) - { - for (ndInt32 colum = elevationData.NumCols - 1; colum >= 0; --colum) - { - ndReal h = minValue + ndReal(elevationData.Heights[srcRow + colum]) * highScale; - dstHeigh[dstRow + colum] = h * yScale; - attributes[dstRow + colum] = 0; - } - srcRow -= elevationData.NumCols; - dstRow += elevationData.NumCols; - } - - m_scale_z = 1.0f; - m_scale_x = info.m_heightfield.m_horizonalScale_x; - m_scale_y = info.m_heightfield.m_horizonalScale_z; - m_tileSize_x = info.m_heightfield.m_width; - m_tileSize_y = info.m_heightfield.m_height; - - ndInt32 size = info.m_heightfield.m_width * info.m_heightfield.m_height; - for (ndInt32 i = 0; i < size; ++i) - { - m_heightfield.Push(dstHeigh[i]); - m_materials.Push(attributes[i]); - } - - delete heightfield; - } + check(0); + //if (m_savedMeshComponent && (m_heightfield.Num() == 0)) + //{ + // const ULandscapeHeightfieldCollisionComponent* const tile = Cast(m_savedMeshComponent); + // check(tile); + // + // const ULandscapeHeightfieldCollisionComponent::FHeightfieldGeometryRef* const heightfieldRef = tile->HeightfieldRef; + // const Chaos::FHeightField* const mapData = heightfieldRef->HeightfieldGeometry; + // check(mapData); + // const Chaos::FHeightField::FData& elevationData = mapData->GeomData; + // + // const Chaos::FVec3 elevationScale(elevationData.Scale); + // // this is not a bug, y and z are swapped after the mapping + // ndFloat32 xScale = elevationScale[0] * UNREAL_INV_UNIT_SYSTEM; + // ndFloat32 zScale = elevationScale[1] * UNREAL_INV_UNIT_SYSTEM; + // + // ndShapeHeightfield* const heightfield = new ndShapeHeightfield( + // ndInt32(mapData->GetNumCols()), ndInt32(mapData->GetNumRows()), + // ndShapeHeightfield::m_normalDiagonals, xScale, zScale); + // + // ndReal minValue = elevationData.MinValue; + // ndReal highScale = elevationData.HeightPerUnit; + // + // const ndShape* const shape = heightfield; + // const ndShapeInfo info(shape->GetShapeInfo()); + // ndInt8* const attributes = info.m_heightfield.m_atributes; + // ndReal* const dstHeigh = info.m_heightfield.m_elevation; + // ndReal yScale = ndReal(elevationScale[2] * UNREAL_INV_UNIT_SYSTEM); + // + // ndInt32 dstRow = 0; + // ndInt32 srcRow = (ndInt32(elevationData.NumRows) - 1) * elevationData.NumCols; + // for (ndInt32 row = ndInt32(elevationData.NumRows) - 1; row >= 0; --row) + // { + // for (ndInt32 colum = elevationData.NumCols - 1; colum >= 0; --colum) + // { + // ndReal h = minValue + ndReal(elevationData.Heights[srcRow + colum]) * highScale; + // dstHeigh[dstRow + colum] = h * yScale; + // attributes[dstRow + colum] = 0; + // } + // srcRow -= elevationData.NumCols; + // dstRow += elevationData.NumCols; + // } + // + // m_scale_z = 1.0f; + // m_scale_x = info.m_heightfield.m_horizonalScale_x; + // m_scale_y = info.m_heightfield.m_horizonalScale_z; + // m_tileSize_x = info.m_heightfield.m_width; + // m_tileSize_y = info.m_heightfield.m_height; + // + // ndInt32 size = info.m_heightfield.m_width * info.m_heightfield.m_height; + // for (ndInt32 i = 0; i < size; ++i) + // { + // m_heightfield.Push(dstHeigh[i]); + // m_materials.Push(attributes[i]); + // } + // + // delete heightfield; + //} BuildNewtonShape(); Super::ApplyPropertyChanges(); diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionLandscape.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionLandscape.h index dd1584878..e86179fab 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionLandscape.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionLandscape.h @@ -24,7 +24,7 @@ class UNewtonCollisionLandscape : public UNewtonCollision // Sets default values for this component's properties UNewtonCollisionLandscape(); - virtual void SetGlobalTransform() override; + //virtual void SetGlobalTransform() override; protected: virtual void Serialize(FArchive& Ar) override; diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionPolygonalMesh.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionPolygonalMesh.cpp index 4f6719afa..19c2800e2 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionPolygonalMesh.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionPolygonalMesh.cpp @@ -8,6 +8,62 @@ #include "NewtonSceneActor.h" #include "ThirdParty/newtonLibrary/Public/dNewton/ndNewton.h" +class UNewtonCollisionPolygonalMesh::ndShapeStatic : public ndShapeStatic_bvh +{ + public: + ndShapeStatic(const ndPolygonSoupBuilder& meshBuilder, UNewtonCollisionPolygonalMesh* const self) + :ndShapeStatic_bvh(meshBuilder) + ,m_self(self) + ,m_vertexCount(0) + { + } + + static ndIntersectStatus AaabbIntersectCallback( + void* const context, + const ndFloat32* const polygon, ndInt32 strideInBytes, + const ndInt32* const indexArray, ndInt32 indexCount, ndFloat32 hitDistance) + { + ndShapeStatic* const self = (ndShapeStatic*)context; + UNewtonCollisionPolygonalMesh* const polyMesh = self->m_self; + + for (ndInt32 i = indexCount - 1; i >= 0; --i) + { + self->m_vertexCount = ndMax(self->m_vertexCount, indexArray[i]); + } + + for (ndInt32 i = 2; i < indexCount; ++i) + { + polyMesh->m_indexData.Push(indexArray[0]); + polyMesh->m_indexData.Push(indexArray[i - 1]); + polyMesh->m_indexData.Push(indexArray[i + 0]); + } + return m_continueSearh; + } + + void ScanMesh() + { + ndInt32 vCount = GetVertexCount(); + ndInt32 stride = GetStrideInBytes() / sizeof(ndFloat32); + const ndFloat32* const points = GetLocalVertexPool(); + + ndVector p0(-1.0e10f, -1.0e10f, -1.0e10f, 0.0f); + ndVector p1(1.0e10f, 1.0e10f, 1.0e10f, 0.0f); + const ndFastAabb aabb(p0, p1); + m_vertexCount = -1; + ForAllSectors(aabb, ndVector(0.0f), 1.0f, AaabbIntersectCallback, this); + m_vertexCount++; + for (ndInt32 j = 0; j < m_vertexCount; ++j) + { + int i = j * stride; + FVector3f p(points[i + 0], points[i + 1], points[i + 2]); + m_self->m_vetexData.Push(p); + } + } + + UNewtonCollisionPolygonalMesh* m_self; + int m_vertexCount; +}; + UNewtonCollisionPolygonalMesh::UNewtonCollisionPolygonalMesh() :Super() { @@ -66,105 +122,57 @@ ndShape* UNewtonCollisionPolygonalMesh::CreateShape() const return shape; } -class UNewtonCollisionPolygonalMesh::ndShapeStatic : public ndShapeStatic_bvh +void UNewtonCollisionPolygonalMesh::InitStaticMeshCompoment(const USceneComponent* const meshComponent) { - public: - ndShapeStatic(const ndPolygonSoupBuilder& meshBuilder, UNewtonCollisionPolygonalMesh* const self) - :ndShapeStatic_bvh(meshBuilder) - ,m_self(self) - ,m_vertexCount(0) - { - } + SetTransform(meshComponent); - static ndIntersectStatus AaabbIntersectCallback( - void* const context, - const ndFloat32* const polygon, ndInt32 strideInBytes, - const ndInt32* const indexArray, ndInt32 indexCount, ndFloat32 hitDistance) - { - ndShapeStatic* const self = (ndShapeStatic*)context; - UNewtonCollisionPolygonalMesh* const polyMesh = self->m_self; - for (ndInt32 i = 2; i < indexCount; ++i) - { - polyMesh->m_indexData.Push(indexArray[0]); - polyMesh->m_indexData.Push(indexArray[i - 1]); - polyMesh->m_indexData.Push(indexArray[i + 0]); - self->m_vertexCount = ndMax(self->m_vertexCount, indexArray[0]); - self->m_vertexCount = ndMax(self->m_vertexCount, indexArray[i + 0]); - self->m_vertexCount = ndMax(self->m_vertexCount, indexArray[i + 1]); - } - return m_continueSearh; - } + const UStaticMeshComponent* const staticMeshComponent = Cast(meshComponent); + check(staticMeshComponent); + UStaticMesh* const staticMesh = staticMeshComponent->GetStaticMesh().Get(); - void ScanMesh() + ndVector face[8]; + + ndPolygonSoupBuilder meshBuilder; + meshBuilder.Begin(); + + const FVector uScale(GetComponentTransform().GetScale3D()); + const ndVector scale(ndFloat32(uScale.X), ndFloat32(uScale.Y), ndFloat32(uScale.Z), ndFloat32(0.0f)); + const ndVector bakedScale(scale.Scale(UNREAL_INV_UNIT_SYSTEM)); + + FTriMeshCollisionData collisionData; + bool data = staticMesh->GetPhysicsTriMeshData(&collisionData, true); + if (data) { - ndInt32 vCount = GetVertexCount(); - ndInt32 stride = GetStrideInBytes() / sizeof(ndFloat32); - const ndFloat32* const points = GetLocalVertexPool(); - - ndVector p0(-1.0e10f, -1.0e10f, -1.0e10f, 0.0f); - ndVector p1( 1.0e10f, 1.0e10f, 1.0e10f, 0.0f); - const ndFastAabb aabb(p0, p1); - m_vertexCount = -1; - ForAllSectors(aabb, ndVector(0.0f), 1.0f, AaabbIntersectCallback, this); - m_vertexCount++; - for (ndInt32 j = 0; j < m_vertexCount; ++j) + for (int i = collisionData.Indices.Num() - 1; i >= 0; --i) { - int i = j * stride; - FVector3f p(points[i + 0], points[i + 1], points[i + 2]); - m_self->m_vetexData.Push(p); + ndInt32 i0 = collisionData.Indices[i].v0; + ndInt32 i1 = collisionData.Indices[i].v1; + ndInt32 i2 = collisionData.Indices[i].v2; + + const FVector3f p0(collisionData.Vertices[i0]); + const FVector3f p1(collisionData.Vertices[i1]); + const FVector3f p2(collisionData.Vertices[i2]); + const ndVector q0(ndFloat32(p0.X), ndFloat32(p0.Y), ndFloat32(p0.Z), ndFloat32(0.0f)); + const ndVector q1(ndFloat32(p1.X), ndFloat32(p1.Y), ndFloat32(p1.Z), ndFloat32(0.0f)); + const ndVector q2(ndFloat32(p2.X), ndFloat32(p2.Y), ndFloat32(p2.Z), ndFloat32(0.0f)); + + face[0] = q0 * bakedScale; + face[1] = q1 * bakedScale; + face[2] = q2 * bakedScale; + + //for now MaterialIndex = 0 + ndInt32 materialIndex = 0; + meshBuilder.AddFace(&face[0].m_x, sizeof(ndVector), 3, materialIndex); } } - - UNewtonCollisionPolygonalMesh* m_self; - int m_vertexCount; -}; + meshBuilder.End(true); + ndShapeStatic* const polyTree= new ndShapeStatic(meshBuilder, this); + polyTree->ScanMesh(); + delete polyTree; +} void UNewtonCollisionPolygonalMesh::ApplyPropertyChanges() { - UStaticMesh* const staticMesh = FindStaticMesh(); - if (staticMesh && (m_vetexData.Num() == 0)) - { - ndVector face[8]; - - ndPolygonSoupBuilder meshBuilder; - meshBuilder.Begin(); - - const FVector uScale(GetComponentTransform().GetScale3D()); - const ndVector scale(ndFloat32(uScale.X), ndFloat32(uScale.Y), ndFloat32(uScale.Z), ndFloat32(0.0f)); - const ndVector bakedScale(scale.Scale(UNREAL_INV_UNIT_SYSTEM)); - - FTriMeshCollisionData collisionData; - bool data = staticMesh->GetPhysicsTriMeshData(&collisionData, true); - if (data) - { - for (int i = collisionData.Indices.Num() - 1; i >= 0; --i) - { - ndInt32 i0 = collisionData.Indices[i].v0; - ndInt32 i1 = collisionData.Indices[i].v2; - ndInt32 i2 = collisionData.Indices[i].v1; - - const FVector3f p0(collisionData.Vertices[i0]); - const FVector3f p1(collisionData.Vertices[i1]); - const FVector3f p2(collisionData.Vertices[i2]); - const ndVector q0(ndFloat32(p0.X), ndFloat32(p0.Y), ndFloat32(p0.Z), ndFloat32(0.0f)); - const ndVector q1(ndFloat32(p1.X), ndFloat32(p1.Y), ndFloat32(p1.Z), ndFloat32(0.0f)); - const ndVector q2(ndFloat32(p2.X), ndFloat32(p2.Y), ndFloat32(p2.Z), ndFloat32(0.0f)); - - face[0] = q0 * bakedScale; - face[1] = q1 * bakedScale; - face[2] = q2 * bakedScale; - - //for now MaterialIndex = 0 - ndInt32 materialIndex = 0; - meshBuilder.AddFace(&face[0].m_x, sizeof(ndVector), 3, materialIndex); - } - } - meshBuilder.End(true); - ndShapeStatic* const polyTree= new ndShapeStatic(meshBuilder, this); - polyTree->ScanMesh(); - delete polyTree; - } - BuildNewtonShape(); Super::ApplyPropertyChanges(); } diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionPolygonalMesh.h b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionPolygonalMesh.h index 396b5423b..9e20d6a81 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionPolygonalMesh.h +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonCollisionPolygonalMesh.h @@ -20,6 +20,7 @@ class UNewtonCollisionPolygonalMesh : public UNewtonCollision public: // Sets default values for this component's properties UNewtonCollisionPolygonalMesh(); + virtual void InitStaticMeshCompoment(const USceneComponent* const meshComponent) override; protected: virtual void Serialize(FArchive& Ar) override; diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonSceneActor.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonSceneActor.cpp index 8268840dc..7e20f85b5 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonSceneActor.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonSceneActor.cpp @@ -64,8 +64,7 @@ void ANewtonSceneActor::CreateCollisionFromUnrealPrimitive(TObjectPtrAttachToComponent(RootBody, FAttachmentTransformRules::KeepRelativeTransform); - childComp->SetGeometryMesh(staticComponent); - childComp->SetGlobalTransform(); + childComp->InitStaticMeshCompoment(staticComponent); childComp->MarkRenderDynamicDataDirty(); childComp->NotifyMeshUpdated(); }; @@ -122,8 +121,7 @@ void ANewtonSceneActor::CreateCollisionFromUnrealPrimitive(TObjectPtrAttachToComponent(RootBody, FAttachmentTransformRules::KeepRelativeTransform); - childComp->SetGeometryMesh(staticComponent); - childComp->SetGlobalTransform(); + childComp->InitStaticMeshCompoment(staticComponent); childComp->MarkRenderDynamicDataDirty(); childComp->NotifyMeshUpdated(); }; @@ -134,7 +132,6 @@ void ANewtonSceneActor::CreateCollisionFromUnrealPrimitive(TObjectPtrGetName() == FString("CWall_001")) GenerateStaticMeshCollision(sceneActor); } } @@ -277,8 +275,7 @@ void ANewtonSceneActor::GenerateLandScapeCollision(const ALandscapeProxy* const AddInstanceComponent(collisionTile); collisionTile->AttachToComponent(RootBody, FAttachmentTransformRules::KeepRelativeTransform); - collisionTile->SetGeometryMesh(tile); - collisionTile->SetGlobalTransform(); + collisionTile->InitStaticMeshCompoment(tile); collisionTile->MarkRenderDynamicDataDirty(); collisionTile->NotifyMeshUpdated(); } diff --git a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonSceneRigidBody.cpp b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonSceneRigidBody.cpp index a154cdb89..f8955369c 100644 --- a/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonSceneRigidBody.cpp +++ b/newton-4.00/applications/toolsAndWrapers/newtonUnreal/newton/Source/newton/Private/NewtonSceneRigidBody.cpp @@ -14,6 +14,11 @@ UNewtonSceneRigidBody::UNewtonSceneRigidBody() :Super() { + const FTransform transform; + SetComponentToWorld(transform); + SetRelativeScale3D_Direct(transform.GetScale3D()); + SetRelativeRotation_Direct(FRotator(transform.GetRotation())); + SetRelativeLocation_Direct(transform.GetLocation()); } void UNewtonSceneRigidBody::RemoveAllCollisions()