protected override void CalculateCPU(Component_Skeleton skeleton, Component_Mesh originalMesh, Component_Mesh modifiableMesh)
        {
            if (EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Simulation)
            {
                if (Component_Scene.All != null && Component_Scene.All.Length > 0)
                {
//					Component_MeshInSpace[] sphs = new Component_MeshInSpace[2];
//					Component_MeshInSpace sph = Component_Scene.All[0]?.GetComponent<Component_MeshInSpace>("chest");
//					sphs[0] = sph?.GetComponent<Component_MeshInSpace>("upper_arm.R");
//					sphs[1] = sphs[0]?.GetComponent<Component_MeshInSpace>("forearm.R");

//					var bones = skeleton?.GetBones(false);
//					if (bones != null)
//					{
//						var sR = Array.Find(bones, item => item.Name == "upper_arm.R");
//						sR.Transform = new Transform(sphs[0].TransformV.Position, sphs[0].TransformV.Rotation, sR.Transform.Value.Scale);
//						var sR1 = Array.Find(bones, item => item.Name == "forearm.R");
//						sR1.Transform = new Transform(sphs[1].TransformV.Position, sphs[1].TransformV.Rotation, sR1.Transform.Value.Scale);

//					}

                    Component_MeshInSpace sph = Component_Scene.All[0]?.GetComponent <Component_MeshInSpace>("chest");
                    var sphch = sph.GetComponents <Component_MeshInSpace>(false, true, false);

                    var bones = skeleton?.GetBones(false);
                    if (bones != null)
                    {
                        var sR = Array.Find(bones, item => item.Name == "chest");
                        sR.Transform = new Transform(sph.TransformV.Position, sph.TransformV.Rotation, sR.Transform.Value.Scale);
                        var chB = sR.GetComponents <Component_SkeletonBone>(false, true, false);

                        for (int i = 0; i < chB.Length; i = i + 1)
                        {
                            var cursph = Array.Find(sphch, item => item.Name == chB[i].Name);
                            if (cursph != null)
                            {
                                chB[i].Transform = new Transform(cursph.TransformV.Position, cursph.TransformV.Rotation, chB[i].Transform.Value.Scale);
                            }
                        }
                    }
                }

                MainViewport_UpdateBeforeOutput(Project.SimulationApp.MainViewport, skeleton);
                base.CalculateCPU(skeleton, originalMesh, modifiableMesh);
            }
        }
        private static void MainViewport_UpdateBeforeOutput(Viewport viewport, Component_Skeleton skeleton)
        {
            if (Component_Scene.All != null && Component_Scene.All.Length > 0)
            {
                var sk = skeleton;

                if (sk != null)
                {
                    var bones = sk?.GetBones(false);
                    if (bones != null)
                    {
                        var renderer = viewport.Simple3DRenderer;
                        renderer.SetColor(new ColorValue(0, 0, 1));

                        var startPosition = new Vector3(0, 0, 0);                        //msh.TransformV.Position;//+ new Vector3(3,0,0);
                        var rootbone      = Array.Find(bones, item => item.Name == "Root");

                        var comps = rootbone?.GetComponents <Component_SkeletonBone>();
                        drawBones(comps, renderer, startPosition, new Vector3(0, 0, 0));
                    }
                }
            }
        }
Exemple #3
0
        static void ImportScene(ImportContext context)
        {
            var settings = context.settings;
            var scene    = context.scene;

            if (context.settings.component.ForceFrontXAxis)
            {
                //Через такой конструктор не получится создать такие же оси как EPreDefinedAxisSystem.eMax - Front Axis имеет обратное направление, а направление задать нельзя.
                //new FbxAxisSystem( FbxAxisSystem.EUpVector.eZAxis, FbxAxisSystem.EFrontVector.eParityOdd, FbxAxisSystem.ECoordSystem.eRightHanded );
                //FromFBX Docs:
                //The enum values ParityEven and ParityOdd denote the first one and the second one of the remain two axes in addition to the up axis.
                //For example if the up axis is X, the remain two axes will be Y And Z, so the ParityEven is Y, and the ParityOdd is Z ;

                //We desire to convert the scene from Y-Up to Z-Up. Using the predefined axis system: Max (UpVector = +Z, FrontVector = -Y, CoordSystem = +X (RightHanded))
                var maxAxisSystem = new FbxAxisSystem(FbxAxisSystem.EPreDefinedAxisSystem.eMax);

                if (!scene.GetGlobalSettings().GetAxisSystem().eq(maxAxisSystem))
                {
                    maxAxisSystem.ConvertScene(scene);                       //No conversion will take place if the scene current axis system is equal to the new one. So condition can be removed.
                }
            }

            //convert units
            if (!scene.GetGlobalSettings().GetSystemUnit().eq(FbxSystemUnit.m))
            {
                FbxSystemUnit.m.ConvertScene(scene);
            }

            //get materials data
            var materialsData = GetMaterialsData(context);

            //create Materials group
            context.materialsGroup = context.settings.component.GetComponent("Materials");
            if (context.materialsGroup == null /*&& materialsData.Count != 0*/ && settings.updateMaterials)
            {
                context.materialsGroup      = context.settings.component.CreateComponent <Component>();
                context.materialsGroup.Name = "Materials";
            }

            //create materials
            foreach (var data in materialsData)
            {
                Component_Material material = null;
                if (context.settings.updateMaterials)
                {
                    material = CreateMaterial(context.materialsGroup, data);
                }
                else
                {
                    if (context.materialsGroup != null)
                    {
                        material = context.materialsGroup.GetComponent(data.Name) as Component_Material;
                    }
                }
                if (material != null)
                {
                    context.materialByIndex.Add(data.Index, material);
                }
            }

            //-------------------------

            var additionalTransform = new Matrix4(settings.component.Rotation.Value.ToMatrix3() * Matrix3.FromScale(settings.component.Scale), settings.component.Position);

            var options = new ImportOptions
            {
                NormalsOptions         = NormalsAndTangentsLoadOptions.FromFileIfPresentOrCalculate,
                TangentsOptions        = NormalsAndTangentsLoadOptions.FromFileIfPresentOrCalculate,
                ImportPostProcessFlags = ImportPostProcessFlags.FixInfacingNormals
            };

            options.ImportPostProcessFlags |= ImportPostProcessFlags.SmoothNormals | ImportPostProcessFlags.SmoothTangents;
            if (context.settings.component.FlipUVs)
            {
                options.ImportPostProcessFlags |= ImportPostProcessFlags.FlipUVs;
            }

            var sceneLoader = new SceneLoader();

            var mode = settings.component.Mode.Value;

            if (mode == Component_Import3D.ModeEnum.Auto)
            {
                mode = Component_Import3D.ModeEnum.OneMesh;
            }

            //create one mesh (OneMesh mode)
            if (mode == Component_Import3D.ModeEnum.OneMesh && settings.updateMeshes)
            {
                sceneLoader.Load(scene, context.manager, options, additionalTransform);
                Component_Skeleton skeletonComponent = CreateSkeletonComponent(context, sceneLoader.Skeleton, out int[] newIndexFromOldIndex, out SkeletonBone[] oldBoneFromNewIndex, additionalTransform);