Esempio n. 1
0
        static bool Prefix(ref RenderManager.CameraInfo cameraInfo, ref TreeInfo info, Vector3 position, float scale, float brightness, Vector4 objectIndex)
        {
            if (info.m_prefabInitialized)
            {
                if (cameraInfo == null || (UnityEngine.Object)info.m_lodMesh1 == (UnityEngine.Object)null || cameraInfo.CheckRenderDistance(position, info.m_lodRenderDistance))
                {
                    var instance = Singleton <TreeManager> .instance;
                    if (instance == null)
                    {
                        return(false);
                    }
                    var materialBlock = instance.m_materialBlock;
                    var matrix        = default(Matrix4x4);

                    Quaternion rotation;
                    lock (App.Config.GraphicsLock) {
                        if (App.Config.Graphics.randomTrees)
                        {
                            #if false
                            UInt32 randIdent =
                                ((UInt32)info.GetInstanceID() << 16) |
                                (((UInt32)(BitConverter.DoubleToInt64Bits(position.magnitude) >> 32)) & 0xFFFF)
                            ;
                            var r = new System.Random((int)randIdent);
                            //Log.Debug($"tree rand: {Convert.ToString(randIdent, 2)}, {r.NextDouble() * 360}");

                            rotation = Quaternion.Euler(0, (float)r.NextDouble() * 360, 0);
                            #endif

                            // same angle as in "Random Tree Rotation" mod
                            long setofBits = BitConverter.DoubleToInt64Bits(position.magnitude);
                            rotation = Quaternion.Euler(0, setofBits % 360, 0);
                        }
                        else
                        {
                            rotation = Quaternion.identity;
                        }
                    }

                    matrix.SetTRS(position, rotation, new Vector3(scale, scale, scale));

                    var color = info.m_defaultColor * brightness;
                    color.a = Singleton <WeatherManager> .instance.GetWindSpeed(position);

                    lock (App.Config.GraphicsLock) {
                        color.a *= App.Config.Graphics.treeMoveFactor;
                    }

                    materialBlock.Clear();
                    materialBlock.SetColor(instance.ID_Color, color);
                    materialBlock.SetVector(instance.ID_ObjectIndex, objectIndex);
                    instance.m_drawCallData.m_defaultCalls++;

                    Graphics.DrawMesh(info.m_mesh, matrix, info.m_material, info.m_prefabDataLayer, null, 0, materialBlock);
                }
                else
                {
                    position.y += info.m_generatedInfo.m_center.y * (scale - 1f);

                    var color = info.m_defaultColor * brightness;
                    color.a = Singleton <WeatherManager> .instance.GetWindSpeed(position);

                    lock (App.Config.GraphicsLock) {
                        color.a *= App.Config.Graphics.treeMoveFactor;
                    }

                    info.m_lodLocations[info.m_lodCount]     = new Vector4(position.x, position.y, position.z, scale);
                    info.m_lodColors[info.m_lodCount]        = color.linear;
                    info.m_lodObjectIndices[info.m_lodCount] = objectIndex;
                    info.m_lodMin = Vector3.Min(info.m_lodMin, position);
                    info.m_lodMax = Vector3.Max(info.m_lodMax, position);

                    if (++info.m_lodCount == info.m_lodLocations.Length)
                    {
                        TreeInstance.RenderLod(cameraInfo, info);
                    }
                }
            }
            return(false);
        }