Exemplo n.º 1
0
        public SkinnedMesh(GPUSkinnedMeshComponent c, MeshInstancer m, int initial_lod = MeshInstancer.MaxLODLevel)
        {
            if (!c.Initialized())
            {
                throw new System.Exception("Error, input GPUSkinnedMeshComponent must be added to MeshInstancer before creating instances!");
            }

            this.skeleton         = new Skeleton(c.anim, m);
            this.m                = m;
            this._init            = false;
            this._anim_tick_start = 0;
            this._current_anim    = null;

            // create parent mesh instance
            this.mesh = new InstanceData <InstanceProperties>(c.MeshTypes[initial_lod][0]);

            // create other additional instances if this skinned mesh needs multiple instances
            if (c.MeshTypes[0].Length > 1)
            {
                this.sub_mesh = new InstanceData <InstanceProperties> [c.MeshTypes[0].Length - 1];
                for (int i = 1; i < c.MeshTypes[0].Length; i++)
                {
                    this.sub_mesh[i - 1] = new InstanceData <InstanceProperties>(c.MeshTypes[initial_lod][i]);
                }
            }
            else
            {
                this.sub_mesh = null;
            }
        }
Exemplo n.º 2
0
 public SkinnedMesh(MeshType mesh, AnimationController anim, MeshInstancer m)
 {
     this.skeleton         = new Skeleton(anim, m);
     this.mesh             = new InstanceData <InstanceProperties>(mesh);
     this.m                = m;
     this._init            = false;
     this._anim_tick_start = 0;
     this._current_anim    = null;
     this.sub_mesh         = null;
 }
Exemplo n.º 3
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;
            }
        }