Esempio n. 1
0
        protected override Entity Create()
        {
            var root = base.Create();

            pointMesh = new LightPointMesh(GraphicsDevice);
            pointMesh.Build();

            pointMaterial = GizmoEmissiveColorMaterial.Create(GraphicsDevice, (Color) new Color4(GetLightColor(GraphicsDevice), 1f));

            pointEntity = new Entity("Point Mesh of {0}".ToFormat(root.Id))
            {
                new ModelComponent
                {
                    Model = new Model
                    {
                        pointMaterial,
                        new Mesh {
                            Draw = pointMesh.MeshDraw
                        },
                    },
                    RenderGroup = RenderGroup,
                }
            };

            return(root);
        }
Esempio n. 2
0
        protected override Entity Create()
        {
            var root = base.Create();

            spotMesh = new LightSpotMesh(GraphicsDevice);
            spotMesh.Build(GraphicsCommandList, LightSpot);

            spotMaterial = GizmoUniformColorMaterial.Create(GraphicsDevice, (Color) new Color4(GetLightColor(GraphicsDevice), 1f));

            spotEntity = new Entity("Spot Mesh of {0}".ToFormat(root.Id))
            {
                new ModelComponent
                {
                    Model = new Model
                    {
                        spotMaterial,
                        new Mesh {
                            Draw = spotMesh.MeshDraw
                        },
                    },
                    RenderGroup = RenderGroup,
                }
            };

            return(root);
        }
        static void ImportFile(string path, string relativePath, string output)
        {
            string[] arr  = relativePath.Split('.');
            string   name = Path.GetFileNameWithoutExtension(relativePath);

            switch (arr[arr.Length - 1])
            {
            case "jpg":
            case "jpeg":
            case "dds":
            case "tiff":
            case "tif":
            case "psd":
            case "tga":
            case "bmp":
            case "gif":
            case "png":
                break;
                if ((name.ToLower().EndsWith("bump") && !name.ToLower().StartsWith("bump")) || (name.ToLower().EndsWith("normal") && !name.ToLower().StartsWith("normal")))
                {
                    TextureAsset tex = NormalMapTextureFactory.Create();
                    tex.Source = new UFile(relativePath);
                    if (!overwrite && File.Exists($"{output}/{name}{TextureAsset.FileExtension}"))
                    {
                        Console.WriteLine($"{output}/{name}{TextureAsset.FileExtension} exists - not writing.");
                        break;
                    }
                    else
                    {
                        AssetFileSerializer.Save($"{output}/{name}{TextureAsset.FileExtension}", tex, null);
                    }
                }
                else
                {
                    TextureAsset tex = ColorTextureFactory.Create();
                    tex.Source = new UFile(relativePath);
                    if (!overwrite && File.Exists($"{output}/{name}{TextureAsset.FileExtension}"))
                    {
                        Console.WriteLine($"{output}/{name}{TextureAsset.FileExtension} exists - not writing.");
                        break;
                    }
                    AssetFileSerializer.Save($"{output}/{name}{TextureAsset.FileExtension}", tex, null);
                    MaterialAsset mat = DiffuseMaterialFactory.Create();
                    ((ComputeTextureColor)((MaterialDiffuseMapFeature)mat.Attributes.Diffuse).DiffuseMap).Texture = GetTexture(tex);
                    AssetFileSerializer.Save($"{output}/{name}{MaterialAsset.FileExtension}", mat, null);
                }
                break;

            case "dae":
            case "3ds":
            case "obj":
            case "blend":
            case "x":
            case "md2":
            case "md3":
            case "dxf":
            case "fbx":
                if (!overwrite && File.Exists($"{output}/{name}{ModelAsset.FileExtension.Split(';')[0]}"))
                {
                    Console.WriteLine($"{output}/{name}{ModelAsset.FileExtension.Split(';')[0]} exists - not writing.");
                    break;
                }
                ModelAsset model = DefaultAssetFactory <ModelAsset> .Create();

                model.Source = new UFile(relativePath);
                Scene scene = ctx.ImportFile(path, PostProcessSteps.None);
                Dictionary <string, Stride.Rendering.Material> materials = new Dictionary <string, Stride.Rendering.Material>();
                for (int i = 0; i < scene.MaterialCount; i++)
                {
                    if (materials.ContainsKey(scene.Materials[i].Name))
                    {
                        model.Materials.Add(new ModelMaterial()
                        {
                            Name             = scene.Materials[i].Name,
                            MaterialInstance = new MaterialInstance(materials[scene.Materials[i].Name])
                        });
                        continue;
                    }

                    if (!overwrite && File.Exists($"{output}/{scene.Materials[i].Name}{MaterialAsset.FileExtension}"))
                    {
                        Console.WriteLine($"{output}/{scene.Materials[i].Name}{MaterialAsset.FileExtension} exists - not writing parent mesh.");
                        break;
                    }
                    MaterialAsset materialAsset = DiffuseMaterialFactory.Create();

                    // set diffuse (if possible)
                    if (scene.Materials[i].HasTextureDiffuse)
                    {
                        string       diffPath = Path.GetRelativePath(output, Path.Combine(Path.GetDirectoryName(path), scene.Materials[i].TextureDiffuse.FilePath));
                        TextureAsset asset    = ImportTexture(diffPath, TextureType.Diffuse);
                        if (!overwrite && File.Exists($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension}"))
                        {
                            Console.WriteLine($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension} exists - not writing parent mesh.");
                            break;
                        }
                        AssetFileSerializer.Save($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension}", asset, null);
                        Texture tex = GetTexture(asset);
                        SetTexture(materialAsset, tex, TextureType.Diffuse);
                    }

                    // normals
                    if (scene.Materials[i].HasTextureNormal)
                    {
                        string       normPath = Path.GetRelativePath(output, Path.Combine(Path.GetDirectoryName(path), scene.Materials[i].TextureNormal.FilePath));
                        TextureAsset asset    = ImportTexture(normPath, TextureType.Normals);
                        if (!overwrite && File.Exists($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension}"))
                        {
                            Console.WriteLine($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension} exists - not writing parent mesh.");
                            break;
                        }
                        AssetFileSerializer.Save($"{output}/{asset.Source.GetFileNameWithoutExtension()}{TextureAsset.FileExtension}", asset, null);
                        Texture tex = GetTexture(asset);
                        SetTexture(materialAsset, tex, TextureType.Normals);
                    }


                    AssetFileSerializer.Save($"{output}/{scene.Materials[i].Name}{MaterialAsset.FileExtension}", materialAsset, null);
                    Stride.Rendering.Material material = GetMaterial(materialAsset, scene.Materials[i].Name);
                    model.Materials.Add(new ModelMaterial()
                    {
                        Name             = scene.Materials[i].Name,
                        MaterialInstance = new MaterialInstance(material)
                    });
                    materials.Add(scene.Materials[i].Name, material);
                }
                AssetFileSerializer.Save($"{output}/{name}{ModelAsset.FileExtension.Split(';')[0]}", model, null);
                break;

            default:
                Console.WriteLine($"The file extension \".{arr[arr.Length - 1]}\" is not supported. ({path})");
                break;
            }
        }