Exemple #1
0
        void update()
        {
            // randomly add/remove skinned mesh every frame
            for (int i = 0; i < 20; i++)
            {
                var x = r.Next() % N;
                var y = r.Next() % N;

                bool remove                 = !adding;
                var  gpu_skinned_mesh       = r.Next() % 2 == 1 ? model1 : model2;
                GPUAnimation.Animation anim = gpu_skinned_mesh.anim.animations[r.Next(1, gpu_skinned_mesh.anim.animations.Length)];
                var mscale = gpu_skinned_mesh == model1 ? Model1Scale : Vector3.one;

                if (!this.skins[x, y].Initialized() && !remove)
                {
                    var skin = new SkinnedMesh(gpu_skinned_mesh, this.m);
                    skin.SetRadius(1.75f);
                    skin.Initialize();
                    skin.mesh.position = new Vector3(x, this.y_offset, y);
                    skin.mesh.scale    = mscale;
                    skin.SetAnimation(anim, speed: 0.1f + (float)r.NextDouble() * 2.0f, start_time: (float)r.NextDouble());

                    // create & assign path
                    Path path = new Path(path_length: 4, m: this.m, use_constants: true);
                    this.p.InitializePath(ref path);
                    this.p.SetPathConstants(path, new Vector3(0, 1, 0), new Vector3(0, 0, 1), skin.mesh.rotation, skin.mesh.position);
                    this.p.UpdatePath(ref path);
                    skin.mesh.SetPath(path, this.m);

                    skin.UpdateAll();
                    skins[x, y] = skin;
                    paths[x, y] = path;
                }
                else if (this.skins[x, y].Initialized() && remove)
                {
                    skins[x, y].Dispose();
                    this.p.DeletePath(ref paths[x, y]);
                }
            }

            // reset if adding
            time_seconds += Time.deltaTime;
            if (time_seconds > period)
            {
                adding       = !adding;
                time_seconds = 0;
            }
        }