コード例 #1
0
        public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode)
        {
            // Prepare to export, pass it off
            if (file.fullName.ToUpper().EndsWith(".XMODEL_EXPORT"))
            {
                // Parse settings
                bool   ExportSiegeModel = false;
                string Cosmetic         = string.Empty;

                var SplitSettings = optionsString.Trim().Split(';');
                foreach (var Setting in SplitSettings)
                {
                    if (string.IsNullOrWhiteSpace(Setting))
                    {
                        continue;
                    }

                    var SettingValue = Setting.Split('=');
                    if (SettingValue.Length < 2)
                    {
                        continue;
                    }

                    if (SettingValue[0] == "exportsiege")
                    {
                        ExportSiegeModel = (SettingValue[1] == "1");
                    }
                    else if (SettingValue[0] == "cosmeticroot")
                    {
                        Cosmetic = CODXModel.CleanNodeName((SettingValue[1].Trim()));
                    }
                }

                // Export the model
                CODXModel.ExportXModel(file.fullName, CODXModel.XModelType.Export, ExportSiegeModel, Cosmetic);
            }
        }
コード例 #2
0
        public static void ExportXAnim(string FilePath, XAnimType FileType, bool Grab = true, bool ExportTagAlign = false)
        {
            // Configure scene
            using (var MayaCfg = new MayaSceneConfigure())
            {
                // First, get the current selection
                var ExportObjectList = new MSelectionList();
                MGlobal.getActiveSelectionList(ExportObjectList);

                // If empty, select all joints
                if (ExportObjectList.DependNodes(MFn.Type.kJoint).Count() == 0)
                {
                    // Select all joints
                    MGlobal.executeCommand("string $selected[] = `ls -type joint`; select -r $selected;");
                    // Get it again
                    MGlobal.getActiveSelectionList(ExportObjectList);
                }

                // If still empty, error blank scene
                if (ExportObjectList.DependNodes(MFn.Type.kJoint).Count() == 0)
                {
                    MGlobal.displayError("[CODTools] The current scene has no joints...");
                    return;
                }

                // Progress
                MayaCfg.StartProgress("Exporting XAnim...", ((int)ExportObjectList.length + Math.Max((MayaCfg.SceneEnd - MayaCfg.SceneStart) + 1, 1)));

                // Create new anim
                var Result = new XAnim(System.IO.Path.GetFileNameWithoutExtension(FilePath));

                // Metadata
                var SceneName = string.Empty;
                MGlobal.executeCommand("file -q -sceneName", out SceneName);

                Result.Comments.Add(string.Format("Export filename: '{0}'", FilePath));
                Result.Comments.Add(string.Format("Source filename: '{0}'", SceneName));
                Result.Comments.Add(string.Format("Export time: {0}", DateTime.Now.ToString()));

                // Iterate and add joints
                var UniqueBones      = new HashSet <string>();
                var JointControllers = new List <MFnIkJoint>();

                foreach (var Joint in ExportObjectList.DependNodes(MFn.Type.kJoint))
                {
                    // Step
                    MayaCfg.StepProgress();

                    // Grab the controller
                    var Path       = CODXModel.GetObjectDagPath(Joint);
                    var Controller = new MFnIkJoint(Path);

                    // Create a new bone
                    var TagName = CODXModel.CleanNodeName(Controller.name);

                    if (UniqueBones.Contains(TagName))
                    {
                        continue;
                    }
                    UniqueBones.Add(TagName);

                    // Add to the controller list
                    JointControllers.Add(Controller);

                    // Add to the part list
                    Result.Parts.Add(new Part(TagName));
                }

                // Add TAG_ALIGN
                if (ExportTagAlign)
                {
                    Result.Parts.Add(new Part("TAG_ALIGN"));
                }


                // Iterate over the frame range, then generate part frames
                for (int i = MayaCfg.SceneStart; i < (MayaCfg.SceneEnd + 1); i++)
                {
                    // Step and set time
                    MayaCfg.StepProgress();
                    MayaCfg.SetTime(i);

                    // Iterate over the parts for this time
                    for (int p = 0; p < JointControllers.Count; p++)
                    {
                        // Make new frame
                        var NewFrame = new PartFrame();

                        // Fetch the world-space position and rotation
                        var WorldPosition = JointControllers[p].getTranslation(MSpace.Space.kWorld);

                        var WorldRotation = new MQuaternion(MQuaternion.identity);
                        JointControllers[p].getRotation(WorldRotation, MSpace.Space.kWorld);

                        // Create the matrix
                        NewFrame.Offset         = WorldPosition * (1 / 2.54);
                        NewFrame.RotationMatrix = WorldRotation.asMatrix;

                        // Add it
                        Result.Parts[p].Frames.Add(NewFrame);
                    }

                    // Add TAG_ALIGN
                    if (ExportTagAlign)
                    {
                        var NewFrame = new PartFrame();
                        NewFrame.Offset         = new MVector(0, 0, 0);
                        NewFrame.RotationMatrix = new MMatrix();

                        Result.Parts[JointControllers.Count].Frames.Add(NewFrame);
                    }
                }

                // Reset time
                MayaCfg.SetTime(MayaCfg.SceneStart);

                // Grab XAnim notetracks
                if (Grab)
                {
                    LoadNotetracks(ref Result);
                }

                // Write
                switch (FileType)
                {
                case XAnimType.Export:
                    Result.WriteExport(FilePath);
                    break;

                case XAnimType.Bin:
                    Result.WriteBin(FilePath);
                    break;

                case XAnimType.SiegeAnimSource:
                    Result.WriteSiegeSource(FilePath);
                    break;
                }
            }

            // Log complete
            MGlobal.displayInfo(string.Format("[CODTools] Exported {0}", System.IO.Path.GetFileName(FilePath)));
        }