Exemplo n.º 1
0
 public void DepthPrepass(RenderState rstate, Matrix4 world, MaterialAnimCollection mc)
 {
     if (ready)
     {
         Mesh.DepthPrepass(rstate, StartMesh, endMesh, StartVertex, world, mc);
     }
 }
Exemplo n.º 2
0
 public void DepthPrepass(RenderState rstate, Matrix4 world, MaterialAnimCollection mc)
 {
     if (ready)
     {
         if (needsOptimize)
         {
             Optimize();
         }
         if (optimized != null)
         {
             for (int i = 0; i < optimized.Optimized.Length; i++)
             {
                 var m = optimized.Optimized[i].Material;
                 if (m == null)
                 {
                     m = vMeshLibrary.FindMaterial(0);
                 }
                 m.Render.World = world;
                 m.Render.ApplyDepthPrepass(rstate);
                 Mesh.VertexBuffer.Draw(PrimitiveTypes.TriangleList, optimized.Optimized[i].VertexOffset, optimized.Optimized[i].StartIndex, optimized.Optimized[i].PrimitiveCount);
             }
             for (int i = 0; i < optimized.NormalDraw.Length; i++)
             {
                 Mesh.Meshes[optimized.NormalDraw[i]].DepthPrepass(rstate, Mesh, StartVertex + Mesh.VertexOffset, Mesh.IndexOffset, world, mc);
             }
         }
         else
         {
             Mesh.DepthPrepass(rstate, StartMesh, endMesh, StartVertex, world, mc);
         }
     }
 }
Exemplo n.º 3
0
 public void Draw(RenderState rstate, Matrix4 world, Lighting light, MaterialAnimCollection mc)
 {
     if (ready)
     {
         Mesh.Draw(rstate, StartMesh, endMesh, StartVertex, world, light, mc);
     }
 }
Exemplo n.º 4
0
 public void Draw(RenderState rstate, Matrix4 world, Lighting light, MaterialAnimCollection mc)
 {
     if (Mesh.FlexibleVertexFormat == (D3DFVF.XYZ | D3DFVF.NORMAL))
     {
         return;
     }
     if (ready)
     {
         Mesh.Draw(rstate, StartMesh, endMesh, StartVertex, world, light, mc);
     }
 }
Exemplo n.º 5
0
 public void DrawBuffer(CommandBuffer buffer, Matrix4 world, Lighting light, MaterialAnimCollection mc)
 {
     if (Mesh.FlexibleVertexFormat == (D3DFVF.XYZ | D3DFVF.NORMAL))
     {
         return;
     }
     if (ready)
     {
         Mesh.DrawBuffer(buffer, StartMesh, endMesh, StartVertex, world, light, Center, mc);
     }
 }
Exemplo n.º 6
0
        private void load(IntermediateNode root, ILibFile additionalLibrary)
        {
            this.additionalLibrary = additionalLibrary;
            ready = false;

            Hardpoints = new List <HardpointDefinition>();
            var lvls = new Dictionary <int, VMeshRef>();

            foreach (Node node in root)
            {
                switch (node.Name.ToLowerInvariant())
                {
                case "exporter version":
                    break;

                case "vmeshlibrary":
                    IntermediateNode vMeshLibraryNode = node as IntermediateNode;
                    if (VMeshLibrary == null)
                    {
                        VMeshLibrary = new VmsFile(vMeshLibraryNode, this);
                    }
                    else
                    {
                        throw new Exception("Multiple vmeshlibrary nodes in 3db root");
                    }
                    break;

                case "material library":
                    IntermediateNode materialLibraryNode = node as IntermediateNode;
                    if (MaterialLibrary == null)
                    {
                        MaterialLibrary = new MatFile(materialLibraryNode, this);
                    }
                    else
                    {
                        throw new Exception("Multiple material library nodes in 3db root");
                    }
                    break;

                case "texture library":
                    IntermediateNode textureLibraryNode = node as IntermediateNode;
                    if (TextureLibrary == null)
                    {
                        TextureLibrary = new TxmFile(textureLibraryNode);
                    }
                    else
                    {
                        throw new Exception("Multiple texture library nodes in 3db root");
                    }
                    break;

                case "hardpoints":
                    IntermediateNode hardpointsNode = node as IntermediateNode;
                    if (hardpointsNode == null)
                    {
                        break;
                    }
                    foreach (Node hpn in hardpointsNode)
                    {
                        if (hpn is LeafNode)
                        {
                            continue;                                     //No nodes here
                        }
                        var hardpointTypeNode = (IntermediateNode)hpn;
                        switch (hardpointTypeNode.Name.ToLowerInvariant())
                        {
                        //OfType<> to avoid crashes with bad models
                        case "fixed":
                            foreach (IntermediateNode fixedNode in hardpointTypeNode.OfType <IntermediateNode>())
                            {
                                Hardpoints.Add(new FixedHardpointDefinition(fixedNode));
                            }
                            break;

                        case "revolute":
                            foreach (IntermediateNode revoluteNode in hardpointTypeNode.OfType <IntermediateNode>())
                            {
                                Hardpoints.Add(new RevoluteHardpointDefinition(revoluteNode));
                            }
                            break;

                        default:
                            Hardpoints.Add(new FixedHardpointDefinition(hardpointTypeNode));
                            break;
                        }
                    }
                    break;

                case "vmeshpart":
                {
                    IntermediateNode vMeshPartNode = node as IntermediateNode;
                    if (vMeshPartNode.Count == 1)
                    {
                        LeafNode vMeshRefNode = vMeshPartNode[0] as LeafNode;
                        lvls.Add(0, new VMeshRef(vMeshRefNode.DataSegment, this));
                    }
                    else
                    {
                        throw new Exception("Invalid VMeshPart: More than one child or zero elements");
                    }
                }
                break;

                case "multilevel":
                    IntermediateNode multiLevelNode = node as IntermediateNode;
                    foreach (Node multiLevelSubNode in multiLevelNode)
                    {
                        if (multiLevelSubNode.Name.StartsWith("level", StringComparison.OrdinalIgnoreCase))
                        {
                            if (multiLevelSubNode is LeafNode)
                            {
                                continue;
                            }
                            IntermediateNode levelNode = multiLevelSubNode as IntermediateNode;
                            if (levelNode.Count == 1)
                            {
                                int level = 0;
                                if (!int.TryParse(levelNode.Name.Substring(5), out level))
                                {
                                    throw new Exception("Invalid Level: Missing index");
                                }

                                IntermediateNode vMeshPartNode = levelNode[0] as IntermediateNode;

                                if (vMeshPartNode.Count == 1)
                                {
                                    LeafNode vMeshRefNode = vMeshPartNode[0] as LeafNode;
                                    if (vMeshRefNode != null && vMeshRefNode.Name.Equals("vmeshref",
                                                                                         StringComparison.OrdinalIgnoreCase))
                                    {
                                        lvls.Add(level, new VMeshRef(vMeshRefNode.DataSegment, this));
                                    }
                                }
                                else
                                {
                                    throw new Exception("Invalid VMeshPart: More than one child or zero elements");
                                }
                            }
                            //else throw new Exception("Invalid Level: More than one child or zero elements");
                        }
                        else if (multiLevelSubNode.Name.Equals("switch2", StringComparison.OrdinalIgnoreCase))
                        {
                            LeafNode switch2Node = multiLevelSubNode as LeafNode;
                            Switch2 = switch2Node.SingleArrayData;
                        }
                        else
                        {
                            throw new Exception("Invalid node in " + multiLevelNode.Name + ": " + multiLevelSubNode.Name);
                        }
                    }
                    break;

                case "vmeshwire":
                    VMeshWire = new VMeshWire(node as IntermediateNode, this);
                    break;

                case "mass properties":
                    // TODO 3db Mass Properties
                    break;

                case "extent tree":
                    // TODO 3db Extent Tree
                    break;

                case "materialanim":
                    MaterialAnim = new MaterialAnimCollection((IntermediateNode)node);
                    break;

                default:
                    FLLog.Error("3db", (Path ?? "") + ": Invalid node: " + node.Name);
                    break;
                }
            }

            //Sort levels in order
            var lvl2 = new List <VMeshRef>();

            for (int i = 0; i < 100; i++)
            {
                if (lvls.ContainsKey(i))
                {
                    lvl2.Add(lvls[i]);
                }
                else
                {
                    break;
                }
            }
            Levels = lvl2.ToArray();
        }
Exemplo n.º 7
0
        public CmpFile(IntermediateNode rootnode, ILibFile additionalLibrary)
        {
            this.additionalLibrary = additionalLibrary;

            Models     = new Dictionary <string, ModelFile>();
            Constructs = new ConstructCollection();
            Parts      = new Dictionary <int, Part>();

            foreach (Node node in rootnode)
            {
                switch (node.Name.ToLowerInvariant())
                {
                case "exporter version":
                    break;

                case "vmeshlibrary":
                    IntermediateNode vMeshLibraryNode = node as IntermediateNode;
                    if (VMeshLibrary == null)
                    {
                        VMeshLibrary = new VmsFile(vMeshLibraryNode, this);
                    }
                    else
                    {
                        throw new Exception("Multiple vmeshlibrary nodes in cmp root");
                    }
                    break;

                case "animation":
                    IntermediateNode animationNode = node as IntermediateNode;
                    if (Animation == null)
                    {
                        Animation = new AnmFile(animationNode, Constructs);
                    }
                    else
                    {
                        throw new Exception("Multiple animation nodes in cmp root");
                    }
                    break;

                case "material library":
                    IntermediateNode materialLibraryNode = node as IntermediateNode;
                    if (MaterialLibrary == null)
                    {
                        MaterialLibrary = new MatFile(materialLibraryNode, this);
                    }
                    else
                    {
                        throw new Exception("Multiple material library nodes in cmp root");
                    }
                    break;

                case "texture library":
                    IntermediateNode textureLibraryNode = node as IntermediateNode;
                    if (TextureLibrary == null)
                    {
                        TextureLibrary = new TxmFile(textureLibraryNode);
                    }
                    else
                    {
                        throw new Exception("Multiple texture library nodes in cmp root");
                    }
                    break;

                case "cmpnd":
                    IntermediateNode cmpndNode = node as IntermediateNode;
                    int maxIndices             = int.MaxValue;
                    foreach (Node SubNode in cmpndNode)
                    {
                        if (SubNode is LeafNode)
                        {
                            continue;
                        }
                        var cmpndSubNode = (IntermediateNode)SubNode;
                        if (cmpndSubNode.Name.Equals("cons", StringComparison.OrdinalIgnoreCase))
                        {
                            Constructs.AddNode(cmpndSubNode);
                        }
                        else if (
                            cmpndSubNode.Name.StartsWith("part_", StringComparison.OrdinalIgnoreCase) ||
                            cmpndSubNode.Name.Equals("root", StringComparison.OrdinalIgnoreCase)
                            )
                        {
                            string objectName = string.Empty, fileName = string.Empty;
                            int    index = -1;

                            foreach (LeafNode partNode in cmpndSubNode)
                            {
                                switch (partNode.Name.ToLowerInvariant())
                                {
                                case "object name":
                                    objectName = partNode.StringData;
                                    break;

                                case "file name":
                                    fileName = partNode.StringData;
                                    break;

                                case "index":
                                    if (partNode.Int32Data != null)
                                    {
                                        index = partNode.Int32Data.Value;
                                    }
                                    else
                                    {
                                        index = partNode.Int32ArrayData [0];
                                    }
                                    break;

                                default: throw new Exception("Invalid node in " + cmpndSubNode.Name + ": " + partNode.Name);
                                }
                            }
                            if (Parts.ContainsKey(index))
                            {
                                FLLog.Error("Cmp", "Duplicate index");
                                Parts.Add(maxIndices--, new Part(objectName, fileName, Models, Constructs));
                            }
                            else
                            {
                                Parts.Add(index, new Part(objectName, fileName, Models, Constructs));
                            }
                        }
                        else
                        {
                            throw new Exception("Invalid node in " + cmpndNode.Name + ": " + cmpndSubNode.Name);
                        }
                    }
                    break;

                case "materialanim":
                    MaterialAnim = new MaterialAnimCollection((IntermediateNode)node);
                    break;

                default:
                    if (node.Name.EndsWith(".3db", StringComparison.OrdinalIgnoreCase))
                    {
                        ModelFile m = new ModelFile(node as IntermediateNode, this);
                        Models.Add(node.Name, m);
                    }
                    else
                    {
                        FLLog.Error("Cmp", Path ?? "Utf" + ": Invalid Node in cmp root: " + node.Name);
                    }
                    break;
                }
            }
        }
Exemplo n.º 8
0
 public void DrawBuffer(CommandBuffer buffer, Matrix4 world, ref Lighting light, MaterialAnimCollection mc, Material overrideMat = null)
 {
     if (ready)
     {
         if (needsOptimize)
         {
             Optimize();
         }
         if (optimized != null)
         {
             for (int i = 0; i < optimized.Optimized.Length; i++)
             {
                 var m = optimized.Optimized[i].Material;
                 if (m == null)
                 {
                     m = vMeshLibrary.FindMaterial(0);
                 }
                 MaterialAnim ma = null;
                 if (mc != null)
                 {
                     mc.Anims.TryGetValue(m.Name, out ma);
                 }
                 buffer.AddCommand(
                     m.Render,
                     ma,
                     world,
                     light,
                     Mesh.VertexBuffer,
                     PrimitiveTypes.TriangleList,
                     optimized.Optimized[i].VertexOffset,
                     optimized.Optimized[i].StartIndex,
                     optimized.Optimized[i].PrimitiveCount,
                     SortLayers.OBJECT,
                     0
                     );
             }
             for (int i = 0; i < optimized.NormalDraw.Length; i++)
             {
                 Mesh.Meshes[optimized.NormalDraw[i]].DrawBuffer(buffer, Mesh, Mesh.VertexOffset, StartVertex, Mesh.IndexOffset, world, ref light, mc, overrideMat);
             }
         }
         else
         {
             Mesh.DrawBuffer(buffer, StartMesh, endMesh, StartVertex, world, ref light, Center, mc, overrideMat);
         }
     }
 }
Exemplo n.º 9
0
        public CmpFile(IntermediateNode rootnode, ILibFile additionalLibrary)
        {
            this.additionalLibrary = additionalLibrary;

            Models     = new Dictionary <string, ModelFile>();
            Cameras    = new Dictionary <string, CmpCameraInfo>();
            Constructs = new ConstructCollection();
            Parts      = new List <Part>();
            List <string> modelNames = new List <string>();

            foreach (Node node in rootnode)
            {
                switch (node.Name.ToLowerInvariant())
                {
                case "exporter version":
                    break;

                case "vmeshlibrary":
                    IntermediateNode vMeshLibraryNode = node as IntermediateNode;
                    if (VMeshLibrary == null)
                    {
                        VMeshLibrary = new VmsFile(vMeshLibraryNode, this);
                    }
                    else
                    {
                        throw new Exception("Multiple vmeshlibrary nodes in cmp root");
                    }
                    break;

                case "animation":
                    IntermediateNode animationNode = node as IntermediateNode;
                    if (Animation == null)
                    {
                        Animation = new AnmFile(animationNode, Constructs);
                    }
                    else
                    {
                        throw new Exception("Multiple animation nodes in cmp root");
                    }
                    break;

                case "material library":
                    IntermediateNode materialLibraryNode = node as IntermediateNode;
                    if (MaterialLibrary == null)
                    {
                        MaterialLibrary = new MatFile(materialLibraryNode, this);
                    }
                    else
                    {
                        throw new Exception("Multiple material library nodes in cmp root");
                    }
                    break;

                case "texture library":
                    IntermediateNode textureLibraryNode = node as IntermediateNode;
                    if (TextureLibrary == null)
                    {
                        TextureLibrary = new TxmFile(textureLibraryNode);
                    }
                    else
                    {
                        throw new Exception("Multiple texture library nodes in cmp root");
                    }
                    break;

                case "cmpnd":
                    IntermediateNode cmpndNode = node as IntermediateNode;
                    foreach (Node SubNode in cmpndNode)
                    {
                        if (SubNode is LeafNode)
                        {
                            continue;
                        }
                        var cmpndSubNode = (IntermediateNode)SubNode;
                        if (cmpndSubNode.Name.Equals("cons", StringComparison.OrdinalIgnoreCase))
                        {
                            Constructs.AddNode(cmpndSubNode);
                        }
                        else if (
                            cmpndSubNode.Name.StartsWith("part_", StringComparison.OrdinalIgnoreCase) ||
                            cmpndSubNode.Name.Equals("root", StringComparison.OrdinalIgnoreCase)
                            )
                        {
                            string objectName = string.Empty, fileName = string.Empty;

                            foreach (LeafNode partNode in cmpndSubNode)
                            {
                                switch (partNode.Name.ToLowerInvariant())
                                {
                                case "object name":
                                    objectName = partNode.StringData;
                                    break;

                                case "file name":
                                    fileName = partNode.StringData;
                                    break;

                                case "index":
                                    break;

                                default:
                                    FLLog.Error("Cmp", "Invalid node in " + cmpndSubNode.Name + ": " + partNode.Name);
                                    break;
                                }
                            }
                            Parts.Add(new Part(objectName, fileName, Models, Cameras, Constructs));
                        }
                        else
                        {
                            throw new Exception("Invalid node in " + cmpndNode.Name + ": " + cmpndSubNode.Name);
                        }
                    }
                    break;

                case "materialanim":
                    MaterialAnim = new MaterialAnimCollection((IntermediateNode)node);
                    break;

                default:
                    if (node is IntermediateNode)
                    {
                        var im = (IntermediateNode)node;
                        if (im.Any(x => x.Name.Equals("vmeshpart", StringComparison.OrdinalIgnoreCase) ||
                                   x.Name.Equals("multilevel", StringComparison.OrdinalIgnoreCase)))
                        {
                            ModelFile m = new ModelFile(im, this);
                            m.Path = node.Name;
                            Models.Add(node.Name, m);
                            modelNames.Add(node.Name);
                            break;
                        }
                        else if (im.Any(x => x.Name.Equals("camera", StringComparison.OrdinalIgnoreCase)))
                        {
                            var cam = new CmpCameraInfo(im);
                            Cameras.Add(im.Name, cam);
                            break;
                        }
                    }
                    FLLog.Error("Cmp", Path ?? "Utf" + ": Invalid Node in cmp root: " + node.Name);
                    break;
                }
            }
            //FL handles cmpnd nodes that point to non-existant models: fix up here
            List <Part> broken = new List <Part>();

            for (int i = 0; i < Parts.Count; i++)
            {
                if (Parts[i].IsBroken())
                {
                    broken.Add(Parts[i]);
                }
            }
            foreach (var b in broken)
            {
                Parts.Remove(b);
            }
        }
Exemplo n.º 10
0
 public void DrawBuffer(CommandBuffer buffer, Matrix4 world, ref Lighting light, MaterialAnimCollection mc, Material overrideMat = null)
 {
     if (ready)
     {
         Mesh.DrawBuffer(buffer, StartMesh, endMesh, StartVertex, world, ref light, Center, mc, overrideMat);
     }
 }