Inheritance: MonoBehaviour
Exemple #1
0
        //world grid management
        static private void addLightToGrid(lightInstance light)
        {
            LocalLight   l  = light.mSimEditorObject;
            BBoundingBox bb = new BBoundingBox();

            bb.addPoint(l.mAABB.min);
            bb.addPoint(l.mAABB.max);
            bb.min += l.getPosition();
            bb.max += l.getPosition();

            //walk every world chunk, update our bounds, do intersections
            BBoundingBox worldAABB = new BBoundingBox();

            for (int x = 0; x < mWorldChunks.GetLength(0); x++)
            {
                for (int y = 0; y < mWorldChunks.GetLength(1); y++)
                {
                    worldAABB.max   = mWorldChunks[x, y].mQNPointer.getDesc().m_maxPostDeform;
                    worldAABB.min   = mWorldChunks[x, y].mQNPointer.getDesc().m_minPostDeform;
                    worldAABB.max.Y = 300;
                    worldAABB.min.Y = -300;

                    if (bb.intersect(worldAABB))
                    {
                        mWorldChunks[x, y].mLightsAffectingMe.Add(light);
                        light.mWorldChunksImAffecting.Add(mWorldChunks[x, y]);
                    }
                }
            }
        }
Exemple #2
0
        public static MapLights ReadLights(string path)
        {
            /*string assetPath = path.Replace(".ded", ".asset");*/
            GameObject subGO = Scene.BeginEditingPrefab(path, "Lights");

            try
            {
                MapLights lights = subGO.AddComponent<MapLights>();

                BinaryReader reader = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read));

                reader.SkipInt16(); //Usually the area's code
                reader.SkipInt16(); //Usually 1, saw a 20
                short globalLightsCount = reader.ReadInt16();
                reader.SkipInt16(0);
                short globalLightsOffset = reader.ReadInt16();
                reader.SkipInt16(0);
                reader.SkipBytes(8, 0);

                short weirdLightsCount = reader.ReadInt16();
                reader.SkipInt16(0);
                short weirdLightsOffset = reader.ReadInt16();
                reader.SkipInt16(0);
                reader.SkipBytes(8, 0);
                
                short lightsCount = reader.ReadInt16();
                reader.SkipInt16(0);
                short lightsOffset = reader.ReadInt16();
                reader.SkipInt16(0);

                reader.SkipBytes(40, 0);
                short ambientOffset = reader.ReadInt16();
                reader.SkipBytes(24, 0);

                Matrix4x4 transMat = lights.GetComponentInParent<Scene>().GetSH3ToUnityMatrix();

                reader.BaseStream.Position = globalLightsOffset;
                for (int i = 0; i != globalLightsCount; i++)
                {
                    GlobalLight gl = new GlobalLight();
                    gl.rotation = reader.ReadQuaternion();
                    gl.Unknown1 = reader.ReadVector3();
                    reader.SkipInt16(0);
                    gl.Unknown2 = reader.ReadInt16();
                    lights.globalLights.Add(gl);
                }

                reader.BaseStream.Position = weirdLightsOffset;
                for (int i = 0; i != weirdLightsCount; i++)
                {
                    LocalLight ll = new LocalLight();
                    ll.color = reader.ReadColor();
                    ll.Unknown1 = reader.ReadSingle();
                    ll.Range = reader.ReadSingle();
                    reader.SkipBytes(8, 0);
                    ll.position = reader.ReadVector3YInverted();
                    reader.SkipInt16(0x0);
                    ll.Unknown2 = reader.ReadInt16();
                    lights.weirdLights.Add(ll);
                }

                reader.BaseStream.Position = lightsOffset;
                for (int i = 0; i != lightsCount; i++)
                {
                    LocalLight ll = new LocalLight();
                    ll.color = reader.ReadColor();
                    ll.Unknown1 = reader.ReadSingle();
                    ll.Range = reader.ReadSingle();
                    reader.SkipBytes(8, 0);
                    ll.position = reader.ReadVector3YInverted();
                    reader.SkipInt16(0x0);
                    ll.Unknown2 = reader.ReadInt16();
                    lights.localLights.Add(ll);

                    GameObject lightGO = new GameObject("Light " + i);
                    lightGO.transform.SetParent(subGO.transform);
                    lightGO.transform.localPosition = transMat.MultiplyPoint(ll.position);

                    Light light = lightGO.AddComponent<Light>();
                    light.type = LightType.Point;
                    light.range = ll.Range * Scene.GLOBAL_SCALE;
                    light.color = ll.color;
                    light.intensity = 8.0f;
                    light.bounceIntensity = 1.0f;
                }

                reader.BaseStream.Position = ambientOffset;
                lights.Unknown1 = reader.ReadVector4();
                lights.Unknown2 = reader.ReadVector4();
                lights.ambientColor = reader.ReadColor();
                lights.Unknown3 = reader.ReadVector4();

                reader.Close();

                Scene.FinishEditingPrefab(path, subGO);

                return lights;

            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            return null;
        }