public override dNewtonCollision Create(NewtonWorld world)
        {
            dNewtonCollision shape = base.Create(world);

            m_Scale.y = 1.0f;
            return(shape);
        }
示例#2
0
        public override dNewtonCollision Create(NewtonWorld world)
        {
            if (m_Mesh == null)
            {
                return(null);
            }

            if (m_Mesh.triangles.Length < 3)
            {
                return(null);
            }

            Vector3 scale = GetBaseScale();

            if (m_FreezeScale == false)
            {
                scale = new Vector3(1.0f, 1.0f, 1.0f);
            }

            Vector3[] vertices    = m_Mesh.vertices;
            float[]   triVertices = new float[3 * 3];
            IntPtr    floatsPtr   = Marshal.AllocHGlobal(3 * 3 * Marshal.SizeOf(typeof(float)));

            dNewtonCollisionMesh collision = new dNewtonCollisionMesh(world.GetWorld());

            collision.BeginFace();
            for (int i = 0; i < m_Mesh.subMeshCount; i++)
            {
                int[] submesh = m_Mesh.GetTriangles(i);
                for (int j = 0; j < submesh.Length; j += 3)
                {
                    int k = submesh[j];
                    triVertices[0] = vertices[k].x * scale.x;
                    triVertices[1] = vertices[k].y * scale.y;
                    triVertices[2] = vertices[k].z * scale.z;

                    k = submesh[j + 1];
                    triVertices[3] = vertices[k].x * scale.x;
                    triVertices[4] = vertices[k].y * scale.y;
                    triVertices[5] = vertices[k].z * scale.z;

                    k = submesh[j + 2];
                    triVertices[6] = vertices[k].x * scale.x;
                    triVertices[7] = vertices[k].y * scale.y;
                    triVertices[8] = vertices[k].z * scale.z;

                    Marshal.Copy(triVertices, 0, floatsPtr, triVertices.Length);
                    collision.AddFace(3, floatsPtr, 3 * sizeof(float), i);
                }
            }

            collision.EndFace(m_Optimize);
            Marshal.FreeHGlobal(floatsPtr);

            m_IsTrigger = false;
            SetMaterial(collision);
            SetLayer(collision);
            return(collision);
        }
        public override dNewtonCollision Create(NewtonWorld world)
        {
            dNewtonCollision collider = new dNewtonCollisionCapsule(world.GetWorld(), m_Radius0, m_Radius1, m_Height);

            SetMaterial(collider);
            SetLayer(collider);
            return(collider);
        }
示例#4
0
        public override dNewtonCollision Create(NewtonWorld world)
        {
            dNewtonCollisionScene collider = new dNewtonCollisionScene(world.GetWorld());

            SetMaterial(collider);
            SetLayer(collider);
            return(collider);
        }
        public override dNewtonCollision Create(NewtonWorld world)
        {
            dNewtonCollision collider = new dNewtonCollisionSphere(world.GetWorld(), m_Radius);

            SetMaterial(collider);
            SetLayer(collider);
            return(collider);
        }
示例#6
0
 public override dNewtonCollision Create(NewtonWorld world)
 {
     dNewtonCollision collider = new dNewtonCollisionChamferedCylinder(world.GetWorld(), m_Radius, m_Height);
     SetMaterial(collider);
     SetLayer(collider);
     m_Scale.y = 4.0f;
     return collider;
 }
        public override dNewtonCollision Create(NewtonWorld world)
        {
            dNewtonCollision collider = new dNewtonCollisionBox(world.GetWorld(), m_Size.x, m_Size.y, m_Size.z);

            SetMaterial(collider);
            SetLayer(collider);
            return(collider);
        }
        public dNewtonCollision CreateBodyShape(NewtonWorld world)
        {
            dNewtonCollision shape = Create(world);

            if (shape != null)
            {
                UpdateParams(shape);
            }
            return(shape);
        }
        void OnDestroy()
        {
            if (ReferenceEquals(s_Current, this))
            {
                s_Current = null;
            }

            DestroyScene();
            m_onWorldCallback = null;
            m_onWorldBodyTransfromUpdateCallback = null;
        }
        private void Awake()
        {
            if (ReferenceEquals(s_Current, null))
            {
                s_Current = this;
            }
            else if (!ReferenceEquals(s_Current, this))
            {
                Destroy(this);
            }

            m_onWorldCallback = new OnWorldUpdateCallback(OnWorldUpdate);
            m_onWorldBodyTransfromUpdateCallback = new OnWorldBodyTransfromUpdateCallback(OnBodyTransformUpdate);

            m_World.SetAsyncUpdate(m_AsyncUpdate);
            m_World.SetFrameRate(1f / Time.fixedDeltaTime);
            m_World.SetThreadsCount(m_NumberOfThreads);
            m_World.SetSolverIterations(m_SolverIterationsCount);
            m_World.SetBroadPhase(m_BroadPhaseType);
            m_World.SetGravity(m_Gravity.x, m_Gravity.y, m_Gravity.z);
            m_World.SetSubSteps(m_SubSteps);
            m_World.SetParallelSolverOnLargeIsland(m_UseParallerSolver);
            m_World.SetDefaultMaterial(m_DefaultRestitution, m_DefaultStaticFriction, m_DefaultKineticFriction, true);
            m_World.SetCallbacks(m_onWorldCallback, m_onWorldBodyTransfromUpdateCallback);

            //Load all physics plug ins and choose the best one
            m_World.SelectPlugin(IntPtr.Zero);
            if (m_UseParallerSolver && (m_PluginsOptions > 0))
            {
                string path = Application.dataPath;
                m_World.LoadPlugins(path);
                int index = 1;
                for (IntPtr plugin = m_World.FirstPlugin(); plugin != IntPtr.Zero; plugin = m_World.NextPlugin(plugin))
                {
                    if (index == m_PluginsOptions)
                    {
                        Debug.Log("Using newton physics solver: " + m_World.GetPluginName(plugin));
                        m_World.SelectPlugin(plugin);
                    }
                    index++;
                }
            }
            else
            {
                m_World.UnloadPlugins();
            }

            InitScene();
        }
示例#11
0
        public override dNewtonCollision Create(NewtonWorld world)
        {
            TerrainData data = m_terrain.terrainData;
            //Debug.Log("xxxx  " + data.alphamapWidth + "   xxx  " + data.detailHeight);
            //Debug.Log("xxxx  " + data.heightmapScale);
            //Debug.Log("xxxx  " + data.size);

            int     resolution = data.heightmapResolution;
            dVector scale      = new dVector(data.size.x, data.size.y, data.size.z, 0.0f);

            m_oldSize       = data.size;
            m_oldResolution = resolution;

            data.GetHeights(0, 0, resolution, resolution);

            int   hash           = 0;
            float elevationScale = data.size.y;

            float[] elevation = new float[resolution * resolution];
            for (int z = 0; z < resolution; z++)
            {
                for (int x = 0; x < resolution; x++)
                {
                    float value = data.GetHeight(x, z);
                    elevation[z * resolution + x] = value;
                    hash = Utils.dRand((int)(elevationScale * value), hash);
                }
            }
            m_elevationHash = hash;

            IntPtr elevationPtr = Marshal.AllocHGlobal(resolution * resolution * Marshal.SizeOf(typeof(float)));

            Marshal.Copy(elevation, 0, elevationPtr, elevation.Length);
            dNewtonCollision collider = new dNewtonCollisionHeightField(world.GetWorld(), elevationPtr, resolution, scale);

            Marshal.FreeHGlobal(elevationPtr);

            SetDefualtParams();
            SetMaterial(collider);
            SetLayer(collider);
            return(collider);
        }
示例#12
0
        public override dNewtonCollision Create(NewtonWorld world)
        {
            if (m_Mesh == null)
            {
                return(null);
            }

            if (m_Mesh.vertices.Length < 4)
            {
                return(null);
            }

            float[] array = new float[3 * m_Mesh.vertices.Length];
            for (int i = 0; i < m_Mesh.vertices.Length; i++)
            {
                array[i * 3 + 0] = m_Mesh.vertices[i].x;
                array[i * 3 + 1] = m_Mesh.vertices[i].y;
                array[i * 3 + 2] = m_Mesh.vertices[i].z;
            }

            IntPtr floatsPtr = Marshal.AllocHGlobal(array.Length * Marshal.SizeOf(typeof(float)));

            Marshal.Copy(array, 0, floatsPtr, array.Length);
            dNewtonCollision collision = new dNewtonCollisionConvexHull(world.GetWorld(), m_Mesh.vertices.Length, floatsPtr, 0.01f * (1.0f - m_Quality));

            if (collision.IsValid() == false)
            {
                collision.Dispose();
                collision = null;
            }
            Marshal.FreeHGlobal(floatsPtr);

            SetMaterial(collision);
            SetLayer(collision);
            return(collision);
        }
 abstract public dNewtonCollision Create(NewtonWorld world);
 public override dNewtonCollision Create(NewtonWorld world)
 {
     return(new dNewtonCollisionNull(world.GetWorld()));
 }