示例#1
0
文件: Testbed.cs 项目: vr3dvr/FastLSM
    // Update is called once per frame
    void Update()
    {
        for (int i = 0; i != mBodies.Count; ++i)
        {
            DeformableModel body = mBodies[i];

            body.ShapeMatch();
            body.CalculateParticleVelocities(h);
            body.PerformRegionDamping();
            body.ApplyParticleVelocities(h);

            for (int j = 0; j != body.mParticles.Count; ++j)
            {
                SmParticle particle = body.mParticles[j];
                particle.mF += vGravity;

                if (particle.mX.y < 0.0f)
                {
                    particle.mF.y -= particle.mX.y;
                    //particle.mF = Vector3.zero;
                    particle.mV   = Vector3.zero;
                    particle.mX.y = 0.0f;

                    //Debug.Log("Touch[" + j.ToString() + "]");
                }
            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (null != mDeformableModel)
        {
            mDeformableModel.ShapeMatch();
            mDeformableModel.CalculateParticleVelocities(h);
            mDeformableModel.PerformRegionDamping();
            mDeformableModel.ApplyParticleVelocities(h);


            for (int j = 0; j != mDeformableModel.mParticles.Count; ++j)
            {
                SmParticle particle = mDeformableModel.mParticles[j];
                particle.mF += vGravity;

                if (particle.mX.y < 0.0f)
                {
                    particle.mF.y -= particle.mX.y;
                    particle.mV    = Vector3.zero;
                    particle.mX.y  = 0.0f;
                }
            }
        }

        //deform mesh
        for (int x = 0; x != mCellInfos.GetLength(0); ++x)
        {
            for (int y = 0; y != mCellInfos.GetLength(1); ++y)
            {
                for (int z = 0; z != mCellInfos.GetLength(2); ++z)
                {
                    SmCellInfo info = mCellInfos[x, y, z];
                    if (info.mValid)
                    {
                        LatticeLocation ll = mDeformableModel.GetLatticeLocation(new Point3(x, y, z));
                        if (null == ll)
                        {
                            continue;
                        }

                        for (int w = 0; w != info.mVertices.Count; ++w)
                        {
                            VertexPosition vp = info.mVertices[w];

                            mMeshVertices[vp.mMeshIndex][vp.mVertexIndex] =
                                ll.mParticles[0].mX * (1.0f - vp.mOriginPosition.x) * (1.0f - vp.mOriginPosition.y) * (1.0f - vp.mOriginPosition.z) +
                                ll.mParticles[1].mX * (vp.mOriginPosition.x) * (1.0f - vp.mOriginPosition.y) * (1.0f - vp.mOriginPosition.z) +
                                ll.mParticles[3].mX * (1.0f - vp.mOriginPosition.x) * (1.0f - vp.mOriginPosition.y) * (vp.mOriginPosition.z) +
                                ll.mParticles[2].mX * (1.0f - vp.mOriginPosition.x) * (vp.mOriginPosition.y) * (1.0f - vp.mOriginPosition.z) +
                                ll.mParticles[6].mX * (vp.mOriginPosition.x) * (vp.mOriginPosition.y) * (1.0f - vp.mOriginPosition.z) +
                                ll.mParticles[5].mX * (1.0f - vp.mOriginPosition.x) * (vp.mOriginPosition.y) * (vp.mOriginPosition.z) +
                                ll.mParticles[4].mX * (vp.mOriginPosition.x) * (1.0f - vp.mOriginPosition.y) * (vp.mOriginPosition.z) +
                                ll.mParticles[7].mX * (vp.mOriginPosition.x) * (vp.mOriginPosition.y) * (vp.mOriginPosition.z);
                        }
                    }
                }
            }
        }

        Vector3 vLocal  = Vector3.zero;
        Vector3 vOrigin = Vector3.zero;

        for (int i = 0; i != mMeshFilters.Length; ++i)
        {
            MeshFilter mf = mMeshFilters[i];


            for (int j = 0; j != mMeshVertices[i].Length; ++j)
            {
                vLocal              = mMeshVertices[i][j];
                vOrigin             = mMeshTransforms[i].InverseTransformPoint(transform.TransformPoint(vLocal));
                mMeshVertices[i][j] = vOrigin;
            }

            mf.mesh.vertices = mMeshVertices[i];
            mf.mesh.RecalculateNormals();
            mf.mesh.RecalculateBounds();
        }
    }