public static Actor CreateCog(StillDesign.PhysX.Scene scene)
        {
            var actorDesc = new ActorDescription();


            float radius  = 6f;
            float radius2 = 6.8f;

            for (int i = 0; i < 16; i++)
            {
                SphereShapeDescription desc = new SphereShapeDescription(0.6f);
                float angle = (i + 0.5f) * MathHelper.TwoPi * (1 / 16f);
                desc.LocalPosition = new Vector3(radius * (float)Math.Sin(angle), radius * (float)Math.Cos(angle), 0);
                actorDesc.Shapes.Add(desc);

                desc = new SphereShapeDescription(0.2f);
                desc.LocalPosition = new Vector3(radius2 * (float)Math.Sin(angle), radius2 * (float)Math.Cos(angle), 0);
                actorDesc.Shapes.Add(desc);
            }



            actorDesc.BodyDescription      = new BodyDescription();
            actorDesc.BodyDescription.Mass = 10;

            actorDesc.GlobalPose = Matrix.CreateRotationX(MathHelper.PiOver2);

            return(scene.CreateActor(actorDesc));
        }
示例#2
0
        public static void RunCharacterTest()
        {
            Core core = new Core();

            StillDesign.PhysX.Scene scene = core.CreateScene();

            ControllerManager manager = scene.CreateControllerManager();

            CapsuleControllerDescription desc = new CapsuleControllerDescription(2, 10);
            CapsuleController            capsuleController = manager.CreateController <CapsuleController>(desc);


            BoxShapeDescription boxShapeDesc = new BoxShapeDescription(1, 1, 1);
            ActorDescription    actorDesc    = new ActorDescription(boxShapeDesc);

            actorDesc.BodyDescription = new BodyDescription(1f);

            Actor actor = scene.CreateActor(actorDesc);

            //capsuleController.Move( Vector3.Up );

            // Update Physics
            scene.Simulate(1.0f / 60.0f);
            scene.FlushStream();
            scene.FetchResults(SimulationStatus.RigidBodyFinished, true);

            capsuleController.Move(Vector3.Up);

            core.Dispose();
        }
        public void Initialize(StillDesign.PhysX.Scene _scene)
        {
            scene = _scene;

            manager = scene.CreateControllerManager();



            CapsuleControllerDescription capsuleControllerDesc = new CapsuleControllerDescription(0.5f, 1);

            controllerHitReport            = new PlayerControllerHitReport();
            capsuleControllerDesc.Callback = controllerHitReport;

            /*{
             *  Callback = new ControllerHitReport()
             * };*/

            CapsuleController capsuleController = manager.CreateController <CapsuleController>(capsuleControllerDesc);

            capsuleController.Position   = player.Position.xna();
            capsuleController.Actor.Name = "PlayerController";
            capsuleController.SetCollisionEnabled(true);


            controller = capsuleController;
        }
 public void UpdateScene(float elapsed, StillDesign.PhysX.Scene scene)
 {
     scene.Simulate(elapsed);
     //_scene.Simulate( 1.0f / 60.0f );
     scene.FlushStream();
     scene.FetchResults(SimulationStatus.RigidBodyFinished, true);
 }
        public void TestSyncOnlineClient()
        {
            var conn = NetworkingUtilities.ConnectTCP(10045, "5.149.17.16");

            //var conn = NetworkingClientTest.ConnectTCP(10045, "127.0.0.1");
            conn.Receiving = true;
            var client = new ClientPacketManagerNetworked(conn);

            var clientSyncer = new ClientSyncer(client);



            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var game = new XNAGame();

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;


                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var client1 = clientSyncer.CreateActor(physicsEngine.Scene.CreateActor(actorDesc));

                client1.ID = 2; // Identify
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);

                clientSyncer.Update(game.Elapsed);
            };

            client.SyncronizeRemotePacketIDs();
            client.WaitForUDPConnected();

            game.Run();

            physicsEngine.Dispose();
        }
示例#6
0
        public static Actor CreateDynamicSphereActor(StillDesign.PhysX.Scene scene, float radius, float mass)
        {
            ActorDescription actorDesc = new ActorDescription(new SphereShapeDescription(radius));

            actorDesc.BodyDescription = new BodyDescription(mass);

            return(scene.CreateActor(actorDesc));
        }
        /// <summary>
        /// You can put a scale (-1) operation in the global pose, it works! (not for convex meshes though!)
        /// NOTE: WARNING: scaling not supported!!! (still not supported, it has been delayed for several reasons)
        /// </summary>
        /// <param name="data"></param>
        /// <param name="scene"></param>
        /// <param name="globalPose"></param>
        /// <returns></returns>
        private ActorDescription createActorDesc(MeshCollisionData data, StillDesign.PhysX.Scene scene, Matrix globalPose)
        {
            // From PhysX SDK:
            //There are some performance implications of compound shapes that the user should be aware of:
            //You should avoid static actors being compounds; there's a limit to the number of triangles allowed in one actor's mesh shapes and subshapes exceeding the limit will be ignored.
            //TODO: is this about triangle meshes only? EDIT: i dont think so



            // Pull scaling out of the transformation
            Vector3    scale, translation;
            Quaternion rotation;

            globalPose.Decompose(out scale, out rotation, out translation);

            //globalPose = Matrix.CreateFromQuaternion(rotation) * Matrix.CreateTranslation(translation);
            var scaleMat = Matrix.Identity;// Matrix.CreateScale(scale);


            ActorDescription actorDesc = new ActorDescription();

            for (int i = 0; i < data.Boxes.Count; i++)
            {
                var box   = data.Boxes[i];
                var shape = new BoxShapeDescription(box.Dimensions);
                shape.LocalPose = box.Orientation * scaleMat;
                actorDesc.Shapes.Add(shape);
            }

            for (int i = 0; i < data.ConvexMeshes.Count; i++)
            {
                var convex = data.ConvexMeshes[i];
                var shape  = new ConvexShapeDescription();
                shape.ConvexMesh = MeshPhysicsPool.CreateConvexMesh(scene, convex);

                shape.Flags = ShapeFlag.Visualization;
                actorDesc.Shapes.Add(shape);
            }



            if (data.TriangleMesh != null)
            {
                TriangleMesh triangleMesh;
                triangleMesh = MeshPhysicsPool.CreateTriangleMesh(scene, data.TriangleMesh);

                TriangleMeshShapeDescription shapeDesc = new TriangleMeshShapeDescription();
                shapeDesc.TriangleMesh = triangleMesh;
                shapeDesc.Flags        = ShapeFlag.Visualization; // Vizualization enabled, obviously (not obviously enabled, obvious that this enables visualization)

                actorDesc.Shapes.Add(shapeDesc);
            }

            actorDesc.GlobalPose = globalPose;
            return(actorDesc);
        }
        public Actor CreateActorStatic(StillDesign.PhysX.Scene scene, MeshCollisionData data, Matrix globalPose)
        {
            ActorDescription actorDesc = createActorDesc(data, scene, globalPose);

            if (actorDesc.Shapes.Count == 0)
            {
                return(null);
            }
            return(scene.CreateActor(actorDesc));
        }
        public Actor CreateActorDynamic(StillDesign.PhysX.Scene scene, MeshCollisionData data, Matrix globalPose)
        {
            ActorDescription actorDesc = createActorDesc(data, scene, globalPose);

            actorDesc.BodyDescription = new BodyDescription(10f); //TODO mass

            if (actorDesc.Shapes.Count == 0)
            {
                return(null);
            }
            return(scene.CreateActor(actorDesc));
        }
        public void Dispose()
        {
            if (Scene != null)
            {
                Scene.Dispose();
                Scene = null;
            }
            //if (_core != null)
            //{
            //    _core.Dispose();

            //}
            //_core = null;
        }
示例#11
0
 internal void disposeInternal()
 {
     if (node != null)
     {
         node.RemoveStaticObject(this);
     }
     builder = null;
     scene   = null;
     if (Actor != null)
     {
         Actor.Dispose();
     }
     Actor = null;
 }
        public void Initialize()
        {
            //
            if (Scene != null)
            {
                return;
            }


            var scene = CreateDefaultScene();

            this.Scene = scene;


            HardwareVersion ver     = Core.HardwareVersion;
            SimulationType  simType = this.Scene.SimulationType;
        }
        public void InitDynamic(StillDesign.PhysX.Scene _scene)
        {
            if (actor != null)
            {
                throw new InvalidOperationException();
            }

            scene          = _scene;
            actor          = Builder.CreateActorDynamic(scene, Mesh.GetCollisionData(), World);
            actor.UserData = actorUserData;
            updateActorFlags();
            var bs = Microsoft.Xna.Framework.BoundingSphere.CreateFromBoundingBox(Builder.CalculateBoundingBox(Mesh.GetCollisionData()));

            boundingRadius = bs.Radius;

            if (ActorCreated != null)
            {
                ActorCreated(actor);
            }
        }
示例#14
0
        public PEngine()
        {
            Stoped    = true;
            Paused    = false;
            Time      = 0;
            LastTime  = 0;
            DeltaTime = 0;
            Ph.CoreDescription CoreDesc = new Ph.CoreDescription();

            PUserOutput UserOut = new PUserOutput();

            Ph.Core core = new Ph.Core(CoreDesc, UserOut);
            Core = core;

            Ph.SceneDescription SceneDesc = new Ph.SceneDescription();
            //grawitacja
            SceneDesc.Gravity            = new PhMath.Vector3(0, 0, 0);
            SceneDesc.TimestepMethod     = Ph.TimestepMethod.Fixed;
            SceneDesc.GroundPlaneEnabled = true;
            Ph.Scene scene = Core.CreateScene(SceneDesc);
            Scene = scene;

            Scene.DefaultMaterial.DynamicFriction        = 0.5f;
            Scene.DefaultMaterial.StaticFriction         = 0.5f;
            Scene.DefaultMaterial.Restitution            = 0f;
            Scene.DefaultMaterial.RestitutionCombineMode = Ph.CombineMode.Minimum;
            Scene.DefaultMaterial.FrictionCombineMode    = Ph.CombineMode.Max;

            core.SetParameter(Ph.PhysicsParameter.VisualizationScale, 1.0f);
            core.SetParameter(Ph.PhysicsParameter.VisualizeCollisionShapes, true);
            core.SetParameter(Ph.PhysicsParameter.VisualizeClothMesh, true);
            core.SetParameter(Ph.PhysicsParameter.VisualizeJointLocalAxes, true);
            core.SetParameter(Ph.PhysicsParameter.VisualizeJointLimits, true);
            core.SetParameter(Ph.PhysicsParameter.VisualizeFluidPosition, true);
            core.SetParameter(Ph.PhysicsParameter.VisualizeFluidEmitters, false); // Slows down rendering a bit too much
            core.SetParameter(Ph.PhysicsParameter.VisualizeForceFields, true);
            core.SetParameter(Ph.PhysicsParameter.VisualizeSoftBodyMesh, true);

            Core.Foundation.RemoteDebugger.Connect("localhost");
        }
        private void InitTestScene(StillDesign.PhysX.Scene scene)
        {
            ActorDescription actorDesc;
            Actor            actor;

            CapsuleShapeDescription capsuleShapeDesc = new CapsuleShapeDescription(1, 3);

            actorDesc = new ActorDescription(capsuleShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalOrientation = Matrix.CreateRotationX(MathHelper.PiOver2);



            BoxShapeDescription boxShapeDesc = new BoxShapeDescription(40, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(0, 4, 0);


            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(40f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(15, 40, 0);

            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(-13, 5, 0);

            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(-7, 5, 0);

            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(-10, 5, 0);

            boxShapeDesc = new BoxShapeDescription(1, 1, 1);

            actorDesc = new ActorDescription(boxShapeDesc);
            actorDesc.BodyDescription = new BodyDescription(1f);

            actor = scene.CreateActor(actorDesc);
            actor.GlobalPosition = new Vector3(-4, 5, 0);
        }
        public void TestSyncOnlineServer()
        {
            var server = new ServerPacketManagerNetworked(10045, 10046);


            var serverSyncer = new ServerSyncer(server);



            server.Start();


            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var game = new XNAGame();
            ServerSyncedActor server1 = null;

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                server1 = serverSyncer.CreateActor(serverScene.CreateActor(actorDesc));
                ((WorldPhysxSyncActor)server1.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Impulse);
                server1.ID = 2; // Identify
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);

                serverSyncer.Update(game.Elapsed);

                if (game.Keyboard.IsKeyDown(Keys.Up))
                {
                    ((WorldPhysxSyncActor)server1.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Force);
                }
                if (game.Keyboard.IsKeyDown(Keys.Down))
                {
                    ((WorldPhysxSyncActor)server1.Actor).Actor.AddForce(-Vector3.UnitX * 200, ForceMode.Force);
                }
            };

            game.Run();

            physicsEngine.Dispose();
        }
        public void TestSyncDirect()
        {
            var client = new ClientSyncedActor();
            var server = new ServerSyncedActor();

            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var   game          = new XNAGame();
            float totalTime     = 0;
            float timeSinceTick = 0;
            float tickRate      = 1 / 30f;
            int   tickNumber    = 0;
            float packetLoss    = 0.25f;

            var rand = new Random();

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                server.Actor = new WorldPhysxSyncActor(serverScene.CreateActor(actorDesc));
                ((WorldPhysxSyncActor)server.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Impulse);

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                client.Actor =
                    new WorldPhysxSyncActor(physicsEngine.Scene.CreateActor(actorDesc));
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);
                totalTime     += game.Elapsed;
                timeSinceTick += game.Elapsed;
                int totalMiliseconds = (int)(totalTime * 1000);

                while (timeSinceTick > tickRate)
                {
                    timeSinceTick -= tickRate;
                    //Do a tick
                    tickNumber++;
                    server.Tick();
                    var p = new UpdateEntityPacket();
                    p.Positie     = server.Positie;
                    p.RotatieQuat = server.RotatieQuat;
                    if (rand.NextDouble() < 1 - packetLoss)
                    {
                        client.AddEntityUpdate(tickNumber, p);
                    }
                }

                client.Process(totalMiliseconds, tickRate);
            };

            game.Run();

            physicsEngine.Dispose();
        }
        public void TestSyncOnline()
        {
            var server  = new ServerPacketManagerNetworked(10045, 10046);
            var success = new AutoResetEvent(false);



            var serverSyncer = new ServerSyncer(server);



            server.Start();

            var conn = NetworkingUtilities.ConnectTCP(10045, "127.0.0.1");

            conn.Receiving = true;
            var client = new ClientPacketManagerNetworked(conn);

            var clientSyncer = new ClientSyncer(client);



            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var game = new XNAGame();

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var server1 = serverSyncer.CreateActor(serverScene.CreateActor(actorDesc));
                ((WorldPhysxSyncActor)server1.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Impulse);

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var client1 = clientSyncer.CreateActor(physicsEngine.Scene.CreateActor(actorDesc));

                client1.ID = server1.ID;                         // Identify
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);

                serverSyncer.Update(game.Elapsed);
                clientSyncer.Update(game.Elapsed);
            };

            client.SyncronizeRemotePacketIDs();
            client.WaitForUDPConnected();

            game.Run();

            physicsEngine.Dispose();
        }
        public void TestSyncOffline()
        {
            var serverpm = new SimpleServerPacketManager();
            var clientpm = serverpm.CreateClient();


            var clientSyncer = new ClientSyncer(clientpm);
            var serverSyncer = new ServerSyncer(serverpm);

            var physicsEngine = new PhysicsEngine();

            StillDesign.PhysX.Scene serverScene = null;

            PhysicsDebugRendererXNA debugRenderer;
            PhysicsDebugRendererXNA debugRendererServer;
            var   game          = new XNAGame();
            float totalTime     = 0;
            float timeSinceTick = 0;
            float tickRate      = 1 / 30f;
            int   tickNumber    = 0;
            float packetLoss    = 0.25f;


            var rand = new Random();

            game.InitializeEvent += delegate
            {
                physicsEngine.Initialize();
                serverScene = physicsEngine.CreateScene(physicsEngine.Scene.Gravity, true);


                debugRenderer = new PhysicsDebugRendererXNA(game, physicsEngine.Scene);
                game.AddXNAObject(debugRenderer);
                debugRendererServer = new PhysicsDebugRendererXNA(game, serverScene);
                game.AddXNAObject(debugRendererServer);

                ActorDescription       actorDesc;
                SphereShapeDescription shape;

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var server = serverSyncer.CreateActor(serverScene.CreateActor(actorDesc));
                ((WorldPhysxSyncActor)server.Actor).Actor.AddForce(Vector3.UnitX * 200, ForceMode.Impulse);

                shape     = new SphereShapeDescription(1);
                actorDesc = new ActorDescription(shape);
                actorDesc.BodyDescription = new BodyDescription(10);

                var client = clientSyncer.CreateActor(physicsEngine.Scene.CreateActor(actorDesc));

                client.ID = server.ID;                         // Identify
            };

            game.UpdateEvent += delegate
            {
                physicsEngine.Update(game);
                physicsEngine.UpdateScene(game.Elapsed, serverScene);

                serverSyncer.Update(game.Elapsed);
                clientSyncer.Update(game.Elapsed);
            };

            game.Run();

            physicsEngine.Dispose();
        }
 /// <summary>
 /// This constructor enables physics
 /// </summary>
 /// <param name="scene"></param>
 /// <param name="center"></param>
 /// <param name="radius"></param>
 public ClientPhysicsTestSphere(StillDesign.PhysX.Scene scene, Vector3 center, float radius)
 {
     this.scene = scene;
     Center     = center;
     Radius     = radius;
 }
 public PhysicsDebugRenderer(DX11Game _game, Scene _physXScene)
 {
     game       = _game;
     physXScene = _physXScene;
     Enabled    = true;
 }
示例#22
0
文件: PhysX.cs 项目: sikora507/OpenC1
 public void Delete()
 {
     Scene.ShutdownWorkerThreads();
     Scene.Dispose();
     Core.Dispose();
     Scene = null;
     Core = null;
     _instance = null;
 }
 public PhysicsDebugRendererXNA(IXNAGame _game, StillDesign.PhysX.Scene _physXScene)
 {
     game       = _game;
     physXScene = _physXScene;
     enabled    = true;
 }
示例#24
0
 public void LoadInClientPhysics(StillDesign.PhysX.Scene _scene, ClientPhysicsQuadTreeNode root)
 {
     scene = _scene;
     //root.OrdenObject(this);
     root.AddStaticObject(this);
 }
        public static TriangleMesh CreateTriangleMesh(Vector3[] positions, int[] indices, StillDesign.PhysX.Scene scene)
        {
            TriangleMeshDescription triangleMeshDesc = new TriangleMeshDescription();

            triangleMeshDesc.AllocateVertices <Vector3>(positions.Length);
            triangleMeshDesc.AllocateTriangles <int>(indices.Length); // int indices, should be short but whatever



            triangleMeshDesc.VerticesStream.SetData(positions);


            triangleMeshDesc.TriangleStream.SetData(indices);

            triangleMeshDesc.VertexCount   = positions.Length;
            triangleMeshDesc.TriangleCount = indices.Length / 3;

            System.IO.MemoryStream stream = new System.IO.MemoryStream();

            Cooking.InitializeCooking();
            Cooking.CookTriangleMesh(triangleMeshDesc, stream);
            Cooking.CloseCooking();

            stream.Position = 0;

            return(scene.Core.CreateTriangleMesh(stream));
        }