public CGfxMeshPrimitives CreateMeshPrimitives(CRenderContext rc, UInt32 atom)
        {
            var mesh = new CGfxMeshPrimitives();

            if (false == mesh.Init(rc, RName.GetRName(null), atom))
            {
                return(null);
            }

            return(mesh);
        }
        public CGfxMeshPrimitives NewMeshPrimitives(CRenderContext rc, RName name, UInt32 atom)
        {
            if (name.IsExtension(CEngineDesc.MeshSourceExtension) == false)
            {
                return(null);
            }
            lock (MeshPrimitives)
            {
                CGfxMeshPrimitives mesh;
                if (true == MeshPrimitives.TryGetValue(name, out mesh))
                {
                    return(mesh);
                }
                mesh = new CGfxMeshPrimitives();

                if (false == mesh.Init(rc, name, atom))
                {
                    return(null);
                }

                MeshPrimitives.Add(name, mesh);
                return(mesh.CloneMeshPrimitives());
            }
        }
Beispiel #3
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;
        }