Example #1
0
        private static SceneStaticObject GetChildInfo(Transform transform, string resPath)
        {
            if (string.IsNullOrEmpty(resPath))
            {
                return(null);
            }
            Renderer[] renderers = transform.gameObject.GetComponentsInChildren <MeshRenderer>();
            if (renderers == null || renderers.Length == 0)
            {
                return(null);
            }
            Vector3 min = renderers[0].bounds.min;
            Vector3 max = renderers[0].bounds.max;

            for (int i = 1; i < renderers.Length; i++)
            {
                min = Vector3.Min(renderers[i].bounds.min, min);
                max = Vector3.Max(renderers[i].bounds.max, max);
            }
            Vector3 size   = max - min;
            Bounds  bounds = new Bounds(min + size / 2, size);

            if (size.x <= 0)
            {
                size.x = 0.2f;
            }
            if (size.y <= 0)
            {
                size.y = 0.2f;
            }
            if (size.z <= 0)
            {
                size.z = 0.2f;
            }
            bounds.size = size;
            int               lightmapIndex       = renderers[0].lightmapIndex;
            Vector4           lightmapScaleOffset = renderers[0].lightmapScaleOffset;
            SceneStaticObject obj = new SceneStaticObject(bounds, transform.position, transform.eulerAngles, transform.localScale, resPath, lightmapIndex, lightmapScaleOffset);

            return(obj);
        }
Example #2
0
        private static SceneStaticObject GetChildInfo(Transform transform, string resPath, Vector3 boundScale)
        {
            int resID = GetResID(resPath);

            if (string.IsNullOrEmpty(resPath))
            {
                return(null);
            }
            Renderer[] renderers = transform.gameObject.GetComponentsInChildren <MeshRenderer>();
            if (renderers == null || renderers.Length == 0)
            {
                return(null);
            }
            Vector3 min = renderers[0].bounds.min;
            Vector3 max = renderers[0].bounds.max;

            for (int i = 1; i < renderers.Length; i++)
            {
                min = Vector3.Min(renderers[i].bounds.min, min);
                max = Vector3.Max(renderers[i].bounds.max, max);
            }
            Vector3 size   = max - min;
            Bounds  bounds = new Bounds(min + size / 2, size);

            if (size.x <= 0)
            {
                size.x = 0.2f;
            }
            if (size.y <= 0)
            {
                size.y = 0.2f;
            }
            if (size.z <= 0)
            {
                size.z = 0.2f;
            }
            bounds.size = size;
            var expandAmount = size;

            if (boundScale.x != 1)
            {
                expandAmount.x *= boundScale.x;
            }
            if (boundScale.y != 1)
            {
                expandAmount.y *= boundScale.y;
            }
            if (boundScale.z != 1)
            {
                expandAmount.z *= boundScale.z;
            }
            if (expandAmount != size)
            {
                bounds.Expand(expandAmount);
            }
            bool              useLightProbe       = renderers[0].lightProbeUsage != UnityEngine.Rendering.LightProbeUsage.Off;
            int               lightmapIndex       = useLightProbe?-1:renderers[0].lightmapIndex;
            Vector4           lightmapScaleOffset = renderers[0].lightmapScaleOffset;
            SceneStaticObject obj = new SceneStaticObject(bounds, transform.position, transform.eulerAngles, transform.localScale, resID, lightmapIndex, lightmapScaleOffset);

            return(obj);
        }