コード例 #1
0
        public override async Task <ImageSource[]> GetSnapshotImage(bool forceCreate)
        {
            if (mIsGenerationSnapshot)
            {
                return(null);
            }
            var snapShotFile = ResourceName.Address + ".snap";

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

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

            mIsGenerationSnapshot = true;
            var rc         = EngineNS.CEngine.Instance.RenderContext;
            var meshSource = EngineNS.CEngine.Instance.MeshPrimitivesManager.GetMeshPrimitives(rc,
                                                                                               EngineNS.CEngine.Instance.FileManager.GetRName("Meshes/sphere.vms", EngineNS.RName.enRNameType.Editor), true);
            var mCurMesh = EngineNS.CEngine.Instance.MeshManager.CreateMesh(rc, meshSource /*, EditorCommon.SnapshotProcess.SnapshotCreator.GetShadingEnv()*/);

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

            var mtlInst = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, ResourceName);

            var SyncOK = await mCurMesh.SetMaterialInstanceAsync(rc, 0, mtlInst, null);

            if (SyncOK == true)
            {
                var snapShorter = new EditorCommon.SnapshotProcess.SnapshotCreator();//EngineNS.Editor.SnapshotCreator();//
                SyncOK = await snapShorter.InitEnviroment();

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

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

                mCurMesh.PreUse(true);//就这个地方用,别的地方别乱用,效率不好
                snapShorter.World.AddActor(actor);
                snapShorter.World.GetScene(EngineNS.RName.GetRName("SnapshorCreator")).AddActor(actor);

                actor.Placement.Location = new EngineNS.Vector3(0, 0, 0);

                //var nouse = snapShorter.SaveToFile(snapShotFile);
                actor.PreUse(true);
                await snapShorter.SaveToFile(snapShotFile, 1000, 8);
            }

            mIsGenerationSnapshot = false;
            return(await EditorCommon.ImageInit.GetImage(snapShotFile));
        }
コード例 #2
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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        public override async Task <ImageSource[]> GetSnapshotImage(bool forceCreate)
        {
            if (mIsGenerationSnapshot)
            {
                return(null);
            }
            var snapShotFile = ResourceName.Address + ".snap";

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

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

            mIsGenerationSnapshot = true;
            var rc = EngineNS.CEngine.Instance.RenderContext;

            var uvAnim = await EngineNS.CEngine.Instance.UVAnimManager.GetUVAnimAsync(rc, ResourceName);

            if (uvAnim == null)
            {
                mIsGenerationSnapshot = false;
                return(null);
            }
            var snapCreator = new EditorCommon.SnapshotProcess.SnapshotCreator();
            var scOK        = await snapCreator.InitEnviroment();

            if (scOK == false)
            {
                mIsGenerationSnapshot = false;
                return(null);
            }
            var img2D = await EngineNS.Graphics.Mesh.CGfxImage2D.CreateImage2D(rc, uvAnim.MaterialInstanceRName, 0, 0, 0, 1, 1);

            if (img2D == null)
            {
                return(null);
            }
            var texture = EngineNS.CEngine.Instance.TextureManager.GetShaderRView(rc, uvAnim.TextureRName);

            img2D.SetTexture("texture", texture);
            var desc = texture.TxPicDesc;

            if (desc.Width == 0 || desc.Height == 0)
            {
                return(null);
            }
            float drawWidth, drawHeight;

            // todo: 这里要根据Frame的UV计算出真正的大小
            if (desc.Width > desc.Height)
            {
                var delta = snapCreator.mWidth / desc.Width;
                drawWidth  = snapCreator.mWidth;
                drawHeight = desc.Height * delta;
            }
            else
            {
                var delta = snapCreator.mHeight / desc.Height;
                drawHeight = snapCreator.mHeight;
                drawWidth  = desc.Width * delta;
            }
            img2D.RenderMatrix         = EngineNS.Matrix.Scaling(drawWidth, drawHeight, 1.0f);
            snapCreator.TickLogicEvent = (sc, arg) =>
            {
                sc.World?.Tick();
                sc.World?.CheckVisible(rc.ImmCommandList, sc.Camera);
                sc.mRP_Snapshot.OnAfterTickLogicArgument = arg;
                sc.mRP_Snapshot.TickLogic(null, rc);

                var designRect   = new EngineNS.RectangleF(0, 0, drawWidth, drawHeight);
                var tempClipRect = designRect;

                uvAnim.CheckAndAutoReferenceFromTemplateUVAnim();
                bool frameChanged;
                var  frame = uvAnim.GetUVFrame(EngineNS.Support.Time.GetTickCount(), out frameChanged);

                using (var posData = EngineNS.Support.NativeListProxy <EngineNS.Vector3> .CreateNativeList())
                    using (var uvData = EngineNS.Support.NativeListProxy <EngineNS.Vector2> .CreateNativeList())
                    {
                        frame.UpdateVertexes(posData, ref designRect, ref tempClipRect);
                        frame.UpdateUVs(uvData, ref designRect, ref tempClipRect);
                        img2D.RenderMatrix = EngineNS.Matrix.Scaling(tempClipRect.Width, tempClipRect.Height, 1) * EngineNS.Matrix.Translate(tempClipRect.Left, tempClipRect.Top, 0.0f);
                        img2D.SetUV(uvData, rc.ImmCommandList);
                        img2D.SetVertexBuffer(posData, rc.ImmCommandList);
                    }
            };
            snapCreator.mRP_Snapshot.OnDrawUI += (cmd, view) =>
            {
                var mtlMesh = img2D.Mesh.MtlMeshArray[0];
                var pass    = img2D.GetPass();
                pass.ViewPort = view.Viewport;
                if (pass.RenderPipeline == null)
                {
                    var rplDesc = new EngineNS.CRenderPipelineDesc();
                    pass.RenderPipeline = rc.CreateRenderPipeline(rplDesc);
                }
                pass.RenderPipeline.RasterizerState   = mtlMesh.MtlInst.CustomRasterizerState;
                pass.RenderPipeline.DepthStencilState = mtlMesh.MtlInst.CustomDepthStencilState;
                pass.RenderPipeline.BlendState        = mtlMesh.MtlInst.CustomBlendState;

                pass.BindCBuffer(pass.Effect.ShaderProgram, pass.Effect.CacheData.CBID_View, view.ScreenViewCB);
                pass.ShadingEnv.BindResources(img2D.Mesh, pass);
                cmd.PushPass(pass);
            };
            await snapCreator.SaveToFile(snapShotFile, 1000, 4);

            mIsGenerationSnapshot = false;
            return(await EditorCommon.ImageInit.GetImage(snapShotFile));
        }