public void TestPhysicsBoxColliderCreate() { var geometry = new BoxGeometry { Size = new float2(0.01f, 120.40f), Center = new float2(-10.10f, 10.12f), Angle = 0f, BevelRadius = 0f }; const uint UserData = 0xDEADBEEF; using (var colliderBlob = PhysicsBoxCollider.Create(geometry, CollisionFilter.Default, PhysicsMaterial.Default, UserData)) { ref var collider = ref colliderBlob.GetColliderRef <PhysicsBoxCollider>(); Assert.AreEqual(ColliderType.Box, collider.ColliderType); Assert.AreEqual(CollisionType.Convex, collider.CollisionType); Assert.AreEqual(UserData, collider.UserData); Assert.AreEqual(CollisionFilter.Default, collider.Filter); Assert.AreEqual(PhysicsMaterial.Default, collider.Material); Assert.AreEqual(geometry.Size, collider.Size); Assert.AreEqual(geometry.Size, collider.Geometry.Size); Assert.AreEqual(geometry.Center, collider.Center); Assert.AreEqual(geometry.Center, collider.Geometry.Center); Assert.AreEqual(geometry.Angle, collider.Angle); Assert.AreEqual(geometry.Angle, collider.Geometry.Angle); Assert.AreEqual(geometry.BevelRadius, collider.BevelRadius); Assert.AreEqual(geometry.BevelRadius, collider.Geometry.BevelRadius); }
internal override ShapeComputationData GenerateComputationData( LegacyBox shape, ColliderInstance colliderInstance, NativeList <float3> allConvexHullPoints, NativeList <float3> allMeshVertices, NativeList <int3> allMeshTriangles ) { var res = base.GenerateComputationData(shape, colliderInstance, allConvexHullPoints, allMeshVertices, allMeshTriangles); res.ShapeType = ShapeType.Box; var worldCenter = math.mul(shape.transform.localToWorldMatrix, new float4(shape.center, 1f)); var shapeFromWorld = math.inverse( new float4x4(new RigidTransform(shape.transform.rotation, shape.transform.position)) ); var geometry = new BoxGeometry { Center = math.mul(shapeFromWorld, worldCenter).xyz, Orientation = quaternion.identity }; var linearScale = (float3)shape.transform.lossyScale; geometry.Size = math.abs(shape.size * linearScale); geometry.BevelRadius = math.min(ConvexHullGenerationParameters.Default.BevelRadius, math.cmin(geometry.Size) * 0.5f); res.BoxProperties = geometry; return(res); }
private void CreateFunnel(Scene scene) { // Create two boxes that angle inwards to create a funnel var material = scene.Physics.CreateMaterial(0.1f, 0.1f, 0.1f); var rigidActor = scene.Physics.CreateRigidDynamic(); var boxGeom = new BoxGeometry(10, 0.25f, 5); var boxShape = rigidActor.CreateShape(boxGeom, material); rigidActor.GlobalPose = Matrix.RotationX(0.2f) * Matrix.Translation(0, 7, -5.1f); rigidActor.SetMassAndUpdateInertia(10); rigidActor.Flags = RigidDynamicFlags.Kinematic; scene.AddActor(rigidActor); // var rigidActor2 = scene.Physics.CreateRigidDynamic(); var boxGeom2 = new BoxGeometry(10, 0.25f, 5); var boxShape2 = rigidActor2.CreateShape(boxGeom2, material); rigidActor2.GlobalPose = Matrix.RotationX(-0.2f) * Matrix.Translation(0, 7, 5.1f); rigidActor2.SetMassAndUpdateInertia(10); rigidActor2.Flags = RigidDynamicFlags.Kinematic; scene.AddActor(rigidActor2); }
protected override void OnCreate() { base.OnCreate(); _tileColliderArchetype = EntityManager.CreateArchetype( typeof(TileColliderTag), typeof(FixTranslation), typeof(PhysicsColliderBlob)); // Create tile collider BoxGeometry boxGeometry = new BoxGeometry() { Size = float2(1, 1) }; PolygonGeometry triangleGeometry = new PolygonGeometry() { Vertices = new NativeArray <float2>(new float2[] { new float2(-.5f, -.5f), new float2(-.5f, .5f), new float2(.5f, -0.5f), }, Allocator.Temp) }; CollisionFilter filter = CollisionFilter.FromLayer(SimulationGameConstants.Physics.LAYER_TERRAIN); PhysicsMaterial material = PhysicsMaterial.Default; _fullTileCollider = Collider.Create(boxGeometry, filter, material); _cornerTileCollider = Collider.Create(triangleGeometry); }
/// <summary> /// /// </summary> /// <param name="control"></param> public override void Load(Control control) { base.Load(control); camera = new PerspectiveCamera(75, control.Width / (float)control.Height, 1, 1100); controls = new DeviceOrientationControls(camera); scene = new Scene(); geometry = new SphereGeometry(500, 16, 8); geometry.ApplyMatrix(new Matrix4().MakeScale(-1, 1, 1)); var material = new MeshBasicMaterial() { Map = ImageUtils.LoadTexture(@"examples\textures/2294472375_24a3b8ef46_o.jpg") }; mesh = new Mesh(geometry, material); scene.Add(mesh); var geometry2 = new BoxGeometry(100, 100, 100, 4, 4, 4); var material2 = new MeshBasicMaterial() { Color = Color.Purple, Side = Three.BackSide, Wireframe = true }; var mesh2 = new Mesh(geometry2, material2); scene.Add(mesh2); controls.Connect(); }
public void Broadphase_ImmediateBuild_DynamicBoxTest([Values(0, 1, 10, 100)] int dynamicBodyCount) { var physicsWorld = CreatePhysicsWorld(staticBodies: 1, dynamicBodies: dynamicBodyCount); { var geometry = new BoxGeometry { Center = new float2(-10f, 0f), Size = new float2(10f) }; AddStaticBoxToWorld(ref physicsWorld, 0, geometry); } for (var i = 0; i < dynamicBodyCount; ++i) { var geometry = new BoxGeometry { Center = new float2(i * 11f, 0f), Size = new float2(10f) }; AddDynamicBoxToWorld(ref physicsWorld, i, geometry); } physicsWorld.CollisionWorld.Broadphase.Build( physicsWorld.StaticBodies, physicsWorld.DynamicBodies, physicsWorld.BodyMotionData, physicsWorld.BodyMotionVelocity, PhysicsSettings.Constants.CollisionTolerance, physicsWorld.TimeStep, physicsWorld.Settings.Gravity); physicsWorld.Dispose(); }
public unsafe void PhysicsBodyOverlapPointTest() { var geometry = new BoxGeometry { Size = new float2(2f), }; using (var collider = PhysicsBoxCollider.Create(geometry)) { var physicsBody = new PhysicsBody(collider); var queryInput = new OverlapPointInput() { Filter = CollisionFilter.Default }; var closestHit = new OverlapPointHit(); var allHits = new NativeList <OverlapPointHit>(Allocator.Temp); // OK case. var positionOK = new float2(1f); queryInput.Position = positionOK; Assert.IsTrue(physicsBody.OverlapPoint(queryInput)); Assert.IsTrue(physicsBody.OverlapPoint(queryInput, out closestHit)); Assert.IsTrue(physicsBody.OverlapPoint(queryInput, ref allHits)); // Fail Case. var positionFail = new float2(-10f); queryInput.Position = positionFail; Assert.IsFalse(physicsBody.OverlapPoint(queryInput)); Assert.IsFalse(physicsBody.OverlapPoint(queryInput, out closestHit)); Assert.IsFalse(physicsBody.OverlapPoint(queryInput, ref allHits)); allHits.Dispose(); } }
public TestBox(BoxGeometry geometry, float3 translation, quaternion rotation) { Entity = EntityManager.CreateEntity( typeof(PhysicsColliderBlob), typeof(LocalToWorld) ); Geometry = geometry; PhysicsTransform = new PhysicsTransform(translation, rotation); Translation = translation; Rotation = rotation; var colliderBlob = PhysicsBoxCollider.Create(Geometry); Aabb = colliderBlob.Value.CalculateAabb(PhysicsTransform); EntityManager.AddComponentData( Entity, new PhysicsColliderBlob { Collider = colliderBlob } ); EntityManager.AddComponentData( Entity, new LocalToWorld { Value = new float4x4(rotation, translation) } ); }
public void Box_Box_Sweep() { using (var physics = CreatePhysicsAndScene()) { // Create a 10x10x10 box and place it to the right and on the ground var box = CreateBoxActor(physics.Scene, 5, 5, 5); box.GlobalPose = Matrix4x4.CreateTranslation(20, 5, 0); var sweepGeom = new BoxGeometry(2, 2, 2); // var hitActors = new List <RigidActor>(); // Sweep the small box to the right 50units, it should hit our bigger box physics.Scene.Sweep(sweepGeom, Matrix4x4.CreateTranslation(0, 2, 0), new Vector3(1, 0, 0), 50, 10, (hits) => { // Record all the hits to make sure we only end up with one hitActors.AddRange(hits.Select(h => h.Actor)); return(true); }); Assert.AreEqual(1, hitActors.Count); Assert.AreEqual(box, hitActors[0]); } }
internal override ShapeComputationData GenerateComputationData( LegacyBox shape, ColliderInstance colliderInstance, NativeList <float3> allConvexHullPoints, NativeList <float3> allMeshVertices, NativeList <int3> allMeshTriangles ) { var res = base.GenerateComputationData(shape, colliderInstance, allConvexHullPoints, allMeshVertices, allMeshTriangles); res.ShapeType = ShapeType.Box; var shapeLocalToWorld = shape.transform.localToWorldMatrix; var worldCenter = math.mul(shapeLocalToWorld, new float4(shape.center, 1f)); var transformRotation = shape.transform.rotation; var rigidBodyTransform = Math.DecomposeRigidBodyTransform(shapeLocalToWorld); var shapeFromWorld = math.inverse(new float4x4(rigidBodyTransform)); var orientationFixup = math.inverse(math.mul(math.inverse(transformRotation), rigidBodyTransform.rot)); var geometry = new BoxGeometry { Center = math.mul(shapeFromWorld, worldCenter).xyz, Orientation = orientationFixup }; var linearScale = float4x4.TRS(float3.zero, math.inverse(orientationFixup), shape.transform.lossyScale).DecomposeScale(); geometry.Size = math.abs(shape.size * linearScale); geometry.BevelRadius = math.min(ConvexHullGenerationParameters.Default.BevelRadius, math.cmin(geometry.Size) * 0.5f); res.BoxProperties = geometry; return(res); }
static public BlobAssetReference <Collider> ProduceColliderBlob (this UnityEngine.BoxCollider shape, int groupIndex) { var worldCenter = math.mul(shape.transform.localToWorldMatrix, new float4(shape.center, 1f)); var shapeFromWorld = math.inverse( new float4x4(new RigidTransform(shape.transform.rotation, shape.transform.position)) ); var geometry = new BoxGeometry { Center = math.mul(shapeFromWorld, worldCenter).xyz, Orientation = quaternion.identity }; var linearScale = (float3)shape.transform.lossyScale; geometry.Size = math.abs(shape.size * linearScale); geometry.BevelRadius = math.min(ConvexHullGenerationParameters.Default.BevelRadius, math.cmin(geometry.Size) * 0.5f); return(BoxCollider.Create( geometry, GetFilter(shape, groupIndex) //ProduceCollisionFilter( shape ), //ProduceMaterial( shape ) )); }
public void Overlap() { using (var core = CreatePhysicsAndScene()) { // Just up from the ground, 20 units ahead var box1 = CreateBoxActor(core.Scene, 0, 2, 20); var box2 = CreateBoxActor(core.Scene, 0, 2, 40); box1.Name = "Box1"; box2.Name = "Box2"; BoxGeometry overlappingBox = new BoxGeometry(100, 100, 100); OverlapHit[] hits = null; bool result = core.Scene.Overlap ( geometry: overlappingBox, pose: Matrix4x4.Identity, maximumOverlaps: 2, hitCall: hit => { hits = hit; return(true); } ); Assert.IsNotNull(hits); Assert.AreEqual(2, hits.Length); Assert.AreEqual(box2, hits[0].Actor); Assert.AreEqual(box1, hits[1].Actor); } }
public void Broadphase_ScheduleBuildJobs_DynamicBoxTest([Values(0, 1, 10, 100)] int dynamicBodyCount) { var physicsWorld = CreatePhysicsWorld(staticBodies: 1, dynamicBodies: dynamicBodyCount); { var geometry = new BoxGeometry { Center = new float2(-10f, 0f), Size = new float2(10f) }; AddStaticBoxToWorld(ref physicsWorld, 0, geometry); } for (var i = 0; i < dynamicBodyCount; ++i) { var geometry = new BoxGeometry { Center = new float2(i * 11f, 0f), Size = new float2(10f) }; AddDynamicBoxToWorld(ref physicsWorld, i, geometry); } using (var buildStaticTree = new NativeArray <int>(new[] { 1 }, Allocator.TempJob)) { physicsWorld.CollisionWorld.Broadphase.ScheduleBuildJobs(ref physicsWorld, buildStaticTree, default).Complete(); physicsWorld.Dispose(); } }
protected override JobHandle OnUpdate(JobHandle inputDependencies) { SelectionAreaData selectionAreaData = GetSingleton <SelectionAreaData> (); if (selectionAreaData.isSelecting) { CreateIfDontExist(); Entities.WithAll <SelectionAreaTag> ().ForEach((Entity entity, ref Translation translation, ref NonUniformScale scale, ref PhysicsCollider collider) => { var center = math.lerp(selectionAreaData.upperRightPosition, selectionAreaData.lowerLeftPosition, 0.5f); var size = new float3(selectionAreaData.startPosition.x - selectionAreaData.currentPosition.x, selectionAreaData.startPosition.y - selectionAreaData.currentPosition.y, 1); BoxGeometry boxGeometry = new BoxGeometry() { Center = new float3(0, 0, 0) - new float3(selectionAreaData.startPosition.x - selectionAreaData.currentPosition.x, selectionAreaData.startPosition.y - selectionAreaData.currentPosition.y, 1) / 2, Size = size * math.sign(size) + new float3(1, 1, 1), Orientation = quaternion.identity, BevelRadius = 0, }; BlobAssetReference <Unity.Physics.Collider> boxColliser = Unity.Physics.BoxCollider.Create(boxGeometry); collider.Value = boxColliser; translation.Value = selectionAreaData.startPosition; scale.Value = selectionAreaData.selectionAreaSize; }).Run(); return(default);
private void CreateFunnel(Scene scene) { // Create two boxes that angle inwards to create a funnel var material = scene.Physics.CreateMaterial(0.1f, 0.1f, 0.1f); var rigidActor = scene.Physics.CreateRigidDynamic(); var boxGeom = new BoxGeometry(10, 0.25f, 5); var boxShape = rigidActor.CreateShape(boxGeom, material); rigidActor.GlobalPose = Matrix4x4.CreateRotationX(0.2f) * Matrix4x4.CreateTranslation(0, 7, -5.1f); rigidActor.SetMassAndUpdateInertia(10); rigidActor.Flags = RigidDynamicFlags.Kinematic; scene.AddActor(rigidActor); // var rigidActor2 = scene.Physics.CreateRigidDynamic(); var boxGeom2 = new BoxGeometry(10, 0.25f, 5); var boxShape2 = rigidActor2.CreateShape(boxGeom2, material); rigidActor2.GlobalPose = Matrix4x4.CreateRotationX(-0.2f) * Matrix4x4.CreateTranslation(0, 7, 5.1f); rigidActor2.SetMassAndUpdateInertia(10); rigidActor2.Flags = RigidDynamicFlags.Kinematic; scene.AddActor(rigidActor2); }
public unsafe void PhysicsBodyCalculateDistancePointTest() { var geometry = new BoxGeometry { Size = new float2(1f), }; using (var collider = PhysicsBoxCollider.Create(geometry)) { var physicsBody = new PhysicsBody(collider); var queryInput = new PointDistanceInput { Position = new float2(-10f), Filter = CollisionFilter.Default }; var closestHit = new DistanceHit(); var allHits = new NativeList <DistanceHit>(Allocator.Temp); // OK case : with enough max distance queryInput.MaxDistance = 10000.0f; Assert.IsTrue(physicsBody.CalculateDistance(queryInput)); Assert.IsTrue(physicsBody.CalculateDistance(queryInput, out closestHit)); Assert.IsTrue(physicsBody.CalculateDistance(queryInput, ref allHits)); // Fail case : not enough max distance queryInput.MaxDistance = 1; Assert.IsFalse(physicsBody.CalculateDistance(queryInput)); Assert.IsFalse(physicsBody.CalculateDistance(queryInput, out closestHit)); Assert.IsFalse(physicsBody.CalculateDistance(queryInput, ref allHits)); allHits.Dispose(); } }
public void SweepAny() { using (var core = CreatePhysicsAndScene()) { // Just up from the ground, 20 units ahead var box1 = CreateBoxActor(core.Scene, 0, 2, 20); var box2 = CreateBoxActor(core.Scene, 0, 2, 40); box1.Name = "Box1"; box2.Name = "Box2"; // Use a box of 10x10x10 to sweep with BoxGeometry sweepBox = new BoxGeometry(10, 10, 10); // Sweep the box forwards 25 units to hit box1 var sweep = core.Scene.SweepAny ( sweepBox, Matrix.Translation(0, 2, 0), new Vector3(0, 0, 1), 25, SceneQueryFlags.All ); Assert.IsNotNull(sweep); Assert.AreEqual(box1, sweep.Shape.Actor); } }
public override void CreateScene(CompoundDemoScene sceneSettings) { // // Floor // { // BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.BoxCollider.Create(new float3(0, -0.1f, 0), Quaternion.identity, new float3(10.0f, 0.1f, 10.0f), 0.05f); // CreatedColliders.Add(collider); // CreateStaticBody(float3.zero, quaternion.identity, collider); // } // Dynamic compound { var box = new BoxGeometry { Center = float3.zero, Orientation = quaternion.identity, Size = new float3(1), BevelRadius = 0.05f }; var sphere = new SphereGeometry { Center = float3.zero, Radius = 0.5f }; var children = new NativeArray <CompoundCollider.ColliderBlobInstance>(3, Allocator.Temp) { [0] = new CompoundCollider.ColliderBlobInstance { CompoundFromChild = new RigidTransform(quaternion.identity, new float3(-1, 0, 0)), Collider = Unity.Physics.BoxCollider.Create(box) }, [1] = new CompoundCollider.ColliderBlobInstance { CompoundFromChild = RigidTransform.identity, Collider = Unity.Physics.SphereCollider.Create(sphere) }, [2] = new CompoundCollider.ColliderBlobInstance { CompoundFromChild = new RigidTransform(quaternion.identity, new float3(1, 0, 0)), Collider = Unity.Physics.BoxCollider.Create(box) } }; foreach (var child in children) { CreatedColliders.Add(child.Collider); } BlobAssetReference <Unity.Physics.Collider> collider = CompoundCollider.Create(children); CreatedColliders.Add(collider); children.Dispose(); CreateDynamicBody(new float3(0, 1, 0), quaternion.identity, collider, float3.zero, float3.zero, 1.0f); } }
protected unsafe override void Start() { //float3 gravity = new float3(0, -9.81f, 0); float3 gravity = float3.zero; base.init(gravity); // // Floor // { // BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.BoxCollider.Create(new float3(0, -0.1f, 0), Quaternion.identity, new float3(10.0f, 0.1f, 10.0f), 0.05f); // CreateStaticBody(float3.zero, quaternion.identity, collider); // } // Dynamic compound { var box = new BoxGeometry { Center = float3.zero, Orientation = quaternion.identity, Size = new float3(1), BevelRadius = 0.05f }; var sphere = new SphereGeometry { Center = float3.zero, Radius = 0.5f }; var children = new NativeArray <CompoundCollider.ColliderBlobInstance>(3, Allocator.Temp) { [0] = new CompoundCollider.ColliderBlobInstance { CompoundFromChild = new RigidTransform(quaternion.identity, new float3(-1, 0, 0)), Collider = Unity.Physics.BoxCollider.Create(box) }, [1] = new CompoundCollider.ColliderBlobInstance { CompoundFromChild = RigidTransform.identity, Collider = Unity.Physics.SphereCollider.Create(sphere) }, [2] = new CompoundCollider.ColliderBlobInstance { CompoundFromChild = new RigidTransform(quaternion.identity, new float3(1, 0, 0)), Collider = Unity.Physics.BoxCollider.Create(box) } }; BlobAssetReference <Unity.Physics.Collider> collider = CompoundCollider.Create(children); children.Dispose(); CreateDynamicBody(new float3(0, 1, 0), quaternion.identity, collider, float3.zero, float3.zero, 1.0f); } }
public void Execute() { var center = Box[0].Center; var size = Box[0].Size; var bevelRadius = Box[0].BevelRadius; float4x4 bakeToShape; var basisPriority = k_DefaultAxisPriority; var sheared = localToWorld.HasShear(); if (localToWorld.HasNonUniformScale() || sheared) { if (sheared) { var basisToWorld = GetBasisToWorldMatrix(localToWorld, center, orientation, size); basisPriority = GetBasisAxisPriority(basisToWorld); } bakeToShape = GetPrimitiveBakeToShapeMatrix(localToWorld, shapeToWorld, ref center, ref orientation, size, basisPriority); var s = new float3( math.length(bakeToShape[basisPriority[2]]), math.length(bakeToShape[basisPriority[1]]), math.length(bakeToShape[basisPriority[0]]) ); bevelRadius *= math.cmin(s / size); size = s; } else { bakeToShape = GetPrimitiveBakeToShapeMatrix(localToWorld, shapeToWorld, ref center, ref orientation, 1f, basisPriority); var s = new float3( math.length(bakeToShape.c0), math.length(bakeToShape.c1), math.length(bakeToShape.c2) ); bevelRadius *= math.cmin(s); size *= s; } Box[0] = new BoxGeometry { Center = center, Orientation = orientation, Size = size, BevelRadius = bevelRadius }; }
public void BoxCollider_Create_WhenSizeInvalid_Throws( [Values(float.PositiveInfinity, float.NegativeInfinity, float.NaN, -1f)] float errantValue ) { var geometry = new BoxGeometry { Size = new float3(errantValue), Orientation = quaternion.identity }; var ex = Assert.Throws <ArgumentException>(() => BoxCollider.Create(geometry)); Assert.That(ex.Message, Does.Match(nameof(BoxGeometry.Size))); }
private bool IsPointInBox(BoxGeometry box, Vector3 boxPosition, Vector3 point) { Vector3 min = boxPosition - box.HalfExtents; Vector3 max = boxPosition + box.HalfExtents; bool outside = point.X <min.X || point.X> max.X || point.Y <min.Y || point.Y> max.Y || point.Z <min.Z || point.Z> max.Z; return(!outside); }
protected override void Setup() { base.Setup(); m_BoxGeometry = new BoxGeometry { Size = new float2(0.01f, 120.40f), Center = new float2(-10.10f, 10.12f), }; m_CapsuleGeometry = new CapsuleGeometry { Vertex0 = new float2(0f, 3f), Vertex1 = new float2(0f, -2f), Radius = 1.5f }; m_CircleGeometry = new CircleGeometry { Center = new float2(-10.10f, 10.12f), Radius = 3.0f }; m_Vertices = new NativeArray <float2>( new float2[] { new float2(-1f, -2f), new float2(2f, -3f), new float2(4f, 5f), new float2(-6f, 7f) }, Allocator.Persistent ); m_GiftWrappedIndices = new NativeArray <int>( new int[] { 2, 3, 0, 1 }, Allocator.Persistent ); Assert.IsTrue(m_Vertices.Length >= 3, "Test array must contain at least 3 points."); Assert.AreEqual(m_Vertices.Length, m_GiftWrappedIndices.Length, "Test array lengths do not match."); m_PolygonGeometry = new PolygonGeometry { Vertices = m_Vertices, BevelRadius = 0.0f }; }
private RigidDynamic CreateBox(Vector3 position) { var actor = _scene.Physics.CreateRigidDynamic(); var boxGeom = new BoxGeometry(2, 2, 2); var boxShape = actor.CreateShape(boxGeom, _material); actor.GlobalPose = Matrix4x4.CreateTranslation(position); actor.SetMassAndUpdateInertia(10); _scene.AddActor(actor); return(actor); }
private static PhysicsCollider CreateBoxCollider(float sizeX, float sizeY, float sizeZ, float centerX, float centerY, float centerZ, CollisionFilter filter, PhysicsMaterial physicsMaterial) { BoxGeometry boxGeo = new BoxGeometry { Center = new float3(centerX, centerY, centerZ), Orientation = quaternion.identity, Size = new float3(sizeX, sizeY, sizeZ), BevelRadius = 0.05f }; return(new PhysicsCollider { Value = BoxCollider.Create(boxGeo, filter, physicsMaterial) }); }
public Unity.Entities.Entity CreateEntity() { BoxGeometry box = new BoxGeometry { Center = float3.zero, Orientation = quaternion.identity, Size = new float3(1), BevelRadius = 0.0f }; entity = GameMaster.Instance.CreateBody(this.transform.position, this.transform.rotation, Unity.Physics.BoxCollider.Create(box), Vector3.zero, Vector3.zero, 1.0f, !isStatic); return(entity); }
private static void CreateBoxes(Scene scene, Material material) { for (int i = 0; i < 10; i++) { var rigidActor = scene.Physics.CreateRigidDynamic(); var boxGeom = new BoxGeometry(2, 2, 2); var boxShape = rigidActor.CreateShape(boxGeom, material); rigidActor.GlobalPose = Matrix.Translation(-20, 10 + i * (boxGeom.Size.Y + 0.5f), 0); rigidActor.SetMassAndUpdateInertia(10); scene.AddActor(rigidActor); } }
// a helper to show the world-axis-aligned bounding box for an object public static BoundingBoxHelper Create(Renderer renderer, Object3D o, Color?color = null) { var c = color.HasValue ? color.Value : new Color(0x888888); var geo = new BoxGeometry(1, 1, 1); var mat = new MeshBasicMaterial(renderer) { Diffuse = c, UseWireframe = true }; var boundingBoxHelper = new BoundingBoxHelper(geo, mat); boundingBoxHelper.o = o; boundingBoxHelper.box = Box3.Empty; return(boundingBoxHelper); }
public void SetBox(float3 center, float3 size, quaternion orientation) { var euler = m_PrimitiveOrientation; euler.SetValue(orientation); var box = new BoxGeometry { Center = center, Size = size, Orientation = orientation, BevelRadius = BevelRadius }; SetBox(box, euler); }
public unsafe void PhysicsBodyCastColliderTest() { var geometry = new BoxGeometry { Size = new float2(1f), }; using (var collider = PhysicsBoxCollider.Create(geometry)) { var physicsBody = new PhysicsBody(collider); var queryInput = new ColliderCastInput() { Rotation = float2x2.identity }; var closestHit = new ColliderCastHit(); var allHits = new NativeList <ColliderCastHit>(Allocator.Temp); var circleGeometry = new CircleGeometry { Radius = 0.5f }; using (var circleBlob = PhysicsCircleCollider.Create(circleGeometry)) { queryInput.Collider = circleBlob; // OK case. var startOK = new float2(-10f, -10f); var endOK = new float2(10f, 10f); queryInput.Start = startOK; queryInput.End = endOK; Assert.IsTrue(physicsBody.CastCollider(queryInput)); Assert.IsTrue(physicsBody.CastCollider(queryInput, out closestHit)); Assert.IsTrue(physicsBody.CastCollider(queryInput, ref allHits)); // Fail Case. var startFail = new float2(-10f, -10f); var endFail = new float2(10f, -10f); queryInput.Start = startFail; queryInput.End = endFail; Assert.IsFalse(physicsBody.CastCollider(queryInput)); Assert.IsFalse(physicsBody.CastCollider(queryInput, out closestHit)); Assert.IsFalse(physicsBody.CastCollider(queryInput, ref allHits)); } allHits.Dispose(); } }
public WorldEditor() { InitializeComponent(); m_initialized = false; m_showingResourceSelector = false; m_resourceSelectorWindow = new ResourceViewerWindow(); InitGrid(); m_actorList = new CustomList("Actor :", 0); m_actorList.addControlsIntoGrid(ref m_grid); m_boxGeometryActor = new BoxGeometry(1, ref m_grid); this.Content = m_grid; }
public static void StackOfBoxes(Scene scene) { for (int i = 0; i < 10; i++) { var rigidActor = scene.Physics.CreateRigidDynamic(); var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f); var boxGeom = new BoxGeometry(2, 2, 2); var boxShape = rigidActor.CreateShape(boxGeom, material); rigidActor.GlobalPose = Matrix.Translation(0, 10 + i * boxGeom.Size.Y, 0); rigidActor.SetMassAndUpdateInertia(10); scene.AddActor(rigidActor); } }
private static void CreateBoxes(Scene scene, Material material) { for (int i = 0; i < 10; i++) { var rigidActor = scene.Physics.CreateRigidDynamic(); var boxGeom = new BoxGeometry(2, 2, 2); var boxShape = rigidActor.CreateShape(boxGeom, material); rigidActor.GlobalPose = Matrix.Translation(-20, 10 + i * (boxGeom.Size.Y + 0.5f), 0); rigidActor.SetMassAndUpdateInertia(10); scene.AddActor(rigidActor); // Spin the cube rigidActor.AddTorque(new Vector3(0, 50000, 0), ForceMode.Acceleration, true); } }
public void Overlap() { using (var core = CreatePhysicsAndScene()) { // Just up from the ground, 20 units ahead var box1 = CreateBoxActor(core.Scene, 0, 2, 20); var box2 = CreateBoxActor(core.Scene, 0, 2, 40); box1.Name = "Box1"; box2.Name = "Box2"; BoxGeometry overlappingBox = new BoxGeometry(100, 100, 100); OverlapHit[] hits = null; bool result = core.Scene.Overlap ( geometry: overlappingBox, pose: Matrix.Identity, maximumOverlaps: 2, hitCall: hit => { hits = hit; return true; } ); Assert.IsNotNull(hits); Assert.AreEqual(2, hits.Length); Assert.AreEqual(box2, hits[0].Actor); Assert.AreEqual(box1, hits[1].Actor); } }
private RigidActor CreateFlagPole() { var polePosition = new Vector3(0, 25, 0); // Create a flag pole to attach the cloth to var material = this.Scene.Physics.CreateMaterial(0.1f, 0.1f, 0.1f); var rigidActor = this.Scene.Physics.CreateRigidStatic(); var boxGeom = new BoxGeometry(0.5f, 25, 0.5f); var boxShape = rigidActor.CreateShape(boxGeom, material); rigidActor.GlobalPose = Matrix4x4.CreateTranslation(polePosition); this.Scene.AddActor(rigidActor); return rigidActor; }
private bool IsPointInBox(BoxGeometry box, Vector3 boxPosition, Vector3 point) { Vector3 min = boxPosition - box.HalfExtents; Vector3 max = boxPosition + box.HalfExtents; bool outside = point.X < min.X || point.X > max.X || point.Y < min.Y || point.Y > max.Y || point.Z < min.Z || point.Z > max.Z; return !outside; }
//private void CreateFlagPole(Cloth cloth) //{ // var polePosition = new Vector3(0, 30, 0); // // Create a flag pole to attach the cloth to // var material = this.Scene.Physics.CreateMaterial(0.1f, 0.1f, 0.1f); // var rigidActor = this.Scene.Physics.CreateRigidStatic(); // var boxGeom = new BoxGeometry(2, 30, 2); // var boxShape = rigidActor.CreateShape(boxGeom, material); // rigidActor.GlobalPose = Matrix.Translation(polePosition); // //rigidActor.SetMassAndUpdateInertia(10); // //rigidActor.Flags = RigidDynamicFlags.Kinematic; // this.Scene.AddActor(rigidActor); // // Attach the cloth // var clothGrid = new VertexGrid(25, 25); // // TODO: Clean up the below code // // I'd like this to use the FindPointsInsideBoxGeom method instead (more generic) // Vector3[] p; // int[] i; // FindPointsInsideBoxGeom(boxGeom, polePosition, clothGrid, out p, out i); // p = clothGrid.Points.Take(75).ToArray(); // i = Enumerable.Range(0, 75).ToArray(); // var f = new int[p.Length]; // var attachment = this.Scene.Physics.CreateAttachment(cloth, boxShape, i, p, f); //} private void FindPointsInsideBoxGeom(BoxGeometry box, Vector3 boxPosition, VertexGrid grid, out Vector3[] points, out int[] indices) { var i = new List<Vector3>(); var j = new List<int>(); foreach (int index in grid.Indices) { Vector3 p = grid.Points[index] + new Vector3(0, 5, 0); if (IsPointInBox(box, boxPosition, p)) { i.Add(p); j.Add(index); } } points = i.ToArray(); indices = j.ToArray(); }
public void OverlapMultiple() { using (var core = CreatePhysicsAndScene()) { // Just up from the ground, 20 units ahead var box1 = CreateBoxActor(core.Scene, 0, 2, 20); var box2 = CreateBoxActor(core.Scene, 0, 2, 40); box1.Name = "Box1"; box2.Name = "Box2"; BoxGeometry overlappingBox = new BoxGeometry(100, 100, 100); var overlap = core.Scene.OverlapMultiple(overlappingBox, Matrix.Identity); Assert.IsNotNull(overlap); Assert.AreEqual(2, overlap.Length); Assert.AreEqual(box2, overlap[0].Actor); Assert.AreEqual(box1, overlap[1].Actor); } }
public void SweepMultiple() { using (var core = CreatePhysicsAndScene()) { // Just up from the ground, 20 units ahead var box1 = CreateBoxActor(core.Scene, 0, 2, 20); var box2 = CreateBoxActor(core.Scene, 0, 2, 40); box1.Name = "Box1"; box2.Name = "Box2"; // Use a box of 10x10x10 to sweep with BoxGeometry sweepBox = new BoxGeometry(10, 10, 10); // Sweep the box forwards 25 units to hit box1 var sweep = core.Scene.SweepMultiple ( sweepBox, Matrix.Translation(0, 2, 0), null, new Vector3(0, 0, 1), 25, SceneQueryFlags.All, 2, null ); Assert.IsNotNull(sweep); Assert.AreEqual(1, sweep.Count()); var hit = sweep.ElementAt(0); Assert.IsNotNull(hit); Assert.IsNotNull(hit.Shape); Assert.AreEqual(box1, hit.Shape.Actor); } }