Exemplo n.º 1
0
        private void GenerateCrossfadeFrame()
        {
            if (currentCrossFade.generatedFrame == currentCrossFade.currentFrame)
            {
                return;
            }
            int vertexCount = currentCrossFade.toFrame.verts.Length;

            currentCrossFade.PopulateFrame(vertexCount);
            Vector3[] from = currentCrossFade.fromFrame.verts;
            Vector3[] to   = currentCrossFade.toFrame.verts;
            // generate the frames for the crossfade
            CrossFadeFrameData frame  = currentCrossFade.frame;
            Vector3            center = Vector3.zero;
            Vector3            min    = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Vector3            max    = new Vector3(float.MinValue, float.MinValue, float.MinValue);
            float delta = currentCrossFade.currentFrame / (float)currentCrossFade.framesNeeded;

            for (int j = 0; j < frame.positions.Length; j++)
            {
                Vector3 pos = Vector3.Lerp(from[j], to[j], delta);
                if (pos.x < min.x)
                {
                    min.x = pos.x;
                }
                if (pos.y < min.y)
                {
                    min.y = pos.y;
                }
                if (pos.z < min.z)
                {
                    min.z = pos.z;
                }
                if (pos.x > max.x)
                {
                    max.x = pos.x;
                }
                if (pos.y > max.y)
                {
                    max.y = pos.y;
                }
                if (pos.z > max.z)
                {
                    max.z = pos.z;
                }
                center            += pos;
                frame.positions[j] = pos;
            }
            center /= frame.positions.Length;
            currentCrossFade.frame          = frame;
            currentCrossFade.frame.bounds   = new Bounds(center, max - min);
            currentCrossFade.generatedFrame = currentCrossFade.currentFrame;
        }
Exemplo n.º 2
0
 public void PopulateFrame(int length)
 {
     if (frame == null)
     {
         frame = new CrossFadeFrameData();
     }
     if (frame.positions == null)
     {
         frame.positions = AllocatedArray <Vector3> .Get(length);
     }
     if (frame.normals == null)
     {
         frame.normals = AllocatedArray <Vector3> .Get(length);
     }
 }