Exemplo n.º 1
0
        public override void RenderCloneGeometry(InstanceState instanceState, ref Matrix4x4 matrix4x, Vector3 deltaPosition, float deltaAngle, Vector3 center, bool followTerrain, RenderManager.CameraInfo cameraInfo, Color toolColor)
        {
            TreeState state = instanceState as TreeState;

            TreeInfo info = state.info as TreeInfo;

            Randomizer randomizer = new Randomizer(state.instance.id.Tree);
            float      scale      = info.m_minScale + (float)randomizer.Int32(10000u) * (info.m_maxScale - info.m_minScale) * 0.0001f;
            float      brightness = info.m_minBrightness + (float)randomizer.Int32(10000u) * (info.m_maxBrightness - info.m_minBrightness) * 0.0001f;

            Vector3 newPosition = matrix4x.MultiplyPoint(state.position - center);

            newPosition.y = state.position.y + deltaPosition.y;

            if (followTerrain)
            {
                newPosition.y = newPosition.y - state.terrainHeight + TerrainManager.instance.SampleOriginalRawHeightSmooth(newPosition);
            }

            TreeInstance.RenderInstance(cameraInfo, info, newPosition, scale, brightness, RenderManager.DefaultColorLocation);
        }
Exemplo n.º 2
0
        public static bool RenderInstancePrefix(NetLane __instance, RenderManager.CameraInfo cameraInfo, ushort segmentID, uint laneID, NetInfo.Lane laneInfo, NetNode.Flags startFlags, NetNode.Flags endFlags, Color startColor, Color endColor, float startAngle, float endAngle, bool invert, int layerMask, Vector4 objectIndex1, Vector4 objectIndex2, ref RenderManager.Instance data, ref int propIndex)
        {
            NetLaneProps laneProps = laneInfo.m_laneProps;

            if (!(laneProps != null) || laneProps.m_props == null)
            {
                return(false);
            }
            bool flag  = (laneInfo.m_finalDirection & NetInfo.Direction.Both) == NetInfo.Direction.Backward || (laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == NetInfo.Direction.AvoidForward;
            bool flag2 = flag != invert;

            if (flag)
            {
                NetNode.Flags flags = startFlags;
                startFlags = endFlags;
                endFlags   = flags;
            }
            Texture _HeightMap       = null;
            Vector4 _HeightMapping   = Vector4.zero;
            Vector4 _SurfaceMapping  = Vector4.zero;
            Texture _HeightMap2      = null;
            Vector4 _HeightMapping2  = Vector4.zero;
            Vector4 _SurfaceMapping2 = Vector4.zero;
            int     num = laneProps.m_props.Length;

            for (int i = 0; i < num; i++)
            {
                NetLaneProps.Prop prop = laneProps.m_props[i];
                if (__instance.m_length < prop.m_minLength)
                {
                    continue;
                }
                int num2 = 2;
                if (prop.m_repeatDistance > 1f)
                {
                    num2 *= Mathf.Max(1, Mathf.RoundToInt(__instance.m_length / prop.m_repeatDistance));
                }
                int num3 = propIndex;
                if (propIndex != -1)
                {
                    propIndex = num3 + (num2 + 1 >> 1);
                }
                if (!prop.CheckFlags((NetLane.Flags)__instance.m_flags, startFlags, endFlags))
                {
                    continue;
                }
                float num4 = prop.m_segmentOffset * 0.5f;
                if (__instance.m_length != 0f)
                {
                    num4 = Mathf.Clamp(num4 + prop.m_position.z / __instance.m_length, -0.5f, 0.5f);
                }
                if (flag2)
                {
                    num4 = 0f - num4;
                }
                PropInfo finalProp = prop.m_finalProp;
                if (finalProp != null && (layerMask & (1 << finalProp.m_prefabDataLayer)) != 0)
                {
                    Color      color = (prop.m_colorMode != NetLaneProps.ColorMode.EndState) ? startColor : endColor;
                    Randomizer r     = new Randomizer((int)laneID + i);
                    for (int j = 1; j <= num2; j += 2)
                    {
                        if (r.Int32(100u) >= prop.m_probability)
                        {
                            continue;
                        }
                        float    num5      = num4 + (float)j / (float)num2;
                        PropInfo variation = finalProp.GetVariation(ref r);
                        float    scale     = variation.m_minScale + (float)r.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f;
                        if (prop.m_colorMode == NetLaneProps.ColorMode.Default)
                        {
                            color = variation.GetColor(ref r);
                        }
                        Vector3 vector = __instance.m_bezier.Position(num5);
                        if (propIndex != -1)
                        {
                            vector.y = (float)(int)data.m_extraData.GetUShort(num3++) * 0.015625f;
                        }
                        vector.y += prop.m_position.y;
                        if (!cameraInfo.CheckRenderDistance(vector, variation.m_maxRenderDistance))
                        {
                            continue;
                        }
                        Vector3 vector2 = __instance.m_bezier.Tangent(num5);
                        if (!(vector2 != Vector3.zero))
                        {
                            continue;
                        }
                        if (flag2)
                        {
                            vector2 = -vector2;
                        }
                        vector2.y = 0f;
                        if (prop.m_position.x != 0f)
                        {
                            vector2   = Vector3.Normalize(vector2);
                            vector.x += vector2.z * prop.m_position.x;
                            vector.z -= vector2.x * prop.m_position.x;
                        }
                        float num6 = Mathf.Atan2(vector2.x, 0f - vector2.z);
                        if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f)
                        {
                            float num7 = endAngle - startAngle;
                            if (num7 > (float)Math.PI)
                            {
                                num7 -= (float)Math.PI * 2f;
                            }
                            if (num7 < -(float)Math.PI)
                            {
                                num7 += (float)Math.PI * 2f;
                            }
                            float num8 = startAngle + num7 * num5;
                            num7 = num8 - num6;
                            if (num7 > (float)Math.PI)
                            {
                                num7 -= (float)Math.PI * 2f;
                            }
                            if (num7 < -(float)Math.PI)
                            {
                                num7 += (float)Math.PI * 2f;
                            }
                            num6 += num7 * prop.m_cornerAngle;
                            if (num7 != 0f && prop.m_position.x != 0f)
                            {
                                float num9 = Mathf.Tan(num7);
                                vector.x += vector2.x * num9 * prop.m_position.x;
                                vector.z += vector2.z * num9 * prop.m_position.x;
                            }
                        }
                        Vector4 objectIndex3 = (!(num5 > 0.5f)) ? objectIndex1 : objectIndex2;
                        num6 += prop.m_angle * ((float)Math.PI / 180f);
                        InstanceID id = default(InstanceID);
                        id.NetSegment = segmentID;
                        if (variation.m_requireWaterMap)
                        {
                            if (_HeightMap == null)
                            {
                                Singleton <TerrainManager> .instance.GetHeightMapping(Singleton <NetManager> .instance.m_segments.m_buffer[segmentID].m_middlePosition, out _HeightMap, out _HeightMapping, out _SurfaceMapping);
                            }
                            if (_HeightMap2 == null)
                            {
                                Singleton <TerrainManager> .instance.GetWaterMapping(Singleton <NetManager> .instance.m_segments.m_buffer[segmentID].m_middlePosition, out _HeightMap2, out _HeightMapping2, out _SurfaceMapping2);
                            }
#if UseTask
                            Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true, _HeightMap, _HeightMapping, _SurfaceMapping, _HeightMap2, _HeightMapping2, _SurfaceMapping2));
#else
                            PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true, _HeightMap, _HeightMapping, _SurfaceMapping, _HeightMap2, _HeightMapping2, _SurfaceMapping2);
#endif
                        }
                        else if (!variation.m_requireHeightMap)
                        {
#if UseTask
                            Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true));
#else
                            PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true);
#endif
                        }
                    }
                }
                TreeInfo finalTree = prop.m_finalTree;
                if (!(finalTree != null) || (layerMask & (1 << finalTree.m_prefabDataLayer)) == 0)
                {
                    continue;
                }
                Randomizer r2 = new Randomizer((int)laneID + i);
                for (int k = 1; k <= num2; k += 2)
                {
                    if (r2.Int32(100u) >= prop.m_probability)
                    {
                        continue;
                    }
                    float    t          = num4 + (float)k / (float)num2;
                    TreeInfo variation2 = finalTree.GetVariation(ref r2);
                    float    scale2     = variation2.m_minScale + (float)r2.Int32(10000u) * (variation2.m_maxScale - variation2.m_minScale) * 0.0001f;
                    float    brightness = variation2.m_minBrightness + (float)r2.Int32(10000u) * (variation2.m_maxBrightness - variation2.m_minBrightness) * 0.0001f;
                    Vector3  position   = __instance.m_bezier.Position(t);
                    if (propIndex != -1)
                    {
                        position.y = (float)(int)data.m_extraData.GetUShort(num3++) * 0.015625f;
                    }
                    position.y += prop.m_position.y;
                    if (prop.m_position.x != 0f)
                    {
                        Vector3 vector3 = __instance.m_bezier.Tangent(t);
                        if (flag2)
                        {
                            vector3 = -vector3;
                        }
                        vector3.y   = 0f;
                        vector3     = Vector3.Normalize(vector3);
                        position.x += vector3.z * prop.m_position.x;
                        position.z -= vector3.x * prop.m_position.x;
                    }
#if UseTask
                    Patcher.Dispatcher.Add(() => TreeInstance.RenderInstance(cameraInfo, variation2, position, scale2, brightness, RenderManager.DefaultColorLocation));
#else
                    TreeInstance.RenderInstance(cameraInfo, variation2, position, scale2, brightness, RenderManager.DefaultColorLocation);
#endif
                }
            }
            return(false);
        }
Exemplo n.º 3
0
        public static bool RenderPropsPrefix(BuildingAI __instance, RenderManager.CameraInfo cameraInfo, ushort buildingID, ref Building data, int layerMask, ref RenderManager.Instance instance, bool renderFixed, bool renderNonfixed, bool isActive)
        {
            if (__instance.m_info.m_props == null || ((layerMask & __instance.m_info.m_treeLayers) == 0 && !cameraInfo.CheckRenderDistance(instance.m_position, __instance.m_info.m_maxPropDistance + 72f)))
            {
                return(false);
            }
            int             length          = data.Length;
            Texture         _HeightMap      = null;
            Vector4         _HeightMapping  = Vector4.zero;
            Vector4         _SurfaceMapping = Vector4.zero;
            Matrix4x4       lhs             = Matrix4x4.zero;
            bool            flag            = false;
            DistrictManager instance2       = Singleton <DistrictManager> .instance;
            byte            district        = instance2.GetDistrict(data.m_position);
            Vector3         position        = data.m_position;
            ushort          num             = Building.FindParentBuilding(buildingID);

            if (num != 0)
            {
                position = Singleton <BuildingManager> .instance.m_buildings.m_buffer[num].m_position;
            }
            byte park = instance2.GetPark(position);

            for (int i = 0; i < __instance.m_info.m_props.Length; i++)
            {
                BuildingInfo.Prop prop = __instance.m_info.m_props[i];
                Randomizer        r    = new Randomizer((buildingID << 6) | prop.m_index);
                if (r.Int32(100u) >= prop.m_probability || length < prop.m_requiredLength)
                {
                    continue;
                }
                PropInfo finalProp = prop.m_finalProp;
                TreeInfo finalTree = prop.m_finalTree;
                if (finalProp != null)
                {
                    finalProp = finalProp.GetVariation(ref r, ref instance2.m_districts.m_buffer[district], park);
                    float num2  = finalProp.m_minScale + (float)r.Int32(10000u) * (finalProp.m_maxScale - finalProp.m_minScale) * 0.0001f;
                    Color color = finalProp.GetColor(ref r);
                    if ((layerMask & (1 << finalProp.m_prefabDataLayer)) == 0 && !finalProp.m_hasEffects)
                    {
                        continue;
                    }
                    Vector4 dataVector = instance.m_dataVector3;
                    Vector3 vector;
                    if (prop.m_fixedHeight)
                    {
                        if (!renderFixed)
                        {
                            continue;
                        }
                        if (__instance.m_info.m_isFloating)
                        {
                            if (!flag)
                            {
                                Singleton <TerrainManager> .instance.HeightMap_sampleWaterHeightAndNormal(instance.m_position, 0.15f, out float h, out Vector3 normal);

                                Vector3 position2 = instance.m_position;
                                position2.y = h;
                                Quaternion q = Quaternion.FromToRotation(Vector3.up, normal) * instance.m_rotation;
                                lhs  = Matrix4x4.TRS(position2, q, Vector3.one);
                                flag = true;
                            }
                            Matrix4x4 rhs = default(Matrix4x4);
                            rhs.SetTRS(prop.m_position, Quaternion.AngleAxis(prop.m_radAngle * 57.29578f, Vector3.down), new Vector3(num2, num2, num2));
                            rhs    = lhs * rhs;
                            vector = rhs.MultiplyPoint(Vector3.zero);
                            if (cameraInfo.CheckRenderDistance(vector, finalProp.m_maxRenderDistance))
                            {
                                InstanceID propRenderID = GetPropRenderIDReverse(__instance, buildingID, i, ref data);
                                PropInstance.RenderInstance(cameraInfo, finalProp, propRenderID, rhs, vector, num2, data.m_angle + prop.m_radAngle, color, dataVector, isActive);
                                continue;
                            }
                        }
                        else
                        {
                            vector = instance.m_dataMatrix1.MultiplyPoint(prop.m_position);
                            if (__instance.m_info.m_requireHeightMap)
                            {
                                vector.y = (float)(int)instance.m_extraData.GetUShort(i) * 0.015625f;
                            }
                        }
                    }
                    else
                    {
                        if (!renderNonfixed)
                        {
                            continue;
                        }
                        vector = instance.m_dataMatrix1.MultiplyPoint(prop.m_position);
                        if (!__instance.m_info.m_isFloating)
                        {
                            vector.y = (float)(int)instance.m_extraData.GetUShort(i) * 0.015625f;
                        }
                        if (!__instance.m_info.m_colorizeEverything || finalProp.m_isDecal)
                        {
                            dataVector.z = 0f;
                        }
                    }
                    if (!cameraInfo.CheckRenderDistance(vector, finalProp.m_maxRenderDistance))
                    {
                        continue;
                    }
                    InstanceID propRenderID2 = GetPropRenderIDReverse(__instance, buildingID, i, ref data);
                    if (finalProp.m_requireWaterMap)
                    {
                        if (_HeightMap == null)
                        {
                            Singleton <TerrainManager> .instance.GetWaterMapping(data.m_position, out _HeightMap, out _HeightMapping, out _SurfaceMapping);
                        }
#if UseTask
                        var localData     = data;
                        var localInstance = instance;
                        Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, finalProp, propRenderID2, vector, num2, localData.m_angle + prop.m_radAngle, color, dataVector, isActive, localInstance.m_dataTexture0, localInstance.m_dataVector1, localInstance.m_dataVector2, _HeightMap, _HeightMapping, _SurfaceMapping));
#else
                        PropInstance.RenderInstance(cameraInfo, finalProp, propRenderID2, vector, num2, data.m_angle + prop.m_radAngle, color, dataVector, isActive, instance.m_dataTexture0, instance.m_dataVector1, instance.m_dataVector2, _HeightMap, _HeightMapping, _SurfaceMapping);
#endif
                    }
                    else if (finalProp.m_requireHeightMap)
                    {
#if UseTask
                        var localData     = data;
                        var localInstance = instance;
                        Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, finalProp, propRenderID2, vector, num2, localData.m_angle + prop.m_radAngle, color, dataVector, isActive, localInstance.m_dataTexture0, localInstance.m_dataVector1, localInstance.m_dataVector2));
#else
                        PropInstance.RenderInstance(cameraInfo, finalProp, propRenderID2, vector, num2, data.m_angle + prop.m_radAngle, color, dataVector, isActive, instance.m_dataTexture0, instance.m_dataVector1, instance.m_dataVector2);
#endif
                    }
                    else
                    {
#if UseTask
                        var localData     = data;
                        var localInstance = instance;
                        Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, finalProp, propRenderID2, vector, num2, localData.m_angle + prop.m_radAngle, color, dataVector, isActive));
#else
                        PropInstance.RenderInstance(cameraInfo, finalProp, propRenderID2, vector, num2, data.m_angle + prop.m_radAngle, color, dataVector, isActive);
#endif
                    }
                }
                else
                {
                    if (!(finalTree != null))
                    {
                        continue;
                    }
                    finalTree = finalTree.GetVariation(ref r);
                    float scale      = finalTree.m_minScale + (float)r.Int32(10000u) * (finalTree.m_maxScale - finalTree.m_minScale) * 0.0001f;
                    float brightness = finalTree.m_minBrightness + (float)r.Int32(10000u) * (finalTree.m_maxBrightness - finalTree.m_minBrightness) * 0.0001f;
                    if ((layerMask & (1 << finalTree.m_prefabDataLayer)) != 0 && ((!prop.m_fixedHeight) ? renderNonfixed : renderFixed))
                    {
                        Vector3 position3 = instance.m_dataMatrix1.MultiplyPoint(prop.m_position);
                        if (!prop.m_fixedHeight || __instance.m_info.m_requireHeightMap)
                        {
                            position3.y = (float)(int)instance.m_extraData.GetUShort(i) * 0.015625f;
                        }
                        Vector4 dataVector2 = instance.m_dataVector3;
                        if (!__instance.m_info.m_colorizeEverything)
                        {
                            dataVector2.z = 0f;
                        }
#if UseTask
                        var localData     = data;
                        var localInstance = instance;
                        Patcher.Dispatcher.Add(() => TreeInstance.RenderInstance(cameraInfo, finalTree, position3, scale, brightness, dataVector2));
#else
                        TreeInstance.RenderInstance(cameraInfo, finalTree, position3, scale, brightness, dataVector2);
#endif
                    }
                }
            }

            return(false);
        }