private List <RName> CreateFromFBX(RName name) { var rc = EngineNS.CEngine.Instance.RenderContext; var sa = new AssetImport.FbxImporter(); var assetName = name; var meshesList = new List <RName>(); ImportOption importOption; importOption.SkeletonAssetName = null; sa.Import(assetName, RName.GetRName("Mesh"), importOption, (uint)(AssetImport.aiPostProcessSteps.aiProcess_DontSplitMeshByMaterial | AssetImport.aiPostProcessSteps.aiProcess_GenNormals)); foreach (var meshPri in sa.MeshPrimitives) { var meshName = RName.GetRName("Mesh/" + meshPri.Key + CEngineDesc.MeshExtension); var meshPrimitiveName = meshPri.Value.Name; // 用createMesh 不行 //var mesh = CEngine.Instance.MeshManager.CreateMesh(rc, meshName, CEngine.Instance.ShadingEnvManager.DefaultShadingEnv); var mesh = CEngine.Instance.MeshManager.NewMesh(rc, meshName, meshPrimitiveName); mesh.Init(rc, meshName, meshPri.Value); var mtl = EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstance(rc, RName.GetRName("Material/defaultmaterial.instmtl")); for (int i = 0; i < mesh.MtlMeshArray.Length; ++i) { mesh.SetMaterial(rc, (uint)i, mtl); } mesh.SaveMesh(); meshesList.Add(meshName); } return(meshesList); }
private EngineNS.GamePlay.Actor.GActor CreateActorFBX(RName assetName) { var rc = EngineNS.CEngine.Instance.RenderContext; var sa = new AssetImport.FbxImporter(); //var assetName = RName.GetRName("Mesh/AxisWithAni.FBX"); ImportOption importOption; importOption.SkeletonAssetName = null; sa.Import(assetName, RName.GetRName("Mesh"), importOption, (uint)(AssetImport.aiPostProcessSteps.aiProcess_DontSplitMeshByMaterial)); var meshName = RName.GetRName("Mesh/" + sa.MeshPrimitives.First().Key + ".gms"); var meshPrimitiveName = sa.MeshPrimitives.First().Value.Name; var mesh = CEngine.Instance.MeshManager.NewMesh(rc, meshName, meshPrimitiveName); mesh.Init(rc, meshName, sa.MeshPrimitives.First().Value); var mtl = EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstance(rc, RName.GetRName("Material/defaultmaterial.instmtl")); for (int i = 0; i < mesh.MtlMeshArray.Length; ++i) { mesh.SetMaterial(rc, (uint)i, mtl); } var actor = EngineNS.GamePlay.Actor.GActor.NewMeshActor(mesh); var skinModifier = mesh.MdfQueue.FindModifier <EngineNS.Graphics.Mesh.CGfxSkinModifier>(); var skeletonAnimationNode = sa.Actions.First().Value; //var skeletonAnimationNode = new EngineNS.Graphics.Mesh.Animation.CGfxAnimationSequence(); //skeletonAnimationNode.Init(sklAction); skeletonAnimationNode.AnimationPose = skinModifier.Skeleton.BoneTab; var animationCom = new EngineNS.GamePlay.Component.GAnimationInstance(); animationCom.AnimationNode = skeletonAnimationNode; actor.AddComponent(animationCom); actor.Placement.Location = new Vector3(-1.0f, 0.0f, 0.0f); actor.Placement.Scale /= 10; return(actor); }