コード例 #1
0
ファイル: ThnScript.cs プロジェクト: darkzter/Librelancer
        ThnEntity GetEntity(LuaTable table)
        {
            object o;

            var e = new ThnEntity();

            e.Name = (string)table["entity_name"];
            e.Type = ThnEnum.Check <EntityTypes>(table["type"]);
            if (table.TryGetValue("srt_grp", out o))
            {
                e.SortGroup = (int)(float)table["srt_grp"];
            }
            if (table.TryGetValue("usr_flg", out o))
            {
                e.UserFlag = (int)(float)table["usr_flg"];
            }
            if (table.TryGetValue("lt_grp", out o))
            {
                e.LightGroup = (int)(float)table["lt_grp"];
            }

            Vector3 tmp;

            if (table.TryGetVector3("ambient", out tmp))
            {
                e.Ambient = tmp;
            }
            if (table.TryGetVector3("up", out tmp))
            {
                e.Up = tmp;
            }
            if (table.TryGetVector3("front", out tmp))
            {
                e.Front = tmp;
            }

            if (table.TryGetValue("template_name", out o))
            {
                e.Template = (string)o;
            }
            if (table.TryGetValue("flags", out o))
            {
                if (o is float)
                {
                    e.ObjectFlags = ConvertFlags(e.Type, table);
                }
                else
                {
                    e.ObjectFlags = (ThnObjectFlags)o;
                }
            }
            if (table.TryGetValue("userprops", out o))
            {
                var usrprops = (LuaTable)o;
                if (usrprops.TryGetValue("category", out o))
                {
                    e.MeshCategory = (string)o;
                }
                if (usrprops.TryGetValue("nofog", out o))
                {
                    e.NoFog = ThnEnum.Check <bool>(o);
                }
            }

            if (table.TryGetValue("spatialprops", out o))
            {
                var spatialprops = (LuaTable)o;
                if (spatialprops.TryGetVector3("pos", out tmp))
                {
                    e.Position = tmp;
                }
                if (spatialprops.TryGetValue("orient", out o))
                {
                    e.RotationMatrix = GetMatrix((LuaTable)o);
                }
            }

            if (table.TryGetValue("cameraprops", out o))
            {
                var cameraprops = (LuaTable)o;
                if (cameraprops.TryGetValue("fovh", out o))
                {
                    e.FovH = (float)o;
                }
                if (cameraprops.TryGetValue("hvaspect", out o))
                {
                    e.HVAspect = (float)o;
                }
            }
            if (table.TryGetValue("lightprops", out o))
            {
                var lightprops = (LuaTable)o;
                e.LightProps = new ThnLightProps();
                if (lightprops.TryGetValue("on", out o))
                {
                    e.LightProps.On = ThnEnum.Check <bool>(o);
                }
                else
                {
                    e.LightProps.On = true;
                }
                var r = new RenderLight();
                r.Position = e.Position.Value;
                if (lightprops.TryGetValue("type", out o))
                {
                    var tp = ThnEnum.Check <LightTypes>(o);
                    if (tp == LightTypes.Point)
                    {
                        r.Kind = LightKind.Point;
                    }
                    if (tp == LightTypes.Direct)
                    {
                        r.Kind = LightKind.Directional;
                    }
                    if (tp == LightTypes.Spotlight)
                    {
                        r.Kind    = LightKind.Spotlight;
                        r.Falloff = 1f;
                    }
                }
                else
                {
                    throw new Exception("Light without type");
                }
                if (lightprops.TryGetVector3("diffuse", out tmp))
                {
                    r.Color = new Color4(tmp.X, tmp.Y, tmp.Z, 1);
                }
                if (lightprops.TryGetVector3("direction", out tmp))
                {
                    r.Direction = tmp;
                }
                if (lightprops.TryGetValue("range", out o))
                {
                    r.Range = (int)(float)o;
                }
                if (lightprops.TryGetValue("theta", out o))
                {
                    r.Theta = r.Phi = (float)o;
                }
                if (lightprops.TryGetVector3("atten", out tmp))
                {
                    r.Attenuation = new Vector4(tmp, 0);
                }
                e.LightProps.Render = r;
            }
            if (table.TryGetValue("pathprops", out o))
            {
                var pathprops = (LuaTable)o;
                if (pathprops.TryGetValue("path_data", out o))
                {
                    e.Path = new MotionPath((string)o);
                }
            }
            return(e);
        }
コード例 #2
0
ファイル: ThnScript.cs プロジェクト: Regenhardt/Librelancer
        ThnEntity GetEntity(LuaTable table)
        {
            object o;

            var e = new ThnEntity();

            e.Name = (string)table["entity_name"];
            e.Type = ThnTypes.Convert <EntityTypes>(table["type"]);
            if (table.TryGetValue("srt_grp", out o))
            {
                e.SortGroup = (int)(float)table["srt_grp"];
            }
            if (table.TryGetValue("usr_flg", out o))
            {
                e.UserFlag = (int)(float)table["usr_flg"];
            }
            if (table.TryGetValue("lt_grp", out o))
            {
                e.LightGroup = (int)(float)table["lt_grp"];
            }

            Vector3 tmp;

            if (table.TryGetVector3("ambient", out tmp))
            {
                e.Ambient = tmp;
            }
            if (table.TryGetVector3("up", out tmp))
            {
                e.Up = tmp;
            }
            if (table.TryGetVector3("front", out tmp))
            {
                e.Front = tmp;
            }

            if (table.TryGetValue("template_name", out o))
            {
                e.Template = (string)o;
            }
            if (table.TryGetValue("flags", out o))
            {
                if (o is float)
                {
                    e.ObjectFlags = ConvertFlags(e.Type, table);
                }
                else
                {
                    e.ObjectFlags = (ThnObjectFlags)o;
                }
            }
            if (table.TryGetValue("userprops", out o))
            {
                var usrprops = (LuaTable)o;
                if (usrprops.TryGetValue("category", out o))
                {
                    e.MeshCategory = (string)o;
                }
                if (usrprops.TryGetValue("nofog", out o))
                {
                    e.NoFog = ThnTypes.Convert <bool>(o);
                }
                if (usrprops.TryGetValue("Actor", out o))
                {
                    e.Actor = o.ToString();
                }
                if (usrprops.TryGetValue("TextString", out o))
                {
                    e.DisplayText         = new ThnDisplayText();
                    e.DisplayText.TextIDS = FuzzyInt(o);
                    if (usrprops.TryGetValue("TextStart", out o))
                    {
                        e.DisplayText.Start = FuzzyFloat(o);
                    }
                }

                if (usrprops.TryGetValue("main_object", out o))
                {
                    e.MainObject = true;
                }
            }
            if (table.TryGetValue("audioprops", out o))
            {
                var aprops = (LuaTable)o;
                e.AudioProps = new ThnAudioProps();
                if (aprops.TryGetValue("rmix", out o))
                {
                    e.AudioProps.Rmix = (float)o;
                }
                if (aprops.TryGetValue("ain", out o))
                {
                    e.AudioProps.Ain = (float)o;
                }
                if (aprops.TryGetValue("dmax", out o))
                {
                    e.AudioProps.Dmax = (float)o;
                }
                if (aprops.TryGetValue("atout", out o))
                {
                    e.AudioProps.Atout = (float)o;
                }
                if (aprops.TryGetValue("pan", out o))
                {
                    e.AudioProps.Pan = (float)o;
                }
                if (aprops.TryGetValue("dmin", out o))
                {
                    e.AudioProps.Dmin = (float)o;
                }
                if (aprops.TryGetValue("aout", out o))
                {
                    e.AudioProps.Aout = (float)o;
                }
                if (aprops.TryGetValue("attenuation", out o))
                {
                    e.AudioProps.Attenuation = (float)o;
                }
            }
            if (table.TryGetValue("spatialprops", out o))
            {
                var spatialprops = (LuaTable)o;
                if (spatialprops.TryGetVector3("pos", out tmp))
                {
                    e.Position = tmp;
                }
                if (spatialprops.TryGetValue("orient", out o))
                {
                    e.RotationMatrix = GetMatrix((LuaTable)o);
                }
            }

            if (table.TryGetValue("cameraprops", out o))
            {
                var cameraprops = (LuaTable)o;
                if (cameraprops.TryGetValue("fovh", out o))
                {
                    e.FovH = (float)o;
                }
                if (cameraprops.TryGetValue("hvaspect", out o))
                {
                    e.HVAspect = (float)o;
                }
                if (cameraprops.TryGetValue("nearplane", out o))
                {
                    e.NearPlane = (float)o;
                }
                if (cameraprops.TryGetValue("farplane", out o))
                {
                    e.FarPlane = (float)o;
                }
            }
            if (table.TryGetValue("lightprops", out o))
            {
                var lightprops = (LuaTable)o;
                e.LightProps = new ThnLightProps();
                if (lightprops.TryGetValue("on", out o))
                {
                    e.LightProps.On = ThnTypes.Convert <bool>(o);
                }
                else
                {
                    e.LightProps.On = true;
                }
                var r = new RenderLight();
                r.Position = e.Position.Value;
                if (lightprops.TryGetValue("type", out o))
                {
                    var tp = ThnTypes.Convert <LightTypes>(o);
                    if (tp == LightTypes.Point)
                    {
                        r.Kind = LightKind.Point;
                    }
                    if (tp == LightTypes.Direct)
                    {
                        r.Kind = LightKind.Directional;
                    }
                    if (tp == LightTypes.Spotlight)
                    {
                        r.Kind    = LightKind.Spotlight;
                        r.Falloff = 1f;
                    }
                }
                else
                {
                    throw new Exception("Light without type");
                }
                if (lightprops.TryGetVector3("diffuse", out tmp))
                {
                    r.Color = new Color3f(tmp.X, tmp.Y, tmp.Z);
                }
                if (lightprops.TryGetVector3("ambient", out tmp))
                {
                    r.Ambient = new Color3f(tmp.X, tmp.Y, tmp.Z);
                }
                if (lightprops.TryGetVector3("direction", out tmp))
                {
                    r.Direction = tmp;
                }
                if (lightprops.TryGetValue("range", out o))
                {
                    r.Range = (int)(float)o;
                }
                if (lightprops.TryGetValue("theta", out o))
                {
                    r.Theta = r.Phi = (float)o;
                }
                if (lightprops.TryGetVector3("atten", out tmp))
                {
                    r.Attenuation = tmp;
                }
                e.LightProps.Render = r;
            }
            if (table.TryGetValue("pathprops", out o))
            {
                var pathprops = (LuaTable)o;
                if (pathprops.TryGetValue("path_data", out o))
                {
                    e.Path = new MotionPath((string)o);
                }
            }
            return(e);
        }