public UNPhysicsTemplate(Vector3 position, float spreadX, float spreadZ, int densityIndex, FoliagePrototype prototype)
 {
     this.position     = position;
     this.spread.x     = spreadX;
     this.spread.y     = spreadZ;
     this.densityIndex = densityIndex;
     this.prototype    = prototype;
 }
示例#2
0
        /// <summary>
        /// This method will make sure that the map exists and if it doesnt it will create it.
        ///
        /// Used mainly for the rendering so if the user accidently/ purposely removed the grass map it will automatically generate a new one so it wont affect the system.
        /// </summary>
        /// <param name="manager"></param>
        /// <returns></returns>
        public Texture2D SafeGetMap(FoliagePrototype prototype, FoliageManagerInstance instance)
        {
            if (map == null)
            {
                map = UNMapGenerators.GenerateGrassMap(prototype.id, instance);
                UpdateMap();
            }

            return(map);
        }
示例#3
0
        public static FoliageGrassMap CreateGrassMap(int prototypeIndex, FoliageManagerInstance mInstance)
        {
            FoliagePrototype prototype = FoliageDB.sortedPrototypes[prototypeIndex];

            FoliageGrassMap grassMap = new FoliageGrassMap(GenerateGrassMap(prototypeIndex, mInstance), prototype, mInstance);

            grassMap.UpdateMap();

            return(grassMap);
        }
示例#4
0
        public UNBatcMeshhProcessingTask(List <UNCombineInstance> _instances, Material _material, Mesh _mesh, FoliagePrototype _prototype, bool _multiThread, bool _applyInstantly, int _lastID)
        {
            instances      = _instances;
            material       = _material;
            mesh           = _mesh;
            multiThread    = _multiThread;
            applyInstantly = _applyInstantly;

            prototype = _prototype;

            lastID = _lastID;

            meshData = prototype.FoliageInstancedMeshData.meshData;
        }
示例#5
0
        public static void CombineMeshes(List <UNCombineInstance> FoliageInstances, Material _mat, Mesh mesh, FoliagePrototype prototype, bool multiThread, int sortingID, bool applyInstantly, System.Action <UNBatchTask> onDone)
        {
            if (FoliageInstances.Count == 0)
            {
                mesh.Clear(); // clear mesh as its null at the moment.
                return;
            }

            var processTask = new Threading.ThreadTask <UNBatcMeshhProcessingTask>((UNBatcMeshhProcessingTask process) =>
            {
                if (process.instances.Count <= 0)
                {
                    return;
                }

                int instancesCount = process.instances.Count;

                UNMeshData meshData = process.meshData;

                Vector3[] vertices = new Vector3[meshData.verticesLength * instancesCount];
                Vector3[] normals  = new Vector3[meshData.normalsLength * instancesCount];
                Vector2[] uv1s     = new Vector2[meshData.uv1sLength * instancesCount];
                Vector2[] uv2s     = new Vector2[meshData.verticesLength * instancesCount];
                Vector2[] uv3s     = new Vector2[meshData.verticesLength * instancesCount];
                Vector2[] uv4s     = new Vector2[meshData.verticesLength * instancesCount];
                int[] subMeshes    = new int[meshData.trianglesLength * instancesCount];

                int verticesOffset  = 0;
                int normalsOffset   = 0;
                int uv1sOffset      = 0;
                int uv2sOffset      = 0;
                int subMeshesOffset = 0;

                for (int i = 0; i < process.instances.Count; i++)
                {
                    MergeMesh(process.instances[i], i, process.material, vertices, normals, uv1s, uv2s, uv3s, uv4s, subMeshes, meshData, verticesOffset, normalsOffset, uv1sOffset, uv2sOffset, subMeshesOffset);

                    verticesOffset  += meshData.verticesLength;
                    normalsOffset   += meshData.normalsLength;
                    uv1sOffset      += meshData.uv1sLength;
                    uv2sOffset      += meshData.verticesLength;
                    subMeshesOffset += meshData.trianglesLength;
                }

                UNBatchTask batchTask = new UNBatchTask(vertices, normals, uv1s, uv2s, uv3s, uv4s, subMeshes, process.mesh, process.lastID);
                Threading.ThreadTask <UNBatchTask, bool, System.Action <UNBatchTask> > batckTaskInstance = new Threading.ThreadTask <UNBatchTask, bool, System.Action <UNBatchTask> >((UNBatchTask _batchTask, bool _applyInstantely, System.Action <UNBatchTask> _action) =>
                {
                    _batchTask.Apply();

                    if (_action != null)
                    {
                        _action(_batchTask);
                    }
                }, batchTask, process.applyInstantly, onDone);

                if (process.multiThread)
                {
                    Threading.ThreadManager.instance.RunOnUnityThread(batckTaskInstance);
                }
                else
                {
                    batckTaskInstance.Invoke();
                }
            }, new UNBatcMeshhProcessingTask(FoliageInstances, _mat, mesh, prototype, multiThread, applyInstantly, sortingID));

            if (multiThread)
            {
                Threading.ThreadManager.instance.RunOnThread(processTask);
            }
            else
            {
                processTask.Invoke();
            }
        }
示例#6
0
 public FoliageGrassMap(Texture2D texture, Color32[] pixels, FoliagePrototype prototype, FoliageManagerInstance mInstance) : base(texture, pixels, mInstance)
 {
     _prototypeID = prototype.id;
 }
示例#7
0
 public FoliageGrassMap(Texture2D texture, FoliagePrototype prototype, FoliageManagerInstance mInstance) : this(texture, texture.GetPixels32(), prototype, mInstance)
 {
 }