Пример #1
0
        public void DSavePhyMesh(EngineNS.Graphics.Mesh.CGfxMeshPrimitives MeshPrimitives, string type)
        {
            if (MeshPrimitives == null)
            {
                return;
            }

            MeshPrimitives.SetRName(mEditMesh.Name);
            if (type.Equals("Triangle"))
            {
                MeshPrimitives.CookAndSavePhyiscsGeomAsTriMesh(CEngine.Instance.RenderContext, EngineNS.CEngine.Instance.PhyContext);
            }
            else if (type.Equals("Convex"))
            {
                MeshPrimitives.CookAndSavePhyiscsGeomAsConvex(CEngine.Instance.RenderContext, EngineNS.CEngine.Instance.PhyContext);
            }

            Action action = async() =>
            {
                var info = await EditorCommon.Resources.ResourceInfoManager.Instance.CreateResourceInfoFromResource(MeshPrimitives.Name.Address + (type.Equals("Triangle") ? CEngineDesc.PhyTriangleMeshGeom : CEngineDesc.PhyConvexGeom));

                await info.Save();
            };

            action();
        }
Пример #2
0
 public void BindGeometry(Graphics.Mesh.CGfxMeshPrimitives mesh, UInt32 atomIndex, float lod)//lod(0-1)
 {
     mGeometryMesh = mesh;
     if (mesh != null)
     {
         SDK_IPass_BindGeometry(CoreObject, mesh.CoreObject, atomIndex, lod);
     }
 }
Пример #3
0
        private async System.Threading.Tasks.Task ShowCurrentProgressMesh()
        {
            if (mPreviewActor != null)
            {
                mPreviewSceneControl.RemoveActor(mPreviewActor);
            }
            var rc = EngineNS.CEngine.Instance.RenderContext;

            mEditMeshPrimitive = mProgressMesh.CookMesh(rc);
            await CreatePreviewMeshesActor(mEditMeshPrimitive, false);
        }
Пример #4
0
        public static Graphics.Mesh.CGfxMeshPrimitives MergeGeomsAsMeshSimple(CRenderContext rc, List <Graphics.Mesh.CGfxMeshPrimitives> meshArray, List <Matrix> transforms)
        {
            var aabb   = new BoundingBox();
            var geom   = MergeGeoms(rc, meshArray, transforms, ref aabb);
            var result = new Graphics.Mesh.CGfxMeshPrimitives();

            result.InitFromGeomtryMesh(rc, geom, 1, ref aabb);

            var desc = new CDrawPrimitiveDesc();

            desc.SetDefault();
            foreach (var i in meshArray)
            {
                var td = new CDrawPrimitiveDesc();
                i.GetAtom(0, 0, ref td);
                desc.NumPrimitives += td.NumPrimitives;
            }
            result.PushAtomLOD(0, ref desc);
            return(result);
        }
Пример #5
0
        protected override async System.Threading.Tasks.Task CreateVmsAndGms(CRenderContext rc, uint meshIndex)
        {
            if (!mImportOption.ImportMesh)
            {
                return;
            }
            //导入不经过MeshPrimitivesManager
            //var meshPrimitive = CEngine.Instance.MeshPrimitivesManager.NewMeshPrimitives(rc,, 1);
            //meshPrimitive.Name

            var namePtr    = SDK_AssetImporter_GetMeshNameByIndex(mCoreObject, meshIndex);
            var ansiString = Marshal.PtrToStringAnsi(namePtr);

            if (MeshPrimitives.ContainsKey(ansiString))
            {
                ansiString += meshIndex.ToString();
            }
            var atom          = SDK_AssetImporter_GetMesAtomByIndex(mCoreObject, meshIndex);
            var meshPrimitive = new EngineNS.Graphics.Mesh.CGfxMeshPrimitives();
            var fullPath      = RName.EditorOnly_GetRNameFromAbsFile(mAbsSavePath + "/" + ansiString + CEngineDesc.MeshSourceExtension);

            CEngine.Instance.MeshPrimitivesManager.RemoveMeshPimitives(fullPath);
            if (Async)
            {
                await CEngine.Instance.EventPoster.Post(async() =>
                {
                    OnResourceImportCheck(this, AsseetImportType.AIT_Import, "CreateMeshPrimitive");
                    meshPrimitive.Init(rc, fullPath, atom);
                    SDK_AssetImporter_GetMeshPrimitiveByIndex(mCoreObject, rc.CoreObject, meshIndex, meshPrimitive.CoreObject);
                    var skinNativePointer = SDK_AssetImporter_BuildMeshPrimitiveSkinModifierByIndex(mCoreObject, rc.CoreObject, meshIndex, meshPrimitive.CoreObject);
                    if (skinNativePointer.GetPointer() != IntPtr.Zero)
                    {
                        var skinModifier      = new CGfxSkinModifier(skinNativePointer);
                        var nativeSkeleton    = CGfxSkinModifier.SDK_GfxSkinModifier_GetSkeleton(skinNativePointer);
                        CGfxSkeleton skeleton = new CGfxSkeleton(nativeSkeleton);
                        EngineNS.Bricks.Animation.Pose.CGfxSkeletonPose pose = new EngineNS.Bricks.Animation.Pose.CGfxSkeletonPose();
                        for (uint i = 0; i < skeleton.BoneTab.BoneNumberNative; ++i)
                        {
                            pose.NewBone(skeleton.BoneTab.GetBoneNative(i).BoneDescNative);
                        }
                        CGfxSkeleton csSkeleton = new CGfxSkeleton();
                        csSkeleton.BoneTab      = pose;
                        skinModifier.Skeleton   = csSkeleton;
                        meshPrimitive.MdfQueue.AddModifier(skinModifier);
                        if (mImportOption.SkeletonAssetName != null && mImportOption.SkeletonAssetName != RName.EmptyName)
                        {
                            var skeletonAsset          = EngineNS.CEngine.Instance.SkeletonAssetManager.GetSkeleton(rc, mImportOption.SkeletonAssetName, false);
                            skinModifier.SkeletonAsset = mImportOption.SkeletonAssetName.Name;
                            mSkeletonAsset             = mImportOption.SkeletonAssetName.Name;
                        }
                        else
                        {
                            OnResourceImportCheck(this, AsseetImportType.AIT_Import, "CreateSkeleton");
                            var pureName               = CEngine.Instance.FileManager.GetPureFileFromFullName(mAbsFileName, false);
                            var path                   = mAbsSavePath + "/" + pureName + CEngineDesc.SkeletonExtension;
                            var assetName              = RName.EditorOnly_GetRNameFromAbsFile(path);
                            var skeletonAsset          = EngineNS.CEngine.Instance.SkeletonAssetManager.CreateSkeletonAsset(rc, assetName, skinModifier);
                            skinModifier.SkeletonAsset = assetName.Name;
                            mSkeletonAsset             = assetName.Name;
                            if (!mSkeletonNeedInfo.ContainsKey(pureName))
                            {
                                mSkeletonNeedInfo.Add(pureName, assetName);
                            }
                        }
                    }
                    MeshPrimitives.Add(ansiString, meshPrimitive);
                    if (mImportOption.AsPhyGemoConvex || mImportOption.AsPhyGemoTri)
                    {
                        foreach (var i in MeshPrimitives.Values)
                        {
                            CGfxMeshPrimitives meshprimitive = i as CGfxMeshPrimitives;
                            if (mImportOption.AsPhyGemoConvex)
                            {
                                meshprimitive.CookAndSavePhyiscsGeomAsConvex(CEngine.Instance.RenderContext, EngineNS.CEngine.Instance.PhyContext);
                            }
                            else if (mImportOption.AsPhyGemoTri)
                            {
                                meshprimitive.CookAndSavePhyiscsGeomAsTriMesh(CEngine.Instance.RenderContext, EngineNS.CEngine.Instance.PhyContext);
                            }
                        }
                    }
                    else
                    {
                        await CEngine.Instance.EventPoster.Post(() =>
                        {
                            meshPrimitive.SaveMesh();
                            return(true);
                        }, EngineNS.Thread.Async.EAsyncTarget.Render);
                        //gms
                        if (mImportOption.CreatedGms)
                        {
                            OnResourceImportCheck(this, AsseetImportType.AIT_Import, "CreateMesh");
                            var meshRName = RName.EditorOnly_GetRNameFromAbsFile(mAbsSavePath + "/" + ansiString + CEngineDesc.MeshExtension);
                            var mesh      = CEngine.Instance.MeshManager.CreateMesh(rc, meshRName, meshPrimitive);
                            CEngine.Instance.MeshManager.RemoveMesh(meshRName);
                            mesh.Init(rc, meshRName, meshPrimitive);
                            var mtl = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, RName.GetRName("Material/defaultmaterial.instmtl"));
                            for (int i = 0; i < mesh.MtlMeshArray.Length; ++i)
                            {
                                await mesh.SetMaterialInstanceAsync(rc, (uint)i, mtl, CEngine.Instance.PrebuildPassData.DefaultShadingEnvs);
                            }
                            Meshes.Add(ansiString, mesh);
                            mesh.SaveMesh();
                        }
                    }
                    return(true);
                }, EngineNS.Thread.Async.EAsyncTarget.AsyncEditor);
            }
            else
            {
                OnResourceImportCheck(this, AsseetImportType.AIT_Import, "CreateMeshPrimitive");
                meshPrimitive.Init(rc, fullPath, atom);
                SDK_AssetImporter_GetMeshPrimitiveByIndex(mCoreObject, rc.CoreObject, meshIndex, meshPrimitive.CoreObject);
                var skinNativePointer = SDK_AssetImporter_BuildMeshPrimitiveSkinModifierByIndex(mCoreObject, rc.CoreObject, meshIndex, meshPrimitive.CoreObject);
                if (skinNativePointer.GetPointer() != IntPtr.Zero)
                {
                    var skinModifier = new CGfxSkinModifier(skinNativePointer);
                    meshPrimitive.MdfQueue.AddModifier(skinModifier);
                    if (mImportOption.SkeletonAssetName != null)
                    {
                        var skeletonAsset = EngineNS.CEngine.Instance.SkeletonAssetManager.GetSkeleton(rc, mImportOption.SkeletonAssetName, false);
                        skinModifier.SkeletonAsset = mImportOption.SkeletonAssetName.Name;
                    }
                    else
                    {
                        var pureName      = CEngine.Instance.FileManager.GetPureFileFromFullName(mAbsFileName, false);
                        var path          = mAbsSavePath + "/" + pureName + CEngineDesc.SkeletonExtension;
                        var assetName     = RName.EditorOnly_GetRNameFromAbsFile(path);
                        var skeletonAsset = EngineNS.CEngine.Instance.SkeletonAssetManager.CreateSkeletonAsset(rc, assetName, skinModifier);
                        skinModifier.SkeletonAsset = assetName.Name;
                        if (!mSkeletonNeedInfo.ContainsKey(pureName))
                        {
                            mSkeletonNeedInfo.Add(pureName, assetName);
                        }
                    }
                }
                MeshPrimitives.Add(ansiString, meshPrimitive);
                meshPrimitive.SaveMesh();

                //gms
                if (mImportOption.CreatedGms)
                {
                    OnResourceImportCheck(this, AsseetImportType.AIT_Import, "CreateMes");
                    var meshRName = RName.EditorOnly_GetRNameFromAbsFile(mAbsSavePath + "/" + ansiString + CEngineDesc.MeshExtension);
                    var mesh      = CEngine.Instance.MeshManager.CreateMesh(rc, meshRName, meshPrimitive);
                    CEngine.Instance.MeshManager.RemoveMesh(meshRName);
                    mesh.Init(rc, meshRName, meshPrimitive);
                    var mtl = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, RName.GetRName("Material/defaultmaterial.instmtl"));

                    for (int i = 0; i < mesh.MtlMeshArray.Length; ++i)
                    {
                        await mesh.SetMaterialInstanceAsync(rc, (uint)i, mtl, CEngine.Instance.PrebuildPassData.DefaultShadingEnvs);
                    }
                    Meshes.Add(ansiString, mesh);
                    mesh.SaveMesh();
                }
            }
            //foreach(var mp in MeshPrimitives)
            //{
            //    mp.Value.SaveMesh();
            //}
            //foreach(var mesh in Meshes)
            //{
            //    mesh.Value.SaveMesh();
            //}
            //var info = await EditorCommon.Resources.ResourceInfoManager.Instance.CreateResourceInfoFromResource(fullPath.Address);
            //info.Save();
            return;
        }
Пример #6
0
        public static void MakeUIScale9(CRenderContext rc, CGfxMeshPrimitives result, float x, float y, float w, float h, float z, bool lh = true, bool flipUVWhenGL = false)
        {
            var dpDesc = new CDrawPrimitiveDesc();

            dpDesc.SetDefault();
            dpDesc.NumPrimitives = 18;
            result.PushAtomLOD(0, ref dpDesc);
            unsafe
            {
                var ibData = new UInt16[54];
                ibData[0]  = 0;
                ibData[1]  = 1;
                ibData[2]  = 2;
                ibData[3]  = 0;
                ibData[4]  = 2;
                ibData[5]  = 3;
                ibData[6]  = 4;
                ibData[7]  = 5;
                ibData[8]  = 6;
                ibData[9]  = 4;
                ibData[10] = 6;
                ibData[11] = 7;
                ibData[12] = 8;
                ibData[13] = 9;
                ibData[14] = 10;
                ibData[15] = 8;
                ibData[16] = 10;
                ibData[17] = 11;
                ibData[18] = 12;
                ibData[19] = 13;
                ibData[20] = 14;
                ibData[21] = 12;
                ibData[22] = 14;
                ibData[23] = 15;
                ibData[24] = 16;
                ibData[25] = 17;
                ibData[26] = 18;
                ibData[27] = 16;
                ibData[28] = 18;
                ibData[29] = 19;
                ibData[30] = 20;
                ibData[31] = 21;
                ibData[32] = 22;
                ibData[33] = 20;
                ibData[34] = 22;
                ibData[35] = 23;
                ibData[36] = 24;
                ibData[37] = 25;
                ibData[38] = 26;
                ibData[39] = 24;
                ibData[40] = 26;
                ibData[41] = 27;
                ibData[42] = 28;
                ibData[43] = 29;
                ibData[44] = 30;
                ibData[45] = 28;
                ibData[46] = 30;
                ibData[47] = 31;
                ibData[48] = 32;
                ibData[49] = 33;
                ibData[50] = 34;
                ibData[51] = 32;
                ibData[52] = 34;
                ibData[53] = 35;
                if (lh == false)
                {
                    ibData[1]  = 2;
                    ibData[2]  = 1;
                    ibData[4]  = 3;
                    ibData[5]  = 2;
                    ibData[7]  = 6;
                    ibData[8]  = 5;
                    ibData[10] = 7;
                    ibData[11] = 6;
                    ibData[13] = 10;
                    ibData[14] = 9;
                    ibData[16] = 11;
                    ibData[17] = 10;
                    ibData[19] = 14;
                    ibData[20] = 13;
                    ibData[22] = 15;
                    ibData[23] = 14;
                    ibData[25] = 18;
                    ibData[26] = 17;
                    ibData[28] = 19;
                    ibData[29] = 18;
                    ibData[31] = 22;
                    ibData[32] = 21;
                    ibData[34] = 23;
                    ibData[35] = 22;
                    ibData[37] = 26;
                    ibData[38] = 25;
                    ibData[40] = 27;
                    ibData[41] = 26;
                    ibData[43] = 30;
                    ibData[44] = 29;
                    ibData[46] = 31;
                    ibData[47] = 30;
                    ibData[49] = 34;
                    ibData[50] = 33;
                    ibData[52] = 35;
                    ibData[53] = 34;
                }

                var mesh   = result.GeometryMesh;
                var vbDesc = new CVertexBufferDesc();

                var vbTempPos = new Vector3[16];
                var deltaW    = w / 3;
                var deltaH    = h / 3;
                for (int yV = 0; yV < 4; yV++)
                {
                    for (int xV = 0; xV < 4; xV++)
                    {
                        vbTempPos[yV * 4 + xV].SetValue(x + deltaW * xV, y + deltaH * yV, z);
                    }
                }
                var vbPos = new Vector3[36];
                vbPos[0]  = vbTempPos[0];
                vbPos[1]  = vbTempPos[1];
                vbPos[2]  = vbTempPos[5];
                vbPos[3]  = vbTempPos[4];
                vbPos[4]  = vbTempPos[1];
                vbPos[5]  = vbTempPos[2];
                vbPos[6]  = vbTempPos[6];
                vbPos[7]  = vbTempPos[5];
                vbPos[8]  = vbTempPos[2];
                vbPos[9]  = vbTempPos[3];
                vbPos[10] = vbTempPos[7];
                vbPos[11] = vbTempPos[6];
                vbPos[12] = vbTempPos[4];
                vbPos[13] = vbTempPos[5];
                vbPos[14] = vbTempPos[9];
                vbPos[15] = vbTempPos[8];
                vbPos[16] = vbTempPos[5];
                vbPos[17] = vbTempPos[6];
                vbPos[18] = vbTempPos[10];
                vbPos[19] = vbTempPos[9];
                vbPos[20] = vbTempPos[6];
                vbPos[21] = vbTempPos[7];
                vbPos[22] = vbTempPos[11];
                vbPos[23] = vbTempPos[10];
                vbPos[24] = vbTempPos[8];
                vbPos[25] = vbTempPos[9];
                vbPos[26] = vbTempPos[13];
                vbPos[27] = vbTempPos[12];
                vbPos[28] = vbTempPos[9];
                vbPos[29] = vbTempPos[10];
                vbPos[30] = vbTempPos[14];
                vbPos[31] = vbTempPos[13];
                vbPos[32] = vbTempPos[10];
                vbPos[33] = vbTempPos[11];
                vbPos[34] = vbTempPos[15];
                vbPos[35] = vbTempPos[14];
                fixed(Vector3 *pV3 = &vbPos[0])
                {
                    vbDesc.InitData  = (IntPtr)pV3;
                    vbDesc.Stride    = (UInt32)sizeof(Vector3);
                    vbDesc.ByteWidth = (UInt32)sizeof(Vector3) * 36;
                    vbDesc.CPUAccess = (UInt32)ECpuAccess.CAS_WRITE;
                    var vb = rc.CreateVertexBuffer(vbDesc);

                    mesh.BindVertexBuffer(EVertexSteamType.VST_Position, vb);
                }

                var vbTempUV = new Vector2[16];
                var deltaU   = 1.0f / 3;
                var deltaV   = 1.0f / 3;
                for (int yV = 0; yV < 4; yV++)
                {
                    for (int xV = 0; xV < 4; xV++)
                    {
                        if (lh == false && CEngine.Instance.Desc.RHIType == ERHIType.RHT_D3D11)
                        {
                            vbTempUV[yV * 4 + xV].SetValue(deltaU * xV, 1 - deltaV * yV);
                        }
                        else if (flipUVWhenGL && CEngine.Instance.Desc.RHIType == ERHIType.RHT_OGL)
                        {
                            vbTempUV[yV * 4 + xV].SetValue(deltaU * xV, 1 - deltaV * yV);
                        }
                        else
                        {
                            vbTempUV[yV * 4 + xV].SetValue(deltaU * xV, deltaV * yV);
                        }
                    }
                }
                var vbUV = new Vector2[36];
                vbUV[0]  = vbTempUV[0];
                vbUV[1]  = vbTempUV[1];
                vbUV[2]  = vbTempUV[5];
                vbUV[3]  = vbTempUV[4];
                vbUV[4]  = vbTempUV[1];
                vbUV[5]  = vbTempUV[2];
                vbUV[6]  = vbTempUV[6];
                vbUV[7]  = vbTempUV[5];
                vbUV[8]  = vbTempUV[2];
                vbUV[9]  = vbTempUV[3];
                vbUV[10] = vbTempUV[7];
                vbUV[11] = vbTempUV[6];
                vbUV[12] = vbTempUV[4];
                vbUV[13] = vbTempUV[5];
                vbUV[14] = vbTempUV[9];
                vbUV[15] = vbTempUV[8];
                vbUV[16] = vbTempUV[5];
                vbUV[17] = vbTempUV[6];
                vbUV[18] = vbTempUV[10];
                vbUV[19] = vbTempUV[9];
                vbUV[20] = vbTempUV[6];
                vbUV[21] = vbTempUV[7];
                vbUV[22] = vbTempUV[11];
                vbUV[23] = vbTempUV[10];
                vbUV[24] = vbTempUV[8];
                vbUV[25] = vbTempUV[9];
                vbUV[26] = vbTempUV[13];
                vbUV[27] = vbTempUV[12];
                vbUV[28] = vbTempUV[9];
                vbUV[29] = vbTempUV[10];
                vbUV[30] = vbTempUV[14];
                vbUV[31] = vbTempUV[13];
                vbUV[32] = vbTempUV[10];
                vbUV[33] = vbTempUV[11];
                vbUV[34] = vbTempUV[15];
                vbUV[35] = vbTempUV[14];
                fixed(Vector2 *pV2 = &vbUV[0])
                {
                    vbDesc.InitData  = (IntPtr)pV2;
                    vbDesc.Stride    = (UInt32)sizeof(Vector2);
                    vbDesc.ByteWidth = (UInt32)sizeof(Vector2) * 36;
                    vbDesc.CPUAccess = (UInt32)ECpuAccess.CAS_WRITE;
                    var vb = rc.CreateVertexBuffer(vbDesc);

                    mesh.BindVertexBuffer(EVertexSteamType.VST_UV, vb);
                }

                fixed(UInt16 *pV = &ibData[0])
                {
                    var ibDesc = new CIndexBufferDesc();

                    ibDesc.InitData  = (IntPtr)pV;
                    ibDesc.ByteWidth = (UInt32)sizeof(UInt16) * 54;
                    var ib = rc.CreateIndexBuffer(ibDesc);

                    mesh.BindIndexBuffer(ib);
                }

                result.ResourceState.ResourceSize = 20 * 16;
                mesh.Dirty = true;
            }
            result.ResourceState.StreamState = EStreamingState.SS_Valid;
            result.ResourceState.KeepValid   = true;
        }