Exemplo n.º 1
0
        // -------------------------
        // --------- UUID ----------
        // -------------------------

        public static string GenerateUUID()
        {
            MUuid mUuid = new MUuid();

            mUuid.generate();
            return(mUuid.asString());
        }
Exemplo n.º 2
0
        public void Export(string outputDirectory, string outputFileName, string outputFormat, bool generateManifest, bool onlySelected, bool autoSaveMayaFile, bool exportHiddenObjects, bool copyTexturesToOutput)
        {
            RaiseMessage("Exportation started", Color.Blue);
            var progression = 0.0f;

            ReportProgressChanged(progression);

            // Store export options
            _onlySelected        = onlySelected;
            _exportHiddenObjects = exportHiddenObjects;
            isBabylonExported    = outputFormat == "babylon" || outputFormat == "binary babylon";

            // Check directory exists
            if (!Directory.Exists(outputDirectory))
            {
                RaiseError("Exportation stopped: Output folder does not exist");
                ReportProgressChanged(100);
                return;
            }

            var watch = new Stopwatch();

            watch.Start();

            var outputBabylonDirectory = outputDirectory;
            var babylonScene           = new BabylonScene(outputBabylonDirectory);

            // Save scene
            if (autoSaveMayaFile)
            {
                RaiseMessage("Saving Maya file");
                // TODO
                //MFileIO.save();
            }

            // Force output file extension to be babylon
            outputFileName = Path.ChangeExtension(outputFileName, "babylon");

            // Producer
            babylonScene.producer = new BabylonProducer
            {
                name             = "Maya",
                version          = "2018",
                exporter_version = "1.0",
                file             = outputFileName
            };

            // Global
            babylonScene.autoClear = true;
            // TODO - Retreive colors from Maya
            //babylonScene.clearColor = Loader.Core.GetBackGround(0, Tools.Forever).ToArray();
            //babylonScene.ambientColor = Loader.Core.GetAmbient(0, Tools.Forever).ToArray();

            // TODO - Add custom properties
            _exportQuaternionsInsteadOfEulers = true;

            // --------------------
            // ------ Meshes ------
            // --------------------
            RaiseMessage("Exporting meshes");
            // Get all meshes
            var            dagIterator = new MItDag(MItDag.TraversalType.kDepthFirst, MFn.Type.kMesh);
            List <MObject> mObjects    = new List <MObject>();

            while (!dagIterator.isDone)
            {
                var mObject = dagIterator.currentItem();
                mObjects.Add(mObject);
                dagIterator.next();
            }
            // Export all meshes
            var progressionStep = 100.0f / mObjects.Count;

            foreach (MObject mObject in mObjects)
            {
                ExportMesh(mObject, babylonScene);

                // Update progress bar
                progression += progressionStep;
                ReportProgressChanged(progression);
            }
            RaiseMessage(string.Format("Total meshes: {0}", babylonScene.MeshesList.Count), Color.Gray, 1);

            dagIterator = new MItDag(MItDag.TraversalType.kDepthFirst, MFn.Type.kMesh);

            // Switch from right to left handed coordinate system
            MUuid mUuid = new MUuid();

            mUuid.generate();
            var rootNode = new BabylonMesh
            {
                name    = "root",
                id      = mUuid.asString(),
                scaling = new float[] { 1, 1, -1 }
            };

            foreach (var babylonMesh in babylonScene.MeshesList)
            {
                // Add root meshes as child to root node
                if (babylonMesh.parentId == null)
                {
                    babylonMesh.parentId = rootNode.id;
                }
            }
            babylonScene.MeshesList.Add(rootNode);

            // --------------------
            // ----- Materials ----
            // --------------------
            // TODO - Materials

            // Output
            babylonScene.Prepare(false, false);
            if (isBabylonExported)
            {
                Write(babylonScene, outputBabylonDirectory, outputFileName, outputFormat, generateManifest);
            }

            // TODO - Export glTF

            watch.Stop();
            RaiseMessage(string.Format("Exportation done in {0:0.00}s", watch.ElapsedMilliseconds / 1000.0), Color.Blue);
        }