public override async System.Threading.Tasks.Task <ImageSource[]> GetSnapshotImage(bool forceCreate)
        {
            if (mIsGenerationSnapshot == true)
            {
                return(null);
            }
            var snapShotFile = ResourceName.Address + EditorCommon.Program.SnapshotExt;

            if (forceCreate == false)
            {
                var imgSource = await EditorCommon.ImageInit.GetImage(snapShotFile);

                if (imgSource != null)
                {
                    return(imgSource);
                }
            }

            mIsGenerationSnapshot = true;
            var rc         = CEngine.Instance.RenderContext;
            var meshSource = CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(rc, ResourceName, true);

            var curMesh = CEngine.Instance.MeshManager.CreateMesh(rc, meshSource /*, EditorCommon.SnapshotProcess.SnapshotCreator.GetShadingEnv()*/);

            if (curMesh == null)
            {
                mIsGenerationSnapshot = false;
                return(null);
            }

            var mtl = EngineNS.CEngine.Instance.MaterialInstanceManager.DefaultMaterialInstance;

            for (UInt32 i = 0; i < curMesh.MtlMeshArray.Length; i++)
            {
                await curMesh.SetMaterialInstanceAsync(EngineNS.CEngine.Instance.RenderContext, i, mtl, null);
            }

            var snapShorter = new EditorCommon.SnapshotProcess.SnapshotCreator();//EngineNS.Editor.SnapshotCreator();//

            snapShorter.SkyName   = EngineNS.RName.GetRName("Mesh/sky.gms");
            snapShorter.FloorName = EngineNS.RName.GetRName(@"editor/floor.gms");
            var eye = new EngineNS.Vector3();

            eye.SetValue(1.6f, 1.5f, -3.6f);
            var at = new EngineNS.Vector3();

            at.SetValue(0.0f, 0.0f, 0.0f);
            var up = new EngineNS.Vector3();

            up.SetValue(0.0f, 1.0f, 0.0f);
            await snapShorter.InitEnviroment();

            snapShorter.Camera.LookAtLH(eye, at, up);

            var actor = EngineNS.GamePlay.Actor.GActor.NewMeshActorDirect(curMesh);

            actor.Placement.Location = new Vector3(0, -0.5f, 0);

            curMesh.PreUse(true);//就这个地方用,别的地方别乱用,效率不好
            snapShorter.World.AddActor(actor);
            snapShorter.World.GetScene(RName.GetRName("SnapshorCreator")).AddActor(actor);
            snapShorter.FocusActor = actor;
            await snapShorter.SaveToFile(snapShotFile, 1, curMesh.Editor_GetSnapshortFrameNumber());

            mIsGenerationSnapshot = false;

            return(await EditorCommon.ImageInit.GetImage(snapShotFile));
        }
Пример #2
0
        static async System.Threading.Tasks.Task RealMain(CMDEngine cmdEngine, string[] args)
        {
            await EngineNS.CEngine.Instance.InitSystem(IntPtr.Zero, 0, 0, EngineNS.ERHIType.RHT_VirtualDevice, true);

            await EngineNS.CEngine.Instance.OnEngineInited();

            CIPlatform.Instance.PlayMode = CIPlatform.enPlayMode.Cook;

            switch (args[0].ToLower())
            {
            case "pack":
            {
                var src = FindArgument(args, "src=").Substring("src=".Length);
                if (src == null)
                {
                    return;
                }
                var tar = FindArgument(args, "tar=").Substring("tar=".Length);
                if (tar == null)
                {
                    return;
                }

                AssetsPacker.PackAList(src, tar);

                var pak = new EngineNS.IO.CPakFile();
                pak.LoadPak(tar);
                for (UInt32 i = 0; i < pak.AssetNum; i++)
                {
                    var name = pak.GetAssetName(i);
                    var sz   = pak.GetAssetSize(i);
                    var szip = pak.GetAssetSizeInPak(i);
                }
                cmdEngine.IsRun = false;
            }
            break;

            case "unpack":
            {
            }
            break;

            case "cook":
            {
                var entry = FindArgument(args, "entry=").Substring("entry=".Length);
                var rn    = EngineNS.RName.GetRName(entry);

                var platformStr = FindArgument(args, "platform=").Substring("platform=".Length);
                var platforms   = platformStr.Split('+');

                var copyRInfo = FindArgument(args, "copyrinfo");

                EngineNS.IO.XmlHolder AssetInfos = EngineNS.IO.XmlHolder.NewXMLHolder("AssetsPackage", "");         //For andorid

                string[] sm    = null;
                var      smStr = FindArgument(args, "shadermodel=");
                if (smStr != null)
                {
                    sm = smStr.Substring("shadermodel=".Length).Split('+');
                }

                if (FindArgument(args, "genvsproj") != null)
                {
                    CMDEngine.CMDEngineInstance.IsNeedProject = true;
                }

                var texEncoder = FindArgument(args, "texencoder=");
                if (texEncoder != null)
                {
                    ResourceCooker.TexCompressFlags = 0;
                    var texFormats = texEncoder.Substring("texencoder=".Length).Split('+');
                    if (FindArgument(texFormats, "PNG") != null)
                    {
                        ResourceCooker.TexCompressFlags |= ResourceCooker.ETexCompressMode.PNG;
                    }
                    if (FindArgument(texFormats, "ETC2") != null)
                    {
                        ResourceCooker.TexCompressFlags |= ResourceCooker.ETexCompressMode.ETC2;
                    }
                    if (FindArgument(texFormats, "ASTC") != null)
                    {
                        ResourceCooker.TexCompressFlags |= ResourceCooker.ETexCompressMode.ASTC;
                    }
                }

                var pakAssets = FindArgument(args, "pak=");
                if (pakAssets != null)
                {
                    pakAssets = pakAssets.Substring("pak=".Length);
                }
                try
                {
                    foreach (var i in platforms)
                    {
                        CEngine.Instance.FileManager.CookingPlatform = i;
                        var cooker = new AssetCooker();
                        await cooker.CollectAssets(rn, i, copyRInfo != null?true : false, sm);
                        await CookPlatformShader(args, i, sm, cooker.MaterialAssets);

                        cooker.DirectCopyFiles(i);
                        CMDEngine.CMDEngineInstance.SaveAssetinfos(i);

                        if (pakAssets != null)
                        {
                            var listFileName = CEngine.Instance.FileManager.Cooked + CEngine.Instance.FileManager.CookingPlatform + "/tmp_pakassets.alist";
                            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(listFileName))
                            {
                                var files = CEngine.Instance.FileManager.GetFiles(CEngine.Instance.FileManager.CookingRoot, "*.*", System.IO.SearchOption.AllDirectories);
                                foreach (var j in files)
                                {
                                    var  absName = j.ToLower();
                                    bool error   = false;
                                    absName = CEngine.Instance.FileManager.NormalizePath(absName, out error);
                                    if (absName.EndsWith(".rinfo"))
                                    {
                                        continue;
                                    }
                                    if (absName.EndsWith(".cs"))
                                    {
                                        continue;
                                    }
                                    if (absName.EndsWith(".noused"))
                                    {
                                        continue;
                                    }

                                    var NameInPak = absName.Substring(CEngine.Instance.FileManager.CookingRoot.Length);
                                    sw.WriteLine($"{absName} {NameInPak} normal");
                                }
                            }

                            AssetsPacker.PackAList(listFileName, pakAssets);
                        }
                    }
                }
                catch (Exception ex)
                {
                    EngineNS.Profiler.Log.WriteException(ex);
                }
                finally
                {
                    cmdEngine.IsRun = false;
                }
            }
            break;

            case "bake":
            {
            }
            break;

            case "localhost":
            {
            }
            break;

            case "gen_proj":
            {
                if (args.Length != 2)
                {
                    return;
                }

                GenProject.Instance.Command(args);

                cmdEngine.IsRun = false;
            }
            break;

            case "fresh_rinfo":
            {
                var subdir = FindArgument(args, "dir=").Substring("dir=".Length);

                var types    = FindArgument(args, "type=").Substring("type=".Length);
                var resTypes = types.Split('+');

                var nouse = cmdEngine.FreshRInfo(subdir, resTypes);

                cmdEngine.IsRun = false;
            }
            break;

            case "rname_change":
            {
                Dictionary <string, string> changeList = new Dictionary <string, string>();
                var name = FindArgument(args, "name=");
                if (name != null)
                {
                    name = name.Substring("name=".Length);

                    var seg = name.Split('+');
                    foreach (var i in seg)
                    {
                        var rnPair = i.Split('#');

                        if (rnPair.Length != 2)
                        {
                            EngineNS.Profiler.Log.WriteLine(EngineNS.Profiler.ELogTag.Warning, "RName", $"rename resource arguments error:{i}");
                            continue;
                        }

                        var rn = RName.GetRName(rnPair[0]);
                        if (CEngine.Instance.FileManager.FileExists(rn.Address))
                        {
                            var rnModifier = new RNameModifier();
                            rnModifier.CollectRefObjects(rn);

                            await rnModifier.SaveRefObjects(rn, rnPair[1]);

                            changeList[rnPair[0]] = rnPair[1];
                        }
                        else
                        {
                            EngineNS.Profiler.Log.WriteLine(EngineNS.Profiler.ELogTag.Warning, "RName", $"rename resource doesn't exist:{i}");
                        }
                    }
                }

                //移动目录
                var dir = FindArgument(args, "dir=");
                if (dir != null)
                {
                    dir = dir.Replace('&', ' ');
                    dir = dir.Substring("dir=".Length);
                    var seg = dir.Split('#');
                    if (seg.Length != 2)
                    {
                        EngineNS.Profiler.Log.WriteLine(EngineNS.Profiler.ELogTag.Warning, "RName", $"rename directory:{dir}");
                    }
                    else
                    {
                        var src   = seg[0].ToLower();
                        var tar   = seg[1].ToLower();
                        var files = CEngine.Instance.FileManager.GetFiles(EngineNS.CEngine.Instance.FileManager.ProjectContent + src, "*.rinfo", System.IO.SearchOption.AllDirectories);
                        foreach (var i in files)
                        {
                            bool error;
                            var  sf = EngineNS.CEngine.Instance.FileManager.NormalizePath(i, out error);
                            sf = sf.Substring(EngineNS.CEngine.Instance.FileManager.ProjectContent.Length);
                            sf = sf.Substring(0, sf.Length - ".rinfo".Length);
                            var rn  = EngineNS.RName.GetRName(sf);
                            var sf2 = sf.Substring(src.Length);
                            sf2 = tar + sf2;

                            if (CEngine.Instance.FileManager.FileExists(rn.Address))
                            {
                                var rnModifier = new RNameModifier();
                                rnModifier.CollectRefObjects(rn);
                                await rnModifier.SaveRefObjects(rn, sf2);

                                changeList[sf] = sf2;
                            }
                        }
                    }
                }

                foreach (var i in changeList)
                {
                    CEngine.Instance.FileManager.RNameRemap[i.Key] = i.Value;
                }

                var map = FindArgument(args, "savemap=");
                if (map != null)
                {
                    map = map.Substring("savemap=".Length);
                    var seg = map.Split('+');
                    foreach (var i in seg)
                    {
                        var rn = RName.GetRName(i);
                        EngineNS.GamePlay.GWorld World = new EngineNS.GamePlay.GWorld();
                        World.Init();
                        var scene = await EngineNS.GamePlay.GGameInstance.LoadScene(CEngine.Instance.RenderContext, World, rn);

                        if (scene != null)
                        {
                            EngineNS.Vector3 pos    = new EngineNS.Vector3(0, -10, 0);
                            EngineNS.Vector3 lookAt = new EngineNS.Vector3(0, 0, 0);
                            EngineNS.Vector3 up     = new EngineNS.Vector3(0, 1, 0);
                            {
                                var xnd = await EngineNS.IO.XndHolder.LoadXND(rn.Address + "/scene.map");

                                if (xnd != null)
                                {
                                    var att = xnd.Node.FindAttrib("ED_info");
                                    if (att != null)
                                    {
                                        att.BeginRead();

                                        att.Read(out pos);
                                        att.Read(out lookAt);
                                        att.Read(out up);
                                        att.EndRead();
                                    }
                                    xnd.Dispose();
                                }
                            }

                            await scene.SaveScene(rn, null, (InScene, InXnd) =>
                                {
                                    var att = InXnd.Node.AddAttrib("ED_info");
                                    att.BeginWrite();
                                    att.Write(pos);
                                    att.Write(lookAt);
                                    att.Write(up);
                                    att.EndWrite();
                                });
                        }
                    }
                }
                cmdEngine.IsRun = false;
            }
            break;

            default:
                break;
            }
        }
Пример #3
0
        public override async Task <ImageSource[]> GetSnapshotImage(bool forceCreate)
        {
            if (mIsGenerationSnapshot == true)
            {
                return(null);
            }
            var snapShotFile = ResourceName.Address + EditorCommon.Program.SnapshotExt;

            if (forceCreate == false)
            {
                var imgSource = await EditorCommon.ImageInit.GetImage(snapShotFile);

                if (imgSource != null)
                {
                    return(imgSource);
                }
            }

            if (mIsGenerationSnapshot == true)
            {
                return(null);
            }

            mIsGenerationSnapshot = true;
            var rc       = CEngine.Instance.RenderContext;
            var mCurMesh = await CEngine.Instance.MeshManager.CreateMeshAsync(rc, ResourceName /*, EditorCommon.SnapshotProcess.SnapshotCreator.GetShadingEnv()*/);

            if (mCurMesh == null)
            {
                mIsGenerationSnapshot = false;
                return(null);
            }

            var snapShorter = new EditorCommon.SnapshotProcess.SnapshotCreator();//EngineNS.Editor.SnapshotCreator();//

            snapShorter.SkyName   = EngineNS.RName.GetRName("Mesh/sky.gms");
            snapShorter.FloorName = EngineNS.RName.GetRName(@"editor/floor.gms");
            var eye = new EngineNS.Vector3();

            eye.SetValue(1.6f, 1.5f, -3.6f);
            var at = new EngineNS.Vector3();

            at.SetValue(0.0f, 0.0f, 0.0f);
            var up = new EngineNS.Vector3();

            up.SetValue(0.0f, 1.0f, 0.0f);
            await snapShorter.InitEnviroment();

            snapShorter.Camera.LookAtLH(eye, at, up);

            var actor = EngineNS.GamePlay.Actor.GActor.NewMeshActorDirect(mCurMesh);

            mCurMesh.PreUse(true);//就这个地方用,别的地方别乱用,效率不好
            snapShorter.World.AddActor(actor);
            snapShorter.World.GetScene(RName.GetRName("SnapshorCreator")).AddActor(actor);
            snapShorter.FocusActor   = actor;
            actor.Placement.Location = new Vector3(0, 0, 0);

            await snapShorter.SaveToFile(snapShotFile, 1, mCurMesh.Editor_GetSnapshortFrameNumber());

            mIsGenerationSnapshot = false;

            return(await EditorCommon.ImageInit.GetImage(snapShotFile));
        }
Пример #4
0
        private async System.Threading.Tasks.Task UpdateSelected(List <int> verts)
        {
            var rc = EngineNS.CEngine.Instance.RenderContext;

            foreach (var i in VertActors)
            {
                mPreviewSceneControl.RemoveActor(i);
            }
            VertActors.Clear();

            SelectedVerts = verts;

            if (verts.Count == 0)
            {
                return;
            }

            float bvl  = this.mPreviewActor.GetComponentMesh(null).MeshPrimitives.AABB.GetMaxSide() / 20;
            var   size = new EngineNS.Vector3(bvl, bvl, bvl);
            var   mtl0 = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, RName.GetRName("TitanDemo/greentest.instmtl"));

            var mtl1 = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, RName.GetRName("TitanDemo/redtest.instmtl"));

            foreach (var i in verts)
            {
                var curVert = mProgressMesh.Vertices[i];
                var center  = curVert.Position;

                var mesh = await EngineNS.CEngine.Instance.MeshManager.CreateMeshAsync(rc, RName.GetRName("editor/basemesh/box_center.gms"));

                var actor = EngineNS.GamePlay.Actor.GActor.NewMeshActorDirect(mesh);
                actor.Placement.Location = center;
                actor.Placement.Scale    = size;
                actor.GetComponentMesh(null).SetMaterialInstance(rc, 0, mtl0, null);

                VertActors.Add(actor);
                mPreviewSceneControl.AddDynamicActor(actor);

                foreach (var j in curVert.Linker.Vertices)
                {
                    curVert = mProgressMesh.Vertices[j];
                    center  = curVert.Position;

                    mesh = await EngineNS.CEngine.Instance.MeshManager.CreateMeshAsync(rc, RName.GetRName("editor/basemesh/box_center.gms"));

                    actor = EngineNS.GamePlay.Actor.GActor.NewMeshActorDirect(mesh);
                    actor.Placement.Location = center;
                    actor.Placement.Scale    = size;
                    actor.GetComponentMesh(null).SetMaterialInstance(rc, 0, mtl1, null);

                    VertActors.Add(actor);
                    mPreviewSceneControl.AddDynamicActor(actor);
                }
            }

            if (mGraphLines == null || mGraphLines.GraphActor == null)
            {
                mGraphLines                   = new EngineNS.Bricks.GraphDrawer.GraphLines();
                mGraphLines.LinesGen          = mLineGen;
                mGraphLines.LinesGen.Interval = 0f;
                mGraphLines.LinesGen.Segement = 100f;
                RName lineMaterial = RName.GetRName("editor/icon/icon_3d/material/line_df.instmtl");

                var curVert = mProgressMesh.Vertices[verts[0]];
                var start   = curVert.Position;
                mGraphLines.LinesGen.Start = start;

                var lnkVerts = curVert.Linker.Vertices;
                var end      = mProgressMesh.Vertices[lnkVerts[0]];

                mLineGen.SetVector3Points(new Vector3[] { start, end.Position });
                var mtl = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(
                    EngineNS.CEngine.Instance.RenderContext,
                    lineMaterial);

                await mGraphLines.Init(mtl, 0);

                mGraphLines.UpdateGeomMesh(CEngine.Instance.RenderContext, 0);
                mGraphLines.GraphActor.Placement.Location = Vector3.Zero;

                mPreviewSceneControl.AddDynamicActor(mGraphLines.GraphActor);
            }
            else
            {
                mGraphLines.GraphActor.Visible = verts.Count > 0;

                var curVert = mProgressMesh.Vertices[verts[0]];
                var start   = curVert.Position;
                mGraphLines.LinesGen.Start = start;

                var            lnkVerts = curVert.Linker.Vertices;
                List <Vector3> points   = new List <Vector3>();
                foreach (var i in verts)
                {
                    curVert = mProgressMesh.Vertices[i];
                    start   = curVert.Position;
                    foreach (var j in curVert.Linker.Vertices)
                    {
                        curVert = mProgressMesh.Vertices[j];
                        var end = curVert.Position;

                        points.Add(start);
                        points.Add(end);
                    }
                }

                mLineGen.SetVector3Points(points.ToArray());
                mGraphLines.UpdateGeomMesh(CEngine.Instance.RenderContext, bvl * 0.1f);
            }
        }