Exemplo n.º 1
0
        public static EditableUtf Generate(IconType type, string iconName, LUtfNode textureNode, bool alpha)
        {
            var    modelFile    = new EditableUtf();
            var    unique       = IdSalt.New();
            string textureName  = $"data.icon.{iconName}.{unique}.tga";
            string materialName = $"data.icon.{iconName}.{unique}";
            string meshName     = $"data.icon.{iconName}.lod0-{unique}.vms";
            //VMeshLibrary
            var geom = new Geometry();

            geom.Vertices = type == IconType.Commodity ? vertices_commodity : vertices_ship;
            geom.Indices  = new Indices()
            {
                Indices16 = (type == IconType.Commodity ? indices_commodity : indices_ship)
            };
            geom.Attributes = VertexAttributes.Position | VertexAttributes.Normal | VertexAttributes.Texture1;
            geom.Groups     = new TriangleGroup[]
            {
                new TriangleGroup()
                {
                    BaseVertex = 0, StartIndex = 0, Material = new SimpleMesh.Material()
                    {
                        Name = materialName
                    }, IndexCount = 6
                }
            };
            geom.CalculateBounds();
            var vmsLib = new LUtfNode()
            {
                Name = "VMeshLibrary", Parent = modelFile.Root, Children = new List <LUtfNode>()
            };

            modelFile.Root.Children.Add(vmsLib);
            var vmsName = new LUtfNode()
            {
                Name = meshName, Parent = vmsLib, Children = new List <LUtfNode>()
            };

            vmsLib.Children.Add(vmsName);
            vmsName.Children.Add(new LUtfNode()
            {
                Name   = "VMeshData",
                Parent = vmsName,
                Data   = GeometryWriter.VMeshData(geom)
            });
            //VMeshPart
            var vmeshPart = new LUtfNode()
            {
                Name = "VMeshPart", Parent = modelFile.Root, Children = new List <LUtfNode>()
            };

            modelFile.Root.Children.Add(vmeshPart);
            vmeshPart.Children.Add(new LUtfNode()
            {
                Name = "VMeshRef", Parent = vmeshPart, Data = GeometryWriter.VMeshRef(geom, meshName)
            });

            //Texture
            var textureLibrary = new LUtfNode()
            {
                Name   = "Texture Library",
                Parent = modelFile.Root
            };

            textureLibrary.Children = new List <LUtfNode>();
            var clonedTex = textureNode.MakeCopy();

            clonedTex.Parent = textureLibrary;
            clonedTex.Name   = textureName;
            textureLibrary.Children.Add(clonedTex);
            modelFile.Root.Children.Add(textureLibrary);
            //Material
            var materialLibrary = new LUtfNode()
            {
                Name   = "Material Library",
                Parent = modelFile.Root
            };

            materialLibrary.Children = new List <LUtfNode>();
            var material = new LUtfNode()
            {
                Name   = materialName,
                Parent = materialLibrary
            };

            material.Children = new List <LUtfNode>();
            material.Children.Add(new LUtfNode()
            {
                Name   = "Type",
                Parent = material,
                Data   = Encoding.ASCII.GetBytes(alpha ? "DcDtOcOt" : "DcDt")
            });
            material.Children.Add(new LUtfNode()
            {
                Name   = "Dt_name",
                Parent = material,
                Data   = Encoding.ASCII.GetBytes(textureName)
            });
            material.Children.Add(new LUtfNode()
            {
                Name   = "Dt_flags",
                Parent = material,
                Data   = BitConverter.GetBytes((int)SamplerFlags.Default)
            });
            materialLibrary.Children.Add(material);
            modelFile.Root.Children.Add(materialLibrary);

            return(modelFile);
        }
Exemplo n.º 2
0
        public static EditableUtf Generate(string iconName, LUtfNode textureNode, bool alpha)
        {
            var    modelFile    = new EditableUtf();
            var    unique       = IdSalt.New();
            string textureName  = $"data.icon.{iconName}.{unique}.tga";
            string materialName = $"data.icon.{iconName}.{unique}";
            string meshName     = $"data.icon.{iconName}.lod0-{unique}.vms";
            //VMeshLibrary
            var geom = new ColladaGeometry();

            geom.Vertices  = vertices;
            geom.Indices   = indices;
            geom.FVF       = D3DFVF.NORMAL | D3DFVF.XYZ | D3DFVF.TEX1;
            geom.Drawcalls = new[]
            {
                new ColladaDrawcall()
                {
                    StartVertex = 0, EndVertex = 3, Material = new ColladaMaterial()
                    {
                        Name = materialName
                    }, StartIndex = 0, TriCount = 2
                }
            };
            geom.CalculateDimensions();
            var vmsLib = new LUtfNode()
            {
                Name = "VMeshLibrary", Parent = modelFile.Root, Children = new List <LUtfNode>()
            };

            modelFile.Root.Children.Add(vmsLib);
            var vmsName = new LUtfNode()
            {
                Name = meshName, Parent = vmsLib, Children = new List <LUtfNode>()
            };

            vmsLib.Children.Add(vmsName);
            vmsName.Children.Add(new LUtfNode()
            {
                Name   = "VMeshData",
                Parent = vmsName,
                Data   = geom.VMeshData()
            });
            //VMeshPart
            var vmeshPart = new LUtfNode()
            {
                Name = "VMeshPart", Parent = modelFile.Root, Children = new List <LUtfNode>()
            };

            modelFile.Root.Children.Add(vmeshPart);
            vmeshPart.Children.Add(new LUtfNode()
            {
                Name = "VMeshRef", Parent = vmeshPart, Data = geom.VMeshRef(meshName)
            });

            //Texture
            var textureLibrary = new LUtfNode()
            {
                Name   = "Texture Library",
                Parent = modelFile.Root
            };

            textureLibrary.Children = new List <LUtfNode>();
            var clonedTex = textureNode.MakeCopy();

            clonedTex.Parent = textureLibrary;
            clonedTex.Name   = textureName;
            textureLibrary.Children.Add(clonedTex);
            modelFile.Root.Children.Add(textureLibrary);
            //Material
            var materialLibrary = new LUtfNode()
            {
                Name   = "Material Library",
                Parent = modelFile.Root
            };

            materialLibrary.Children = new List <LUtfNode>();
            var material = new LUtfNode()
            {
                Name   = materialName,
                Parent = materialLibrary
            };

            material.Children = new List <LUtfNode>();
            material.Children.Add(new LUtfNode()
            {
                Name   = "Type",
                Parent = material,
                Data   = Encoding.ASCII.GetBytes(alpha ? "DcDtOcOt" : "DcDt")
            });
            material.Children.Add(new LUtfNode()
            {
                Name   = "Dt_name",
                Parent = material,
                Data   = Encoding.ASCII.GetBytes(textureName)
            });
            material.Children.Add(new LUtfNode()
            {
                Name   = "Dt_flags",
                Parent = material,
                Data   = BitConverter.GetBytes((int)SamplerFlags.Default)
            });
            materialLibrary.Children.Add(material);
            modelFile.Root.Children.Add(materialLibrary);

            return(modelFile);
        }