Exemplo n.º 1
0
 public ModelViewer(string title, string name, IDrawable drawable, RenderState rstate, ViewportManager viewports, CommandBuffer commands, ResourceManager res)
 {
     Title                       = title;
     Name                        = name;
     this.drawable               = drawable;
     this.rstate                 = rstate;
     this.vps                    = viewports;
     this.res                    = res;
     buffer                      = commands;
     wireframeMaterial3db        = new Material(res);
     wireframeMaterial3db.Dc     = Color4.White;
     wireframeMaterial3db.DtName = ResourceManager.WhiteTextureName;
     normalsDebugMaterial        = new Material(res);
     normalsDebugMaterial.Type   = "NormalDebugMaterial";
     lighting                    = Lighting.Create();
     lighting.Enabled            = true;
     lighting.Ambient            = Color4.Black;
     lighting.Lights.Add(new RenderLight()
     {
         Kind      = LightKind.Directional,
         Direction = new Vector3(0, -1, 0),
         Color     = Color4.White
     });
     lighting.Lights.Add(new RenderLight()
     {
         Kind      = LightKind.Directional,
         Direction = new Vector3(0, 0, 1),
         Color     = Color4.White
     });
     lighting.NumberOfTilesX = -1;
     GizmoRender.Init(res);
 }
        void DrawHardpoints(ICamera cam)
        {
            var matrix = GetModelMatrix();

            GizmoRender.Scale = gizmoScale;
            GizmoRender.Begin();

            foreach (var tr in gizmos)
            {
                if (tr.Enabled || tr.Override != null)
                {
                    var transform = tr.Override ?? tr.Definition.Transform;
                    //arc
                    if (tr.Definition is RevoluteHardpointDefinition)
                    {
                        var rev = (RevoluteHardpointDefinition)tr.Definition;
                        var min = tr.Override == null ? rev.Min : tr.EditingMin;
                        var max = tr.Override == null ? rev.Max : tr.EditingMax;
                        GizmoRender.AddGizmoArc(transform * (tr.Parent == null ? Matrix4.Identity : tr.Parent.Transform) * matrix, min, max);
                    }
                    //draw (red for editing, light pink for normal)
                    GizmoRender.AddGizmo(transform * (tr.Parent == null ? Matrix4.Identity : tr.Parent.Transform) * matrix, tr.Override != null ? Color4.Red : Color4.LightPink);
                }
            }
            GizmoRender.RenderGizmos(cam, rstate);
        }
        void SetupViewport()
        {
            modelViewport         = new Viewport3D(_window);
            modelViewport.MarginH = 60;
            ResetCamera();
            previewViewport = new Viewport3D(_window);
            imageViewport   = new Viewport3D(_window);
            gizmoScale      = 5;
            if (vmsModel != null)
            {
                gizmoScale = vmsModel.GetRadius() / RADIUS_ONE;
            }
            else if (drawable is DF.DfmFile dfm)
            {
                gizmoScale = dfm.GetRadius() / RADIUS_ONE;
            }
            wireframeMaterial3db        = new Material(res);
            wireframeMaterial3db.Dc     = Color4.White;
            wireframeMaterial3db.DtName = ResourceManager.WhiteTextureName;
            normalsDebugMaterial        = new Material(res);
            normalsDebugMaterial.Type   = "NormalDebugMaterial";
            lighting         = Lighting.Create();
            lighting.Enabled = true;
            lighting.Ambient = Color3f.Black;
            var src = new SystemLighting();

            src.Lights.Add(new DynamicLight()
            {
                Light = new RenderLight()
                {
                    Kind      = LightKind.Directional,
                    Direction = new Vector3(0, -1, 0),
                    Color     = Color3f.White
                }
            });
            src.Lights.Add(new DynamicLight()
            {
                Light = new RenderLight()
                {
                    Kind      = LightKind.Directional,
                    Direction = new Vector3(0, 0, 1),
                    Color     = Color3f.White
                }
            });
            lighting.Lights.SourceLighting   = src;
            lighting.Lights.SourceEnabled[0] = true;
            lighting.Lights.SourceEnabled[1] = true;
            lighting.NumberOfTilesX          = -1;
            if (drawable is DF.DfmFile)
            {
                skel = new DfmSkeletonManager((DF.DfmFile)drawable);
            }
            GizmoRender.Init(res);
        }
Exemplo n.º 4
0
        void DrawSkeleton(ICamera cam)
        {
            var matrix = GetModelMatrix();

            GizmoRender.Scale = gizmoScale;
            GizmoRender.Begin();
            var df = (DF.DfmFile)drawable;

            foreach (var c in df.Constructs.Constructs)
            {
                var b1 = c.BoneA;
                var b2 = c.BoneB;
                if (string.IsNullOrEmpty(c.BoneB))
                {
                    b2 = c.ParentName;
                    b1 = c.BoneA;
                }
                var     conMat = c.Rotation * Matrix4.CreateTranslation(c.Origin);
                DF.Bone bone1  = null;
                DF.Bone bone2  = null;
                foreach (var k in df.Parts.Values)
                {
                    if (k.objectName == b1)
                    {
                        bone1 = k.Bone;
                    }
                    if (k.objectName == b2)
                    {
                        bone2 = k.Bone;
                    }
                }
                if (bone1 == null || bone2 == null)
                {
                    continue;
                }
                GizmoRender.AddGizmo(bone2.BoneToRoot * bone1.BoneToRoot * conMat * matrix);
            }

            /*foreach(var b in df.Bones.Values)
             * {
             *  var tr = b.BoneToRoot;
             *  tr.Transpose();
             *  if (b.Construct != null)
             *      tr *= b.Construct.Transform;
             *  tr *= matrix;
             *
             *  GizmoRender.AddGizmo(tr, true, true);
             * }*/
            GizmoRender.RenderGizmos(cam, rstate);
        }
        void DrawSkeleton(ICamera cam)
        {
            var matrix = GetModelMatrix();

            GizmoRender.Scale = gizmoScale;
            GizmoRender.Begin();

            var dfm = (DF.DfmFile)drawable;

            foreach (var b in dfm.Bones)
            {
                GizmoRender.AddGizmo(b.Value.BoneToRoot * matrix, Color4.Green);
            }
            GizmoRender.RenderGizmos(cam, rstate);
        }
Exemplo n.º 6
0
        void DrawHardpoints(ICamera cam)
        {
            var matrix = Matrix4.CreateRotationX(rotation.Y) * Matrix4.CreateRotationY(rotation.X);

            GizmoRender.Begin();

            foreach (var tr in gizmos)
            {
                if (tr.Enabled)
                {
                    GizmoRender.AddGizmo(tr.Definition.Transform * (tr.Parent == null ? Matrix4.Identity : tr.Parent.Transform) * matrix);
                }
            }
            GizmoRender.RenderGizmos(cam, rstate);
        }
Exemplo n.º 7
0
        void SetupViewport()
        {
            modelViewport                  = new Viewport3D(_window);
            modelViewport.MarginH          = 60;
            modelViewport.DefaultOffset    =
                modelViewport.CameraOffset = new Vector3(0, 0, drawable.GetRadius() * 2);
            modelViewport.ModelScale       = drawable.GetRadius() / 2.6f;
            previewViewport                = new Viewport3D(_window);
            imageViewport                  = new Viewport3D(_window);

            gizmoScale                  = drawable.GetRadius() / RADIUS_ONE;
            wireframeMaterial3db        = new Material(res);
            wireframeMaterial3db.Dc     = Color4.White;
            wireframeMaterial3db.DtName = ResourceManager.WhiteTextureName;
            normalsDebugMaterial        = new Material(res);
            normalsDebugMaterial.Type   = "NormalDebugMaterial";
            lighting         = Lighting.Create();
            lighting.Enabled = true;
            lighting.Ambient = Color3f.Black;
            var src = new SystemLighting();

            src.Lights.Add(new DynamicLight()
            {
                Light = new RenderLight()
                {
                    Kind      = LightKind.Directional,
                    Direction = new Vector3(0, -1, 0),
                    Color     = Color3f.White
                }
            });
            src.Lights.Add(new DynamicLight()
            {
                Light = new RenderLight()
                {
                    Kind      = LightKind.Directional,
                    Direction = new Vector3(0, 0, 1),
                    Color     = Color3f.White
                }
            });
            lighting.Lights.SourceLighting   = src;
            lighting.Lights.SourceEnabled[0] = true;
            lighting.Lights.SourceEnabled[1] = true;
            lighting.NumberOfTilesX          = -1;
            GizmoRender.Init(res);
        }
Exemplo n.º 8
0
        void SetupViewport()
        {
            modelViewport               = new Viewport3D(rstate, vps);
            modelViewport.Zoom          = drawable.GetRadius() * 2;
            modelViewport.ZoomStep      = modelViewport.Zoom / 3.26f;
            wireframeMaterial3db        = new Material(res);
            wireframeMaterial3db.Dc     = Color4.White;
            wireframeMaterial3db.DtName = ResourceManager.WhiteTextureName;
            normalsDebugMaterial        = new Material(res);
            normalsDebugMaterial.Type   = "NormalDebugMaterial";
            lighting         = Lighting.Create();
            lighting.Enabled = true;
            lighting.Ambient = Color4.Black;
            var src = new SystemLighting();

            src.Lights.Add(new DynamicLight()
            {
                Light = new RenderLight()
                {
                    Kind      = LightKind.Directional,
                    Direction = new Vector3(0, -1, 0),
                    Color     = Color4.White
                }
            });
            src.Lights.Add(new DynamicLight()
            {
                Light = new RenderLight()
                {
                    Kind      = LightKind.Directional,
                    Direction = new Vector3(0, 0, 1),
                    Color     = Color4.White
                }
            });
            lighting.Lights.SourceLighting   = src;
            lighting.Lights.SourceEnabled[0] = true;
            lighting.Lights.SourceEnabled[1] = true;
            lighting.NumberOfTilesX          = -1;
            GizmoRender.Init(res);
        }
Exemplo n.º 9
0
        void DrawHardpoints(ICamera cam)
        {
            var matrix = GetModelMatrix();

            GizmoRender.Scale = gizmoScale;
            GizmoRender.Begin();

            foreach (var tr in gizmos)
            {
                if (tr.Enabled || tr.Override != null)
                {
                    var transform = tr.Override ?? tr.Definition.Transform;
                    //highlight edited cube
                    if (tr.Override != null)
                    {
                        GizmoRender.CubeColor = Color4.CornflowerBlue;
                        GizmoRender.CubeAlpha = 0.5f;
                    }
                    else
                    {
                        GizmoRender.CubeColor = Color4.Purple;
                        GizmoRender.CubeAlpha = 0.3f;
                    }
                    //arc
                    if (tr.Definition is RevoluteHardpointDefinition)
                    {
                        var rev = (RevoluteHardpointDefinition)tr.Definition;
                        var min = tr.Override == null ? rev.Min : tr.EditingMin;
                        var max = tr.Override == null ? rev.Max : tr.EditingMax;
                        GizmoRender.AddGizmoArc(transform * (tr.Parent == null ? Matrix4.Identity : tr.Parent.Transform) * matrix, min, max);
                    }
                    //
                    GizmoRender.AddGizmo(transform * (tr.Parent == null ? Matrix4.Identity : tr.Parent.Transform) * matrix);
                }
            }
            GizmoRender.RenderGizmos(cam, rstate);
        }
Exemplo n.º 10
0
        void DrawHardpoints(ICamera cam)
        {
            var            matrix     = Matrix4.CreateRotationX(rotation.Y) * Matrix4.CreateRotationY(rotation.X);
            List <Matrix4> hardpoints = new List <Matrix4>();

            if (drawable is CmpFile)
            {
                foreach (var p in ((CmpFile)drawable).Parts)
                {
                    var parentHp = p.Value.Construct != null ? p.Value.Construct.Transform : Matrix4.Identity;
                    parentHp *= matrix;
                    foreach (var hp in p.Value.Model.Hardpoints)
                    {
                        hardpoints.Add(hp.Transform * parentHp);
                    }
                }
            }
            else if (drawable is ModelFile)
            {
                foreach (var hp in ((ModelFile)drawable).Hardpoints)
                {
                    hardpoints.Add(hp.Transform * matrix);
                }
            }
            if (hardpoints.Count == 0)
            {
                return;
            }
            GizmoRender.Begin();
            foreach (var tr in hardpoints)
            {
                //X
                GizmoRender.AddGizmo(tr);
            }
            GizmoRender.RenderGizmos(cam, rstate);
        }