Beispiel #1
0
        /**
         * Deforms the mesh to match the proxy shape. The binding proccess (performed by BindToProxy()) must have been
         * performed succesfully before calling this function.
         */
        public void ApplyProxySkinning()
        {
            Vector3[] vertices = deformedMesh.vertices;
            Vector3[] normals  = deformedMesh.normals;
            Vector4[] tangents = deformedMesh.tangents;

            Vector3[] bindNormals  = sharedMesh.normals;
            Vector4[] bindTangents = sharedMesh.tangents;

            Quaternion proxyToLocal = Quaternion.Inverse(transform.rotation) * proxy.transform.rotation;

            for (int i = 0; i < vertices.Length; ++i)
            {
                vertices[i] = Vector3.zero;
                normals[i]  = Vector3.zero;

                // To hold tangent vector temporarily:
                Vector3 tangent = Vector3.zero;

                ParticleInfluence influence;
                for (int j = 0; j < numInfluences; ++j)
                {
                    influence = influences[i * numInfluences + j];

                    // Get current particle position:
                    Vector3 influencePosition = transform.InverseTransformPoint(proxy.GetParticlePosition(influence.particleIndex));

                    // Calculate delta rotation with respect to bind pose rotation, in local space:
                    Quaternion deltaRotation = proxyToLocal * proxy.GetParticleOrientation(influence.particleIndex) *
                                               bindPoses[influence.particleIndex];

                    // Transform vertex positions, normals and tangents according to the proxy binding, all in local space:
                    vertices[i] += influence.weight * (influencePosition + deltaRotation * influence.bindVector);
                    normals[i]  += influence.weight * (deltaRotation * bindNormals[i]);
                    tangent     += influence.weight * (deltaRotation * (Vector3)bindTangents[i]);
                }

                // Reset tangent w (mirror):
                tangents[i].Set(tangent.x, tangent.y, tangent.z, bindTangents[i].w);
            }

            // Assign new data to the mesh and recalculate bounds:
            deformedMesh.vertices = vertices;
            deformedMesh.normals  = normals;
            deformedMesh.tangents = tangents;
            deformedMesh.RecalculateBounds();
        }
Beispiel #2
0
        public override void UpdateParticleEditorInformation()
        {
            for (int i = 0; i < cloth.positions.Length; i++)
            {
                wsPositions[i]    = cloth.GetParticlePosition(i);
                wsOrientations[i] = cloth.GetParticleOrientation(i);
            }

            if (cloth.clothMesh != null && Camera.current != null)
            {
                for (int i = 0; i < cloth.clothMesh.vertexCount; i++)
                {
                    int     particle      = cloth.topology.visualMap[i];
                    Vector3 camToParticle = Camera.current.transform.position - wsPositions[particle];

                    sqrDistanceToCamera[particle] = camToParticle.sqrMagnitude;
                    facingCamera[particle]        = (Vector3.Dot(cloth.ActorLocalToWorldMatrix.MultiplyVector(cloth.MeshNormals[i]), camToParticle) > 0);
                }
            }
        }