コード例 #1
0
        /// <summary>
        ///  Initialize a mesh instance. This will automatically set the IInstanceMeshData.id, and groupID
        /// as well as IGPUInstance.gpu_initialized fields. **For this function, Only set the data.parentID to an Instane who has already been initialized
        /// by the MeshInstancer.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        public void Initialize <T>(ref InstanceData <T> data) where T : InstanceDataProps
        {
            lock (this._instance_lock)
            {
                //initialize if necessary
                if (!data.gpu_initialized)
                {
                    int free_id      = this.mesh.IDs.GetNewID();
                    int free_prop_id = data.HasProperties ? this.mesh.PropertyIDs.GetNewID() : instancemesh.NULL_ID;

                    data.id              = free_id; //assign free gpu id
                    data.propertyID      = free_prop_id;
                    data.gpu_initialized = true;    //set to initialized

                    if (data.parentID < 0)
                    {
                        data.parentID = instancemesh.NULL_ID;
                    }

                    if (ReferenceEquals(null, data.mesh_type))
                    {
                        throw new System.Exception("Error, must have a non-null mesh type for instance");
                    }

                    data.groupID = data.mesh_type.groupID; //set type
                    return;
                }
                else
                {
                    throw new System.Exception("Error, input data already initialized.");
                }
            }
        }
コード例 #2
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;
            }
        }
コード例 #3
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;
 }
コード例 #4
0
ファイル: GPUMesh.cs プロジェクト: mkrebser/GPUInstance
        public GPUMesh(GPUMeshComponent c, MeshInstancer m, bool has_props = true)
        {
            if (!c.Initialized())
            {
                throw new System.Exception("Error, input GPUMeshComponent must be added to MeshInstancer before creating instances!");
            }

            this.mesh  = new InstanceData <InstanceProperties>(c.MeshTypes[0], has_props);
            this.m     = m;
            this._init = false;
        }
コード例 #5
0
        /// <summary>
        ///  Append an item to the update buffer.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"> data to be appended. The input data will be modified. </param>
        public void Append <T>(ref InstanceData <T> data) where T : InstanceDataProps
        {
            lock (this._instance_lock)
            {
                if (data.DirtyFlags == DirtyFlag.None)
                {
                    return;
                }

                if (!data.gpu_initialized)
                {
                    throw new System.Exception("Error, cannot update uninitialized data");
                }

                this.mesh.Set <InstanceData <T> >(data);

                data.DirtyFlags = DirtyFlag.None;//set not dirty
                return;
            }
        }
コード例 #6
0
        /// <summary>
        ///  Delete a mesh instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        public void Delete <T>(ref InstanceData <T> data) where T : InstanceDataProps
        {
            lock (this._instance_lock)
            {
                if (data.id == instancemesh.NULL_ID)
                {
                    throw new System.Exception("Error, input id to delete is 0 (NULL)");
                }
                if (data.id < 0)
                {
                    throw new System.Exception("No negative ids");
                }
                if (!data.gpu_initialized)
                {
                    throw new System.Exception("Error, not initialized");
                }
                if (ReferenceEquals(null, data.mesh_type) || data.groupID == instancemesh.NULL_ID)
                {
                    throw new System.Exception("Error, input instance data does not have an assigned mesh type!");
                }
                if ((data.HasProperties && data.propertyID == instancemesh.NULL_ID) || (!data.HasProperties && data.propertyID != instancemesh.NULL_ID))
                {
                    throw new System.Exception("Error, input propertyID is invalid");
                }
                if (data.propertyID < 0)
                {
                    throw new System.Exception("Error, input propertyID is negative.");
                }

                mesh.Delete(data);
                this.mesh.IDs.ReleaseID(data.id);
                if (data.HasProperties)
                {
                    this.mesh.PropertyIDs.ReleaseID(data.propertyID);
                }

                data.id = instancemesh.NULL_ID;
                data.gpu_initialized = false;
                data.parentID        = instancemesh.NULL_ID;
            }
        }
コード例 #7
0
ファイル: GPUMesh.cs プロジェクト: mkrebser/GPUInstance
 public GPUMesh(MeshType c, MeshInstancer m, bool has_props = true)
 {
     this.mesh  = new InstanceData <InstanceProperties>(c, has_props);
     this.m     = m;
     this._init = false;
 }