コード例 #1
0
        /// <summary>
        ///   This method iterates the Rhino active document and export all Mitsuba material to the XML file.
        /// </summary>
        private void ExportAllMaterials()
        {
            _materialsUsed = new List <string>();

            foreach (var obj in RhinoDoc.ActiveDoc.Objects.GetObjectList(ObjectType.AnyObject))
            {
                if (!obj.Visible)
                {
                    continue;
                }

                var material = obj.RenderMaterial as MitsubaMaterial;

                if (material != null)
                {
                    var isDuplicated = _materialsUsed.Contains(material.GetMaterialId());
                    _mitsubaXml.CreateMaterialXml(material, obj.Id, isDuplicated);
                    _materialsUsed.Add(material.GetMaterialId());
                }
            }
        }
コード例 #2
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Allow to select one of these
            if (RhinoDoc.ActiveDoc.RenderMaterials.Count < 1)
            {
                MessageBox.Show(@"Please, apply at least one material.", @"Mitsuba Render", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(Result.Failure);
            }

            RenderMaterial renderMaterial = null;

            if (RhinoDoc.ActiveDoc.RenderMaterials.Count == 1)
            {
                renderMaterial = RhinoDoc.ActiveDoc.RenderMaterials.First();
            }
            else
            {
                var materialName = RhinoDoc.ActiveDoc.RenderMaterials.Select(material => material.Name).ToList();

                var userSelectedMaterial = Dialogs.ShowComboListBox("Materials", "Select one material", materialName);

                if (userSelectedMaterial != null)
                {
                    foreach (var material in RhinoDoc.ActiveDoc.RenderMaterials.Where(material => material.Name ==
                                                                                      userSelectedMaterial.ToString()))
                    {
                        renderMaterial = material;
                    }
                }
            }

            if (renderMaterial == null)
            {
                return(Result.Failure);
            }

            XmlElement materialXml;
            var        mitsubaMaterial = renderMaterial as MitsubaMaterial;

            // Create the material XML
            if (mitsubaMaterial != null)
            {
                materialXml = MitsubaXml.CreateMaterialXml(mitsubaMaterial);
            }
            else
            {
                MessageBox.Show(@"Please, select a Mitsuba material", @"Mitsuba Render", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(Result.Failure);
            }

            // Create the files in a temp folder
            var tmpFolder = Path.Combine(Path.GetTempPath(), "Mitsuba");

            if (!Directory.Exists(tmpFolder))
            {
                Directory.CreateDirectory(tmpFolder);
            }

            // Copy model
            var modelFileName = Path.Combine(tmpFolder, "matpreview.serialized");

            File.WriteAllBytes(modelFileName, Resources.matpreview);

            // Copy HDRI
            var envFileName = Path.Combine(tmpFolder, "envmap.exr");

            File.WriteAllBytes(envFileName, Resources.envmap);

            // Copy the project
            var projectFileName = Path.Combine(tmpFolder, "mitsubaproject.xml");
            var project         = Resources.mitsubaproject;

            project = project.Replace("[MATERIAL]", materialXml.OuterXml);
            File.WriteAllText(projectFileName, project);

            MitsubaRenderPlugIn.ExecuteMitsuba(projectFileName, tmpFolder);

            return(Result.Success);
        }